$(function(){
	/*$('.recetteListe').hide();

	var divLength = $("#content-inner").find('.recetteListe').length;

	var divSelect = 0;

	for ( j=0; j<divLength; j++ ) {
		if ( $("#content-inner").find('.recetteListe').eq(j).attr("name") == "selected") {
			divSelect = j;
		}
	}

	$('.recetteListe').eq(divSelect).show();

	$("#content-inner").find('#recette-prev').eq(0).hide();
	$("#content-inner").find('#recette-next').eq(divLength-1).hide();

	$(".recetteListe").find('#recette-next').click(function(){
		divSelect += 1;
		$('.recetteListe').hide();
		$('.recetteListe').eq(divSelect).show();
	})

	$(".recetteListe").find('#recette-prev').click(function(){
		divSelect -= 1;
		$('.recetteListe').hide();
		$('.recetteListe').eq(divSelect).show();
	})*/
	
	
	/*$('[@name=imprimerIngredient_]').click(function() {

		var idPrint = $(this).parent('p').find("span").attr("id");
		printContent(idPrint,divSelect,1);
	})

	/*$('[@name^=imprimeRecette_]').click(function() {

		var idPrint = $(this).parent("p").parent("div").attr("id");
		printContent(idPrint,divSelect,0);
	})*/

	// si partage recette click
	//$('#partageRecette').hide();
	/*$('#envoi-bnt').mouseover(function() {
		var titre = $('.recetteListe').eq(divSelect).find('h1').html();
		var id = $(".recetteListe").eq(divSelect).attr("id");

		$('#recetteIdAffiche').val(id);
		$('#recetteTitreAffiche').val(titre);

console.log($('#recetteIdAffiche').val());
	})*/
		
	/*$(".recetteListe").find('#envoi-ami').click(function() {

		var titre = $('.recetteListe').eq(divSelect).find('h1').html();
		var id = $(".recetteListe").eq(divSelect).attr("id");

		$(".recetteIdAffiche").val(id);
		$(".recetteTitreAffiche").val(titre);
	})*/


	
	// si invite ami click
	/*$('#envoi-bnt').mouseover(function() {
		var titre = $('.recetteListe').eq(divSelect).find('h1').html();
		var id = $(".recetteListe").eq(divSelect).attr("id");
		var photo = $(".recetteListe").eq(divSelect).find('#visuelImage').attr("name");
		$('#recetteIdShow').val(id);
		$('#recetteTitreShow').val(titre);
		$('#recettePhotoShow').val(photo);
	})*/
	
	// pour l'ajout en favoris
	/*$(".recetteListe").find('#favorisRecette').click(function(){
		//console.log($(this));
		var zListeRecetteId = $(this).attr("name");
		var iRecetteId = $('.recetteListe').eq(divSelect).attr('id');
		if (zListeRecetteId)
		{
			var tListeId = zListeRecetteId.split(',');
		}
		var tListeId = '';
		var titre = $('.recetteListe').eq(divSelect).find('h1').html();
		favoris(iRecetteId, tListeId, titre);
	})*/

})

function printContent(id,divSelect,option){
	var title = '';
	var sous_title = '';
	var str = '';
	if (option == '1')
	{
		var nbrPersonne = $("#"+ id +"").find('#nbrPersonneRecette').html();
		title='<h2>Listes des courses du '+divSelect+'</h2>';
		sous_title = '<h3>'+nbrPersonne+'</h3>';
		var ingredient = '<br />' + $("#"+ id +"").find('#ingredientRecette').html();
		str = title + sous_title + ingredient;
	}
	if (option == '0')
	{
		title = $("#"+ id +"").find('h1').html();
		title = '<h1>'+title+'</h1>';
		var image = $("#"+ id +"").find('#visuelImage').html();
		image = '<div style="float:left;">'+image+'</div>'
		nbrPersonne = $("#"+ id +"").find('#nbrPersonneRecette').html();
		var tempsPreparation = $("#"+ id +"").find('#tempPreparationRecette').html();
		var tempsCuisson = $("#"+ id +"").find('#tempCuissonRecette').html();
		var ingredient = '<strong>Ingredients : </strong>';
		ingredient += '<br />' + $("#"+ id +"").find('#ingredientRecette').html();
		var instruction = '<strong>Instructions : </strong>';
		instruction += '<br />' + $("#"+ id +"").find('#instructionRecette').html();
		var astuce = $("#"+ id +"").find('#astuceRecette').html();
		str = title + image + '<br />' + nbrPersonne + '<br />' + tempsPreparation  + '<br />' + tempsCuisson + '<br />' + ingredient + '<br />' +instruction + '<br />' + astuce;
	}

	//str=document.getElementById(id).innerHTML
	newwin=window.open('','printwin','left=100,top=100,width=400,height=400')
	newwin.document.write('<HTML>\n<HEAD>\n')
	newwin.document.write('<TITLE>Print Page</TITLE>\n')
	newwin.document.write('<script>\n')
	newwin.document.write('function chkstate(){\n')
	newwin.document.write('if(document.readyState=="complete"){\n')
	newwin.document.write('window.close()\n')
	newwin.document.write('}\n')
	newwin.document.write('else{\n')
	newwin.document.write('setTimeout("chkstate()",2000)\n')
	newwin.document.write('}\n')
	newwin.document.write('}\n')
	newwin.document.write('function print_win(){\n')
	newwin.document.write('window.print();\n')
	newwin.document.write('chkstate();\n')
	newwin.document.write('}\n')
	newwin.document.write('<\/script>\n')
	newwin.document.write('</HEAD>\n')
	newwin.document.write('<BODY onload="print_win()">\n')
	newwin.document.write(str)
	newwin.document.write('</BODY>\n')
	newwin.document.write('</HTML>\n')
	newwin.document.close()
}

//function favoris(iRecetteId, tListeId, titre) {
	function favoris(iRang, iTypeRecherche, iTheme, iTypeRepas, iModeCuisson, iTempPreparation, iValeurEnergetique, iNombrePersonne, iCivilite, iMorceau, iLimit, iNext, iPrev, iNbrElement) {
		var titre = $('.recetteListe').find('h1').html();
		var zMotCle = $('#favorisRecette').attr('name');
		//'iRang'=>$next, 'iTypeRecherche'=>$iTypeRecherche, 'zMotCle'=>$zMotCle, 'iTheme'=>$iTheme, 'iTypeRepas'=>$iTypeRepas, 'iModeCuisson'=>$iModeCuisson, 'iTempPreparation'=>$iTempPreparation, 'iValeurEnergetique'=>$iValeurEnergetique, 'iNombrePersonne'=>$iNombrePersonne, 'iCivilite'=>$iCivilite, 'iMorceau'=>$iMorceau, 'iLimit'=>$iLimit, 'iNext'=>0, 'iPrev'=>0, 'iNbrElement'=>$iNbrElement
		//var path = ''+j_pathUrl+j_basepath+'index.php?zListeRecetteId='+tListeId+'&iRecetteId='+iRecetteId+'&module=recette&action=recette:afficheRecette';
		var path = ''+j_pathUrl+j_basepath+'index.php?iRang='+iRang+'&iTypeRecherche='+iTypeRecherche+'&zMotCle='+zMotCle+'&iTheme='+iTheme+'&iTypeRepas='+iTypeRepas+'&iModeCuisson='+iModeCuisson+'&iTempPreparation='+iTempPreparation+'&iValeurEnergetique='+iValeurEnergetique+'&iNombrePersonne='+iNombrePersonne+'&iCivilite='+iCivilite+'&iMorceau='+iMorceau+'&iLimit='+iLimit+'&iNext='+iNext+'&iPrev='+iPrev+'&iNbrElement='+iNbrElement+'&module=recette&action=recette:afficheRecette';
		if ( navigator.appName != 'Microsoft Internet Explorer' ){ 
			window.sidebar.addPanel(titre,path,""); 
		}else { 
			window.external.AddFavorite(path,titre); 
		} 
	}
