$(document).ready(function(){
	var big = $("#item_big_image");
	$(".small_photo_link").click(function(e){		e.preventDefault();		var route = $(this).attr("rel");
		$("#big_img_link").attr("href",route);
		big.attr("src",$(this).children("img").attr("src").replace(/small/g,'middle'));	});

	$(".prev").click(function(e){e.preventDefault();});
	$(".next").click(function(e){e.preventDefault();});

	$(".box_gallery_img").hover(function(){		var h = 90;
		$(this).children(".shadow_black").show();
		var h_child = $(this).children().find("span").height();

		$(this).children().find("span").css("padding-top",(h/2 - h_child/2) + "px");	},function(){		$(this).children(".shadow_black").hide();	});

	$(".compare_check").click(function(){		if ($(this).attr("checked")){			//alert('i am checked');
			$(this).parent().parent().parent().parent().parent().css("background-color","#cccccc");
		}else{			//alert('i am not checked');
			$(this).parent().parent().parent().parent().parent().css("background-color","transparent");
		}	});

	if ($(".compare_check").length){		$(".compare_check").each(function(){			if ($(this).attr("checked")){				$(this).parent().parent().parent().parent().parent().css("background-color","#cccccc");			}		});
	}

	$("#submit_compare").click(function(){		if ($(".compare_check:checked").length == 0){			alert('Вы не выбрали товары для сравнения!');			return false;
		}	});

	$(".del_compared").click(function(e){		e.preventDefault();		var id = $(this).parent().children("#current").val();
		$("#item"+id).css("background-color","#F00000");
		$("#item"+id).fadeOut();	});

	$("#click_compare").click(function(){window.location="/compare/";});
	$("#click_calculate").click(function(){window.location="/calculate/";});

	$(".detailed_compare").click(function(e){		e.preventDefault();
		if ($(this).parent().children(".detailed_hidden").css("display") == 'none'){			$(this).parent().children(".detailed_hidden").slideDown("slow");
		}else{			$(this).parent().children(".detailed_hidden").slideUp("slow");
		}	});

	$(".detailed_close").click(function(e){		e.preventDefault();		$(this).parent().parent().slideUp("slow");	});

	$(".csel").click(function(){		if ($("#s6:checked").length){			$(this).parent().children("div").show();
		}else{			$(this).parent().children("div").hide();
		}	});

	$("#cvid1").hover(function(){$("#vid1_div").show();},function(){$("#vid1_div").hide();});
	$("#cvid2").hover(function(){$("#vid2_div").show();},function(){$("#vid2_div").hide();});
	$("#cvid3").hover(function(){$("#vid3_div").show();},function(){$("#vid3_div").hide();});
	$("#cvid4").hover(function(){$("#vid4_div").show();},function(){$("#vid4_div").hide();});
});

function preloadimages(){
	for(var i = 0; i<arguments.length; i++){
		$("<img>").attr("src", arguments[i]);
	}
}

$(function(){
	//Get our elements for faster access and set overlay width
	var div = $('div.gallery-holder'),
		ul = $('ul.gallery-ul'),
		ulPadding = 15;

	//Get menu width
	var divWidth = div.width();

	//Remove scrollbars
	div.css({overflow: 'hidden'});

	//Find last image container
	var lastLi = ul.find('li:last-child');

	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});

$(function(){
	//Get our elements for faster access and set overlay width
	var div = $('div.gallery-holder_main'),
		ul = $('ul.gallery-ul_main'),
		ulPadding = 15;

	//Get menu width
	var divWidth = div.width();

	//Remove scrollbars
	div.css({overflow: 'hidden'});

	//Find last image container
	var lastLi = ul.find('li:last-child');

	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});
