/* (c) 2011 by Michael Sontag, EPS51 & Jens Buss */

$(window).load(function () {
	
});

$(document).ready(function () {

/* ### **** MOUSE OVER IMG **** ### */

	$(".collection div a, .product a").hover(function() {
		$(this).parent().children("h2").css("visibility", "visible");
		$(this).children("img:first").hide();
		$(this).children("img.hidden").show();
	}, function() {
		$(this).parent().children("h2").css("visibility", "hidden");
		$(this).children("img:first").show();
		$(this).children("img.hidden").hide();
	});

/* ### **** SLIDESHOW **** ### */

	$("div.imgContainer").css("width", $("div.imgContainer .image").find("img").size()*1000);
	
	$(".slideNav a.rightSlideNav").click(function() {
		var pics = $(this).parent().parent().children(".slider").children("div.imgContainer").children(".image").find("img").size();
		var index = $(this).parent().parent().children(".slider").children("div.imgContainer").children(".active").prevAll().length+2;
		if(index <= pics) {
			$(".counter").html(index);
			$(this).parent().parent().children(".slider").children("div.imgContainer").children(".image").removeClass("active");
			$(this).parent().parent().children(".slider").scrollTo( $(this).parent().parent().children(".slider").children("div.imgContainer").children(".image:nth-child("+index+")").addClass("active") , 500);
		} else {
			$(".counter").html("1");
			$(this).parent().parent().children(".slider").children("div.imgContainer").children(".image").removeClass("active");
			$(this).parent().parent().children(".slider").scrollTo( $(this).parent().parent().children(".slider").children("div.imgContainer").children(".image:nth-child(1)").addClass("active") , 500);
		}
	});

	$(".slideNav a.leftSlideNav").click(function() {
		var pics = $(this).parent().parent().children(".slider").children("div.imgContainer").children(".image").find("img").size();
		var index = $(this).parent().parent().children(".slider").children("div.imgContainer").children(".active").prevAll().length;
		if(0 < index) {
			$(".counter").html(index);
			$(this).parent().parent().children(".slider").children("div.imgContainer").children(".image").removeClass("active");
			$(this).parent().parent().children(".slider").scrollTo( $(this).parent().parent().children(".slider").children("div.imgContainer").children(".image:nth-child("+index+")").addClass("active") , 500);
		} else {
			$(".counter").html(pics);
			$(this).parent().parent().children(".slider").children("div.imgContainer").children(".image").removeClass("active");
			$(this).parent().parent().children(".slider").scrollTo( $(this).parent().parent().children(".slider").children("div.imgContainer").children(".image:nth-child("+pics+")").addClass("active") , 500);
		}
	});

/* ### **** ORDER **** ### */

	$(".orderBox").hide();

	$(".orderButton").toggle(function() {
		$(".orderBox").slideDown();
	}, function() {
		$(".orderBox").slideUp();
	});

/* ### **** CURSOR FOR > FF4 **** ### */

	var ua = $.browser;
	if ( ua.mozilla && ua.version.slice(0,3) <= "1.9" ) {
		
		$("#lbNextLink").live('mouseover, mousemove', function(e) {
			$(this).css("cursor", "none");
			$("#follower").html("<span class='right'>&rarr;</span>");
			$("#follower").css({
				top: (e.pageY + 10) + "px",
				left: (e.pageX - 30) + "px"
			});
		}).live("mouseout", function() {
			$("#follower").empty();
		});
		
		$("#lbPrevLink").live('mouseover, mousemove', function(e) {
			$(this).css("cursor", "none");
			$("#follower").html("<span class='left'>&larr;</span>");
			$("#follower").css({
				top: (e.pageY + 10) + "px",
				left: (e.pageX - 30) + "px"
			});
		}).live("mouseout", function() {
			$("#follower").empty();
		});
	};
});
