$(document).ready(function(menuderoule, menurenroule, tm, menu2axe, th, h) {

	menu2axe = 1;
	
	$(".menu2, #smenu").bind("mouseover", function() {
		clearTimeout(tm);
		tm = setTimeout(menuderoule, 2);
		th.show();
		$("body").one("mouseover", function() {
			clearTimeout(tm);
			tm = setTimeout(menurenroule, 2);			
		});
		return false;		
	});
	th = $("#smenu");
	h = parseInt(th.height("auto").height());
	th.css({ overflow:"hidden" }).hide().height(0);	
	
	menuderoule = function()
	{
		var act_h = th.height();
		var new_h = act_h + 0.1*(h - act_h);	
		th.height(new_h);		
		if( h - act_h <= 5) {
			th.height(h);
			clearTimeout(tm);
			tm = null;
			return false;
		}	
		tm = setTimeout(menuderoule, 2);	
	}
	
	menurenroule = function()
	{
		var act_h = parseInt(th.height());
		var new_h = act_h - 0.1*(act_h);	
		th.height(new_h);		
		if( act_h <= 5) {
			th.hide();
			//alert("hu");
			clearTimeout(tm);
			tm = null;
			return false;
		}	
		tm = setTimeout(menurenroule, 2);	
	}
	
	
	
	$("#menu ul:first li").bind("mouseover", function() 
	{
		$(this).addClass("over");		
	});
	$("#menu ul:first li").bind("mouseout", function() 
	{
		$(this).removeClass("over");		
	});
	
	$(".shower").bind("click", function() 
	{
		if($(".show").css("display") != "none"){
			$(".show").slideUp(200);
		}
		else{
			$(".show").slideDown(200);
		}
	});	
	
});






$$.addAction(".zoom", function(el) {

	$$.linker({	element : el, after: function(o) {
		o.data = $(o.data);
		$(document.body).append(o.data.css({opacity:0}));	
		o.data.animate({opacity:1}, 200 );		
	}})
})

$$.addAction("#diaporama", function(el) {

	$(".close", el).bind("click", function() { 
		el.animate({opacity:0}, 200, function() {el.remove();});			 
	});
	$(".mini a", el).each( function(i) {
		$(this).bind("click", function(current, selection){
			current = $(".diapo .item.current", el);
			selection = $(".diapo .item", el).eq(i);
			if(current[0] == selection[0]) return false;
			current.animate({ width: "0px" }, function() {
				current.removeClass("current");
			});	
			selection.animate({ width: "800px" }, function() {
				selection.addClass("current");
			});		
		})
	})	
	
		
})
	$$.addAction("#popup", function(el) {

	$(".close", el).bind("click", function() { 
		el.animate({opacity:0}, 600, function() {el.remove();});			 
	});
	
		})



$$.addAction(".palette", function(el, tm, new_x, target, arrow, move) {

	new_x = 0;
	arrow = $("div.arrow",el);
	move = function()
	{
		var dx = (target - new_x);
		new_x += 0.08*dx;	
		arrow.css("margin-left", new_x);		
		if( Math.abs(dx) <= 0) {
			arrow.css("margin-left", target);
			clearTimeout(tm);
			tm = null;
			return false;
		}
		else tm = setTimeout(move, 2);			
	}	

	$("div.text", el).html($("a:first", el).html());
	$("a", el).each(function() {
		this.val = $(this).html();
		$(this).html(" ");
	}).bind("mouseover", function() {
		$("div.text", el).html(this.val);
		target = $(this).offset().left - $(this).parent().offset().left ;
		if(!tm) tm = setTimeout(move, 2);	
	});
})

/*$$.addAction(".trombi", function(el, tm, show) {

	tm = null;
	show = function()
	{		
		$(".return", el).each(function(i, th) {
			
			var dx = (th.originY - th.tx);
			var dy = (th.originX - th.ty);			
			th.tx += 0.13*dx;	
			th.ty += 0.13*dy;
			//$(this).html(this.x)
			$(th).css({left: th.tx+"px", top: th.ty+"px" });
						
			if( Math.abs(Math.round(dx)) <= 0) 
			{				
				$(th).remove();
				//$(th).parent().one("mouseover", select);				
			}
		});	
	
		$(".select", el).each(function(i, th) {
			
			var dx = (10 - th.tx);
			var dy = (160 - th.ty);			
			th.tx += 0.13*dx;	
			th.tx += 0.13*dy;
			$(th).css({left: th.tx+"px", top: th.tx+"px" });
			
			$(".large").html(dx)
						
			if( Math.abs(Math.round(dx)) <= 0) 
			{			
				//$(th).removeClass("select");	
			}
		});	
	
		if($(".box.select", el).length == 0 && $(".box.return", el).length == 0)
		{
			//clearTimeout(tm); 
			//tm=null;
		}
		tm = setTimeout(show);
	}		

	select = function(e) {	
	
		$(".mini", el).css("margin-top", 0);
		$(this).css("margin-top", -72);	
		$(".select", el).removeClass("select").addClass("return");
		
		var clone = $(this).clone(false);
		clone.unbind("mouseover");
		clone.removeClass("mini").addClass("select");
		
		clone[0].originX = $(this).offset().left - el.offset().left;
		clone[0].originY = $(this).offset().top - el.offset().top;
		clone[0].tx = clone[0].originX;
		clone[0].ty = clone[0].originY;
		clone.css({ position:"absolute", left: clone[0].tx+"px", top: clone[0].ty+"px" });
		clone.appendTo(el);		
		
		if(!tm) tm = setTimeout(show);
		return false;
	}
	$(".mini", el).one("mouseover", select);
		
})*/

$$.addAction(".mini img", function(el){
		el.bind("click", function() {
			$(".mini img").removeClass("selected");
			el.addClass("selected");
			$(".large img").attr("src",el.attr("src"));
			$(".large p").html(el.next().html());
			$(".large a").html(el.next().next().html());
			$(".large span").html(el.next().next().next().html());
		})
})
$$.addAction(".large img", function(el){
		el.bind("mouseover", function() {
			$(".large span").show();
		})
		el.bind("mouseout", function() {
			$(".large span").hide();
		})
})



