/***************************/
/*  HORIZONTAL MENU SCRIPT */
/*    WRITTEN BY EYEDEA    */
/*        FOR CMS 3        */
/*     Copyright 2010      */
/***************************/

jQuery(document).ready(function(){
	jQuery(".pageMenu").each(function(){
		var type = jQuery("ul:first", jQuery(this)).attr("id");
		jQuery("ul:first", jQuery(this)).children("li").each(function(){
		var over = jQuery("a img", jQuery(this)).attr("over");
		var up = jQuery("a img", jQuery(this)).attr("src");
		var hasimage = (jQuery("a img", jQuery(this)).length == 0 ? false : true);
		var hasul = (jQuery(this).children("ul").length == 0 ? false : true);
		var img = jQuery("a img", jQuery(this));
		jQuery(this).children("a").hover(function(){
			if(hasimage){ jQuery("img", jQuery(this)).attr("src", over); }
			if(hasul){
				tul = jQuery(this).parent().children("ul");
				if(type == 'vertical'){
					tul.css({ 'left' : jQuery(this).width(), 'margin-top' : '-'+jQuery(this).height()+'px'});
				} else {
					tul.css('top', jQuery(this).outerHeight());
				}
				tul.show();
			}
		},function(){
			var on = true;
			var theparent = jQuery(this).parent();
			jQuery("ul:first", jQuery(this).parent()).hover(function(){
				on = false;
				jQuery("li:first ul", jQuery(this)).show();
				jQuery(this).children("li").each(function(){
					jQuery("ul", jQuery(this)).css({ 'left': jQuery(this).width() });
					jQuery(this).mouseover(function(){
						on = false;
						jQuery("ul:first", jQuery(this)).show();
					});
					jQuery(this).mouseout(function(){
						jQuery("ul:first", jQuery(this)).hide();
					});
				});
			}, function(){
				jQuery(this).hide();
				var on = false;
				if(hasimage){ jQuery("img", jQuery(this).parent()).attr("src", up); }
			});
			setTimeout(function(){ if(on && hasul){ theparent.children("ul").hide(); } if(on && hasimage){ img.attr("src", up) } }, 10);
		});
	});
	});
});
