/*--FUNCTIONS.JS--*/
function toggleFooterZone(element){
	if($('footerZone')){
		switch($('footerZone').style.display){
			case "":
				$('footerZone').style.display = "block";
				$(element).style.backgroundImage = "url(http://elixirdelingerie.visual-link.fr/templates/1/medias/img/arrow_footer_current.gif)";
				//$(element).style.backgroundRepeat = "no-repeat";
				$(element).up().className = "active";
				break;
			case "none":
				$('footerZone').style.display = "block";
				$(element).style.backgroundImage = "url(http://elixirdelingerie.visual-link.fr/templates/1/medias/img/arrow_footer_current.gif)";
				//$(element).style.backgroundRepeat = "no-repeat";
				$(element).up().className = "active";
				break;
			case "block":
				$('footerZone').style.display = "none";
				$(element).style.backgroundImage = "url(http://elixirdelingerie.visual-link.fr/templates/1/medias/img/arrow_footer_int.gif)";
				//$(element).style.backgroundRepeat = "no-repeat";
				$(element).up().className = "";
				break;
			default :
				$('footerZone').style.display = "block";
				$(element).style.backgroundImage = "url(http://elixirdelingerie.visual-link.fr/templates/1/medias/img/arrow_footer_current.gif)";
				//$(element).style.backgroundRepeat = "no-repeat";
				$(element).up().className = "active";
				break;
		}
	}
}


function envoyerAmiSpec(){
	if($('vlbox') && $('envoyer_ami')){
		$('partners').scrollTo(0);
		
		var stockValue = ($("bloc-content").getHeight() + 32)+"px";
		//alert(stockValue);
		
		if(!$('overlay')){
			$('vlbox').insert({after:'<div id="overlay"></div>'});
		}
		//alert($('BgmainMenu').getDimensions());
		$('overlay').setStyle({"position":"absolute","top":"0","left":"0","zIndex":"48","width":"100%","height":stockValue,"background":"#000000"});
		$('overlay').setOpacity(0);
		$('overlay').appear({duration:0.3, from:0, to:0.7});
		Event.observe('overlay','click',function(event){
			$('overlay').fade({duration:0.3, from:0.7, to:0});
			$('vlbox').style.display='none';
		});
		
		$('vlbox').className='friend2';
		var stockTop = $('boxTrigger').cumulativeOffset().top - 367;
		$('vlbox').setStyle({"display":"block","top":stockTop+"px"});
		$('innerVlbox').innerHTML='<p style="text-align:center;padding:15px 0;"><img src="http://elixirdelingerie.visual-link.fr/templates/1/medias/img/vl_boxs/ajax-loader.gif" alt="" />&nbsp;'+$('innerVlbox').className+'...</p>';
		new Ajax.Updater('innerVlbox', '../../../templates/1/ajax/envoyer_ami_formulaire_jeu.php', 
			{ 
				method: 'post' , 
				evalScripts: true , 
				parameters:{url : document.URL}
			}
		);
		
		return false;
	}
}

function envoyerAmi(){
	if($('vlbox') && $('envoyer_ami')){
		$('content').scrollTo(0);
		
		if(!$('overlay')){
			$('vlbox').insert({after:'<div id="overlay"></div>'});
		}
		//alert($('BgmainMenu').getDimensions());
		$('overlay').setStyle({"position":"absolute","top":"0","left":"0","zIndex":"48","width":"100%","height":"100%","background":"#000000"})
		$('overlay').setOpacity(0);
		$('overlay').appear({duration:0.3, from:0, to:0.7});
		Event.observe('overlay','click',function(event){
			$('overlay').fade({duration:0.3, from:0.7, to:0});
			$('vlbox').style.display='none';
		});
		
		$('vlbox').className='friend';
		$('vlbox').style.display='block';
		$('innerVlbox').innerHTML='<p style="text-align:center;padding:15px 0;"><img src="http://elixirdelingerie.visual-link.fr/templates/1/medias/img/vl_boxs/ajax-loader.gif" alt="" />&nbsp;'+$('innerVlbox').className+'...</p>';
		new Ajax.Updater('innerVlbox', '../../../templates/1/ajax/envoyer_ami_formulaire.php', 
			{ 
				method: 'post' , 
				evalScripts: true , 
				parameters:{url : document.URL}
			}
		);
		
		return false;
	}
}


function retour_ami(event){
	new Ajax.Updater('innerVlbox', '../../../../templates/1/ajax/envoyer_ami_formulaire.php', 
		{ 
			method: 'post' , 
			evalScripts: true 
		}
	);
}

function switchLang(element){
	//alert($(element).ancestors()[0].id);
	for(var i=0;i<$(element).ancestors()[1].childElements().length;i++){
		//alert($(element).ancestors()[1].childElements()[i].id);
		$(element).ancestors()[1].childElements()[i].childElements()[0].setStyle({"color":"#824385","fontWeight":"bold"});
	}
	$(element).setStyle({"color":"#B4A2AD","fontWeight":"normal"});
	for(var i=0;i<3;i++){
		//alert($(element).ancestors()[1].nextSiblings('div')[i].id);
		$(element).ancestors()[1].nextSiblings('div')[i].setStyle({"display":"none"});
	}
	var s_name = $(element).up().id;
	var s_id = s_name.substr(4 ,(s_name.length-4));
	s_name = "tailes" + s_id;
	$(s_name).setStyle({"display":"block"});
}

function bugIeFix(){
	$$(".bugIeFix").each(function(el){
		$(el).firstChild.style.visibility = "hidden";
		$(el).style.display = "block";
		if($(el).firstChild.className == "iconProd"){
			$(el).setStyle({"float":"right"});
		}
		$(el).style.width = $(el).firstChild.width+"px";
		$(el).style.height = $(el).firstChild.height+"px";
		$(el).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(el).firstChild.src+"', sizingMethod='crop');";
	});
}

Event.observe(window,'load',function(){

	$$('.lightwindow').each(function(el){
		$(el).writeAttribute('params', 'lightwindow_width=512,lightwindow_height=330');
	});

	if($('select_pays')){
		Event.observe('select_pays','change',function(event){
			if($('select_pays').value){
				$('point_de_vente_form').submit();				
			}
		});
	}
	
	if($('select_departement')){
		Event.observe('select_departement','change',function(event){
			if($('select_departement').value){
				$('point_de_vente_form').submit();				
			}
		});
	}
	
	if($('vlbox') && $('espacePro')){
		Event.observe('espacePro','click',function(event){
			$('content').scrollTo(0);
			
			if(!$('overlay')){
				$('vlbox').insert({after:'<div id="overlay"></div>'});
			}
					//alert($('BgmainMenu').getDimensions());
			$('overlay').setStyle({"position":"absolute","top":"0","left":"0","zIndex":"48","width":"100%","height":"100%","background":"#000000"})
			$('overlay').setOpacity(0);
			$('overlay').appear({duration:0.3, from:0, to:0.7});
			Event.observe('overlay','click',function(event2){
				$('overlay').fade({duration:0.3, from:0.7, to:0});
				$('vlbox').style.display='none';
			});
			
			$('vlbox').className='';
			//$('innerVlbox').innerHTML='<p style="text-align:center;padding:15px 0;"><img src="http://elixirdelingerie.visual-link.fr/templates/1/medias/img/vl_boxs/ajax-loader.gif" alt="" />&nbsp;Chargement...</p>';
			

			$('vlbox').style.display='block';
			
			new Ajax.Updater('innerVlbox', '../../../templates/1/ajax/espace_pro_login_ajax.php', 
				{ 
					method: 'post',
					evalScripts : true
				}
			);	
			
			event.stop();
			return false;
		});
	}
	
	/*if($('select_pays')){
		Event.observe('select_pays','change',function(event){
			alert($('select_pays').value);
			
			if($('select_pays').value){
				
				var pays_choisi = $('select_pays').value;
				
				new Ajax.Updater('select_region','../../../templates/1/ajax/update_departement.php',
					{
						method: 'post',
						evalScripts: true,
						parameters:{pays: pays_choisi}
					}
				);
				
			}
		});
	}*/
	
	
	if($('verticalMenu')){
	
		test_item = false;
		$$('#verticalMenu dt').each(function(el){
			if(el.up().className == "active"){
				test_item = true;
			}
		});
		$$('#verticalMenu dt').each(function(el){
			
			if(test_item){
				if(el.up().className != "active"){
					$$('#verticalMenu dl.inactive dd').each(function(el){
						//el.setStyle({'backgroundPosition':'left top'});
						el.morph('height:0px;', {duration:0.7});
						el.down(0).fade({duration:0.3,from:1,to:0});
						el.ancestors()[0].className = "inactive";
					});
				}
				else{
					if(el.up().down(3).getStyle('visibility') == 'hidden'){
						el.up().down(3).setOpacity(0);
						el.up().down(3).setStyle({'visibility':'visible'});
					}
					$$('#verticalMenu dl.active dd').each(function(el){
						el.ancestors()[0].className = "active";
						//el.setStyle({'backgroundPosition':'-165px top'});
						el.morph('height:210px;', {duration:0.7});
						el.down(0).appear({duration:0.3,delay:0.2});
					});
				}
			}
				
			Event.observe(el,'click',function(){
				if(this.up().down(3).getStyle('visibility') == 'hidden'){
					this.up().down(3).setOpacity(0);
					this.up().down(3).setStyle({'visibility':'visible'});
				}
				if(this.up().className != "active"){
					this.up().className = "toactive";
					$$('#verticalMenu dl.active dd, #verticalMenu dl.inactive dd').each(function(el){
						//el.setStyle({'backgroundPosition':'left top'});
						el.morph('height:0px;', {duration:0.7});
						el.down(0).fade({duration:0.3,from:1,to:0});
						el.ancestors()[0].className = "inactive";
					});
					$$('#verticalMenu dl.toactive dd').each(function(el){
						el.ancestors()[0].className = "active";
						//el.setStyle({'backgroundPosition':'-165px top'});
						el.morph('height:210px;', {duration:0.7});
						el.down(0).appear({duration:0.3,delay:0.2});
					});
				}
				else{
					this.up().className = "inactive";
					$$('#verticalMenu dl.inactive dd').each(function(el){
						el.ancestors()[0].className = "inactive";
						//el.setStyle({'backgroundPosition':'left top'});
						el.morph('height:70px;', {duration:0.7});
						el.down(0).fade({duration:0.3,from:1,to:0});
					});
				}
			});
		})
	}

	if($('lang-produit')){
		$$('#lang-produit li a').each(function(el){
			Event.observe(el, "click", function(el){
				//alert(this.hasClassName('active'));
				var s_name = this.up().id;
				var s_id = s_name.substr((s_name.length-1) ,1);
				s_name = "tailes_" + s_id;
				
				$$('#lang-produit li a').each(function(el){
					$(el).className = "";
				});
				this.className = "active";
				
				$$('div.blocTaille').each(function(el){
					$(el).setStyle({"display":"none"});
				});
				$(s_name).setStyle({"display":"block"});
			});
		});
	}
	
});