/********************************Normal View***********************************
**Normal display of the widget on :********************************************
**Igoogle, Netvibes, Facebook, Firefox, Myspace, Vista (expand mode), Mac OSX.*
*******************************************************************************/


//Replace nomduwidget by a short abreviation of the widget
var meteoView = {
	
	autoplay: false,
	tabTemplate : [],
	tabVille : '',
	maVille : '',
	tabInfoVille : [],
	maxVille : 4,
	divRecherche : true,
	fxRecherche : [],
	fxRecherche2 : null,
	
	//Widget initialization	
	widgetLoaded : function () {
		//feedvalue
		if(CWE.target=="google"){
			fv_createAdLink('fv_campaign_ad')
		}
		
		// sauvegarde les templates
		meteoView.saveTemplate();
		// accueil
		$('mainbutton').addEvent('click',function(){
			if( CWE.getValue('idville') && CWE.getValue('idville').split('|').length>0 )
			{
				meteoView.createSlideshow();
			}else if ( CWE.getValue('idville') && CWE.getValue('idville')!='' && CWE.getValue('idville')!=' '){
				// load
				meteoView.loadTemplate();
			}
		})		
		// About
		CWE.callAjax(config.path + config.templatespath + 'about.html',function (response) {
			CWE.setAbout(response);
			$$("#aboutContent .aboutInstallButton").each(function(e){
				var platform = e.id.split('_')[1];
				if (platform == "firefoxsidebar" && !window.sidebar) {
					e.innerHTML="firefox";
				}else {
					CWE.createInstallLink(platform).injectInside(e);
				}
			})  
		});
		// Parametre
		CWE.createTab('Option(s)', $('divPortefeuille'), 'tabedit').addEvent('click',meteoView.createPortefeuille);
		//
		if(CWE.getValue('autoplay'))
			meteoView.autoplay = CWE.getValue('autoplay');
		// recupere les id des villes sauvegardees
		if ( CWE.idville || CWE.getValue('idville')) { 
			if (CWE.idville) {
				meteoView.tabVille = CWE.idville;
			}else{
				meteoView.tabVille = CWE.getValue('idville');
			}
			meteoView.tabVilleLength = meteoView.tabVille.split('|').length;
			meteoView.tabVille.split('|').each(function(id,i){
				if(i<meteoView.maxVille)
					meteoView.trouverInfo(id, true, true);
			});
		}	
		// ajout evenement sur clique du bouton recherche
		meteoView.fxRecherche[0] =new Fx.Style($('formulaire'),'top',{
			duration: 300,
			wait: false
		});
		meteoView.fxRecherche[1] =new Fx.Style($('voileNoir'),'opacity',{
			duration: 300,
			wait: false
		});
		// recuperation localité
		CWE.getGeoInfo(function(obj){
			meteoView.maVille = obj.city;
			if( obj.city!=null ){
				CWE.setModalMaskContent('Nous avons détecté que<br />vous êtes à proximité de "'+obj.city+'",<br/>veuillez confirmer ce choix.<br/>(Cliquez sur le fond pour fermer.)');
			}else{
				CWE.setModalMaskContent('Veuillez sélectionner votre ville en effectuant une recherche.<br/>(Cliquez sur le fond pour fermer.)');
			}
			$E('.feWidgetMask').addEvent('click', function(event){ 
				CWE.hideModalMask(); 
			});
			// ouverture du formulaire si aucune ville sauvegardee		
			if( !CWE.idville && (!CWE.getValue('idville') || (CWE.getValue('idville') && CWE.getValue('idville')==''))  ) {
				CWE.showModalMask();
				//
				if( obj.city!=null ){				
					$('txtRecherche').value = obj.city;
					$('bnTrouver').addClass('actif');
					meteoView.trouverVille();
				}else{
					meteoView.fxRecherche[0].start(-60, 15);
					meteoView.fxRecherche[1].start(0, 0.7);
					$('recherche').setHTML('Fermer la rechercher <<');
					meteoView.divRecherche = !meteoView.divRecherche;
				}
				CWE.hideModalMask.delay(10000,CWE);				
			}				
		});	
		$('recherche').addEvent('click',function(){
			$('voileNoir').setStyle('height',$('cweMainBody').scrollHeight);
			if ( meteoView.divRecherche ) {
				$('txtRecherche').focus();
				meteoView.fxRecherche[0].start(-60, 15);
				meteoView.fxRecherche[1].start(0, 0.7);				
				$('recherche').setHTML('<img width="12px" height="12px" src="./media/img/system-search-grey.png"/> Fermer la rechercher <<');
			} else {
				meteoView.fxRecherche[0].start(15, -60);
				meteoView.fxRecherche[1].start(0.7, 0);
				$('recherche').setHTML('<img width="12px" height="12px" src="./media/img/system-search-grey.png"/> Cliquer pour rechercher >>');
			}
			meteoView.divRecherche = !meteoView.divRecherche;
		});	
		$('txtRecherche').setProperty("value",recherche);
		// ajout de l'evenement sur le clique du bouton trouver
		$('bnTrouver').addEvent('click',function(){
			if (this.className == "actif") {
				// simulation de clique sur le bouton trouver
				$('recherche').fireEvent('click');
				meteoView.trouverVille();
			}
		});
		$('txtRecherche').addEvent('keyup',function(key){
			var chaine = $('txtRecherche').value;
			var reg = new RegExp("[a-zA-Z0-9]","g");
			if (chaine.match(reg)) {
				$('bnTrouver').addClass('actif');
				if( key.keyCode==13 )
					$('bnTrouver').fireEvent('click');
			} else {
				$('bnTrouver').removeClass('actif');
			}
		});
	},
	
	// recupere les villes
	trouverVille : function (){
		// affiche la div des listes 
		$('divListeRecherche').setStyle('display','block');
		// cache la div info 
		$('divInfoMultiple').setStyles({
		'top':'-5000px'
		,'visibility':'hidden'
		});
		$('divInfoSimple').setStyle('display','none');
		$('divInfoMultiple').setStyle('display','none');
		// recuperer xml
		CWE.callAjax('http://widget.info-meteo.fr/search.php?u=e5a96b12e0c6febd9c039918aebf555c&q='+$('txtRecherche').value,function(xml){
			try{
				if (xml.getElementsByTagName('region')[0].firstChild)
					$('titreListeRecherche').setHTML('<span class="bold">0</span> Résultat(s) pour <span class="bold">'+CWE.encodeHTMLEntities($('txtRecherche').value)+'</span> : <img src="./media/img/favourites_small.gif" /> <span class="bold">Reste <span id="resteVille">'+(meteoView.maxVille-meteoView.tabInfoVille.length)+'</span> ville(s)</span>');
					$('listeRecherche').setHTML('&nbsp;&nbsp;&nbsp;&nbsp;Aucun résultat, veuillez effectuer une autre recherche.');
			}catch(e){
				var li = '';
				var nbRes = xml.getElementsByTagName('ville').length; 
				for(var i=0;i<nbRes;i++){
					var id = xml.getElementsByTagName('ville')[i].getAttribute('id');
					var ville = xml.getElementsByTagName('ville')[i].firstChild.nodeValue;
					var cp = xml.getElementsByTagName('ville')[i].getAttribute('cp');
					if( cp.length==4 )
						cp = '0'+cp;
					if (meteoView.tabVille.indexOf(id, 0) == -1) {
						if (meteoView.tabVille.split('|').length >= meteoView.maxVille) 
							var img = ' <img id="img' + id + '" class="removeAdd" src="./media/img/list-add.png" title="" width="15px" height="15px" />';
						else 
							var img = ' <img id="img' + id + '" class="add" src="./media/img/list-add.png" title="Ajouter à mes favoris" width="15px" height="15px" />';
						li += '<li>'+img+' <span id="li'+id+'" title="Voir la météo">'+ville+' ['+cp+']</span> <span id="mess'+id+'"></span></li>';
					} else {
						var img = ' <img id="img' + id + '" class="supp" src="./media/img/list-remove.gif" title="Supprimer de mes favoris" width="15px" height="15px" />';
						li = '<li>'+img+' <span id="li'+id+'" title="Voir la météo">'+ville+' ['+cp+']</span> <span id="mess'+id+'"></span></li>'+li;
					}				
				}
				$('titreListeRecherche').setHTML('<img src="./media/img/favourites_small.gif" /> <span class="bold">Vous pouvez encore sauvegarder <span id="resteVille">'+(meteoView.maxVille-meteoView.tabInfoVille.length)+'</span> ville(s).</span><br /><span class="bold">'+nbRes+'</span> Résultat(s) pour <span class="bold">'+CWE.encodeHTMLEntities($('txtRecherche').value)+'</span> :');
				$('listeRecherche').setHTML('<ul>'+li+'</ul>');
				// ajout evenement sur le bouton carrousel
				$('lienSlideshow').addEvent('click',function(){
					meteoView.createSlideshow();
				});
				if( !CWE.getValue('idville') || CWE.getValue('idville').split('|').length == 0 )
					$('lienSlideshow').setStyle('display','none');
				else 
					$('lienSlideshow').setStyle('display','block');
				// ajout evenement click sur les images des balise li			
				$$('#divListeRecherche li img').addEvent('click',function(){
					// si le bouton est un bouton add
					if (this.className == 'add') {
						var id = this.getAttribute('id').replace('img', '');
						// si le nombre de ville est au max	
						if (CWE.getValue('idville') && CWE.getValue('idville').split('|').length >= (meteoView.maxVille - 1)) {
							// sauvegarde la ville
							CWE.setValue('idville', CWE.getValue('idville') + '|' + id);
							meteoView.tabVille = CWE.getValue('idville');
							meteoView.trouverInfo(id,true,false);
							// supprime tous les images ajout
							$$('#divListeRecherche li .add').each(function(img){
								img.removeClass('add').addClass('removeAdd');
								img.title='';
							});
						} else {
							// sauvegarde la ville
							if (CWE.getValue('idville')) 
								CWE.setValue('idville', CWE.getValue('idville') + '|' + id);
							else 
								CWE.setValue('idville', id);
							meteoView.tabVille = CWE.getValue('idville');
							meteoView.trouverInfo(id,true,false);
						}
						// change l'image
						$(this.getAttribute('id')).setProperties({
							'src': './media/img/list-remove.gif',
							'class': 'supp'
						});
						$(this.getAttribute('id')).title = 'Supprimer de mes favoris';
						$('mess'+id).setHTML('<img src="./media/img/favourites_small.gif"/>');
						$('mess'+id).setHTML.delay(1000,$('mess'+id),['']);
					} else if (this.className == 'supp') {// si le bouton est un bouton supp
						var id = this.getAttribute('id').replace('img', '');
						// delete la ville
						meteoView.tabVille = CWE.getValue('idville'); 
						meteoView.tabVille = meteoView.tabVille.replace(id+'|','');
						meteoView.tabVille = meteoView.tabVille.replace('|'+id,'');
						meteoView.tabVille = meteoView.tabVille.replace(id,'');
						CWE.setValue('idville', meteoView.tabVille);
						meteoView.tabVille = CWE.getValue('idville');
						meteoView.deleteInfo(id);
						// change l'image
						$(this.getAttribute('id')).setProperties({
							'src': './media/img/list-add.png',
							'class': 'add'
						});
						$(this.getAttribute('id')).title = 'Ajouter à mes favoris';
						// rajoute les images ajout
						$$('#divListeRecherche li .removeAdd').each(function(img){
							img.removeClass('removeAdd').addClass('add');
							img.title = 'Ajouter à mes favoris';
						});		
						$('mess'+id).setHTML('');				
					}
					// info nb ville restante
					$('resteVille').setHTML(meteoView.maxVille-CWE.getValue('idville').split('|').length);
					// affiche / cache lien vers le carrousel											
					if( !CWE.getValue('idville') || CWE.getValue('idville').split('|').length == 0 )
						$('lienSlideshow').setStyle('display','none');
					else 
						$('lienSlideshow').setStyle('display','block');					
				});
				// ajout evenement click sur les balise li
				$$('#divListeRecherche li span').addEvent('click',function(){
					// load
					meteoView.loadTemplate();
					// cache la div des listes 
					$('divListeRecherche').setStyle('display','none');
					// affiche la div info 
					$('divInfoSimple').setStyle('display','block');
					// cache la div info 
					$('divInfoMultiple').setStyle('display','none');
					// affichage des infos
					$('InfoSimple').setHTML('');
					meteoView.trouverInfo(this.getAttribute('id').replace('li',''),false,false);
				});	
			}	
		}, true);		
	},
	
	// recupere les infos d'une ville
	trouverInfo : function (id,save,carrousel){	
		// recuperer xml
		CWE.callAjax('http://widget.info-meteo.fr/search.php?u=e5a96b12e0c6febd9c039918aebf555c&id='+id,function(xml){
			var date = xml.getElementsByTagName('date')[0].firstChild.nodeValue.split(' ')[0].split('-');
			date =  i18n.getDate(new Date(date[0],date[1]-1,date[2]));
			var ville = xml.getElementsByTagName('meteo')[0].getElementsByTagName('ville')[0].firstChild.nodeValue;
			var cp = xml.getElementsByTagName('meteo')[0].getElementsByTagName('cp')[0].firstChild.nodeValue;
			var ico = xml.getElementsByTagName('meteo')[0].getElementsByTagName('ico')[0].firstChild.nodeValue;
			ico = ico.replace('http://www.info-meteo.fr/images/icons/','./media/icone/');
			var temperature = xml.getElementsByTagName('meteo')[0].getElementsByTagName('temperature')[0].firstChild.nodeValue;
			var uniteTemperature = xml.getElementsByTagName('meteo')[0].getElementsByTagName('temperature')[0].getAttribute('unite');
			var description = xml.getElementsByTagName('meteo')[0].getElementsByTagName('description')[0].firstChild.nodeValue;
			var ventDir = replacePTCardinaux(xml.getElementsByTagName('meteo')[0].getElementsByTagName('ventdir')[0].firstChild.nodeValue);
			var ventVit = xml.getElementsByTagName('meteo')[0].getElementsByTagName('ventvit')[0].firstChild.nodeValue;
			var uniteVentVit = xml.getElementsByTagName('meteo')[0].getElementsByTagName('ventvit')[0].getAttribute('unite');
			
			var HTML = '';
			HTML += '<div class="slide">';
			HTML += '<div class="ligOne"><span class="ville">'+ville+' ['+cp+']</span>';
			HTML += '<span class="temperature">'+temperature+'°'+uniteTemperature+'</span></div>'; 
			HTML += '<div class="ligSecond">';
			HTML += '<img class="imgLigSecond" src="'+ico+'" width="72px" height="72px" />';
			HTML += '<div class="description"><span id="date">'+date+'</span><br />'+description+'<br />';
			HTML += 'Vent : '+ventDir+' à '+ventVit+uniteVentVit+'</div>';
			HTML += '</div></div>';
			
			$('InfoSimple').setHTML(HTML);
			// si on sauvegarde les infos
			if (save) {
				meteoView.tabInfoVille.push([id, date, ville, ico, temperature, uniteTemperature, description, ventDir, ventVit, uniteVentVit, cp]);
			}
			if (carrousel) {
				meteoView.tabVilleLength--;
				if(meteoView.tabVilleLength==0)
					meteoView.createSlideshow();
			}
			if (save == false && carrousel == false) {
				// ajout evenement sur le bouton carrousel
				$('lienSlideshow2').addEvent('click', function(){
					meteoView.createSlideshow();
				});
				// ajout evenement sur le bouton sauvegarder			
				$E('.lienAjouter').id = 'save'+id;
				$E('.lienAjouter').addEvent('click', function(){
					$('lienSlideshow2').setStyle('display', 'block');
					// si le nombre de ville est au max	
					if (CWE.getValue('idville') && CWE.getValue('idville').split('|').length >= (meteoView.maxVille - 1)) {
						this.setStyle('display', 'none');
						// sauvegarde la ville					
						var id = this.getAttribute('id').replace('save', '');
						CWE.setValue('idville', CWE.getValue('idville') + '|' + id);
						meteoView.tabVille = CWE.getValue('idville');
						meteoView.trouverInfo(id, true, false);
					} else {							
						// sauvegarde la ville
						var id = this.getAttribute('id').replace('save', '');
						if (CWE.getValue('idville')) 
							CWE.setValue('idville', CWE.getValue('idville') + '|' + id);
						else 
							CWE.setValue('idville', id);
						meteoView.tabVille = CWE.getValue('idville');
						meteoView.trouverInfo(id, true, false);
						// afficher une info bulle
						meteoView.fxRecherche2 = new Fx.Style(this,'opacity',{
							duration: 500,
							wait: false
						});
						setTimeout('meteoView.fxRecherche2.start(1,0)',meteoView.fxRecherche2.options.duration*10);
						this.setHTML(ville+' a été ajouté à vos villes favorites').addClass('text');
					}
					//
				});		
				if ( meteoView.tabVille=='' ) {				
					$('lienSlideshow2').setStyle('display', 'none');
					$('save' + id).setStyle('display', 'block');
				} else if ( meteoView.tabVille!='' && meteoView.tabVille.split('|').length>0 && meteoView.tabVille.split('|').length<meteoView.maxVille && meteoView.tabVille.indexOf(id, 0) != -1 ) {				
					$('lienSlideshow2').setStyle('display', 'block');
					$('save' + id).setStyle('display', 'none');
				} else if ( meteoView.tabVille!='' && meteoView.tabVille.split('|').length>0 && meteoView.tabVille.split('|').length<meteoView.maxVille && meteoView.tabVille.indexOf(id, 0) == -1 ) {
					$('lienSlideshow2').setStyle('display', 'block');
					$('save' + id).setStyle('display', 'block');			
				}else{				
					$('lienSlideshow2').setStyle('display', 'block');
					$('save' + id).setStyle('display', 'none');
				}
			}
		}, true);		
	},
	
	// supprimer ville
	deleteInfo : function (id){
		var i = 0;
		var trouvee = false;
		while(i<meteoView.tabInfoVille.length && !trouvee){
			if( meteoView.tabInfoVille[i][0] == id ){
				trouvee = true;
				meteoView.tabInfoVille.splice(i,1);
			}
			i++;
		}
	},
	
	// creation du slideshow
	createSlideshow : function() {
		// cache la div des listes 
		$('divListeRecherche').setStyle('display','none');
		// caches la div des infos
		$('divInfoSimple').setStyle('display','none');
		// affiche la div carrousel		
		$('divInfoMultiple').setStyle('display','block');
		$('divInfoMultiple').setStyles({
			'top':'0px'
			,'visibility':'visible'
		});
		//meteoView.tabInfoVille.push([id,date,ville,ico,temperature,uniteTemperature,description,ventDir,ventVit,uniteVentVit,cp]);	
		// creation du html		
		var HTML = '';
		var thumbsHTML = '';
		var items = [];
		
		meteoView.tabVille.split('|').each(function(villeInit,i){
			meteoView.tabInfoVille.each(function(ville,i){
				if(ville[0]==villeInit){
					HTML += '<div id="slide'+ville[0]+'" class="slide">';
					HTML += '<div class="ligOne"><span class="ville">'+ville[2]+' ['+ville[10]+']</span>';
					HTML += '<span class="temperature">'+ville[4]+'°'+ville[5]+'</span></div>';
					HTML += '<div class="ligSecond">';
					HTML += '<img class="imgLigSecond" src="'+ville[3]+'" width="72px" height="72px" />';
					HTML += '<div class="description"><span id="date">'+ville[1]+'</span><br />'+ville[6]+'<br />';
					HTML += 'Vent : '+ville[7]+' à '+ville[8]+ville[9]+'</div>';
					HTML += '</div></div>';
					
					thumbsHTML += '<td id="thumbnails'+ville[0]+'" class="thumbnails">';
					thumbsHTML += '<table id="thumbs2" title="'+ville[2]+' ['+ville[10]+']"><tr><td class="tdImg" style="background: url('+ville[3].replace('./media/icone/','./media/icone/m')+') no-repeat 50% 35%;">'+ville[4]+'°'+ville[5];
					thumbsHTML += '</td>';
					thumbsHTML += '<td class="tdVille">'+ville[2]+'</td></tr></table>';
					thumbsHTML += '</td>';
					
					items.push(i);					
				}
			});
		});		
		$('slideShowScreen').setHTML(HTML);
		$('maskThumbs').setHTML('<table id="thumbs"><tbody><tr id="trThumbs">'+thumbsHTML+'</tr></tbody></table>');
		// creation du slideshow
		var slideW = $('content').offsetWidth;
		if( meteoView.slideShow ) 
			meteoView.slideShow.stop()
		meteoView.slideShow = new Fuic.Slideshow ({
			'box': $('slideShowScreen')
			,'items': items
			//,'handles' : $$('#thumbs .thumbnails')
			,'handle_event': 'click'
			,'handleToCarroussel' : false
			,'handles' : $('trThumbs').getChildren()
			//,'handleSize' : Math.floor(slideW/4)
			,'nbVisibleThumbs' : 4
			,'size': 200
			,'interval':5000
			,'autoPlay': meteoView.autoplay
			,'saveState': true
			,'mode':'vertical'
			,'buttons': {
				'play':$('play')
				,'stop':$('stop')
			}
		});
		meteoView.tab2init=true;	
		//
		$('play').addEvent('click',function(){
			$('play').setStyle('display', 'none');
			$('stop').setStyle('display', 'block');
		});
		$('stop').addEvent('click',function(){
			$('play').setStyle('display', 'block');
			$('stop').setStyle('display', 'none');
		});
		if (meteoView.autoplay) {
			$('play').fireEvent('click');
		}else{
			$('stop').fireEvent('click');
		}
		// affiche ou cacher le bouton play/stop si une ville
		if( meteoView.autoplay && meteoView.tabInfoVille.length==1 ){
			$('stop').setStyle('display', 'none');
		}else if( meteoView.autoplay===false && meteoView.tabInfoVille.length==1 ){
			$('play').setStyle('display', 'none');
		}
	},
	
	// creation de la page portefeuille
	createPortefeuille : function (){
		var HTML = '';
		if (meteoView.tabInfoVille.length > 0) {
			//meteoView.tabInfoVille.push([id,date,ville,ico,temperature,uniteTemperature,description,ventDir,ventVit,uniteVentVit,cp]);
			meteoView.tabInfoVille.each(function(ville, i){
				HTML += '<li id="port' + ville[0] + '"><img class="supp" src="./media/img/list-remove.gif" width="15px" height="15px" /> ' + ville[2] + ' ['+ville[10]+']</li>';
			});
			$('listePortefeuille').setHTML('<ul>' + HTML + '</ul>');
			$$('#divPortefeuille li').addEvent('click', function(){
				var id = this.getAttribute('id').replace('port', '');
				// delete la ville
				meteoView.tabVille = CWE.getValue('idville');
				meteoView.tabVille = meteoView.tabVille.replace(id + '|', '');
				meteoView.tabVille = meteoView.tabVille.replace('|' + id, '');
				meteoView.tabVille = meteoView.tabVille.replace(id, '');
				CWE.setValue('idville', meteoView.tabVille);
				meteoView.tabVille = CWE.getValue('idville');
				meteoView.deleteInfo(id);
				if( CWE.getValue('idville')=='' ) {
					//  
					CWE.showModalMask();
					CWE.hideModalMask.delay(10000,CWE);
					if( meteoView.maVille!=null ){
						$('txtRecherche').value = meteoView.maVille;
						$('bnTrouver').addClass('actif');
						meteoView.trouverVille();
					}else{
						meteoView.fxRecherche[0].start(-60, 15);
						meteoView.fxRecherche[1].start(0, 0.7);
						$('recherche').setHTML('Fermer la rechercher <<');
						meteoView.divRecherche = !meteoView.divRecherche;
					}
					$('listeRecherche').setHTML('');
					$('mainbutton').fireEvent('click');
				}else{
					if( $('slide' + id) )					
						$('slide' + id).remove();
					if( $('thumbnails' + id) )
						$('thumbnails' + id).remove();
					if( meteoView.slideShow ){
						meteoView.slideShow.reset({
							'items': $('slideShowScreen').getChildren()
							,'autoPlay' : meteoView.slideShow.isPlaying()
							,'handles' : $('trThumbs').getChildren()
						});
					}					
				}
				// suppression de l'element
				this.remove();
				// affiche ou cacher le bouton play/stop si une ville
				if( meteoView.autoplay && meteoView.tabInfoVille.length==1 ){
					$('stop').setStyle('display', 'none');
				}else if( meteoView.autoplay===false && meteoView.tabInfoVille.length==1 ){
					$('play').setStyle('display', 'none');
				}			
			});
		}else{
			$('listePortefeuille').setHTML('<img src="./media/img/dialog-information.png" width="15px" height="15px" /> Vous n\'avez sauvegardé aucune ville.');
		}
	},
	
	// 
	saveTemplate : function(){
		meteoView.tabTemplate['divListeRecherche'] = $('divListeRecherche').innerHTML;
		meteoView.tabTemplate['divInfoSimple'] = $('divInfoSimple').innerHTML;
		meteoView.tabTemplate['divInfoMultiple'] = $('divInfoMultiple').innerHTML;
		meteoView.tabTemplate['divPortefeuille'] = $('divPortefeuille').innerHTML;
	},
	
	// 
	loadTemplate : function(){
		$('divListeRecherche').setHTML(meteoView.tabTemplate['divListeRecherche']);
		$('divInfoSimple').setHTML(meteoView.tabTemplate['divInfoSimple']);
		$('divInfoMultiple').setHTML(meteoView.tabTemplate['divInfoMultiple']);
		$('divPortefeuille').setHTML(meteoView.tabTemplate['divPortefeuille']);
	},
	
	//Facebook button URL
	changeFacebookButton:function() {
		CWE.setAdderButtonUrl('button_facebook',facebookUrl);
	},
	
	//iGoogle button URL
	changeIgoogleButton:function() {
		CWE.setAdderButtonUrl('button_igoogle',igoogleUrl);
	}
	
	
	//Tabs initialization
	/*initOnglets:function() {
		$('ongletExemple').addEvent('click', function() {
			meteoView.loadTemplate(meteoExemple, false, true);
			meteoView.changeOngletColor('ongletExemple');
		});
		
		$('ongletExemple2').addEvent('click', function() {
			meteoView.loadTemplate(meteoExemple2, false, true);
			meteoView.changeOngletColor('ongletExemple2');
		});
	},*/
	
	
	//Changement d'onglet
	/*changeOngletColor:function(selected) {
		$('ongletExemple').setProperties({'class' : 'onglet', 'style' : ''});
		$('ongletExemple2').setProperties({'class' : 'onglet', 'style' : ''});
		$(selected).setProperties({'class' : 'ongletselected', 'style' : ''});
	},*/
	
	
	//Chargement d'une template
	/*loadTemplate:function(template, xml, loading) {

		if (loading) {
			$(template.view).setHTML(config.loader);
		}
		CWE.callAjax(template.url, function (response) {
			
			config.maview = template;
			
			if (!xml) {			
				var f = new Fx.Style($(template.view),'opacity',{duration: 300, wait: true, transition: Fx.Transitions.Sine.easeIn});
	 			f.start(0.0);
	   			$(template.view).setHTML.delay(300, $(template.view), response);
	   			f.start.delay(310,f,1.0);
				f.start.delay(510,f,1.0);

				meteoView.changeOngletColor.delay(310, meteoView, template.button);
				meteoView.changeOngletColor.delay(510, meteoView, template.button);
			}

		}, xml);
	},
	
	//Bookmark verification
	isBookmarked:function(title) {
		var find = false;
		CWE.bookmarks.each(function(item, i) {
			if(item!=null) {
				if (item.title==title) {
					find = true;
				}
			}
		});
		return find;
	},
	
	
	//About generation
	generateAbout:function() {
		var ab = new Element('div');
	
  		CWE.callAjax(about.url, function (response) {
   			ab.setHTML(response);
   			CWE.setAbout(ab);
   			//$('aboutboxbutton').injectInside('widgetcontent').addClass('buttonapropos').setStyle('background-color' , '#524842');
   			$('aboutpanel').setStyles({'background-color': '#FFFFFF', 'padding-left' : '5px'});
   			
	   		$('aboutboxbutton').addEvent('click', function() {
	  			//$('widget').getParent().setStyle('display', 'none');
	  		});
	 		$('versions').setStyles({'float' : 'left', 'width' : '100%', 'margin-top': '10px', 'font-size': '10px', 'font-style': 'normal'});
  	
	 		var racine = window.location.protocol+'//'+window.location.hostname+window.location.pathname.substr(0,window.location.pathname.indexOf('/',1));
	 		var location = window.location.protocol+'//'+window.location.hostname;
			var ur = racine.replace(/(http:\/\/)/g,"");
			ur += "/";
			ur = ur.replace(/(\/)/g,"_cwe_slashes_");
			$('firefox').setProperty('onclick','javascript:window.sidebar.addPanel("'+document.title+'","'+location+'/index.php/cwe/ffsidebar/'+ur+'","")');
			$('facebook').setProperty('href','http://www.facebook.fr');	
			$('facebook').setProperty('target','_blank');						
			$('igoogle').setProperty('href','http://www.google.com/ig/adde?source=atgs&moduleurl='+window.location.hostname+'/index.php/cwe/google/'+ur);
			$('igoogle').setProperty('target','_blank');
			$('netvibes').setProperty('href','http://www.netvibes.com/subscribe.php?uwa='+location+'/index.php/cwe/uwa/'+ur);
			$('netvibes').setProperty('target','_blank');
			$('vista').setProperty('href',location+'/index.php/cwe/desktop/vista?widget='+racine);
			$('iphone').setProperty('href',location+'/index.php/cwe/iphone/'+ur);
			$('iphone').setProperty('target','_blank');
			
			$('aboutpanel').setStyle('width', '98%');
  		});
	}*/
}