/************************************************
* Role:ce fichier contient les scripts pour la gestion des onglets
* Principe:
- le contenu des onglets sont dans des <DIV> distincts, initialement, le DIV est caché
- les onglets sont dans des <DIV>, un clic dessus affiche le contenu correspondant
- un cookie metro_panel est utilisé pour sauvegarder le idx de l'onglet courant (1,2,3 etc..)
- à la fin de la page, l'onglet courant ds le cookie est affiché
* Convention:
* ID des onglets panelTab_1, panelTab2 etc....
* ID des contenus des onglets panel_1, panel_2 etc...
*************************************************/
var cookieActivePanel=null;//var globale cookie qui garde l'index de l'onglet courant
cookieActivePanel = new Cookie(document, "metro_panel", null, "/");//créer le cookie, valide pour tout le site et expire à la fermeture du browser
/*
*Role:Affiche l'onglet No id, appelé les le onClick des onglets
*Traitement:parcourt les onglets disponibles et affiche le No id et sauvegarde ds le cookie
id: No de l'onglet à afficher
nbPanel: Nombre total des onglets ds la page
*/
function showPanel(id, nbPanel){

document.getElementById("content").style.height = '';
document.getElementById("gauche").style.height = '';

	for (var i=1;i<=nbPanel;i++)
		if (i == id){
			document.getElementById("panelTab_" + i).className = "panelSelected";
			document.getElementById("panel_" + i).className = "visible";
		}else{
			document.getElementById("panelTab_" + i).className = "panelNormal";
			document.getElementById("panel_" + i).className = "hidden";
		}
	cookieActivePanel.number = id;
	cookieActivePanel.store();//mettre à jour le cookie et sauvegarder

    var pageCurrent = window.location.href;
    /*
	 *Date:2008-01-11
	 *DDC 51:on n'affiche pas la grosse photo sur l'onglet Recherche quand une categorie est affichee
	 */
    if (pageCurrent.indexOf("/recettes.html")!= -1 || pageCurrent.indexOf("/recipes.html") != -1){
 	   gererMainPhoto(id, pageCurrent);	
    }	

	}	


/* *********************************************
Date: 2008-12-4
function that recalculates the height of 
the page after a tab is clicked in the 
main page of recipes 

********************************************* */
function  recalculateHeight(theID){
	fixColumns();
}





	function gererMainPhoto(panelId, currentUrl){
	 photo = document.getElementById("recipeIndexPhoto");
	 if (photo == null)//Pas de photo
	 	return;
		switch (panelId){
		case 1:
					if (currentUrl.indexOf("/recettes.html")!= -1 || currentUrl.indexOf("/recipes.html") != -1){
						photo.style.display="block";
					}else{
						photo.style.display="block";
					}
					break;
		case 2:
					photo.style.display="block";
					break;
		case 3:
					/*
					*Date:2008-01-11
					*Billet No41:on n'affiche pas la grosse photo sur l'onglet Recherche pour gagner de l'espace
					*/
					photo.style.display="block";
					break;
		}
	}
		
/*
*Role:Affiche initialement l'onglet courant; appelée au chargement de la page
*Traitement:affiche l'onglet preservé ds le cookie
nbPanel: Nombre total des onglets ds la page
*/	
function setCookiePanel(nbPanel){
cookieActivePanel.load();
if (!cookieActivePanel.number){
	cookieActivePanel.number = 1;
	cookieActivePanel.store();
}
showPanel(cookieActivePanel.number, nbPanel);
var pageCurrent = window.location.href;
if (pageCurrent.indexOf("/recettes.html") != -1 || pageCurrent.indexOf("/recipes.html") != -1){
	id = cookieActivePanel.number;
	gererMainPhoto(parseInt(id), pageCurrent);	
}	
}	

/*
*Role:Réinitialise le cookie pour afficher le 1er onglet; appelée au submit du formulaire
*Traitement:affiche l'onglet preservé ds le cookie
*/	
function resetCookiePanel(){
cookieActivePanel = new Cookie(document, "metro_panel", null, "/");
cookieActivePanel.load();
cookieActivePanel.number = 1;
cookieActivePanel.store();
}

	var tabImages = new Array(2);
	tabImages[0] = new Image(20,20);
	tabImages[0].src = "/images/metro/star_rating_off.gif";
	tabImages[1] = new Image(20,20);
	tabImages[1].src = "/images/metro/star_rating_on.gif";
var secs
var timerID = null
var timerRunning = false
var delay = 3000	
	function swapImages(isOn, name, number) {
		for (var i = 0; i < number ; i++) {
			document.getElementById(name + i).src = (!isOn ? tabImages[0].src : tabImages[1].src);
			}
	}

function showRecipesCateg(id, lng, isSubcategory){
	resetCookiePanel();
  window.location = "/" + lng + "/recettes.html?categoryId=" + id + "&isSubcategory=" + isSubcategory;
}
