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

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