// JavaScript Document
wHome = {
	initialize:function(){
		this.idLayer = "LayerNews";
		this.nameCookie = "MeteoCityPromoNewsletter";

		//> création de l'onglet méteo
		this.buildTabsMeteo();
		
		//> création de l'onglet des médias
		var tabsPhotos = new tabset('PhotosHome',{classNames:{tab:'tabPhotos',panel:'panelPhotos',tabActive:'current'},ids:{tab:'TabPhotos_', panel:'panelPhotos_'}});
		tabsPhotos.autoActivate($('TabPhotos_last'));
		
		//> ajout de l'autocomplete
		var mcHome = new mcSearchCity("","","homeSearchVille","");
		mcHome.modeSearch();
		mcHome.build();
		
		//> on cache 
		$$("img.cartePm").each(function(s){s.hide();});	

		//> calque promo newsletter
		var showLayerNewsletter = true;
		//> test si pas provenance newsletter
		if(location.search){
			var param = location.search.substring(1,location.search.length).split("&");
			for(cpt = 0;cpt<param.length;cpt++){
				if(param[cpt]!= "" && param[cpt] == "from=newsletter"){
					showLayerNewsletter= false;
					break;
				}
			}
		}
		//>	test si cookie
		if(showLayerNewsletter && (getCookieVal(this.nameCookie) == null || getCookieVal(this.nameCookie) == ""))
			showLayerNewsletter = true;
		else
			showLayerNewsletter = false;
			
		if(showLayerNewsletter){
			//> création de l'encart transparent
			this.createLayer();
			//> création du cookie
			this.createCookie();
		}
		//> ajout des toolTips
		this.initGalerie();
		
		//>ajout des popups 
       //this.show_popup('http://www.google.fr','google');		
	   //this.show_popup('http://www.free.fr','free');
		
	},
	//-> création / ajout des actions sur l'onglet météo
	buildTabsMeteo:function(){
		if($("MeteoHome")){
			var tabsMeteo = new tabset('MeteoHome',{classNames:{tab:'tabMeteo',panel:'panelMeteo',tabActive:'current'},ids:{tab:'TabMeteo_', panel:'panelMeteo_'}});
			tabsMeteo.autoActivate($('TabMeteo_today'));
			
			//> ajout des actions sur les boutons matin / après-midi
			if($('BtAmToday') && $('BtPmToday') && $('divCarteAmToday') && $('divCartePmToday')){
				$('BtAmToday').observe('click',function(){
						this.switchCarte("divCarteAmToday","divCartePmToday","BtAmToday","BtPmToday","am");
				}.bind(this));
				$('BtPmToday').observe('click',function(){
						this.switchCarte("divCarteAmToday","divCartePmToday","BtAmToday","BtPmToday","pm");
				}.bind(this));				
			}
			
			if($('BtAmTomorrow') && $('BtPmTomorrow') && $('divCarteAmTomorrow') && $('divCartePmTomorrow')){
				$('BtAmTomorrow').observe('click',function(){
						this.switchCarte("divCarteAmTomorrow","divCartePmTomorrow","BtAmTomorrow","BtPmTomorrow","am");
				}.bind(this));
				$('BtPmTomorrow').observe('click',function(){
						this.switchCarte("divCarteAmTomorrow","divCartePmTomorrow","BtAmTomorrow","BtPmTomorrow","pm");
				}.bind(this));								
			}

			if($('BtAmAfterTomorrow') && $('BtPmAfterTomorrow') && $('divCarteAmAfterTomorrow') && $('divCartePmAfterTomorrow')){
				$('BtAmAfterTomorrow').observe('click',function(){
						this.switchCarte("divCarteAmAfterTomorrow","divCartePmAfterTomorrow","BtAmAfterTomorrow","BtPmAfterTomorrow","am");
				}.bind(this));
				$('BtPmAfterTomorrow').observe('click',function(){
						this.switchCarte("divCarteAmAfterTomorrow","divCartePmAfterTomorrow","BtAmAfterTomorrow","BtPmAfterTomorrow","pm");
				}.bind(this));								
			}
			
			//> active la bonne carte en fonction de l'heure
			currentTime =  new Date();
			//carte de l'après midi
			if(currentTime.getHours() > 11){
				this.switchCarte("divCarteAmToday","divCartePmToday","BtAmToday","BtPmToday","pm");
				this.switchCarte("divCarteAmTomorrow","divCartePmTomorrow","BtAmTomorrow","BtPmTomorrow","pm");
				this.switchCarte("divCarteAmAfterTomorrow","divCartePmAfterTomorrow","BtAmAfterTomorrow","BtPmAfterTomorrow","pm");
			}
			//carte du matin
			else{
				//> on active que les boutons...vu qu'elles st dja affichées
				$('BtAmToday').addClassName('btnMatinSelected');
				$('BtAmTomorrow').addClassName('btnMatinSelected');
				$('BtAmAfterTomorrow').addClassName('btnMatinSelected');
			}
		}
	},
	switchCarte:function(idCarteAm,idCartePm,idBtAm,idBtPm,source){
		if((!$(idCarteAm).visible() && source == "am") || (!$(idCartePm).visible() && source == "pm")){
			if($(idCarteAm).visible()){
				new Effect.Fade(idCarteAm,{ queue: { position: 'front', scope: 'showCarte' } });
				new Effect.Appear(idCartePm,{ queue: { position: 'end', scope: 'showCarte' } });
				
				//> add / remove CSS class des boutons
				$(idBtAm).removeClassName('btnMatinSelected');
				$(idBtPm).addClassName('btnApresmidiSelected');			
			}
			else{
				new Effect.Fade(idCartePm,{ queue: { position: 'front', scope: 'showCarte' } });
				new Effect.Appear(idCarteAm,{ queue: { position: 'end', scope: 'showCarte' } });
	
				//> add / remove CSS class des boutons
				$(idBtAm).addClassName('btnMatinSelected');
				$(idBtPm).removeClassName('btnApresmidiSelected');			
			}			
		}
	},
	//> création du calque
	createLayer:function(){
		if(!$(this.idLayer)){
			var globalD = $('Global').getDimensions();
			var hLayer = globalD.height;

			new Insertion.Top(document.body, '<div id="'+this.idLayer+'" class="layerPromoNewsletter"><div id=\"LayerNewsContener\" class=\"contener\"></div></div>');
			$(this.idLayer).setStyle({'width':'100%','height':hLayer+'px'});
			
			var img1 = new Element('img',{'src':'/library/img/encart-inscription/decouvrez_newsletter.png'});
			var img2 = new Element('img',{'src':'/library/img/encart-inscription/refus.png','id':'imgRefus','class':'link'});
			var img3 = new Element('img',{'src':'/library/img/encart-inscription/accept.png','id':'imgAccept','class':'link'});	
			
			$('LayerNewsContener').insert(img1);
			$('LayerNewsContener').insert(img2);
			$('LayerNewsContener').insert(img3);
			
			$('imgRefus').observe('click',function(){new Effect.Fade(this.idLayer);}.bind(this));
			$('imgAccept').observe('click',function(){window.location.replace('/inscription.aspx?p=flashHome');});
		}
	},
	//> ctéation du cookie
	createCookie:function(){
		date=new Date;
		date.setMonth(date.getMonth()+1); // expire dans un mois
		ecrireCookie(this.nameCookie, "ok", date);		
	},
	//> ajoute les toolTips à la galerie
	initGalerie:function(){
		$$('div.vignette img').each(function(e){
										if(e && e.alt != "")
											new Tip(e,e.alt,{ style:'protogrey',width: 'auto'});
									});
	}	,
	//> Fonction pour afficher un popup sur une page
	show_popup:function(url,name)
    {
      win = window.open (url, name, config='height=300, width=500, toolbar=no, menubar=no,scrollbars=no, resizable=no, location=no, directories=no, status=no');
	  win.blur();
	  window.focus();
    }
	
	
}