$(document).ready(function() {

	first_children_link = $(".page-item-43 ul > li a").attr("href");
	$(".page-item-43 > a").attr("href",first_children_link)
	
	first_children_link = $(".page-item-41 ul > li a").attr("href");
	$(".page-item-41 > a").attr("href",first_children_link)

	$("#warranty_informations").fancybox({
        'autoScale'     	: true,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'autoDimensions' : false,
		'width' : 600,
		'height' : 600
	});
	
	$("ul.tabs").tabs("div.panes > div");
	
	$(".gallery").eq(0).css("display","block");
	
	$("ul.tabs_2").tabs("div.panes_2 > div");
	
	$("ul.tabs_3").tabs("div.panes_3 > div");
	
	height_content = $("#content").height();
	$("#sidebar").height(height_content+10);
	
	$(".tabs_2 li").click(function() {
  		height_content = $("#content").height();
		$("#sidebar").height(height_content+10);
	});
	
	$(".tabs_3 li").click(function() {
  		height_content = $("#content").height();
		$("#sidebar").height(height_content+10);
	});
	
	$(".tabs li").click(function() {
  		height_content = $("#content").height();
		$("#sidebar").height(height_content+10);
	});
	
	$(".thumbnail_gallery").click(function() {
		height_sidebar = $("#sidebar").height();
		$("#content").height(height_sidebar-10);
  		$(".img_active").removeClass("img_active");
   		id = $(this).attr("id");
  		index = id.replace("index_", "");
  		$("#image_"+index).addClass("img_active");
  		$(".index_active").removeClass("index_active");
  		$(this).addClass("index_active");
	});
	
	$(".tabs_2 li").click(function() {
  		index = $(".tabs_2 li").index(this);
		$(".gallery").each(function() {
    		$(this).css("display","none");
  		});
  		$(".gallery").eq(index).css("display","block");
  		$(".gallery").eq(index).children(".img_product").eq(0).addClass("img_active");
  		height_content = $("#content").height();
		$("#sidebar").height(height_content+10);
		$(".gallery").eq(index).children(".thumbnails").children("a").eq(0).addClass("index_active");
	});
	
	$("a.fancy").fancybox({
		'transitionIn': 'elastic',
		'transitionOut': 'elastic',
		'speedIn':	600, 
		'speedOut': 200
	});
	
	if (window.location.search != "") {
		longueur = window.location.search.length - 1;
		data = window.location.search.substr(1,longueur);
		donnees = data.split("&");
		urlvar = new Array();
		urlvarnum = new Array();
		for (var i=0; i < donnees.length; i++) {
		position = donnees[i].indexOf("=");
		variable = donnees[i].substr(0,position);
		pos = position + 1;
		valeur = decodeURI(donnees[i].substr(pos,donnees[i].length));
		while (valeur.search(/\+/) != -1)
			valeur = valeur.replace(/\+/," ");
			urlvar[variable] = valeur;
			urlvarnum[i] = valeur;
		}
		if(urlvar['message'] == "sent"){
			$("#message_sent").fadeIn("fast");
		}
	} 
	
	$(".button_email").click(function() {
  		$("#message_sent").fadeOut("fast");
	});
	
   	$("#email_form").validationEngine()

	Cufon.replace('#menu li a', { fontFamily: 'Replica-light', hover: true });
	
	var windowHeight
	if (self.innerHeight) {// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}
	
	$("#mail h4").css({'color' : '#000', 'font-size' : '13px', 'font-weight' : 'normal', 'margin-bottom' : '5px', 'margin-top' : '10px', 'text-transform' : 'uppercase'});
	$("#mail ul").css({'list-style-position' : 'outside', 'padding-left' : '22px'});
	$("#mail p").css({'line-height':'150%','margin-bottom':'10px'});
	$("#mail ul").css({'list-style-position' : 'outside', 'padding-left' : '22px', 'margin-bottom': '10px', 'margin-top': '10px'});
	$("#mail h2").css({'margin-bottom' : '10px', 'color' : '#ED1C24', 'font-size' : '13px','font-weight' : 'normal','text-transform' : 'uppercase', 'clear' : 'both'});
	$("#mail .alignleft").css({'float' : 'none'});
	$("#mail h5").css({'margin-bottom' : '5px', 'color' : '#000000', 'font-size' : '12px','font-weight' : 'normal','text-transform' : 'uppercase', 'margin-top' : '10px'});
	$("#mail td img").css({'margin-right' : '0px', 'padding-left' : '0px', 'vertical-align': 'middle'});
	$("#mail table td").css({'vertical-align' : 'top'});

	url = window.location.href;
	url = url.toString(url);
	if(url == "http://www.snowpulse.com/" || url == "http://www.snowpulse.com/fr/" || url == "http://www.snowpulse.com/en/" || url == "http://www.snowpulse.com/nl/" || url == "http://www.snowpulse.com/de/" || url == "http://www.snowpulse.com/fr" || url == "http://www.snowpulse.com/en" || url == "http://www.snowpulse.com/nl" || url == "http://www.snowpulse.com/de" || url == "http://www.snowpulse.ch/fr/" || url == "http://www.snowpulse.ch/en/" || url == "http://www.snowpulse.ch/nl/" || url == "http://www.snowpulse.ch/de/" || url == "http://www.snowpulse.ch/fr/" || url == "http://www.snowpulse.ch/en/" || url == "http://www.snowpulse.ch/nl/" || url == "http://www.snowpulse.ch/de" || url == "http://www.snowpulse.ch/"){
		$(".block_under").each(function() {
    		$(this).css("top",windowHeight-380);
  		});
  	}
	
	$("#qtranslate-chooser li:last-child span").css("border","none");
	
	$(window).resize(function() {
  		var windowHeight
		if (self.innerHeight) {// all except Explorer
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowHeight = document.body.clientHeight;
		}
		url = window.location;
		if(url == "http://www.snowpulse.com/"){
			$(".block_under").each(function() {
    		$(this).css("top",windowHeight-380);
  		});
		}
	});

	style = gcookie("style");
	if(style =="snowmobile"){
		$("#snowmobile_button").html("Ski / Snowboard");
	}else{
		$("#snowmobile_button").html("Snowmobile");	
	}
	
	$(".last").mouseenter(function() {
    	$(this).children(".slide").animate({ 
			height: 150
		}, 500 );
  	}).mouseleave(function(){
  		$(this).children(".slide").stop();
    	$(this).children(".slide").animate({ 
			height: 0
		}, 500 );
  });
  
  	$(".block_under").eq(1).children("table").children("tbody").children("tr").eq(0).mouseenter(function() {
    	 	$(".block_under").eq(1).children(".slide").eq(0).animate({ 
			height: 150
		}, 1000 );
  	}).mouseleave(function(){
  		$(".block_under").eq(1).children(".slide").eq(0).stop();
    	$(".block_under").eq(1).children(".slide").eq(0).animate({ 
			height: 0
		}, 1000 );
  });
  
    $(".block_under").eq(1).children("table").children("tbody").children("tr").eq(1).mouseenter(function() {
    	 	$(".block_under").eq(1).children(".slide").eq(1).animate({ 
			height: 150
		}, 1000 );
  	}).mouseleave(function(){
  		$(".block_under").eq(1).children(".slide").eq(1).stop();
    	$(".block_under").eq(1).children(".slide").eq(1).animate({ 
			height: 0
		}, 1000 );
  });
  
    $(".block_under").eq(1).children("table").children("tbody").children("tr").eq(2).mouseenter(function() {
    	 	$(".block_under").eq(1).children(".slide").eq(2).animate({ 
			height: 150
		}, 1000 );
  	}).mouseleave(function(){
  		$(".block_under").eq(1).children(".slide").eq(2).stop();
    	$(".block_under").eq(1).children(".slide").eq(2).animate({ 
			height: 0
		}, 1000 );
  });
	
/*
	setTimeout(function(){
		$("#first_block_home_vertical").fadeIn("slow");
	}, 1000)
*/

});

function changeStyle(){
	cookie_style = gcookie("style");
	if(cookie_style == "normal"){
		scookie("style","snowmobile",7);
		location.reload();
	}else{
		scookie("style","normal",7);
		location.reload();
	}
}

function gcookie(name){
	if(document.cookie.length>0){
        start=document.cookie.indexOf(name+"=");
        pos = start+name.length+1;
        if(start!=0){
                start=document.cookie.indexOf("; "+name+"=");
                pos = start+name.length+3;
        }
        if(start!=-1){
            start=pos;
            end=document.cookie.indexOf(";",start);
            if(end==-1){
            	end=document.cookie.length;
            }
            return unescape(document.cookie.substring(start,end));
        }
	}
	return '';
}

function scookie(name,value,days){
	var expire=new Date();
	expire.setDate(expire.getDate()+days);
	document.cookie=name+'='+escape(value)+';expires='+expire.toGMTString();
	return true;
}


