$(document).ready(function () {
		
		
		$("#products div.product img").mouseover( function () {
			$(this).css("opacity", 1) ;
			$(this).fadeTo("fast", 0.5) ;
			$(this).fadeTo("fast", 1) ;
			
		});
		
		$("#products div.product").click( function () {
			$("#products").fadeOut();
			//$("#product_panel").fadeIn("normal");
		});
		
		$("#product_panel div.back").click( function () {
			$("#product_panel").fadeOut();
			$("#products").fadeIn("normal");
		});
			
		$("#menu_list li.item").mouseover( function () {
				$(this).addClass("active")
		});
		
		$("#menu_list li.item").mouseout( function () {
				$(this).removeClass("active")
		});
		
		$("#menu_list li.item").click( function () {
				
				window.location = $(this).find("a").attr("href");
		});
		
		var promo_num = $("ul.sshow_numbers li").length;
		
		function nextMachine(num)
		{
			$("img.show_machine").fadeOut();
			var current = $("ul.sshow_numbers li.n"+num);
			current.removeClass("active");
			var arg  = 0;
			if(num<promo_num) arg = num+1;
			else arg = 1;
			
			var current = $("ul.sshow_numbers li.n"+arg).addClass("active");
			
			
			$("div.slideshow_image_"+num).fadeOut( function () {
				
				$("div.slideshow_image_"+arg).fadeIn("normal");
				$("div.slideshow_product_name_"+arg).fadeIn();
			});
			$("div.slideshow_product_name_"+num).fadeOut();
			
			$("img.show_machine").fadeIn();
			
			
			setTimeout(function () {nextMachine(arg)}, 4000) ;
		}
		setTimeout(function () {nextMachine(1)}, 7000) ;
		
		
		$("a.fold").click ( function () {
			$(".foldable").hide();
			$("#"+$(this).attr("title")).show();
			
			$("a.fold").parent().parent().removeClass("fold_active");
			$(this).parent().parent().addClass("fold_active");
		});
		
		$("div.prodmenu_item").mouseover( function () {
			if(!$(this).hasClass("fold_active")) $(this).addClass("mouseover");
		});
		
		$("div.prodmenu_item").mouseout( function () {
			$(this).removeClass("mouseover");
		});
		
		function prodModuleClick(subject)
		{
			subject.unbind('click');
			var link = subject.find("div.link a");
			if(link.attr("href")) window.location = link.attr("href");
			else link.trigger('click');
			subject.click( function () { prodModuleClick(subject); });
		}
		
		$("div.prodmenu_item").click( function () {
			prodModuleClick($(this));
		});
		
		$("#request a.submit").click( function() {
			 var name = $("input[name=name]").val();
			 var email = $("input[name=email]").val();
			
			 if(name == "" || email == "")
			{
				
				$("#form_error").html('Please enter your name and email address.');
			} 
			else
			{
			
			 $.ajax({
   				type: "POST",
   				url: "/products/request_quotation",
   				data: $("form[name=request_quotation]").serialize(),
   				success: function(msg){
					$("#request").html(msg);
   				}

 			});
			}
			
		});
		
		$("a.lightbox").lightBox();

})
