$(document).ready(function(){
	$(".header ul li:first, .footer ul li:first, .footer ul.second li:first").addClass("first");
	
	$(".left-column div.entry:first").addClass("top");
	
	$("p + h2").addClass("double");
	
	var before_select = $(".productgroup-bar ul li").index($(".productgroup-bar ul li.current_page_item"));

	$(".productgroup-bar ul li:eq("+(before_select-1)+")").addClass("before-select");
	
	var before_select_p = $(".productgroup-bar ul li").index($(".productgroup-bar ul li.current_page_parent"));

	$(".productgroup-bar ul li:eq("+(before_select_p-1)+")").addClass("before-select");
	
	$("#page_id option:first").before("<option class=\"level-s\" value=\"\">Product Finder</option>");
	
	var test = $("#page_id").clone();
	
	$("#page_id").replaceWith(test);
	
	$("#page_id").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).text() + " ";
              });
          if (str == "") {
					  
		  } else {
			  $("#productfinder").submit();
		  }
        });

	
});						  

$(document).ready(function(){
	var slideshow_pos = 1;
	var slideshow_ctr = Math.ceil($(".product").length / 5);
    if (slideshow_ctr == 1) {
		$(".reflection-nav").hide();	
	}
	var active = false;
	setText();
	$(".back").click(function() {
		/*$(document).stopTime();
		$(document).everyTime(10000, function () {forw();});*/
		backw();
	});
	
	$(".next").click(function() {
		/*$(document).stopTime();
		$(document).everyTime(10000, function () {forw();});*/
		forw();	
	});
	
	function forw() {
		if (!active) {
			active = true;		
			if (slideshow_pos >= slideshow_ctr) {
				slideshow_pos = 1;	
			} else {
				slideshow_pos++;
			}
			animation();
		}
	}
	
	function backw() {
		if (!active) {
			active = true;
			if (slideshow_pos > 1) {
				slideshow_pos--;	
			} else {
				slideshow_pos = slideshow_ctr;
			}
			animation();
		}
	}
	
	function setText() {
		var slideshow_pos_str = slideshow_pos;
		var slideshow_ctr_str = slideshow_ctr; 
		
		if (slideshow_ctr_str < 9) {
			slideshow_ctr_str = "0"+slideshow_ctr_str
		}
		
		if (slideshow_pos_str < 9) {
			slideshow_pos_str = "0"+slideshow_pos_str
		}
		
		$(".pages").text("Page "+slideshow_pos_str+" / "+slideshow_ctr_str);
	}
		
	function animation() {
			$(".panel").animate( { left: -((slideshow_pos-1) * 925) + "px"}, 1500, function () {setText();active = false;} );
	}
	
	/*$(document).everyTime(5000,						   
		function () { 		
			forw();		
		}
	);*/
	
});

$(document).ready(function(){
						   
	var to_show_index = 0;
	var images_count = $(".slideshow").find("img").length;
	
	$(".slideshow").each(function (i) {
		$(this).find("img").hide();
		$(this).find("img:first").show();	
	});	
	
	
	$(document).everyTime(7000,						   
		function () { 		
			to_show_index++;
			if (!(to_show_index < images_count)) {
				to_show_index = 0;
			}
				
			var to_show = $(".slideshow").find("img:eq("+ to_show_index +")");
			var to_hide = $(".slideshow").find("img:visible");
			if (images_count > 1) {
                 		$(to_hide).fadeOut(2000, function () { $(to_show).fadeIn(2000); });
		    }			
		}
	);			
	
});

$(document).ready(function(){
						   
	var to_show_index_start = 0;
	var images_count_start = $(".slideshow-start").find("img").length;
	
	$(".slideshow-start").each(function (i) {
		$(this).find("img").hide();
		$(this).find("img:first").show();	
	});	
	
	
	$(document).everyTime(5000, 					   
		function () { 		
			to_show_index_start++;
			if (!(to_show_index_start < images_count_start)) {
				to_show_index_start = 0;
			}
				
			var to_show_start = $(".slideshow-start").find("img:eq("+ to_show_index_start +")");
			var to_hide_start = $(".slideshow-start").find("img:visible");
			if (images_count_start > 1) {
            	$(to_hide_start).fadeOut(2000, function () { $(to_show_start).fadeIn(2000)});
            }			
		}
	);			
	
});