/** Passe le nom d'une ancre entre des m�thodes */
var myAncor = null;

// prend la valeur passée avec l'url 
function getValue(varname){
  // First, we load the URL into a variable
  var url = window.location.href;

  // Next, split the url by the ?
  var qparts = url.split("?");
  // Check that there is a querystring, return "" if not
  if (qparts.length == 1){
    return "";
  }

  // Then find the querystring, everything after the ?
  var query = qparts[1];

  // Split the query string into variables (separates by &s)
  var vars = query.split("&");

  // Initialize the value with "" as default
  var value = "";

  // Iterate through vars, checking each one for varname
  for (i=0;i<vars.length;i++){
    // Split the variable by =, which splits name and value
    var parts = vars[i].split("=");
    
    // Check if the correct variable
    if (parts[0] == varname) {
      // Load value into variable
      value = parts[1];

      // End the loop
      break;
    }
  }
  
  // Convert escape code
  value = unescape(value);

  // Convert "+"s to " "s
  value.replace(/\+/g," ");

  // Return the value
  return value;
}




/* javascript variable défini la div  #mvContainerEcouter*/
var panelContainerEcouter;
var texteIntroSuite;
var panelContainerCompositeur;
var panelContainerPresse;
var panelContainerCommentaire;
var aSlidingPanel;

Rico.loadModule('Accordion','Corner');

function setSlidingPanel(){
	panelContainerEcouter = Rico.SlidingPanel.top( $('outer_panel'), $('mvContainerEcouter')); 
  	texteIntroSuite = Rico.SlidingPanel.top( $('outer_panel2'), $('mvContainerEcouter2')); 
  	aSlidingPanel = new Array( panelContainerEcouter,texteIntroSuite);
}

Rico.onLoad( function() {
  	setSlidingPanel();
	
  	// ouverture du pannel comment automatique
	if(comment == true){ 
		showCommentaireOnLoad();
	} 
   // chargement initial
   //loadCommentaires();
});

//*********************************************************************
// prend la hauteur de la page 
//*********************************************************************
function getPageScreenHeight() { 
	var yWin = 576; 
	if (self.innerHeight) yWin = self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight) yWin = document.documentElement.clientHeight; 							    else if (document.body) yWin = document.body.clientHeight;
    return yWin;
}

//*********************************************************************
// ouvre la panneau commentaire lors du chargement de la page
//*********************************************************************
function showCommentaireOnLoad(){	
	showOne('colonneLeft_commentaire');
}
//*********************************************************************
// Affiche et cache les div avec les effets de rico et toggle le bouton
//*********************************************************************
function showHideContent(el,elToFlip){
	image = (el.src.indexOf("flip",0) == -1)? "buttonBouleflip.png":"buttonBoule.png";
	
	el.src = "images/"+image ;	
	eval(""+elToFlip+".toggle()");
	
	if(image == "buttonBouleflip.png"){
		//passage du nom de l'ancre (qui est le m�me que celui de l'id)
		//myAncor = el.id;
		//setTimeout("goOnAncor()",500);
	} else{
		// window.scrollTo(0,0);
	}
	
 	//window.location.hash= el.id;	
}

//***************************************************
// Vas sur l'ancre pass�e par la variable myAncor
//***************************************************
function goOnAncor(){
	window.location.hash = myAncor;
}
//***************************************************
// Affiche ou cache la suite du texte dans 'Disque'
//***************************************************
function showHideTextIntro(el,elToFlip){
	oEl = document.getElementById(el);
	
	oEl.style.display = (oEl.style.display == "inline")?"none":"inline";
	
	eval(""+elToFlip+".toggle()");	
}

//*********************************************************************
// affiche le container pour acheter le disque dans la partie central ou pour jouer live et aussi la partie contact
//*********************************************************************

function showOne(panelToShow){
	$("collonneLeft_buyCd").style.display = "none";
	$("collonneLeft_PlayLive").style.display = "none";
	$("collonneLeft_Contact").style.display = "none";
	$("collonneLeft_Liens").style.display = "none";
	$("disqueContenu").style.display = "none";
	$("colonneLeft_compositeur").style.display = "none";
	//$("colonneLeft_Ecouter").style.display = "none";
	$("colonneLeft_presse").style.display = "none";
	$("colonneLeft_commentaire").style.display = "none";
	$(panelToShow).style.display = "block";
	
}
//*********************************************************************
// rétabli les soustitres principaux dans la colonnes de gauche
//*********************************************************************

function loadCommentaires(){
	new Ajax.Request('loadComment.php',  
					 {     method:'get', asynchronous:false,
   
					 onSuccess: function(transport){ $("mvContainerCommentaire").innerHTML =  transport.responseText;    
					// var response = transport.responseText || "no response text";      
					// alert("Success! \n\n" + response);   
					},    
					 onFailure: function(){ alert('Something went wrong...') }   
	}); 
	// si l'affichage de la page est un retour d'une insertion de commentaire ouvrir la div commentaire
	var isComm = getValue("commentaire");
	if(isComm == "true"){
		showCommentaireOnLoad();
	} 
}

/**
* 	Variable globale contenant la monnaie actuellement sélectionnée.
*
*/
var actualCurrency = "CHF";

/**
* Array contenant les prix de livraison
* 
*/
var  aLivraisonPrice = new Array("");
	// livraison pour la suisse (par défaut)
	aLivraisonPrice["EURO"] = 0 ;aLivraisonPrice["CHF"] = 0; aLivraisonPrice["USD"] = 0;		

/**
*	Modifie le pays de livaison.
*
*/
function setPaysLivraison(value,buttonRadio){
	if(!value){
			value = ($$('#livraisonSelect option').find(function(ele){return !!ele.selected})).value;
	}
	if(!buttonRadio){	
		 buttonRadio = $('order_cd').select('[type="radio"]').find(function(re){
						return re.checked;												 
	 	});
	}
		switch(value){
			case "suisse":
				aLivraisonPrice["EURO"] = 0 ;aLivraisonPrice["CHF"] = 0; aLivraisonPrice["USD"] = 0;			
			break;
			case "europe":
				if(buttonRadio.value =="both"){
					aLivraisonPrice["EURO"] = 6.8 ;aLivraisonPrice["CHF"] = 10; aLivraisonPrice["USD"] = 9.5;
				}else{
					aLivraisonPrice["EURO"] = 3.4 ;aLivraisonPrice["CHF"] = 5; aLivraisonPrice["USD"] = 4.3;
				}
				 	
			break;
			case "monde":
				if(buttonRadio.value =="both"){
					aLivraisonPrice["EURO"] = 8.6 ;aLivraisonPrice["CHF"] = 13; aLivraisonPrice["USD"] = 11;
				}else{					
					aLivraisonPrice["EURO"] = 6.8 ;aLivraisonPrice["CHF"] = 10; aLivraisonPrice["USD"] = 9.5;
				}
				 
			break;
		}
			
		$('livraison').innerHTML = aLivraisonPrice[actualCurrency];
		
		setTotal();
}
//***************************************************
// Modifie le prix du cd d'apr�s la currency
//***************************************************
function setCdPrice(selecteur){
	if(selecteur.value == ""){ return false};
	var currencyList = $('order_cd').select('.currency');
	currencyList.each(function(el){el.innerHTML = selecteur.value});
	actualCurrency = selecteur.value;
	switch(selecteur.value){
		case "EURO":
			$("price_concerto").innerHTML ="10";
			$("price_sympho").innerHTML ="10";
			$("price_concerto_sympho").innerHTML ="15";
			
			break;
		case "CHF":
			$("price_concerto").innerHTML ="12";
			$("price_sympho").innerHTML ="12";
			$("price_concerto_sympho").innerHTML ="18";
			
			break;
		case "USD":
			//cd_price.innerHTML ="13";
			$("price_concerto").innerHTML ="13";
			$("price_sympho").innerHTML ="13";
			$("price_concerto_sympho").innerHTML ="21";
			
			break;
	}
	selecteur.value = "";
	// modifie le prix de la livaison 
	$('livraison').innerHTML = aLivraisonPrice[actualCurrency];
	
	setTotal();
	
}

//***************************************************
// Action lorsqu'on sélectionne un button Radio qui défini quel disque acheter
//***************************************************
function buttonRadiolicked(buttonRadio){
	// supprime l'opacité dans la sélection cliquée.
	$('order_cd').select('[type="radio"]').each(function(el,index){
		el.up(".choixdisque").removeClassName('noOpaque');												 
	 });
	buttonRadio.up(".choixdisque").addClassName('noOpaque');
	setPaysLivraison(null,buttonRadio);
	//setTotal(buttonRadio);
}

//*****************************************************
// Affiche le total
//*****************************************************
function setTotal(buttonRadio){
		if(!buttonRadio){
			buttonRadio = $('order_cd').select('[type="radio"]').find(function(re){
						return re.checked;												 
	 		});
		}
		
		// affiche le total
	var cdPrice = _getCDPrice(buttonRadio.value);
	$('total_price').innerHTML = parseInt(cdPrice) + parseFloat($('livraison').innerHTML);
}


//***********************************************
// Private. Trouve le prix du disque actuellement sélectionné
//***********************************************
function _getCDPrice(buttonRadioValue){
	switch(buttonRadioValue){
		case "both":
			return $('price_concerto_sympho').innerHTML;
		break;
		case "symphonie":
			return $('price_sympho').innerHTML;
		break;
		case "concerto":
			return $('price_concerto').innerHTML;
		break;
	}
}

//***************************************************
// Construit l'id du boutton paypal en v�rifiant la valeur de currency et le pays de livraison
//***************************************************
function verifyForm(){
	var buttonRadio = $('order_cd').select('[type="radio"]').find(function(re){
						return re.checked;												 
	 		});
	if(!buttonRadio){
		alert("Veuillez selectionnez un achat.")
		return false;
	};
	var payDeLivraison = ($$('#livraisonSelect option').find(function(ele){return !!ele.selected})).value;
	var numberItem = "";
	switch(buttonRadio.value){
		case "both":
			numberItem = "3";
		break;
		case "symphonie":
			numberItem = "2";
		break;
		case "concerto":
			numberItem = "1";
		break;
	}
	
	switch(actualCurrency){
		case "EURO":
			numberItem += "1"; // numéro défini pour EURO
			break;
		case "CHF":
			numberItem += "2"; // numéro défini pour CHF
			break;
		case "USD":
			numberItem += "3"; // numéro défini pour USD
			break;
	}
	
	switch(payDeLivraison){
		case "suisse":
			numberItem += "1";  // numéro défini pour le pays suisse
			break;
		case "europe":
			numberItem += "2";  // numéro défini pour le pays europe
			break;
		case "monde":
			numberItem += "3";  // numéro défini pour le pays monde
			break;	
	}
	
	// différent id de boutton paypal
					// 100 concerto		200 sympho				300 both   // 10 EURO	20 CHF	30 USD // 1 suisse	2 europe	 3 monde
	var buttonId = {131:"NG9YJ9B9NWX8Y", 132:"NQFDFGZXFZ7L4", 133:"CN6UJHWWTT87Y",
					111:"5CSL7SZ38VNP6", 112:"7PHT8XD4QRXZU", 113:"U2SJXSAJ74C7U",
					121:"9LLTQ4UUNJ6KJ", 122:"WZUVC2HQBEVAG", 123:"75AZSPQT4EQUN",
					231:"4PCCWTR7368WQ",  232:"74YZFDASNUDDA", 233:"E4TQ76K9BTXHE",   
					211:"47KSC3RLWLV3G",  212:"VTG358TVJVNML",  213:"U3BGNV39AGKKU", 
					221:"BTVEGU9X98MG2",  222:"GX8A3SJJSVHP2",  223:"B5N5F528V6BQS",  
					
					331:"KS8APHT86SXGU", 332:"BKRUW35RC6AHU", 333:"BFQU95T3YPM4W",
					311:"ZYLWHM6R3PU7L", 312:"7R75Z4MMG94TW", 313:"X88SQJGZX2NUG",
					321:"E7C757QGB2E8E", 322:"Q93MQZJM6JYNY", 323:"FLTX3BJ68UKQN" 
					};
			
	// défini l'id du nboutton paypal				
	document.payPalForm.hosted_button_id.value = buttonId[numberItem];
	//alert(document.payPalForm.hosted_button_id.value);
	return true;

}


