$(document).ready(function() {
	
  // menu a dx
  if ($('#kwickHome').length) {
	$('#kwickHome .kwicks').kwicks({
		min : 20,
		spacing : 0,
		isVertical : true,
		sticky : true,
		defaultKwick: 5
	});
  }


  //toolTips
  if ($('a.jt').length) {	
	$('a.jt').cluetip({
	  local: true, 
	  hideLocal: false,
	  arrows: true, 
	  dropShadow: false, 
	  cluetipClass: 'jtip'
	});
  }
  
  
  // scroller verticale
  if ($('#stdPanel').length) {
	 $('#stdPanel').jScrollPane();
		//$('#pane3').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
	
	// toggle default box
	  $(".defaultRightAngle").click(function()
	  {
		$(".defaultBottomBoxMainP").slideToggle("slow");
	  });
	}
	
	// carico il carrello
	var randNum = Math.floor(Math.random() * 99999999); // w explorer e la sua cazzo di cache
	$("div#cart").load("/carts/ajax_render_cart/" + randNum);
	
	
	// gestione drag & drop
	$(".drag_in_cart").draggable({helper: 'clone'});
	$(".drop_cart").droppable({
		accept: ".drag_in_cart",
		activeClass: 'droppable-active',
		hoverClass: 'droppable-hover',
		tolerance: "touch",
		drop: function(ev, ui) {
			$.post(
					'/carts/add_product/' + $("#select_prodotto_prezzo").val(), 
					{
					},
					function(data) {
						// ricarico i dati del carrello	
						var randNum = Math.floor(Math.random() * 99999999); // w explorer e la sua cazzo di cache
						
						$("div#cart").load("/carts/ajax_render_cart/" + randNum);
						
						// toggle
	    				$("#cart_panel").animate({height: "420px"}, "swing").animate({height: "350px"}, "fast");
	    				$(".cart_panelBtn").toggle();
					});
		}
	});

	
	// toggle cart panel
	$("#cart_closeBtn").click(function(){
		$("#cart_panel").animate({height: "400px"}, "swing").animate({height: "0px"}, "fast");
		$(".cart_panelBtn").toggle();
		return false;
	});
	
	$("#cart_openBtn").click(function(){
		$("#cart_panel").animate({height: "420px"}, "swing").animate({height: "350px"}, "fast");
		$(".cart_panelBtn").toggle();
		return false;
	});
	
	// menu di primo livello
	closetimer = 0;
		if($("#nav")) {
			$("#nav b").mouseover(function() {
			clearTimeout(closetimer);
				if(this.className.indexOf("hover") != -1) {
					$("#nav ul ul ul:visible").slideUp(500);
					$("#nav em").removeClass("hover");
					$("#nav ul ul:visible").slideUp(500);
					$("#nav i").removeClass("hover");
					$(this).parent().next().fadeOut("fast");
					$(this).removeClass("hover");
				}
				else {
					$("#nav b").removeClass();
					$(this).addClass("hover");
					$("#nav ul ul ul:visible").slideUp(500);
					$("#nav em").removeClass("hover");
					$("#nav ul ul:visible").slideUp(500);
					$("#nav i").removeClass("hover");
					$("#nav ul:visible").fadeOut("fast");
					$(this).parent().next().fadeIn("fast");
				}
				return false;
			});

			$("#nav i").mouseover(function() {
			clearTimeout(closetimer);
				if(this.className.indexOf("hover") != -1) {
					$("#nav ul ul ul:visible").slideUp(500);
					$("#nav em").removeClass("hover");
					$(this).parent().next().slideUp(500);
					$(this).removeClass("hover");
				}
				else {
					$("#nav i").removeClass();
					$(this).addClass("hover");
					$("#nav ul ul ul:visible").slideUp(500);
					$("#nav em").removeClass("hover");
					$("#nav ul ul:visible").slideUp(500);
					$(this).parent().next().slideDown(500);
				}
				return false;
			});

			$("#nav em").mouseover(function() {
			clearTimeout(closetimer);
				if(this.className.indexOf("hover") != -1) {
					$(this).parent().next().fadeOut("fast");
					$(this).removeClass("hover");
				}
				else {
					$("#nav em").removeClass();
					$(this).addClass("hover");
					$("#nav ul ul ul:visible").fadeOut("fast");
					$(this).parent().next().fadeIn("fast");
				}
				return false;
			});

			$("#nav").mouseover(function() {
			clearTimeout(closetimer);
			});

			$("#nav").mouseout(function() {
				closetimer = window.setTimeout(function(){
				$("#nav ul ul ul:visible").fadeOut("slow");
				$("#nav em").removeClass("hover");
				$("#nav ul ul:visible").slideUp(500);
				$("#nav i").removeClass("hover");
				}, 2000);
			}); 
		} // end if
});