/*gestion de larborescence en javascript*/
Event.observe(window, 'load', function() {
									   
	var etatPresentationSite = 0 ; //indique sur le cadre noir est affiche

	function apercuSite() {
		
		$$('.elementSiteVis').each(function(element) {
			//recuperation des infos pour ce site
			element.observe('click', function() {
					var idSite = element.down('.idSite').value ;
					var idSiteUtilisateur = element.down('.idSiteUtilisateur').value;
					var idUtilisateur = $('idUser').value ;
					var idIkodz = $('id_ikodz').value;
					
					new Ajax.Request('../includus/php/arborescence_action.php', {
						method : 'post',
						parameters : 'modeAjax=1&idSiteUtilisateur='+idSiteUtilisateur+'&idUser='+idUtilisateur+'&idSite='+idSite+'&id_ikodz='+idIkodz+'&typeModule=3',
						onComplete: function(transport) {
							if(transport.responseText!=null) {
								if(etatPresentationSite==0) {
									$('apercuSite').innerHTML =  transport.responseText ;
									new Effect.Appear('apercuSite', { duration: '0.5'} );
									etatPresentationSite = 1 ;
									closeApercuSite();
								} else {
									$('apercuSite').innerHTML =  transport.responseText ;
									closeApercuSite();
								}
							}
						}
					});
			});
										 
		});
	}
	
	function closeApercuSite() {
		$('closeSiteApercu').observe('click', function() {
			new Effect.Fade('apercuSite', {from: '1', to:'0', queue:'front' });
			etatPresentationSite = 0 ;   
		});
	}
	
	/*remise des paramètres photo ou couleur background ainsi que la transparence */
	function parametresHome() {
		//recuperation des paramètres (transparence et background
			backgroundValue = $('valueBackground').value ;
			transparenceValue = $('valueTransparence').value ;
			
			$$('.elementSiteVis').each( function(element) {
				new Effect.Opacity(element.id,{ from: '0.5', to: transparenceValue });				 
			});
			$$('.elementSiteVoidVis').each( function(element) {
				new Effect.Opacity(element.id,{ from: '0.5', to: transparenceValue });				 
			});
			
			//modifiaciton de larire plan 
			if(backgroundValue=='../user/backgroundIkodz/defaut.jpg') {
				
			} else if(backgroundValue=='#FFFFFF') {
				
			} else if(backgroundValue.length>7) {
				$('body').setStyle({ backgroundImage: 'url('+backgroundValue+')', backgroundPosition: 'center', backgroundAttachment: 'fixed', backgroundRepeat: 'no-repeat' });
				$('blocHaut').setStyle({ backgroundImage: 'url(../user/background_ikodz/defaut.png)', backgroundPosition: 'center', backgroundAttachment: 'fixed', backgroundRepeat: 'no-repeat'  });
			} else {
				$('body').setStyle({ backgroundColor: backgroundValue, backgroundImage: 'none', backgroundAttachment: 'fixed', backgroundPosition: 'center', backgroundRepeat: 'no-repeat' });
				$('blocHaut').setStyle({ backgroundImage: 'url(../user/background_ikodz/defaut.png)', backgroundPosition: 'center', backgroundAttachment: 'fixed', backgroundRepeat: 'no-repeat'  });
			}
				
			
	}
	
	
	function googleMaps() {
		
		var lattitude = $('lattitudeIkodz').value;
		var longitude = $('longitudeIkodz').value;
		
		if(lattitude!=0 && longitude!=0) {
			var map = new GMap2($('map')); 
				map.setCenter(new GLatLng(lattitude, longitude), 8);
				map.setMapType(G_NORMAL_MAP);
				map.addControl(new GSmallMapControl());
				pMarker = new GMarker(new GLatLng(lattitude, longitude));
				map.addOverlay(pMarker);
		} else {
			var map = new GMap2($('map')); 
				map.setCenter(new GLatLng(48.833, 2.333), 3);
				map.setMapType(G_NORMAL_MAP);
		}
	}		

	
	parametresHome(); // remet les paramètres de lespace 
	apercuSite();
	googleMaps();

});
	
