$(document).ready(function(){

	var url = ""+window.location;	
	
	if(url == "http://www.ateliercuisine.ch/agenda-des-cours/" || url == "http://www.ateliercuisine.ch/en/agenda-des-cours/"){
		SetCookie("category", 9, 0, "/shop/", "www.ateliercuisine.ch");
	}
	
	if(url == "http://www.ateliercuisine.ch/boutique/" || url == "http://www.ateliercuisine.ch/en/boutique/"){
		SetCookie("category", 1369, 0, "/shop/", "www.ateliercuisine.ch");
	}

	$("#menu > li").hover(
	  function () {
	    $(this).css("background-color","#FFF");
	    $(this).children(".children").fadeIn(200);
	  }, 
	  function () {
	    $(this).css("background-color","transparent");
	    $(this).children(".children").fadeOut(200);
	  }
	);
	
	$('#menu > li').each(function() {
    	children_exist = $(this).children(".children").length;
    	if(children_exist == 1){
    		href_first_child = $(this).children(".children").children("li").eq(0).children("a").attr("href");
    		$(this).children("a").attr("href",href_first_child);
    	}
 	});
 	
	flowplayer("a.myPlayer", "http://www.ateliercuisine.ch/wp-content/themes/AC/flv/flowplayer.commercial-3.2.7.swf", {
		key: '#@dc25bdfe2f852f8a3a6',
		clip: {
			scaling: 'fit'
		},
		canvas: { 
			backgroundGradient: 'none'
		},
		play: { 
			label: null, 
			replayLabel: 'Rejouer'
		}
	}); 		
 		
 	$('#slider').nivoSlider({
        effect:'slideInLeft', // Specify sets like: 'fold,fade,sliceDown'
        slices:15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed:300, // Slide transition speed
        pauseTime:20000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:true, // Next & Prev navigation
        directionNavHide:false, // Only show on hover
        controlNav:true, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav:true, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.9, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded
    });
    
    $('#cf_field_5').change(function() {
		value_champ = $(this).attr("value");
		if(value_champ == "Entreprise"){
			$("#li--6").fadeIn();	
		}else{
			$("#li--6").fadeOut();
		}
	});

	$("#cf_field_1").attr("value", $("#about").html());
	$("#cf2_field_1").attr("value", $("#about").html());
    
});

function get_param() {
  var data = [];
  var param;
  for(x = 0; x < arguments.length; ++x) {
    param = location.href.match(new RegExp("/\?".concat(arguments[x],"=","([^\n&]*)")));
    if (param == null) {
      data.push("");
    } else {
      data.push(param[1]);
    }
  }
  return data;
}

function SetCookie ( name, value, expires, path, domain, secure) {
	szCookie = name + "=" + escape (value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = szCookie;
}

function GetCookie (name) {
	if ( document.cookie) {
	index_cookie = document.cookie.indexOf(name);
	if ( index_cookie != -1) {
	   nDeb = (document.cookie.indexOf( "=", index_cookie) + 1);
	   nFin = document.cookie.indexOf( ";", index_cookie);
	   if (nFin == -1) {nFin = document.cookie.length;}
	   return unescape(document.cookie.substring(nDeb, nFin));
	}
	}
	return null;
}

