// JavaScript Document

function getCookie(c_name){
  if (document.cookie.length>0){
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1){ 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}

function setCookie(c_name, value, expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) +
	';path=/';
}

function rollOver(which){ 
	which.src = which.src.replace("_of","_ov");
}

function rollOut(which){ 
	which.src = which.src.replace("_ov","_of");
}

function getY(oElement){
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getX(oElement){
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetLeft;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function close_infolettre_box(){
	document.getElementById("infolettre_iframe_box").style.display = "none";
}

function close_infolettre_over(){
	document.getElementById("infolettre_cancel_button").src = document.getElementById("infolettre_cancel_button").src.replace(/_of/, "_on");
	document.getElementById("infolettre_cancel_text").style.textDecoration = "underline";
}

function close_infolettre_out(){
	document.getElementById("infolettre_cancel_button").src = document.getElementById("infolettre_cancel_button").src.replace(/_on/, "_of");
	document.getElementById("infolettre_cancel_text").style.textDecoration = "none";
}


function checkform(lang)
{
	var doc = document.OptForm;
	if (lang == "fr") {
		if(doc.OFC4_Optin_OptinField_EMail.value == "" || doc.OFC4_Optin_OptinField_EMail.value == "Inscrivez votre courriel"){
			doc.OFC4_Optin_OptinField_EMail.value = "Inscrivez votre courriel";
			doc.OFC4_Optin_OptinField_EMail.style.color = "red";
			return false;
		}	
	}
	if (lang == "en") {
		if(doc.OFC4_Optin_OptinField_EMail.value == "" || doc.OFC4_Optin_OptinField_EMail.value == "Enter your email "){
			doc.OFC4_Optin_OptinField_EMail.value = "Enter your email ";
			doc.OFC4_Optin_OptinField_EMail.style.color = "red";
			return false;
		}
	}
/*	return true;*/
	window.parent.open_infolettre_box(lang,doc.OFC4_Optin_OptinField_EMail.value);
}

function erase(field)
{
	var doc = document.OptForm;
	if(doc.OFC4_Optin_OptinField_EMail.value == "" || doc.OFC4_Optin_OptinField_EMail.value == "Inscrivez votre courriel"){
			field.value = "";
			field.style.color = "#000000";
		}
	}

function open_infolettre_box(lang, email){
	document.getElementById("infolettre_iframe").src = "http://infocourriels.saq.com/Espace_Cocktail/fr/inscription.php?email=" + email;
	if (lang == "en") {
		document.getElementById("infolettre_iframe").src = "http://infocourriels.saq.com/Espace_Cocktail/en/inscription.php?email=" + email;
	}
	document.getElementById("infolettre_iframe_box").style.display = "block";
	document.getElementById("infolettre_iframe_box").style.position = "absolute";
	document.getElementById("infolettre_iframe_box").style.left = getX(document.getElementById("info_lettre")) + "px";
	document.getElementById("infolettre_iframe_box").style.top = (getY(document.getElementById("info_lettre")) - 197)  + "px";
}

function checkKey(lang,e) {
	if (!e) var e = window.event;

	if (e.keyCode) {
		code = e.keyCode;

	} else if (e.which) {
		code = e.which;
	}
	if (code == 13) {
		checkform(lang);
	}
	return false;
}

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
    return sa ? s : s[0];
}
function compare(string, srch){
	var clean_src = new Array('Ã"Ã€ÃÃ‚', 'Ã‹ÃˆÃ‰ÃŠ', 'ÃÃŒÃÃŽ', 'Ã–ÃÃÃ', 'ÃœÃ™ÃšÃ›');
	var clean_dst =  new Array('A', 'E', 'I', 'O', 'U');
	var clean_srch = srch.toUpperCase();
	var clean_string = string.toUpperCase();
	for(var x=0;x<clean_src.length;x++) {
		for(var y=0;y<clean_src[x].length;y++) clean_srch = str_replace(clean_src[x][y], clean_dst[x], clean_srch);
		for(var y=0;y<clean_src[x].length;y++) clean_string = str_replace(clean_src[x][y], clean_dst[x], clean_string);
	}
	return (clean_string.indexOf(clean_srch) > -1);
}
function share_this(){
    if(document.getElementById('share_this').style.display == 'block'){
        document.getElementById('share_this').style.display = 'none';
    }else{
        document.getElementById('share_this').style.display = 'block';
    }
}
function shareIt(which) {
    d = document.location.href;
    d = d.replace("#","");
    title = "espacecocktail.com";
    
    switch (which) {
        case "facebook": {
            shareWin = window.open("http://www.facebook.com/share.php?u=" + d + "&t=" + title);
            break;
        }

        case "Delicious": {
            shareWin = window.open("http://del.icio.us/post?url=" + d + "&title=" + title);
            break;
        }
        
        case "Google": {
            shareWin = window.open("http://www.google.com/bookmarks/mark?op=edit&bkmk=" + d + "&title=" + title);
            break;
        }   
        
        case "MyWeb": {
            //shareWin = window.open("http://www.facebook.com/share.php?u=" + d + "&t=espacecocktail.com");
            break;
        }
        
        case "Digg": {
            shareWin = window.open("http://digg.com/submit?phase=2&url=" + d + "&title=" + title);
            break;
        }
        
        case "Reddit": {
            shareWin = window.open("http://reddit.com/submit?url=" + d  + "&title=" + title);
            break;
        }       

        case "StumbleUpon": {
            shareWin = window.open("http://www.stumbleupon.com/submit?url=" + d +  "&title=" + title);
            break;
        }
    }
}
function swapVidClass(vidNumber) {
  document.getElementById('vid1').style.fontWeight="normal";
  document.getElementById('vid1').style.color="#91908a";
  document.getElementById('vid1').style.textTransform="none";
  
  document.getElementById('vid2').style.fontWeight="normal";
  document.getElementById('vid2').style.color="#91908a";
  document.getElementById('vid2').style.textTransform="none";
  
  document.getElementById('vid3').style.fontWeight="normal";
  document.getElementById('vid3').style.color="#91908a";
  document.getElementById('vid3').style.textTransform="none";
  
  document.getElementById('vid4').style.fontWeight="normal";
  document.getElementById('vid4').style.color="#91908a";
  document.getElementById('vid4').style.textTransform="none";
  
  document.getElementById('vid5').style.fontWeight="normal";
  document.getElementById('vid5').style.color="#91908a";
  document.getElementById('vid5').style.textTransform="none";
  
  document.getElementById('vid6').style.fontWeight="normal";
  document.getElementById('vid6').style.color="#91908a";
  document.getElementById('vid6').style.textTransform="none";
  
  var titleVideo = "vid" + vidNumber;
  document.getElementById(titleVideo).style.fontWeight="bold";
  document.getElementById(titleVideo).style.color="#333333";
  document.getElementById(titleVideo).style.textTransform="uppercase";
}
function getSWF(swfID){
	if(document[swfID]){
		return document[swfID];
	}else if(window[swfID]){
		return window[swfID];
	}else{
		return {};
	}
}
function switchCocktailVersion(which, numOfTabs) {
    // 1 = individuelle, 2 = punch, 3 = sans-alcohol
    indivi_prep = document.getElementById("individuel");
    punch_prep = document.getElementById("punch");
    sans_prep = document.getElementById("sans");
    printImg = document.getElementById("printTitleImg");
    punch_portion = document.getElementById("portion");
    if(document.getElementById("tab1")) {
        btn1 = document.getElementById("tab1");
        ing1 = document.getElementById("ingredient_1");
        etapes1 = document.getElementById("etapes_1");
    }
    
    if(document.getElementById("tab2")) {
        btn2 = document.getElementById("tab2");
        ing2 = document.getElementById("ingredient_2"); 
        etapes2 = document.getElementById("etapes_2");
    }
    
    if(document.getElementById("tab3")) {
        btn3 = document.getElementById("tab3");
        ing3 = document.getElementById("ingredient_3");
        etapes3 = document.getElementById("etapes_3");
    }
    
    switch (which) {
        case 1: 
            if(document.getElementById("tab1")) {
                btn1.src =  base_url + "public/images/" + lang + "/fiche/bt" + numOfTabs + "_ind_on.jpg";
                btn1.style.cursor = "default";
                ing1.style.display="block";
                etapes1.style.display="block";
                indivi_prep.style.display="inline";
                punch_prep.style.display="none";
                sans_prep.style.display="none";             
                printImg.src= base_url + "public/images/" + lang + "/fiche/print_ind.jpg";
                if(punch_portion) {
                    punch_portion.style.display="none"; 
                }
            }
            if(document.getElementById("tab2")) {
                btn2.src = base_url + "public/images/" + lang + "/fiche/bt" + numOfTabs + "_punch_of.jpg";              
                btn2.style.cursor = "pointer";
                ing2.style.display="none";
                etapes2.style.display="none";
                indivi_prep.style.display="inline";
                punch_prep.style.display="none";
                sans_prep.style.display="none";     
                printImg.src= base_url + "public/images/" + lang + "/fiche/print_ind.jpg";
                if(punch_portion) {
                    punch_portion.style.display="none";                 
                }
            }
            if(document.getElementById("tab3")) {
                btn3.src = base_url + "public/images/" + lang + "/fiche/bt" + numOfTabs + "_noalc_of.jpg";
                btn3.style.cursor = "pointer";
                ing3.style.display="none";
                etapes3.style.display="none";
                indivi_prep.style.display="inline";
                punch_prep.style.display="none";
                sans_prep.style.display="none";                 
                printImg.src= base_url + "public/images/" + lang + "/fiche/print_ind.jpg";
                if(punch_portion) {
                    punch_portion.style.display="none"; 
                }
            }
            break;
            
        case 2: 
            if(document.getElementById("tab1")) {
                btn1.src = base_url + "public/images/" + lang + "/fiche/bt" + numOfTabs + "_ind_of.jpg";
                btn1.style.cursor = "pointer";
                ing1.style.display="none";
                etapes1.style.display="none";
                indivi_prep.style.display="none";
                punch_prep.style.display="inline";
                sans_prep.style.display="none";                 
                printImg.src= base_url + "public/images/" + lang + "/fiche/print_punch.jpg";
                if(punch_portion) {
                    punch_portion.style.display="none";     
                }
            }
            if(document.getElementById("tab2")) {
                btn2.src = base_url + "public/images/" + lang + "/fiche/bt" + numOfTabs + "_punch_on.jpg";
                btn2.style.cursor = "default";
                ing2.style.display="block";
                etapes2.style.display="block";
                indivi_prep.style.display="none";
                punch_prep.style.display="inline";
                sans_prep.style.display="none";                 
                printImg.src= base_url + "public/images/" + lang + "/fiche/print_punch.jpg";
                if(punch_portion) {
                    punch_portion.style.display="inline";                   
                }
            }
            if(document.getElementById("tab3")) {
                btn3.src = base_url + "public/images/" + lang + "/fiche/bt" + numOfTabs + "_noalc_of.jpg";
                btn3.style.cursor = "pointer";
                ing3.style.display="none";
                etapes3.style.display="none";
                indivi_prep.style.display="none";
                punch_prep.style.display="inline";
                sans_prep.style.display="none"; 
                printImg.src= base_url + "public/images/" + lang + "/fiche/print_punch.jpg";
                if(punch_portion) {
                    punch_portion.style.display="none"; 
                }
            }
            break;

        case 3: 
            if(document.getElementById("tab1")) {
                btn1.src = base_url + "public/images/" + lang + "/fiche/bt" + numOfTabs + "_ind_of.jpg";
                btn1.style.cursor = "pointer";
                ing1.style.display="none";
                etapes1.style.display="none";
                indivi_prep.style.display="none";
                punch_prep.style.display="none";
                sans_prep.style.display="inline";                   
                printImg.src= base_url + "public/images/" + lang + "/fiche/print_sans.jpg";
                if(punch_portion) {
                    punch_portion.style.display="none"; 
                }
            }
            if(document.getElementById("tab2")) {
                btn2.src = base_url + "public/images/" + lang + "/fiche/bt" + numOfTabs + "_punch_of.jpg";
                btn2.style.cursor = "pointer";
                ing2.style.display="none";
                etapes2.style.display="none";
                indivi_prep.style.display="none";
                punch_prep.style.display="none";
                sans_prep.style.display="inline";               
                printImg.src= base_url + "public/images/" + lang + "/fiche/print_sans.jpg";
                if(punch_portion) {
                    punch_portion.style.display="inline";   
                }
            }
            if(document.getElementById("tab3")) {
                btn3.src = base_url + "public/images/" + lang + "/fiche/bt" + numOfTabs + "_noalc_on.jpg";
                btn3.style.cursor = "default";
                ing3.style.display="block";
                etapes3.style.display="block";
                indivi_prep.style.display="none";
                punch_prep.style.display="none";
                sans_prep.style.display="inline";               
                printImg.src= base_url + "public/images/" + lang + "/fiche/print_sans.jpg";
                if(punch_portion) {
                    punch_portion.style.display="none";                 
                }
            }
            break;
    }
}

var comSearchResults = {
	setType: function(s){
		imgswitch = document.getElementById("my_drink_swap");
		mybackground = imgswitch.style.backgroundImage;
		if (s == 'individuel') {
			mybackground = mybackground.replace("punch", "individuel");
			mybackground = mybackground.replace("sans", "individuel");
		} else if (s == 'punch') {
			mybackground = mybackground.replace("individuel", "punch");
			mybackground = mybackground.replace("sans", "punch");
		} else if (s == 'sans') {
			mybackground = mybackground.replace("individuel", "sans");
			mybackground = mybackground.replace("punch", "sans");
		}
		imgswitch.style.backgroundImage = mybackground;
	}
}

/* Document.ready */
$.noConflict();
jQuery(document).ready(function($) {
	function clickedYes() {
		$('#adult_form').submit();
	}
	
	// Accueil, Age Verification
	$('#age_stain').fadeIn(1000);
	$('#age_glass').fadeIn(1000).animate({"top": "60px"}, 900);
	$('#age_logo').fadeIn(2000);
	
	$('#age_text_oui').delay(1200).fadeIn(800);
	$('#age_text_non').delay(1200).fadeIn(1200);
	$('#age_text_top').delay(1200).fadeIn(400);
	
	$('#age_text_non').click(function() {
		$('#age_texte').fadeOut(600);
		$('#age_sorry').delay(600).fadeIn(600);
	});
	
	$('#age_text_oui').click(function() {
		clickedYes();
	});
	
	
	//Next time use commas and only one declaration, it makes cufon run a lot faster.
	//Ex.: Cufon.replace('.image_flow_title, #cocktail_name, #paginationMenu, etc...');
	
	Cufon.replace('.image_flow_title, #age_text_oui, #age_text_non, #age_text_top, #age_sorry');
	Cufon.replace('#cocktail_name');
	Cufon.replace('#paginationMenu');
	Cufon.replace('#cocktailPageGridbtn, #cocktailPageListbtn', {
		hover: true,
		hoverables: { span: true },
		hover: {
			color: '#666'
		}
	});
	//Cufon.replace('#cocktailPageListbtn');
	Cufon.replace('#cocktailPageFilters');
	Cufon.replace('h2 .cocktail_info');
	Cufon.replace('.stats_puissance');
	Cufon.replace('.stats_saveur');
	Cufon.replace('#cocktail_category');
	Cufon.replace('#alcoholHeader2');
	Cufon.replace('.accueil_header');
	Cufon.replace('.cocktailName');
	Cufon.replace('.searchHeaders');
	Cufon.replace('.drink_name');
	Cufon.replace('#noResultHead');
	Cufon.replace('#noResultTitle');
	Cufon.replace('.cocktailView_list h2');
	
	
	//Menu hover
	$('#menu_content img, #search_go').hover(function(){
		if ( !$(this).hasClass('active') ){
			src = $(this).attr('src').replace("_of","_ov");
			$(this).attr('src', src);
		}
	},function(){
		if ( !$(this).hasClass('active') ){
			src = $(this).attr('src').replace("_ov","_of");
			$(this).attr('src', src);
		}
	});
	
	//News slide in
	$(".bottom_band .textblock").animate({width:"287px"}, { queue:false, duration:300 });
	
	//Search Submit
	$("#search_input_form").submit(function(event){
		sInput = $("#s").attr('value')
		if ( sInput != '' ) {
			sInput = removeAccents(sInput);
			href = $(this).attr('action');
			href = href + escape(sInput.toLowerCase());
			window.location = href;
		}
		event.preventDefault();
	});
	
	//Cocktail
	var urlHash = window.location.hash;
	var urlHash = urlHash.substr(5);

	if(urlHash>0){
		
		var oldHash = '#page'+urlHash;
		var hash = '#page'+urlHash;
		$("#selected_top_"+urlHash).css("color","#000");
		$("#selected_bottom_"+urlHash).css("color","#000");
		console.log(urlHash);
	}
	else{
		var oldHash = '#page1';
		var hash = '#page1';
		var urlHash = 1;
	}
	
	loadInCocktails();
	paginationLimits(urlHash);
	
	$(".cocktailPage").css("display","none");
	$(".wrapper #page"+urlHash).css("display","block");
	
	//Page click
	$("a.pageLink").click(function () { 
		oldHash = hash;
		hash = $(this).attr('href');
		pageNumber = hash.substr(5);
		lastNumber = oldHash.substr(5);
		$("#selected_top_"+pageNumber).css("color","#222");
		$("#selected_top_"+pageNumber).css("text-decoration","none");
		$("#selected_top_"+lastNumber).css("color","#ddd");
		$("#selected_top_"+lastNumber).css("text-decoration","underline");
		$("#selected_bottom_"+pageNumber).css("color","#222");
		$("#selected_bottom_"+pageNumber).css("text-decoration","none");
		$("#selected_bottom_"+lastNumber).css("color","#ddd");
		$("#selected_top_"+lastNumber).css("text-decoration","underline");
		loadOutCocktails();
		paginationLimits(pageNumber);
    });
	
	// Pagination, only show 2 before, 2 after
	function paginationLimits(currentHashInt){
		// Only show 5 pages (.pageLink + #selected_top_1)
		$(".pageLink").each(function(index) {
		
			currentPage =  parseInt(currentHashInt);
			
			if(currentPage<3){
				
				limitPageReach = parseInt(currentPage)+(5-currentPage);
				limitPageBegin = parseInt(currentPage)-2;
				
			}
			else {
				
				limitPageReach = parseInt(currentPage)+2;
				limitPageBegin = parseInt(currentPage)-2;
			
			}
			
			
			$("#selected_top_"+index).fadeIn(100);
			$("#selected_bottom_"+index).fadeIn(100);
			
			if(index>limitPageReach){
				$("#selected_top_"+index).css("display","none");
				$("#selected_bottom_"+index).css("display","none");
			}
			
			if(index<limitPageBegin){
				$("#selected_top_"+index).css("display","none");
				$("#selected_bottom_"+index).css("display","none");
			}
			
		});
		
	}
	
	// Fade In Cocktails
	function loadInCocktails() {
		$(hash+' div.cocktailView').each(function(index) {
			jQuery.easing.def = 'easeOutCubic';
			$(this).children('.cocktailThe').css('bottom','-166px').delay(index*20).animate({bottom: "0px", opacity: "1.0"},{ duration: 900, easing: "swing"} );
			$(this).delay(index*22).animate({bottom: "0px", opacity: "1.0"},{ duration: 900, easing: "swing"} );
		});
	}
	
	// Fade Out Cocktails
	function loadOutCocktails() {
		totalCocktails = $(oldHash+' div.cocktailView').size()
		$(oldHash+' div.cocktailView').each(function(index) {
			jQuery.easing.def = 'easeInCubic';
			$(this).children('.cocktailThe').delay(index*10).animate({bottom: "20px", opacity: "0.0"},{ duration: 300, easing: "swing"} );
			$(this).delay(index*12).animate({opacity: "0.0"},{duration: 300, easing: "swing",complete: 
					function() {
						if (index == (totalCocktails-1)) {
							$(".cocktailPage").css("display","none");
							$(hash).css("display","block");
							loadInCocktails();
						}
					}
				}
			);
		});
	}
	
	// Behaviours
	$(".cocktailView").hover(
		function(){
			jQuery.easing.def = 'easeOutQuad';
			$(this).children(".cocktailOver").animate({"bottom": "0px"},{queue: false, duration: 400, easing: "swing"} );
		}, function(){ 
			jQuery.easing.def = 'easeInSine';
			$(this).children(".cocktailOver").animate({"bottom": "-50px"}, 400);
	});
	
	// Behaviours
	$(".cocktailView").click(function(){
		window.location=$(this).find("a").attr("href"); 
	});
		
	// Search bar form
	$("#more_options").toggle(function(){
		$("#search_options").slideDown();
		$("#search_bar").animate({height: '436px'});
	}, function(){
		$("#search_options").slideUp();
		$("#search_bar").animate({height: '35px'});
	});
	// Search bar form (Homepage)
	$("#more_options_accueil").toggle(function(){
		$("#search_options").slideDown();
		$('#search_bar').animate({marginTop: '179px'});
	}, function(){
		$("#search_options").slideUp();
		$('#search_bar').animate({marginTop: '-2px'});
	});
	// Search bar submit
	$("#search_options .submit").click(function(){
		$('#search_options_form').submit();
	});
	// Search bar reset
	$("#search_options .reset").click(function(){
		$('#search_options .column span').attr('class','option');
		$('#search_options input').attr('value','empty');
	});
	
	//Search bar submenu show
	$(".open_submenu").click(function(e){
		e.stopPropagation();
		showID = $(this).attr('id').replace('open','submenu');
		if ($('#'+showID).is(':hidden')) {
			$('.submenu').fadeOut();
			$('#'+showID).fadeIn();
		} else {
			$('.submenu').fadeOut();
		}
	});
	//Stop propogation on submenu
	$(".submenu").click(function(e){
		e.stopPropagation();
	});
	
	//Submenu bar close
	$(".submenu .close, html").click(function(){
		$('.submenu').fadeOut();
	});
	
	// Search bar checkmarks
	$("#search_options span").click(function(e){
		e.stopPropagation();
		if ( $(this).parent().is('.submenu')){
		//Submenu
			//Set class
			if ( $(this).hasClass('checked') ){
				$(this).attr('class','option');
			} else {
				$(this).attr('class','checked');
			}
			//Find checked elements
			myrels = '';
			$(this).parent().children('span').each(function(index) {
				if ( $(this).hasClass('checked') ){
					myrels += $(this).attr('rel') + '|';
				}
			});
			//Get parent menu element
			menuID = $(this).parent().attr('id').replace('submenu','open');
			//Switch to affect parent menu
			if (myrels == '') {
				//If no submenus are checked, uncheck the parent
				myrels = 'empty|';
				$('#'+menuID).parent().trigger('click');
			} else if ($('#'+menuID).parent().attr('class') != 'checked' ) {
				//If the parent isn't checked yet, check it
				$('#'+menuID).parent().trigger('click');
				$(this).siblings('span').attr('class','option');
			}
			//Set input value
			$(this).parents('.column').find('input').attr('value',myrels.replace(/(\s+)?.$/, ""));
		} else {
		//Main Menu
			//Set submenuID
			if ($(this).children('.open_submenu').length > 0) {
				submenuID = $(this).children('.open_submenu').attr('id').replace('open','submenu');
			} else {
				submenuID = 'not';
			}
			if ( $(this).hasClass('checked') ){
				$(this).attr('class','option');
				$(this).siblings('span').attr('class','option');
				$(this).siblings('.submenu').children('span').attr('class','option');
				$(this).parent('div').find('input').attr('value','empty');
			} else {
				$(this).siblings('span').attr('class','deactivated');
				$(this).attr('class','checked');
				$(this).siblings('.submenu').children('span').attr('class','option');
				$('#'+submenuID).children('span').attr('class','checked');
				id = $(this).attr('rel');
				$(this).parent('div').find('input').attr('value',id);
			}
			//Switch for the submenu hide
			if ($('#'+submenuID).is(':hidden') || (submenuID == 'not')) {
				$('.submenu').fadeOut();
			}
		}
	});
	
	//Carousel
	if ($("#slider").length > 0){
		$("#slider").easySlider({
			prevId: 		'cycleBackward',
			prevText: 		'Previous',
			nextId: 		'cycleForward',	
			nextText: 		'Next',
			controlsShow:		false,
			controlsBefore:	'',
			controlsAfter:		'',	
			controlsFade:		false,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			200,
			auto:			false,
			pause:			2000,
			continuous:		false, 
			numeric: 		false,
			numericId: 		'controls'
		});
	}
	
		// Cocktail Grid Tools
	$("#cocktailPageListbtn").click(function () { 
		$('#cocktailPageGridbtn').removeClass('active');
		$(this).addClass('active');
		Cufon.replace('#cocktailPageGridbtn, #cocktailPageListbtn');
		$(".cocktailView_grid").delay(1000).css("display","none");
		$(".paginationPages").fadeOut(300);
		$(".cocktailView_list").fadeIn(300);
	
	});
	
	
	$("#cocktailPageGridbtn").click(function () { 
		$('#cocktailPageListbtn').removeClass('active');
		$(this).addClass('active');
		Cufon.replace('#cocktailPageGridbtn, #cocktailPageListbtn');
		$(".cocktailView_grid").css("display","block");
		$(".paginationPages").fadeIn(300);
		$(".cocktailView_list").css("display","none");
	});
	
	pagesize = window.screen.width;
	$(document).mousemove(function(e){
		var pageX = e.pageX;
		var pageY = e.pageY;
		if (pageX > (pagesize/2)) {
			$("#cocktailMousePreview").animate({left: pageX-190+"px",top: pageY-40+"px"}, { queue:false, duration:30 });
		} else {
			$("#cocktailMousePreview").animate({left: pageX+30+"px",top: pageY-40+"px"}, { queue:false, duration:30 });
		}
	}); 
   
	$(".cocktailView_list_cocklink").hover(function(){
		var cocktaiImage = $(this).attr('id');
		$("#cocktailMousePreview").show();
		$("#cocktailMousePreview").css("background-image", "url("+cocktaiImage+".png)"); 
	},function(){
		$("#cocktailMousePreview").hide();
	})
	
	
	//Cocktail Fiche
	
	$(".slide_cocktail_bg").css('opacity','0.0');
	$(".backwardImg, .forwardImg").css('opacity','0.3');
	$(".forwardImg").css('marginRight','-5px');
	$(".backwardImg").css('marginLeft','-5px');
	fadeInStain();  // preview_stain
	fadeInDrink();  // preview_drink
	fadeIninfos();  // #cocktail_name
	fadeInSlider(); // img
	
	function fadeInStain() 
	{
		$("div.preview_stain").css('display','none');
		$("div.preview_stain").fadeIn(2000);
	}
	
	function fadeInDrink() 
	{
		$("div.preview_drink").css('opacity','0');
		$("div.preview_drink").animate({"opacity": "1.0", "top": "-100px"}, 600);
	}
	
	function fadeIninfos()
	{
		$("#cocktail_name").css('opacity','0');
		$("#cocktail_category").css('opacity','0');
		$("#cocktail_stats").css('opacity','0');
		$("#cocktail_name").animate({"opacity": "1.0", "margin-right": "0px"}, 400);
		$("#cocktail_category").animate({"opacity": "1.0", "margin-right": "0px"}, 800);
		$("#cocktail_stats").animate({"opacity": "1.0", "margin-right": "0px"}, 1200);
	}
	function fadeInSlider()
	{
		$(".slide_cocktail_box").children("img").each(function(index) {
			$(this).animate({"margin-top": "0px"}, (index/1.5)*100).animate({"opacity": "1.0"}, (index/1.5)*100);
		})
	}
	
	
		// Nav Buttons
	
	$("#cycleForward").hover   (
		function(){
			$(".forwardImg").animate({"opacity": "1.0","margin-right":"0px"}, 300);	
		}, 
		function(){ 
			$(".forwardImg").animate({"opacity": "0.3","margin-right":"-5px"}, 300);
	});
	
	$("#cycleBackward").hover   (
		function(){
			$(".backwardImg").animate({"opacity": "1.0","margin-left":"0px"}, 300);	
		}, 
		function(){ 
			$(".backwardImg").animate({"opacity": "0.3","margin-left":"-5px"}, 300);
	});
	
	
	// Slider
	
	$(".slide_cocktail_box").hover   (
		function(){
			$(this).parent('li').css('width','auto');
			$(this).css('width','140px');
			$(".slide_cocktail_box").stop().css("width","70px");
			$(this).animate({"width": "160px"}, 200);
			$(this).children(".slide_cocktail_bg").css("text-align", "center").animate({"opacity": "1.0","padding-left":"50px"}, 300);
			
		}, function(){ 
			$(this).animate({"width": "70px"}, 400);
			$(this).children(".slide_cocktail_bg").animate({"opacity": "0.0","padding-Left":"60px"}, 100);
	
	});
	
	// Disable search button
	
	if ($("input.search_main_bar").length > 0 ) {
		var searchLenght = $("input.search_main_bar").val().length;
			
		if(searchLenght>0){
			$('.search_main_bar').click(function() {
				
					$("#search_go").attr('disabled', false);
				
			});
		}
	}
	
	//showHalloween();
});

function showHalloween(){
	//Halloweeeeeen
	var halloweenSession=getCookie("halloween");
	if(halloweenSession == undefined || halloweenSession == '') {
		if (document.getElementsByTagName('body')[0].id == "accueil" ){ //here i verify if the cookie is set and add &
			var flashvars = {};
			var params = { };
			var attributes = {   };
			var heightMain;
			var url = basePath + "public/swf/halloween_2011_"+lang+"_date.swf";
			swfobject.embedSWF(url, "flashHalloween", "940", "582", "9", "<?php print base_url(); ?>public/swf/expressInstall.swf", flashvars, params, attributes);
			
			jQuery("#accueil #main_content")[0].style.zIndex = "-1";
			if(lang == "fr"){ heightMain = "265px" } else { heightMain = "285px" }
			jQuery("#accueil #main_content")[0].style.height = heightMain;
			jQuery("#moderation")[0].style.display = "none";
			
			jQuery("#search_bar")[0].style.zIndex = "-1";
			
			setTimeout("closeHalloween();",10500);
		}
	}
}

function closeHalloween(){
	jQuery("#accueil #main_content")[0].style.zIndex = "1";
	jQuery("#accueil #main_content")[0].style.height = "335px";
	jQuery("#search_bar")[0].style.zIndex = "1";
	jQuery("#flashHalloween")[0].style.zIndex = "-1";
	jQuery("#flashHalloween")[0].style.display = "none";
	jQuery("#moderation")[0].style.display = "block";
	
	//here i set the cookie to make it last only one day
	setCookie('halloween', 'true', 1);
}


function removeAccents(strAccents){
    strAccents = strAccents.split('');
    strAccentsOut = new Array();
    strAccentsLen = strAccents.length;
    var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
    var accentsOut = ['A','A','A','A','A','A','a','a','a','a','a','a','O','O','O','O','O','O','O','o','o','o','o','o','o','E','E','E','E','e','e','e','e','e','C','c','D','I','I','I','I','i','i','i','i','U','U','U','U','u','u','u','u','N','n','S','s','Y','y','y','Z','z'];
    for (var y = 0; y < strAccentsLen; y++) {
        if (accents.indexOf(strAccents[y]) != -1) {
            strAccentsOut[y] = accentsOut[accents.indexOf(strAccents[y])];
        }
        else
            strAccentsOut[y] = strAccents[y];
    }
    strAccentsOut = strAccentsOut.join('');
    return strAccentsOut;
}

var YTToggler=false;
function showYT(youtubeID){
	YTToggler=!YTToggler;
	if(YTToggler){
		jQuery("#preview_video").html('<iframe width="520" height="328" src="http://www.youtube.com/embed/'+youtubeID+'?theme=light&color=white&autohide=0&autoplay=1&color1=FFFFFF&color2=FFFFFF&modestbranding=1&border=1&rel=0" frameborder="0" allowfullscreen></iframe>');
		if (lang=='fr') {
			jQuery("#lblYT").html('Fermer la recette en vidéo');
		} else {
			jQuery("#lblYT").html('Hide the video');
		}
	} else {
		setTimeout('jQuery("#preview_video").html("");',1250);
		if (lang=='fr') {
			jQuery("#lblYT").html('Voir la recette en vidéo');
		} else {
			jQuery("#lblYT").html('See the video');
		}
	}
	setTimeout('jQuery("#preview_video").slideToggle(750);',500);
}
