$(window).scroll(function (event) {
	var scroll = $(window).scrollTop();
	console.debug(scroll);
	if (scroll>0) {
		document.getElementById("header").style.top ="0px";
		document.getElementById("banner").style.display ="none";
	}
});

function handlePub() {	
    if ($(document).width() <= 340) {  //iphone 
    		$('#pub1').addClass('pub320');	
    		//$('#pub2').addClass('pub320');	
        $('#pub3').addClass('pub320');	
    		$('#pub1').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 300*250 --><ins class="adsbygoogle" style="display:inline-block;width:300px;height:250px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="9124962796"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
        $('#pub3').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 300*250 bas --><ins class="adsbygoogle" style="display:inline-block;width:300px;height:250px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="8422431190"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
        //$('#pub2').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 300*250 --><ins class="adsbygoogle" style="display:inline-block;width:300px;height:250px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="7398544395"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
    }else if(($(document).width()>340) &&  ($(document).width()<768)) {  //autre tel
				$('#pub1').addClass('pub336');	
				$('#pub3').addClass('pub336');	
    		$('#pub2').addClass('pub320100');	
        $('#pub1').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 336*280 --><ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="1601695991"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
        $('#pub3').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 336*280 bas --><ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="7085298790"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
        $('#pub2').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 320*50 --><ins class="adsbygoogle" style="display:inline-block;width:320px;height:50px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="2355767595"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
		}else if(($(document).width()>=768) &&  ($(document).width()<1010)) {  //ipad
				//$('#pub1').addClass('pub728');	
        $('#pub2').addClass('pub728');	
        $('#pub1').addClass('pub336-2');
        $('#pub4').addClass('pub336-2');
        //$('#pub1').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 728*90 bas --><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="4555162394"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
				$('#pub2').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 728*90 haut --><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="3078429199"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      				
				$('#pub1').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 336 gauche --><ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="6600079998"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
        $('#pub4').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 336 droite --><ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="8076813197"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
            }else{//PC
        $('#pub2').addClass('pub728');	
        $('#pub1').addClass('pub336-2');
        $('#pub4').addClass('pub336-2');
        //$('#pub1').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 728*90 bas --><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="4555162394"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
				$('#pub2').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 728*90 haut --><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="3078429199"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      				
				$('#pub1').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 336 gauche --><ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="6600079998"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
        $('#pub4').html('<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 336 droite --><ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="8076813197"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>');                      
    }
}
var rules = {'a': /[àáâãäå]+/g,	'ae': /[æ]+/g,'c': /[ç]+/g,	'e': /[èéêë]+/g,'i': /[ìíîï]+/g,'n': /[ñ]+/g,'o': /[òóôõö]+/g,'oe': /[?]+/g,'u': /[ùúûü]+/g,'y': /[ýÿ]+/g,' ': /[\'\"]+/g,'': /[\!\<\>]+/g}
function noaccent( s ) {
	s = s.toLowerCase();
	for (var r in rules) s = s.replace(rules[r], r);
	return s;
}
function cherche(){
	if(document.search.q.value=="" || document.search.q.value=="Quelle recette recherchez-vous ?"){
	}else{
		var recherche=document.search.q.value;
		if (recherche.indexOf("recette") > -1) {	   
		document.search.q.value=noaccent(document.search.q.value);
		}else{
		document.search.q.value="Recette "+noaccent(document.search.q.value);
		}
		document.search.qaff.value=noaccent(document.search.q.value);
		document.search.submit();
	}
}
//page recette
var tot=0;
function loadFacebookShareCount(url) {
    $.ajax({
        url: 'https://api.facebook.com/restserver.php?method=links.getStats&urls=' + url,
        jsonp: 'callback',
        dataType: 'jsonp',
        success: function(response) {
            var facebookRegex = new RegExp(/<share_count>(.*)<\/share_count>/);
            var facebookData = facebookRegex.exec(response);
            var facebookShareCount = facebookData[1];
            if (facebookShareCount>1){
	           	if (tot>1){
	           		$('#total-share-count').html(tot);
	           		$('#txt-share-count').css('display','inline');
	           	}
	           	//tot=parseInt(tot)+parseInt(facebookShareCount);
	           	$('#total-share-count').html(tot);
	            $('#facebook-share-count').html('<a target="_blank" class="nodeco" href="https://www.facebook.com/sharer/sharer.php?u='+url+'">Partager  <b style="color: rgba(255, 255, 255, 0.5);">|</b>  ' + facebookShareCount + ' partages</a>');
	          }
        }
    });
}
function loadFacebookShareCountMenu(){
	$.ajax({
        url: 'https://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=408061212701935',
        jsonp: 'callback',
        dataType: 'jsonp',
        success: function(response) {
            var facebookRegex = new RegExp(/<fan_count>(.*)<\/fan_count>/);
            var facebookData = facebookRegex.exec(response);
            var facebookShareCount = facebookData[1];
            if (facebookShareCount>1){	           	
	           	$('#nbfan').html(facebookShareCount);
	           	if ($('#nbfansdesc').length !== 0) {
	           		$('#nbfansdesc').html(facebookShareCount);
	           	}
	           	
	          }
        }
    });
}
function loadTwitterShareCount(url) {
    $.ajax({
        url: 'https://urls.api.twitter.com/1/urls/count.json?url=' + url,
        jsonp: 'callback',
        dataType: 'jsonp',
        success: function(response) {
            var twitterShareCount = response.count;
            if (twitterShareCount>1){
	            if (tot>1){
	           		$('#total-share-count').html(tot);
	           		$('#txt-share-count').css('display','inline');
	           	}
	           	//tot=parseInt(tot)+parseInt(twitterShareCount);
	            $('#total-share-count').html(tot);
	            $('#twitter-share-count').html('<a target="_blank" class="nodeco" href="https://twitter.com/home?status='+url+'">Partager  <b style="color: rgba(255, 255, 255, 0.5);">|</b>  ' + twitterShareCount + ' partages</a>');
	          }
        }
    });
}

function showRecette(typeFav) {
	$('#list').html('');
	var cookieArray = document.cookie.split(/;\s*/);  
	cookieArray.reverse(); 
  var favoriteCount = 0; 
	  for (var i = 0; i < cookieArray.length; i++) {  	
	  	if (cookieArray[i].indexOf(typeFav) === 0) {	    	
	     var note=0;
	      var cookieDataTemp = cookieArray[i].substring(cookieArray[i].indexOf('=') + 1);
	      if(cookieDataTemp!=""){
	      	var tabinfos=cookieDataTemp.split("&");
		      for(j=0;j<tabinfos.length;j++){
		      	infos=tabinfos[j];
		      	info1=infos.substring(0,infos.indexOf('='));
		      	info2=decodeURIComponent(infos.substring(infos.indexOf('=')+1));
		      	switch(info1) {
					    case 'presentation':
					        presentation=info2;
					        break;
					    case 'nbavis':
					        nbavis=info2;
					        break;
					    case 'note':
					        note=info2;
					        break;
					    case 'prep':
					        prep=info2;
					        break;
					    case 'url':
					        url=info2;
					        break;
					    case 'titre':
					        titre=info2;
					        break;
					    default:
					       
						} 
					}
		      if (note!=""){
		      	 favoriteCount++;
				      if (favoriteCount % 2 === 0) {
				        var listItemClass = 'odd';
				      } else {
				        var listItemClass = 'even';
				      }
				      if(favoriteCount===3){
				      	if ($(document).width() <= 340) {  //iphone 
						    		$('#list').append('<div id="pub" class="pub320"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 300x250 --><ins class="adsbygoogle" style="display:inline-block;width:300px;height:250px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="9124962796"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div>');                      
						    }else if(($(document).width()>340) &&  ($(document).width()<768)) {  //autre tel
										$('#list').append('<div id="pub" class="pub336"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 336x280 --><ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="1601695991"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div>');                      
						    }else{  //ipad
										$('#list').append('<div id="pub" class="pub728"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><!-- Recette.com 728x90 haut--><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-0798699095607320" data-ad-slot="3078429199"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div>');                      
  							}
				      }
			      titre=titre.replace(/\+/g," ");
			      prep=prep.replace(/\+/g," ");
			      url=url.replace(/\+/g," ");
			      presentation=presentation.replace(/\+/g," ");
			      note=note.replace(/\+/g," ");
			      nbavis=nbavis.replace(/\+/g," ");
			      var intNote=Math.round(note);
			      var txtnote="";
			     	var txtnbavisR="";
			     	if(parseInt(nbavis)>1){
			     		txtnbavisR=nbavis+" notes";
			     	}else{
			     		txtnbavisR=nbavis+" note";
			     	}
			      var noteDec=Math.round(note*10)/10;
			      for(n=1;n<=intNote;n++){
			      	txtnote=txtnote+'<i class="icon ion-ios7-heart"></i> ';
			      }
			      for(m=1;m<=5-intNote;m++){
			      	txtnote=txtnote+'<i class="icon ion-ios7-heart-outline"></i> ';
			      }
			      var imagePath="http://recette.com/vignette/"+url+".jpg";
						var img = '';
						var http = jQuery.ajax({type:"HEAD",url: imagePath,async: false});
						if(http.status == 200) {
							img = '<img src="http://recette.com/vignette/'+url+'.jpg"/>';
						}
						else {
	    				img = '<img src="http://recette.com/vignette/novignette.png"/>';
						}
						var supfavrecette="";
						if (typeFav==='favRecette'){
							supfavrecette='<i class="icon ion-ios7-trash trash" id="delfav" onclick="addFavorite(\''+titre+'\' ,  \''+url+'\' ,\''+prep+'\', \''+presentation+'\', \''+note+'\', \''+nbavis+'\' );showRecette(\'favRecette\');"></i>';
						}else{
							supfavrecette="";
						}
			      $('#list').append(
			        $('<div>')
			          .addClass('list-item')
			          .addClass(listItemClass)
			          .html('<h2><a href="http://recette.com/'+url+'.htm">'+titre+'</a><span class="very-end"></span>'+supfavrecette+'</h2><div class="photo" onclick="window.location = \'http://recette.com/'+url+'.htm\'">'+img+'<div class="duration"><i class="icon ion-android-clock odd pink"></i> '+prep+'</div></div><div class="avis" onclick="window.location = \'http://recette.com/'+url+'.htm\'"><div class="intro">'+presentation+
			          '</div>'+
			          '<div class="notes-icon" title="Note : '+noteDec+'"><span id="nbnotesA">'+txtnbavisR+' </span>'+txtnote+'</div>'+
			          '<i class="icon ion-arrow-expand dominique-expand"></i></div><br class="clear" /></div>')
			      );	  
			      note="";    
			      titre="";
			    }
		    }
	    }
	  }
	  if(typeFav!=='favRecette'){
	  $('.list-item').each(function() {
	        $(this).click(function() {
	            window.location = $($(this).find('h2 a')[0]).attr('href');
	        });
	    });
	  }
}
function supCookie(url){
	var cookieArray = document.cookie.split(/;\s*/);
  for (var i = 0; i < cookieArray.length; i++) {
  	var namecookie=cookieArray[i];
    if (namecookie.indexOf('favRecette') === 0) {
      if ((decodeURIComponent(namecookie)).indexOf("url="+url+"&")>-1){
      	var thename = namecookie.substring(0,cookieArray[i].indexOf('='));
      	//alert("sup "+thename);
      	document.cookie = thename+"=; path=/";
      	$('#star').css('color','');
				$('#star').mouseout(function() {  		
					    $(this).css('color','');
				});
			}
		}
	}
}
function addFavorite(titre,url,prep,presentation,note,nbavis){
	if(isFavorite(url)){
		supCookie(url);
		alert("La recette "+titre+" a été supprimée de vos favoris");
	}else{
		$.get( "http://recette.com/addFavori.asp?titre="+encodeURIComponent(titre)+"&url="+encodeURIComponent(url)+"&prep="+encodeURIComponent(prep)+"&presentation="+encodeURIComponent(presentation)+"¬e="+encodeURIComponent(note)+"&nbavis="+encodeURIComponent(nbavis) );
		alert("La recette "+titre+" a été ajoutée à vos favoris");
		$('#star').css('color','#e869a5');
		$('#star').mouseout(function() {  		
			    $(this).css('color','#e869a5');
		});
	}
}
function addHistory(titre,url,prep,presentation,note,nbavis){
		$.get( "http://recette.com/addHistory.asp?titre="+encodeURIComponent(titre)+"&url="+encodeURIComponent(url)+"&prep="+encodeURIComponent(prep)+"&presentation="+encodeURIComponent(presentation)+"¬e="+encodeURIComponent(note)+"&nbavis="+encodeURIComponent(nbavis) );
}
function getCookie(name){
  var cookieArray = document.cookie.split(/;\s*/);
  var favoriteCount = 0;
  for (var i = 0; i < cookieArray.length; i++) {
	  	if (cookieArray[i].indexOf(name) === 0) {	    	
	      var cookieDataTemp = cookieArray[i].substring(cookieArray[i].indexOf('=') + 1);
	      return cookieDataTemp;
	    }
	}
}
function isFavorite(url){
	//alert(isfavorite);
 	//var url = window.location.pathname;
 	//var urlF="";
 	url=url.replace("http://http://recette.com/","");
 	//url=url.replace("/","");
 	url=url.replace(".htm","");url=encodeURIComponent(url);
 	var isfavorite=0;
 	//alert("url "+url);
 	numfavrecette=getCookie("numfavrecette");
 	for (n=1;n<=parseInt(numfavrecette);n++){
 		if(isfavorite===0){
   		urlF=getCookie("favRecette"+n);
      //alert(decodeURIComponent(urlF));
	     if((decodeURIComponent(urlF)).indexOf("url="+url+"&")>=0){
	       	isfavorite=1;
	     }else{
	      	isfavorite=0;
	     }
	   }
   }
   
  return isfavorite; 
 }
function addNote(idrecette, note){
	//alert(presentation);
	if(window.XMLHttpRequest) // Firefox 
	   xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject) // Internet Explorer 
	   xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else { // XMLHttpRequest non supporté par le navigateur 
	   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	  return; 
	} 
	document.getElementById("note-label").innerHTML="<span style='color:#e869a5'>Merci!</span>"; 
	xhr_object.open("GET", "http://recette.com/addNote.asp?idrecette="+idrecette+"¬e="+note, false); 
	xhr_object.send(); 
}
var idavisaff=5
function displayAvis(){
		if(idavisaff!=$('.nb_com').text()){		
			for (n=1;n<=5;n++ ){
		  	$("#avis"+(parseInt(n)+parseInt(idavisaff))).fadeIn("slow");
		  }
		  idavisaff=idavisaff+5;
		}
		if(idavisaff>=$('.nb_com').text()){
			$("#butplus").fadeOut("slow");
		}
}
function displayAvisPhotos(){
		if(idavisaff!=$('.nb_com_photo').text()){		
			for (n=1;n<=5;n++ ){
		  	$("#avisphoto"+(parseInt(n)+parseInt(idavisaff))).fadeIn("slow");
		  }
		  idavisaff=idavisaff+5;
		}
		if(idavisaff>=$('.nb_com_photo').text()){
			$("#butplusphoto").fadeOut("slow");
		}
}


function showMenu() {
    $('#menu-expand').css('display', 'none');
    $('#menu-expand i').css('display', 'none');
    $('#menu li').css('display', 'block');
    $('#menu').stop().animate({
        'width': '270px'
    }, 200, function() {
        $('#menu').css('overflow-y', 'scroll');
    });
    if ($('#header').width() !== 1010) {
	    $('.toggle-menu-div').stop().animate({
	        'width': '6px'
	    }, 200, function() {
	    });
	    $('#layer').stop().animate({
	        'width': '100%'
	    }, 0, function() {
	    });
	  }
}

function hideMenu() {
    $('#menu').stop().animate({
        'width': '20px'
    }, 200, function() {
        $('#menu li').css('display', 'none');
        $('#menu-expand').css('display', 'block');
        $('#menu-expand i').css('display', '');
    });
    $('.toggle-menu-div').stop().animate({
        'width': '20px'
    }, 200, function() {
        $('#menu').css('overflow-y', '');
    });
    $('#layer').stop().animate({
        'width': '0'
    }, 0, function() {
    });
}
function toggleMenu() {
    if ($('#menu').css('width') === '270px') {
        hideMenu();
    } else {
        showMenu();
    }
}
function showDescription() {
    $('#description').stop().animate({
        'max-height': '1000px'
    }, 200, function() {
        $('#description-more').removeClass('ion-ios7-plus-outline');
        $('#description-more').addClass('ion-ios7-minus-outline');
    });
}

function hideDescription() {
		//var nbpix=46;
		//if ($('#header').width() !== 1010) {
		//	nbpix=48;
		//}
		nbpix=$('#description').attr('data-original-max-height');
		
    $('#description').stop().animate({
        'max-height': nbpix
    }, 200, function() {
        $('#description-more').removeClass('ion-ios7-minus-outline');
        $('#description-more').addClass('ion-ios7-plus-outline');
    });
}

function toggleDescription() {
    if ($('#description').css('max-height') === '1000px') {
        hideDescription();
    } else {
        showDescription();
    }
}
function showDescriptionR() {
    $('#description-recette').stop().animate({
        'max-height': '1000px'
    }, 200, function() {
        $('#description-more').removeClass('ion-ios7-plus-outline');
        $('#description-more').addClass('ion-ios7-minus-outline');
    });
}

function hideDescriptionR() {
	//var nbpix=42;
	//	if ($('#header').width() !== 1010) {
	//		nbpix=44;
	//	}
	nbpix=$('#description-recette').attr('data-original-max-height');
	//alert(nbpix);
    $('#description-recette').stop().animate({
        'max-height': nbpix
    }, 200, function() {
        $('#description-more').removeClass('ion-ios7-minus-outline');
        $('#description-more').addClass('ion-ios7-plus-outline');
    });
}
function toggleDescriptionR() {
    if ($('#description-recette').css('max-height') === '1000px') {
        hideDescriptionR();
    } else {
        showDescriptionR();
    }
}
function initSwiper() {
    var swipeElement = document.body;
    Hammer(swipeElement).on('dragright swiperight', function(e) {
        showMenu();
    });
    Hammer(swipeElement).on('dragleft swipeleft', function(e) {
        hideMenu();
    });
}

function displayRecette(){
		if(idrecetteaff!=$('.nb_dominique').text()){		
			for (n=1;n<=10;n++ ){
		  	$("#recette"+(parseInt(n)+parseInt(idrecetteaff))).fadeIn("slow");
		  }
		  idrecetteaff=idrecetteaff+10;
		}
		if(idrecetteaff>=$('.nb_dominique').text()){
			$("#butrplus").fadeOut("slow");
		}
}
var idrecetteaff=10

var idclicked=1;
var idclickedV=1;

function init(){
				

	/**$('.photo').each(function() {
	  var old_img = $($(this).find('img')[0]);
	  var img_src = old_img.attr('src');
	  $(this).prepend(
	    $('<div>')
	      .css('background-color', 'transparent')
	      .css('background-image', 'url(' + img_src + ')')
	      .css('background-repeat', 'no-repeat')
	      .css('background-position', '50% 50%')
	      .css('width', '80px')
	      .css('height', '80px')
	      .css('border-radius', '40px')
	      .css('margin-left', '7px')
	  );
	  old_img.remove();
	});*/
	tot=0;
	//alert($(window).width());
	$('#description-recette').attr('data-original-max-height', $('#description-recette').css('max-height'));
	$('#description').attr('data-original-max-height', $('#description').css('max-height'));
	
	   if ($('#header').width() !== 1010) {
	   	initSwiper();
	   	//affichage du menu retractable
	    $('#toggles').click(function() {
	        toggleMenu();
	    });
	    $('#menu').click(function() {
        showMenu();
    	});
    	$('#layer').click(function() {
        hideMenu();
	    });
	    
	   
	    $('#menu li').css('display', 'none');
    	$('#menu').css('width','20px');

    }else{
    	$('#toggles').click(function() {
	        return false;
	    });
	    $('#menu').click(function() {
        return false;
    	});
    	$('#layer').click(function() {
       return false;
	    });
	    $('#menu li').css('display', 'block');
    	$('#menu').css('width','270px');
	  }
	   
		$('#menu li').each(function() {
	        if ($(this).attr('id') !== 'menu-expand') {
	        	if ($($(this).find('a')[0]).attr('target') !== '_blank') {
	            $(this).click(function() {
	            	if(typeof $($(this).find('a')[0]).attr('href') !== 'undefined'){
	                window.location = $($(this).find('a')[0]).attr('href');
	              }
	            });
		        }else{
		        	$(this).click(function() {		        			
		                window.open($($(this).find('a')[0]).attr('href'), '_blank');
		            });
		        }
		      }
	    }); 
	  $('#how a').click(function(e) {
	        e.preventDefault();
	    }); 
    $('.list-item').each(function() {
	        $(this).click(function() {
	            window.location = $($(this).find('h2 a')[0]).attr('href');
	        });
	    });
    $('#description').click(function() {
        toggleDescription();
    });
    $('#description-recette').click(function() {
        toggleDescriptionR();
    });
    $('#tag-rubrique').click(function(event) {
        if ($('#tag-rubrique').css('max-height') === '80px') {
            $('#tag-rubrique-more a').html('-');
            $('tag-rubrique-gradient').css('display', 'none');
            $('#tag-rubrique').stop().animate({
                'max-height': '1500px'
            });
        } else {
            $('#tag-rubrique').stop().animate({
                'max-height': '80px'
            }, function() {
                $('#tag-rubrique-more a').html('+');
                $('#tag-rubrique-gradient').css('display', 'block');
            });
        }
    });
    $(window).scroll(function() {
    	if ($('#header').width() <630) {
        if ($(window).scrollTop() === 0) {
            $('#header-g').css('display', 'none');
            $('#header-share-buttons').css('display', 'none');
            $('#header-logo').css('display', 'inline-block');
        } else {
            $('#header-logo').css('display', 'none');
            $('#header-g').css('display', 'block');
            $('#header-share-buttons').css('display', 'block');
        }
      }
    });
    //page recette
    if ($('#star').length !== 0) {
    	var url = "http://recette.com"+window.location.pathname;
    	//alert(url);
		 	//var url = 'http://recette.com/gateau-aux-fraises-rapide.htm';
	    loadFacebookShareCount(url);
	    //loadTwitterShareCount(url);
	    
     if (isFavorite(url)){
     	$('#star').css('color','#e869a5');
		}else{
     $('#star').mouseout(function() {  		
		    $(this).css('color','');
			});
			$('#star').mouseover(function() {  		
			    $(this).css('color','#e869a5');
			});
		}     
     $('#note i').mouseover(function() {
     		var idnote=$(this).attr('id');
     		var typeF=idnote.substring(0,4);
     		if (typeF=="note"){
	     		idnote=idnote.replace("note-","");
	     		for (n=1;n<=idnote;n++ ){
		        $("#note-"+n).removeClass('ion-ios7-heart-outline');
		        $("#note-"+n).addClass('ion-ios7-heart');
		      }
		    }else if(typeF=="vote"){
	     		idnote=idnote.replace("vote-","");
	     		for (n=1;n<=idnote;n++ ){
		        $("#vote-"+n).removeClass('ion-ios7-heart-outline');
		        $("#vote-"+n).addClass('ion-ios7-heart');
		      }
		    }
		    	
    });
    $('#note i').mouseout(function() {
    	var idnote=$(this).attr('id');
    	var typeF=idnote.substring(0,4);
     	if (typeF=="note"){
        for (n=idclicked;n<=5;n++ ){
     			$("#note-"+n).removeClass('ion-ios7-heart');
        	$("#note-"+n).addClass('ion-ios7-heart-outline');
        }
      }else if(typeF=="vote"){
      	for (n=idclickedV;n<=5;n++ ){
     			$("#vote-"+n).removeClass('ion-ios7-heart');
        	$("#vote-"+n).addClass('ion-ios7-heart-outline');
        }
      }
    });
    $('#note i').click(function() {
    		var idnote=$(this).attr('id');
     		var typeF=idnote.substring(0,4);
     		if (typeF=="note"){
     			idnote=idnote.replace("note-","");
	     		document.formavis.note.value=idnote;
	     		idclicked=parseInt(idnote)+1;
	    		for (n=1;n<=idnote;n++ ){
		        $("#note-"+n).removeClass('ion-ios7-heart-outline');
		        $("#note-"+n).addClass('ion-ios7-heart');
		      }
		      for (n=5;n>idnote;n-- ){
	     			$("#note-"+n).removeClass('ion-ios7-heart');
	        	$("#note-"+n).addClass('ion-ios7-heart-outline');
		      }
		    }else if(typeF=="vote"){
		    	idnote=idnote.replace("vote-","");
	     		document.formnote.vote.value=idnote;
	     		idclickedV=parseInt(idnote)+1;
	    		for (n=1;n<=idnote;n++ ){
		        $("#vote-"+n).removeClass('ion-ios7-heart-outline');
		        $("#vote-"+n).addClass('ion-ios7-heart');
		      }
		      for (n=5;n>idnote;n-- ){
	     			$("#vote-"+n).removeClass('ion-ios7-heart');
	        	$("#vote-"+n).addClass('ion-ios7-heart-outline');
		      }
		      //var xhr_object = null; 
					//document.getElementById("note-label").innerHTML="<span style='color:#e8315d'>Merci!</span>";
					//if(window.XMLHttpRequest) // Firefox 
					//   xhr_object = new XMLHttpRequest(); 
					//else if(window.ActiveXObject) // Internet Explorer 
					//   xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
					//else { // XMLHttpRequest non supporté par le navigateur 
					//   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
					 //  return; 
					//} 
					 
					//xhr_object.open("GET", "<%=urladdavis%>addVote.asp?idcat=<%=idcat%>&idavis=<%=idjeu%>¬e="+i, false); 
					//xhr_object.send(); 
		    }
    });
  }
	/**if ($('.chosen-select').length !== 0) {
		$(".chosen-select").chosen({
		no_results_text: "Il n'y a pas d'ingrédient correspondant", 
		max_selected_options: 4
		});
		$(".chosen-select").bind("chosen:maxselected", function () { alert("Vous pouvez choisir 4 ingrédients maximum!"); }); 
		$(".chosen-select-no").chosen({
		no_results_text: "Il n'y a pas d'ingrédient correspondant", 
		max_selected_options: 2
		});
		$(".chosen-select-no").bind("chosen:maxselected", function () { alert("Vous pouvez choisir 2 ingrédients maximum!"); });
	}*/
	if ($('#ingredient1').length !== 0) {
		$("#ingredient1").select2({ 
  	 	maximumSelectionSize: 4, 
  	 	placeholder: "1 ingrédient minimum"
  	 	});
  	 	$("#ingredientno").select2({ 
  	 	maximumSelectionSize: 2, 
  	 	placeholder: "Sans quel ingrédient?"
  	});
  }
  loadFacebookShareCountMenu();
  handlePub();
}
$(document).ready(function() {	
    init();
});
$(window).bind("orientationchange", function(evt){
	//console.log('orientationchange');
	/*if(window.innerWidth > window.innerHeight){
   	if ($('#header').width() === 1010) {
   	//alert('test '+window.innerWidth);
			$('.toggle-menu-div').css('width', '20px');
	    
	   	showMenu();
	   	$('#toggles').click(function() {
	   		return false;
	    });
	    $('#layer').css('width', '0');
	    $('#header-g').css('display', 'none');
	    $('#header-logo').css('display', 'inline-block');
	    $('#header-share-buttons').css('display', 'inline-block');
	    
	  }
	 }else{
	  	hideMenu();
	 } */
	 if ($('#header').width() === 1010) {
	 	window.location = window.location.href;
	}else{
		//hideMenu();
		//init();
	}
	
  //init();
});


var width = $(window).width();
$(window).resize(function(){
   if($(this).width() != width){
      width = $(this).width();
      init();
   }
});


//$(window).bind('widthChange', function(){
//	alert("changement width");
//        init();
//    });
//$(window).resize(function(){
//	init();
//});