﻿/** variables **/

var imgPath ='http://mobile.orange.fr/content/ge/high/style_oes/img'; //starting path for images
var pathImgProd = imgPath+'/dynamic/'; //path for product images (carousel, etc)
var imgLoader = imgPath+'/common/loading.gif'; // image for the shadowbox loader


function replaceAll(src, strTarget, strSubString)
{
    var strText = src;
    var intIndexOfMatch = strText.indexOf( strTarget );

    // Keep looping while an instance of the target string
    // still exists in the string.
    while (intIndexOfMatch != -1)
    {
        // Relace out the current instance.
        strText = strText.replace( strTarget, strSubString )

        // Get the index of any next matching substring.
        intIndexOfMatch = strText.indexOf( strTarget );
    }

    // Return the updated string with ALL the target strings
    // replaced out with the new substring.
    return( strText );
}
/** init tab menu **/
var OTabs = Class.create();
OTabs.prototype = {
	initialize : function(element) {
		if($$(element) && $$(element).first()){
			this.element = $$(element);
			var options = Object.extend({}, arguments[1] || {});
			
			/* Modif Jérome du 18/03 */
			var content = Element.adjacent(this.element,'div.contentTabs').first();
			var anchor = new Element('a',{'id':Element.identify(this.element.first())+'Anchor','name':'anchor','tabindex':'-1'});
			content.insertBefore(anchor,content.firstChild);
			/* Fin Modif */
			
			this.menu = $A(this.element.first().getElementsByTagName('a'));
			this.show(this.getInitialTab(),true);
			this.menu.each(this.setupTab.bind(this));
		}
	},
	setupTab : function(elm) {
		Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
	},
	activate : function(ev) {
		var elm = Event.findElement(ev, "a");
		Event.stop(ev);
		this.show(elm);
		
		this.menu.without(elm).each(this.hide.bind(this));
		
	},
	hide : function(elm) {
		$(elm).up('li').removeClassName('active');
		$(this.tabID(elm)).removeClassName('active-tab-body');
		$(this.tabID(elm)).hide();
	},
	show : function(elm,focus) {
		$(elm).up('li').addClassName('active');
		$(this.tabID(elm)).addClassName('active-tab-body');
		$(this.tabID(elm)).show();
		$(this.tabID(elm)).tabIndex=-1;
		if(!focus) {
			var anchorId =Element.identify($(elm).up('ul'));
			anchorId += 'Anchor';
			$(anchorId).focus();
		}
		this.menu.without(elm).each(this.hide.bind(this));
	},
	tabID : function(elm) {
		return elm.href.match(/#(\w.+)/)[1];
	},
	getInitialTab : function() {
		if(document.location.href.match(/#(\w.+)/)) {
			var loc = RegExp.$1;
			var elm = this.menu.find(function(value) { return value.href.match(/#(\w.+)/)[1] == loc; });
			return elm || this.menu.first();
		} else {
			return this.menu.first();
		}
	}
}

/** init  fold/unfold menus **/
var OArboMenu = Class.create();
OArboMenu.prototype = {
	initialize : function(element,num) {
		if($$(element)){
			this.element = $$(element);
			var options = Object.extend({}, arguments[1] || {});
				if(!num)
				{
					for(i=0;i<this.element.length;i++)
					{
						this.ArboMenu = $A(this.element[i].getElementsByTagName('a'));
						this.ArboMenu.each(this.setupArboMenu.bind(this));
					}
				}else
				{
					this.initializeTH(this.element);
					var sel = this.element.first();
					this.showTH(sel);
				}
		}
	},
	initializeTH : function(element) {
		this.element = element;
		var options = Object.extend({}, arguments[1] || {});
		this.element.each(this.setupArboMenuTH.bind(this));
	},	
	setupArboMenu: function(elm){
		this.ArboMenu.legalstatus = '0';
		this.hide(this.ArboMenu.first());
		Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
	},	
	setupArboMenuTH: function(elm){
		var link = new Element('a',{'href':'javascript:void(0)'});
		var th = elm.down('th');
		link.insert(th.innerHTML);
		th.update(link);
		Event.observe(link,'click',this.activateTH.bindAsEventListener(link),false);
		this.arboMenuTH = $(elm).nextSiblings();
		($(elm).down('th').hasClassName('active'))?$(elm).down('th').removeClassName('active'):$(elm).down('th').addClassName('active');
		
		for(i=0;i<this.arboMenuTH.length;i++){
			if($(this.arboMenuTH[i]).hasClassName('contentTR'))
			{
				$(this.arboMenuTH[i]).hide();
			}
			else{
				return;
			}
		}		
	},	
	activate :  function(ev) {
		var elm = Event.findElement(ev, "a");
		Event.stop(ev);
		switch(this.ArboMenu.legalstatus){
			case '0':
				this.hide(elm)
			break;
			case 1:
				this.show(elm);
			break;
			default:
				this.show(elm)
			break;
		}
	},
	activateTH :  function(ev) {
		var elm = Event.element(ev).up('tr'); 
		Event.stop(ev);
		this.arboMenuTH = $(elm).nextSiblings();
		($(elm).down('th').hasClassName('active'))?$(elm).down('th').removeClassName('active'):$(elm).down('th').addClassName('active');
		
		for(i=0;i<this.arboMenuTH.length;i++){
			if($(this.arboMenuTH[i]).hasClassName('contentTR'))
			{
				$(this.arboMenuTH[i]).toggle();
					}
			else{
				return;
			}
		}
	},
	showTH : function(elm) {
		if($(elm))
		{
			this.arboMenuTH = $(elm).nextSiblings();
			$(elm).down('th').removeClassName('active');
			
			for(i=0;i<this.arboMenuTH.length;i++){
				if($(this.arboMenuTH[i]).hasClassName('contentTR'))
				{
					$(this.arboMenuTH[i]).toggle();
				}
				else{
					return;
				}
			}
		}
	},
	hide : function(elm) {
		$(elm).addClassName('activate');
		$(this.contentID(elm)).hide();
		this.ArboMenu.legalstatus = '1';
	},
	show : function(elm) {
		$(elm).removeClassName('activate');
		$(this.contentID(elm)).show();
		this.ArboMenu.legalstatus = '0';
	},
	contentID : function(elm) {
		return (elm.href.match(/#(\w.+)/)[1]);
	}
}


/*************************************/

/*** gestion de la barre de menu principale **/
document.observe("dom:loaded", function() {
	if (Prototype.Browser.IE) {
		Prototype.Browser.IEVersion = parseFloat(navigator.appVersion.split(';')[1].strip().split(' ')[1]);
		Prototype.Browser.IE6 =  Prototype.Browser.IEVersion == 6;
	}
	/** pour IE6 qui ne gère pas le hover sur li **/
	if(Prototype.Browser.IE6){
	 $$('#headerNav li').each(function(elm){
				Event.observe($(elm),'mouseover',function(ev){
					var el = Event.findElement(ev,'li');
					$(el).addClassName('sfhover');
					Event.stop(ev);
				});
				
				Event.observe($(elm),'mouseleave',function(ev){
					var el = Event.findElement(ev,'li');
					$(el).removeClassName('sfhover');
					Event.stop(ev);
				});
				
		});
	}	
	/** hide accordion elements via js **/
	$$('.accordionBlock div').each(function(elm){
		$(elm).addClassName('off');
	},false);
	
	
	/** Carousel home mobile **/
	if($$("#homeCarousel") && $$('#homeCarousel ul li').first()){
		$$("#homeCarousel").each(function(elm){
			$(elm).addClassName("withJs");
			$(elm).insert('<a class="button off" id="leftArrow" title="offre précédente" href="#"><img src="'+imgPath+'/common/arrow3.png" alt="offre précédente" /></a><a class="button" id="rightArrow" title="offre suivante" href="#"><img src="'+imgPath+'/common/arrow2.png" alt="offre suivante" /></a>');		
		});
		$$('#homeCarousel ul li').each(function(elm,index){
			if($(elm).id.indexOf('access')!=-1){
					$(elm).setAttribute('id',"access"+index);
				}else{
					$(elm).setAttribute('id',"item"+index);	 
				}
			$(elm).hide();
		});			
				
		if(window.location.hash){
			var hash = window.location.hash;	
			//if(hash.indexOf('item'))hash = hash.replace('sitem','item');
				
				if((hash.indexOf('item')!=-1 || hash.indexOf('access')!=-1) && $$(hash) && $$(hash).first()){
					$$(hash).first().show().addClassName('activate');	
					if($$(hash).first() != $$('#homeCarousel ul li').first()){
						$('leftArrow').removeClassName('off');	
						/* Modification Jerome du 25/03/09 */
						$('leftArrow').firstDescendant().setAttribute('src',imgPath+'/common/arrow1.png');
						/* Fin modif */
					}else{
						$('leftArrow').addClassName('off');
						/* Modification Jerome du 25/03/09 */	
						$('leftArrow').firstDescendant().setAttribute('src',imgPath+'/common/arrow3.png');
						/* Fin modif */
					}
					if($$(hash).first() != $$('#homeCarousel ul li').last()){
						$('rightArrow').removeClassName('off');
						/* Modification Jerome du 25/03/09 */
						$('rightArrow').firstDescendant().setAttribute('src',imgPath+'/common/arrow2.png');
						/* Fin modif */
					}else{
						$('rightArrow').addClassName('off');
						/* Modification Jerome du 25/03/09 */
						$('rightArrow').firstDescendant().setAttribute('src',imgPath+'/common/arrow4.png');
						/* Fin modif */
					}
				}else{
					
					$$('#homeCarousel ul li').first().show().addClassName('activate');
				}
		}else{
			$$('#homeCarousel ul li').first().show().addClassName('activate');
		}
		
	}
	
	
	/** carousel pop quick view **/ 
	if($$(".visuBlock li").length!=1){
		$$(".visuPart").each(function(elm){
			$(elm).addClassName("withJs");
			$(elm).insert('<ul class="quickControler"></ul>');
		});
		$$(".visuBlock li").each(function(elm,index){
			$(elm).id="visuQuick"+index;
			if(index!=0){
				$(elm).hide();
				$$(".quickControler").first().insert('<li id="btn'+index+'" class="btnQuick"><a href="#"><img src="'+imgPath+'/common/bt_quickDot.gif" alt="" /></a></li>');
			}else{
				$$(".quickControler").first().insert('<li id="btn'+index+'" class="btnQuick active"><a href="#"><img src="'+imgPath+'/common/bt_quickDotOn.gif" alt="" /></a></li>');
			}
		});
	}
	
	
	/** test de déplacement du noeud footer **/
	if($('footerToBottom')){$('myFooter2').insert($('footerToBottom'));}
	
	
	/** événement onkeyup pour avis utilisateurs **/
	var maxAvisLength = 1500;
	var idLengthAvis = 'caracter';
	var idTextAvis = 'avistextCom';
	
	var generateText = '<br />il vous reste <span id="'+idLengthAvis+'">'+maxAvisLength+'</span> caract&egrave;res ';
	if($(idTextAvis) && !$(idLengthAvis)){
		 new Insertion.After(idTextAvis,generateText);
	}
	if($(idLengthAvis) && $(idTextAvis)){
		if(parseInt($(idTextAvis).value.length)<=maxAvisLength){
			$(idLengthAvis).update(maxAvisLength-parseInt($(idTextAvis).value.length));
		}else{
			var curTruncatedTxt = $(idTextAvis).value.substring(0,maxAvisLength);
			$(idTextAvis).value=curTruncatedTxt;
			$(idLengthAvis).update(0);
		}
		Event.observe($(idTextAvis),'keyup',function(ev){
			Event.stop(ev);
			if(parseInt($(this).value.length)<=maxAvisLength){
				$(idLengthAvis).update(maxAvisLength-parseInt($(this).value.length));
			}else{
				var curTruncatedTxt = $(this).value.substring(0,maxAvisLength);
				$(this).value=curTruncatedTxt;
				$(idLengthAvis).update(0);
			}
		});
	}
	
	/** annuaire universel, gestion du oui/non **/
	if($('oui') && $('non')){
		//at load
		
		if(Prototype.Browser.IE){$('oui').up('table').setStyle({borderBottom: '1px solid #dddddd'}); }
		
		if($('oui').checked){
			$('oui').up('td').addClassName('noBorder');
			$('oui').up('td').previous('td').addClassName('noBorder');
			$('oui').up('tr').nextSiblings().each(function(elm){
				$(elm).show();
			});
		}else{
			$('oui').up('td').previous('td').removeClassName('noBorder');
			$('oui').up('td').removeClassName('noBorder');
			$('oui').up('tr').nextSiblings().each(function(elm){
				$(elm).hide();
			});
		}
		//at click
		Event.observe($('non'),'click',function(ev){
			$(this).up('td').removeClassName('noBorder');
			$(this).up('td').previous('td').removeClassName('noBorder');
			$(this).up('tr').nextSiblings().each(function(elm){
				$(elm).hide();
			});
		});
		Event.observe($('oui'),'click',function(ev){
			$(this).up('td').addClassName('noBorder');
			$(this).up('td').previous('td').addClassName('noBorder');
			$(this).up('tr').nextSiblings().each(function(elm){
				$(elm).show();
			});
		});	
	}
	/** code reduction, gestion du oui/non **/
	if($('oui_num') && $('non_num')){
		//at load
		
		if(Prototype.Browser.IE){$('oui_num').up('table').setStyle({borderBottom: '1px solid #dddddd'}); }
		
		if($('oui_num').checked){
			$('oui_num').up('td').addClassName('noBorder');
			$('oui_num').up('td').previous('td').addClassName('noBorder');
			$('oui_num').up('tr').nextSiblings().each(function(elm){
				$(elm).show();
			});
		}else{
			$('oui_num').up('td').previous('td').removeClassName('noBorder');
			$('oui_num').up('td').removeClassName('noBorder');
			$('oui_num').up('tr').nextSiblings().each(function(elm){
				$(elm).hide();
			});
		}
		//at click
		Event.observe($('non_num'),'click',function(ev){
			$(this).up('td').removeClassName('noBorder');
			$(this).up('td').previous('td').removeClassName('noBorder');
			$(this).up('tr').nextSiblings().each(function(elm){
				$(elm).hide();
			});
		});
		Event.observe($('oui_num'),'click',function(ev){
			$(this).up('td').addClassName('noBorder');
			$(this).up('td').previous('td').addClassName('noBorder');
			$(this).up('tr').nextSiblings().each(function(elm){
				$(elm).show();
			});
		});	
	}
	
	
	/** coordonnées **/
	if($('particulier') && $('professionnel') && $('particulier_content') && $('professionnel_content')){
		//at load
		
			if($('professionnel').checked == false) {
				$('particulier').checked=true;
				$('professionnel_content').hide();
				$('particulier_content').show();
			} else {
				$('professionnel_content').show();
				$('particulier_content').hide();
			}
		
		//at click
		Event.observe($('particulier'),'click',function(ev){
			$('professionnel_content').hide();
			$('particulier_content').show();
		});
		Event.observe($('professionnel'),'click',function(ev){
			$('professionnel_content').show();
			$('particulier_content').hide();
		});	
	}
	
	/** moyens de paiements **/
	if ($('formPaiement')) {
		$('formPaiement').hide();
		Event.observe($('precoPaiement'),'click',function(ev){
			if(this.checked == true)
				$('formPaiement').show();
			else
				$('formPaiement').hide();
		});
	}
	
	if($('paymentType1') && $('paymentType2')){
		//$('paymentType1').up('li').addClassName('active');
		//$('paymentType1').up('li').next('li').removeClassName('active');
		$('blockTabNav2Paiement').up('div').setStyle({borderTop: 'none'});
		$('blockTabNav2Paiement').setStyle({borderTop: 'solid 1px #ddd'});
		$('contentTabPaiement').setStyle({display: 'none'});
		var divName = $('paymentType1').id+"Onglet";
		$(divName).hide();
		$(divName.replace('1','2')).hide();
		
		Event.observe($('paymentType1'),'click',function(ev){
			$(this).up('li').addClassName('active');
			$(this).up('li').next('li').removeClassName('active');
			var divName = $(this).id+"Onglet";
			$(divName).show();
			$(divName.replace('1','2')).hide();
			$('blockTabNav2Paiement').up('div').setStyle({borderTop: 'solid 1px #ddd'});
			$('blockTabNav2Paiement').setStyle({borderTop: 'none'});
			$('contentTabPaiement').setStyle({display: 'block'});
		});
		Event.observe($('paymentType2'),'click',function(ev){
			$(this).up('li').addClassName('active');
			$(this).up('li').previous('li').removeClassName('active');
			var divName = $(this).id+"Onglet";
			$(divName).show();
			$(divName.replace('2','1')).hide();	
			$('blockTabNav2Paiement').up('div').setStyle({borderTop: 'solid 1px #ddd'});
			$('blockTabNav2Paiement').setStyle({borderTop: 'none'});
			$('contentTabPaiement').setStyle({display: 'block'});
		});
		
		if ($('paymentType1').checked) {
			$('paymentType1').up('li').addClassName('active');
			$('paymentType1').up('li').next('li').removeClassName('active');
			var divName = $('paymentType1').id+"Onglet";
			$(divName).show();
			$(divName.replace('1','2')).hide();
			$('blockTabNav2Paiement').up('div').setStyle({borderTop: 'solid 1px #ddd'});
			$('blockTabNav2Paiement').setStyle({borderTop: 'none'});
			$('contentTabPaiement').setStyle({display: 'block'});
		} else if ($('paymentType2').checked) {
			$('paymentType2').up('li').addClassName('active');
			$('paymentType2').up('li').previous('li').removeClassName('active');
			var divName = $('paymentType2').id+"Onglet";
			$(divName).show();
			$(divName.replace('2','1')).hide();	
			$('blockTabNav2Paiement').up('div').setStyle({borderTop: 'solid 1px #ddd'});
			$('blockTabNav2Paiement').setStyle({borderTop: 'none'});
			$('contentTabPaiement').setStyle({display: 'block'});
		}
	}
	
});
/***************************************/



/* global onload for class behaviors */
Event.observe(window,'load',function(){ 
	
	/* popup FP */
	
	$$('a.fpVisuPopup').each(function(elm){
		
		Event.observe(elm,'click',function(ev){
			Event.stop(ev);
			window.open(elm.href,"popup","menubar=no, status=no, scrollbars=no, width=430, height=60, left=100, top=100");
		});
		
	});
	
	/*** product images behaviors **/
	
	$$('#fpDisplayAllPictures a').each(function(elm){
		var imgUri = replaceAll($(elm).readAttribute('rel'),"'",'"').evalJSON();
		
		Event.observe(elm,'mouseover',function(ev){
			$$('#fpDisplayAllPictures li').each(function(elm){
				$(elm).removeClassName('active');
			});
			$(elm).up('li').addClassName('active');
			Event.stop(ev);
			$$('#fpDisplayPicture img').first().src=imgUri.imgM;
			$$('#zoom a').first().href=imgUri.imgB;
			Shadowbox.setup();
		});
		Event.observe(elm,'click',function(ev){
			$$('#fpDisplayAllPictures li').each(function(elm){
				$(elm).removeClassName('active');
			});
			$(elm).up('li').addClassName('active');
			Event.stop(ev);
			$$('#fpDisplayPicture img').first().src=imgUri.imgM;
			$$('#zoom a').first().href=imgUri.imgB;
			Shadowbox.setup();
		});	
	});
	
	
	/** init popins **/
	var opt = {loadingImage: imgLoader,overlayColor:'#000',overlayOpacity:'0.6',keysClose:['c', 27]};//,overlayBgImage:"img/common/overlay-85.png"
		if (typeof Shadowbox != 'undefined') Shadowbox.init(opt);
	
	// init the product page tabs
	var tabProd = new OTabs('.navTabs');
	new OTabs('.blockTabNav');
	/* gestion des liens 'tous les avis' qui sont hors de la tab bar */
	/* modif SAID7434 11/06/2009 */
	$$('a.touslesavis').each(function(elm) {
		Event.observe(elm,'click',function(elm){
			//Event.stop(elm);
			var touslesavisDone=false;
			$$('#tabProd a[href~=#' + $(this).href.match(/#(\w.+)/)[1] + ']').each(function(elm){
				if(!touslesavisDone) {
					//$$('#tabProd').scrollTo();
					tabProd.show(elm);
					touslesavisDone=true;
				}
			});
		});
	});
	
	/** adding behavior for legal link on/off **/
	new OArboMenu('.legalAccess',false);
	
	/** adding behavior for product page fold/unfold menus **/
	new OArboMenu('table tr.heading',1);
	
	/** increase/decrease quantity **/
	$$('.incLink').each(function(elm){
			Event.observe(elm,'click',function(elm){
				Event.stop(elm);
				var inputId = this.href.match(/#(\w.+)/)[1];
				var inputValP = $F(inputId);
				inputValP++;
				Form.Element.setValue(inputId,inputValP);
			});
	},false);
	$$('.decLink').each(function(elm){
			Event.observe(elm,'click',function(elm){
				Event.stop(elm);
				var inputId = this.href.match(/#(\w.+)/)[1];
				var inputValM = $F(inputId);
				inputValM--;
				if(inputValM<1)inputValM=1;
				Form.Element.setValue(inputId,inputValM);
			});
	},false);
	
	if (typeof accordion != 'undefined')
	{
		// instanciate the right accordions
		if($('nosEngagements'))
		{	
			var nosEngagements = new accordion('nosEngagements',{onEvent : 'mouseover'});
			
			// activate first module of accordions
			nosEngagements.activate($$('#nosEngagements .accordion_toggle')[0]);
			
			$$("#nosEngagements a").invoke("observe", "focus", function(event) {
				$$("#nosEngagements h3").each(function(elm){
					elm.removeClassName("accordion_toggle_active");
				});
				
				$$(".accordion_content").each(function(elm){
					elm.setStyle({display: 'none'});
				});
			
			this.up('h3').addClassName("accordion_toggle_active");
			this.up('h3').next(0).setStyle({display: 'block'});
			});
		}
		if($('nosEngagementsSmall'))
		{
			var nosEngagementsSmall = new accordion('nosEngagementsSmall',{onEvent : 'mouseover'});	
			// activate first module of accordions	
			nosEngagementsSmall.activate($$('#nosEngagementsSmall .accordion_toggle')[0]);
		}
		
	}
	
	/** Meilleures ventes & sélections **/
	$$('.contentListPdt li a.actionBt').each(function(elm){
		
		if($(elm).up('li').hasClassName("active") == false){
			$(elm).up('li').down(".descPart").hide();
		}
		else{
			$(elm).up('li').down(".descPart").show();
		}
		
		Event.observe(elm,'click',function(ev){
			var elm = Event.findElement(ev, "a");
			Event.stop(ev);
			$(elm).up('li').siblings().each(function(el){
				$(el).removeClassName('active');
				$(el).down(".descPart").hide();
			});
			$(elm).up('li').addClassName('active');
			$(elm).up('li').down(".descPart").show();
		});
	})
	
	
	/** selector **/
	
	/** recharges **/
	$$(".stdDeco input[type='radio'], .controlDeco input[type='radio'], .enhancedDeco input[type='radio']").each(function(elm){
			Event.observe(elm,'click',function(event){
				$$(".stdDeco input[type='radio'], .controlDeco input[type='radio'], .enhancedDeco input[type='radio']").each(function(elm){
					if(elm.up('p')) elm.up('p').removeClassName('active');
				});
				var element = event.element(); 
				if(elm.up('p')) $(element).up('p').addClassName('active');
			});
	});
	
	/** recharge rebond **/
	$$(".numCheck input").each(function(elm){
		new Form.Element.Observer(
			elm,
			0.02, // 2 milliseconds
			function(el, value){
				if(value.length == 2 && $(el).next('input'))$(el).next('input').select();
			}
		)
	});
	$$(".cardNum input").each(function(elm){
		new Form.Element.Observer(
			elm,
			0.02, // 2 milliseconds
			function(el, value){
				if(value.length == 4 && $(el).next('input'))$(el).next('input').select();
			}
		)
	});
	
	/*----------------------------------------------------------------------------------------------------------------------*/
	
	/** dépliure **/
	$$(".prixSelon, .comboLike, .voirToutContainer").each(function(elm){
			elm.hide();
	});
	
	$$(".voirTout a, .linkPlus, .comboLikeHead").each(function(elm){
		elm.state = 'off';
		Event.observe(elm,'click',function(ev){
			//var elm = Event.findElement(ev, "a");
			Event.stop(ev);
			if (elm.state == 'off'){
				
				// cas des "voir tout"
				if((elm.up('li'))&&(elm.up('li').className == "voirTout")){
					$$(".voirToutContainer").each(function(elm2){ 
						elm2.hide();
						//Effect.toggle(elm2,'appear');
					});
					$$(".voirTout a").each(function(elm3){ 
						elm3.removeClassName('stateOn');
						elm3.state = 'off';
					});
				}
				$(elm.href.split('#')[1]).show();
				$(elm.href.split('#')[1]).tabIndex=-1;
				$(elm.href.split('#')[1]).focus();
				//Effect.SlideDown($(elm.href.split('#')[1]));
				elm.addClassName('stateOn');
				elm.state = 'on';
			}
			else{
				$(elm.href.split('#')[1]).hide();
				elm.removeClassName('stateOn');
				elm.state = 'off';
			}
			//elm.blur();
			//$("apple").focus();
			return false;
		});
	});
	
	
	/** fermeture du combo */
	actif = window.setTimeout(function() {
					$("comboLike1").hide();
					$('comboLikeHead').removeClassName('stateOn');
					$('comboLikeHead').state = 'off';
				}, 5000);
				
	clearTimeout(actif);
	
	$$("#comboLike1").each(function(elm){
		Event.observe(elm,'mouseout',function(ev){
			actif = setTimeout(function() {
					$("comboLike1").hide();
					$('comboLikeHead').removeClassName('stateOn');
					$('comboLikeHead').state = 'off';
				}, 2000);
		});
		
		Event.observe(elm,'mouseover',function(ev){
			clearTimeout(actif);
		});
		
	});
	
	$$("#comboLike1 li a").invoke("observe", "focus", function(event) {
		clearTimeout(actif);
	});
	
	$$("#comboLike1 li a").invoke("observe", "blur", function(event) {
		actif = setTimeout(function() {
					$("comboLike1").hide();
					$('comboLikeHead').removeClassName('stateOn');
					$('comboLikeHead').state = 'off';
				}, 2000);
	});
	
	$$("#comboLikeHead").invoke("observe", "focus", function(event) {
			$("comboLike1").show();
			$("comboLike1").focus();
	});	
	
	
	
	/*InfoBulles */
	$$(".infoBulleLink").invoke("observe", "focus", function(event) {
			this.down("span").addClassName("showInfoBulle");
	});
	
	$$(".infoBulleLink").invoke("observe", "blur", function(event) {
			this.down("span").removeClassName("showInfoBulle");
	});
	
	$$(".infoBulleLink").invoke("observe", "mouseover", function(event) {
			this.down("span").addClassName("showInfoBulle");
	});
	
	$$(".infoBulleLink").invoke("observe", "mouseout", function(event) {
			this.down("span").removeClassName("showInfoBulle");
	});
	
	/*----------------------------------------------------------------------------------------------------------------------*/
	
	/** Tarifs **/
	$$(".offerContent").each(function(elm){
		Event.observe(elm,'mouseover',function(event){
			var containerId = elm.up(2).readAttribute('id');
			$$("#"+containerId+" .contentOffreRoll").each(function(elt){
				elt.removeClassName('contentOffreRoll');
			});
			elm.addClassName('contentOffreRoll');
		});
		Event.observe(elm,'mouseout',function(event){
				elm.removeClassName('contentOffreRoll');
		});
	});
	
	
	/** Forfaits **/
	$$(".offerContainer").each(function(elm){
		Event.observe(elm,'mouseover',function(event){
			var containerId = elm.up(1).readAttribute('id');
			$$("#"+containerId+" .activeRoll").each(function(elt){
				elt.removeClassName('activeRoll');
			});
			elm.addClassName('activeRoll');
		});
		/* Modification Jérôme du 02/04/09 */
		new Array($(elm.down('a')),$(elm.down('a',1))).each(function(elA) {
			Event.observe(elA,'focus',function(event){
				var containerId = elm.up(1).readAttribute('id');
				$$("#"+containerId+" .activeRoll").each(function(elt){
					elt.removeClassName('activeRoll');
				});
				elm.addClassName('activeRoll');
			});
		});
		/* Fin modif */
		Event.observe(elm,'mouseout',function(event){
				elm.removeClassName('activeRoll');
		});
		/* Modification Jérôme du 02/04/09 */
		new Array($(elm.down('a')),$(elm.down('a',1))).each(function(elA) {
			Event.observe(elA,'blur',function(event){
					elm.removeClassName('activeRoll');
			});
		});
		/* Fin modif */
	});
	
	
	/** Selection mobile **/
	$$(".radioMobileSelect").each(function(elm){
		Event.observe(elm,'click',function(event){
			$(elm).up('.mobileProduct').siblings().each(function(elt){
				$(elt).removeClassName('active');
				$(elt).down('label').innerHTML = "choisir ce mobile";
				/* Modification Jerome du 12/03 => Modification dynamique du title du radio bouton selectionne */
				$(elt).down('label').title = "choisir ce mobile : "+$(elt).down('label').title.substring($(elt).down('label').title.indexOf(":")+2);
			});
			$(elm).up('.mobileProduct').addClassName('active');
			$(elm).siblings('label')[0].innerHTML = "votre choix"
			/* Modification Jerome du 12/03 => Modification dynamique du title des radios boutons deselectionne */
			$(elm).siblings('label')[0].title = "votre choix : "+$(elm).siblings('label')[0].title.substring($(elm).siblings('label')[0].title.indexOf(":")+2);
		});
	});
	
	/** Offres Mobiles **/	
	$$('.offerList dd').each(function(elmDD){
			($(elmDD).index>=0)?$(elmDD).hide():$(elmDD).addClassName('active-offer');
	});
	$$('.offerList dt').each(function(elmDT){
			if($(elmDT).index==0)$(elmDT).addClassName('active');
			Event.observe(elmDT,'mouseover',function(ev){
				var el = Event.findElement(ev,'dt');
				$(el).adjacent('dd').each(function(elmDD){$(elmDD).removeClassName('active-offer').hide()});
				$(el).next('dd').addClassName('active-offer').show();
				$(el).adjacent('dt').each(function(elmDT){$(elmDT).removeClassName('itemActive-offer')});
				$(el).addClassName('itemActive-offer');
				Event.stop(ev);
			});
			Event.observe(elmDT,'focus',function(ev){
				var el = Event.findElement(ev,'dt');
				$(el).adjacent('dd').each(function(elmDD){$(elmDD).removeClassName('active-offer').hide()});
				$(el).next('dd').addClassName('active-offer').show();
				$(el).adjacent('dt').each(function(elmDT){$(elmDT).removeClassName('itemActive-offer')});
				$(el).addClassName('itemActive-offer');
				Event.stop(ev);
			});
	});
	
	/** Carousel home mobile **/
	
	$$("#homeCarousel .button").each(function(elm){
		Event.observe(elm,'click',function(event){
			//gérer click		
			switch($(elm).id){
				case "leftArrow":
						
					//trouver l'index affiché
					var curEl =  $$("#homeCarousel li.activate").first();
					var curIndex =(curEl.id.indexOf('access')!=-1)?curEl.id.replace('access',''):curEl.id.replace('item','');
						curIndex = parseInt(curIndex);
					if(curIndex!=0)
					{
						curEl.removeClassName('activate');
						curEl.hide();
						curIndex--;
						$("rightArrow").removeClassName("off");
						/* Modification Jerome du 25/03/09 */
						$("rightArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow2.png');
						/* Fin modif */
					if(curEl.id.indexOf('access')!=-1){
					var newId = 'access'+(curIndex)
					}
					else
					{
					var newId = 'item'+(curIndex);
					}
						if(curIndex==0){
							$("leftArrow").addClassName('off');
							/* Modification Jerome du 25/03/09 */
							$("leftArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow3.png');
							/* Fin modif */
						}
						$(newId).show().addClassName('activate');
						//window.location.hash = "s"+newId;
					}
					
				break;
				case "rightArrow":
					var curEl =  $$("#homeCarousel li.activate").first();
					var curIndex =(curEl.id.indexOf('access')!=-1)?curEl.id.replace('access',''):curEl.id.replace('item','');
						curIndex = parseInt(curIndex);
					if(curIndex!=$$("#homeCarousel li").length-1)
					{
						curEl.removeClassName('activate');
						curEl.hide();
						curIndex++;
						$("leftArrow").removeClassName("off");
						/* Modification Jerome du 25/03/09 */
						$("leftArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow1.png');
						/* Fin modif */
					if(curEl.id.indexOf('access')!=-1){
						var newId = 'access'+(curIndex)
					}
					else
					{
						var newId = 'item'+(curIndex);
					}
					if(curIndex == $$("#homeCarousel li").length-1){
						$("rightArrow").addClassName('off');
						/* Modification Jerome du 25/03/09 */
						$("rightArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow4.png');
						/* Fin modif */	
					}
						$(newId).show().addClassName('activate');
						//window.location.hash = "s"+newId;
					}
				break;
				default:
				break;
			}
		});
		/* gérer le rollover souris */
		Event.observe(elm,'mouseover',function(event){
			switch($(elm).id){
				case "leftArrow":
					if(!$("leftArrow").hasClassName('off'))
						$("leftArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow5.png');
				break;
				case "rightArrow":
					if(!$("rightArrow").hasClassName('off'))
						$("rightArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow6.png');
				break;
				default:
				break;
			}
			
		});
		Event.observe(elm,'mouseout',function(event){
			switch($(elm).id){
				case "leftArrow":
					if($("leftArrow").hasClassName('off'))
						$("leftArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow3.png');
					else 
						$("leftArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow1.png');
				break;
				case "rightArrow":
					if($("rightArrow").hasClassName('off'))
						$("rightArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow4.png');
					else 
						$("rightArrow").firstDescendant().setAttribute("src",imgPath+'/common/arrow2.png');
				break;
				default:
				break;
			}
			
		});
		/* Fin modif */
	});		
	
	/** quick view **/
	$$(".btnQuick").each(function(elm,index){
		Event.observe(elm,'mouseover',function(event){
			$$(".btnQuick.active").each(function(el){
				var oldIndex = $(el).id;
					oldIndex = oldIndex.replace("btn","");
					oldIndex = parseInt(oldIndex);
				$("visuQuick"+oldIndex).hide();
				$(el).removeClassName('active');
				$(el).down('img').src=$(el).down('img').src.replace('bt_quickDotOn','bt_quickDot');
				//alert(oldIndex);
			 });
			var curIndex =	$(elm).id;
				curIndex = curIndex.replace("btn","");
				curIndex = parseInt(curIndex);
			$("visuQuick"+curIndex).show();
			$(elm).addClassName('active');
			$(elm).down("img").src=$(elm).down("img").src.replace('bt_quickDot','bt_quickDotOn');
		});
	});
	
	enableAddress = function() {
		   $('infos_adresse').removeClassName('disabled')
		   $('select_adresse_proposee').setAttribute("disabled", "disabled");
		   
		   $$("#infos_adresse .textInput").each(function(elm){
		      $(elm).removeAttribute("disabled");
		   });  
		}
		
		disabledAddress = function(inputState){
		   if (inputState == null) {
	         $('infos_adresse').addClassName('disabled');
	      }
	         
	      $$("#infos_adresse .textInput").each(function(elm){
		      $(elm).setAttribute("disabled", "disabled");
		   }); 
		}
		
		//au click sur les boutons radio de la page mes coordonées
		$$("#choix_adresse input").each(function(elm){
	   	//au chargement de la page on recherche le boouton radion qui a le click
	   	inputState = $('infos_adresse').getAttribute("class");
	   	thisInput = $(elm).id;
	   	
	   	if ( ($(elm).getAttribute("checked") == "checked") || ($(elm).getAttribute("checked") == true)) {
	         
	         if (thisInput == "modifier_adresse") {
	   			   enableAddress();
	   			}
	   		   else if (thisInput == "conserver_adresse") {
	   		      $('select_adresse_proposee').setAttribute("disabled", "disabled");
	   		      $('choix_adresse').addClassName('disabled');
	               disabledAddress(inputState);
	   		   }
	   		   else {
	   		      $('select_adresse_proposee').removeAttribute("disabled");
	   		      $('choix_adresse').removeClassName('disabled');
	   		      disabledAddress(inputState);
	   		   }
	   	}
	   	
	   	Event.observe(elm,'click',function(ev){
	   			inputState = $('infos_adresse').getAttribute("class");
	   			thisInput = this.id;
	   			
	   			if (thisInput == "modifier_adresse") {
	   			   enableAddress();
	   			}
	   		   else if (thisInput == "conserver_adresse") {
	   		      $('select_adresse_proposee').setAttribute("disabled", "disabled");
	   		      $('choix_adresse').addClassName('disabled');
	   		      disabledAddress(inputState);
	   		   }
	   		   else {
	   		      $('select_adresse_proposee').removeAttribute("disabled");
	   		      $('choix_adresse').removeClassName('disabled');
	   		      disabledAddress(inputState);
	   		   }
	   			
	   	});
	   });
		

 },false);
