$(document).ready(function(){
	$("a.more").click(function(){return false;});
	//hide submenu when user hovers outside of it
	$("body *:not(#menu a,ul.submenu,ul.submenu *)").hover(function(){
		$("ul.submenu").css({'display' : 'none'});
		$("#menu a").removeClass("marked");
	});
	$("#menu a").each(function(i,e){
		$(e).hover(function(){
			//assume that the last classname of element points to the right submenu (ul) class
			var classes=$(this).attr("class").split(" ");
			var whichMenu=classes[classes.length-1];
			if($(this).hasClass("more")){
				//compute position for submenu given offset and dimensions of calling element
				var offset=$(this).parent().offset();
				offset.left=($(this).offset()).left;
				var dims=new Object();
				dims.w=$(this).width();
				dims.h=$(this).parent().height();
			}
			$("#menu a:not(."+whichMenu+")").removeClass("marked");
			// stop other menu animations,hide all visible submenus and show the right one 
			if(!$(this).hasClass("marked")){
				$(this).addClass("marked");
				$("ul.submenu").stop(true,true).css({'display' : 'none'});
				if($(this).hasClass("more")){
					$("ul."+whichMenu+".submenu").css({
						'position' : 'absolute',
						'top' : (offset.top+dims.h+1)+'px',
						'left' : (offset.left-1.5)+'px'
					}).slideDown($("ul."+whichMenu+".submenu > li").length*100);
				}
			}
			return false;
		});
	});
	// for ourKittensPanel
	$(".listTextItem").each(function(i,e){
		$(e).hover(function(){
			var thumbId=$(this).attr("id").replace("link","");
			var classes=$(this).attr("class").split(" ");
			var thumbGroup=classes[classes.length-1];
			$(".listTextItem."+thumbGroup).children("a").removeClass("marked");
			$(this).children("a").addClass("marked");
			var thumbIdString=$(this).attr("id").replace("link","thumb");
			var img=new Image();
			$(img).load(function(){
				$(".listImageItem."+thumbGroup).attr({src: img.src,id: img.id}).animate({opacity: 0},"normal","swing",
					function(){$(".listImageItem."+thumbGroup).animate({opacity: 1},"slow","swing");});
			});
			$(".listImageItem."+thumbGroup).animate({opacity: 0},"slow","swing",function(){
				img.src="/img/show/id/"+thumbId+"/w/250";
				img.id=thumbIdString;
			});
			return false;
		});
	});
});
