
window.addEvent('domready', function() {						 

	/*
	$$('input').addEvents({
		'focus': function(el){ this.addClass('hover');},
		'blur': function(el){ this.removeClass('hover');}
	});
	*/
	$$('.delete').addEvent('click', function(ev){
			if( !confirm("Etes-vous sûr de vouloir supprimer ?") ) { new Event(ev).stop(); return; } });
	
	if( $('formLogin') ) {
		$('clogin').addEvents({	
			'focus': function() {
				if(this.value=='identifiant') 
					this.value='';			
			},	
			'blur': function() {
				if(this.value=='') 
					this.value = 'identifiant';			
			}
				
		});
		
		$('cmdp').addEvents({	
			'focus': function() {
				if(this.value=='********') 
					this.value='';			
			},	
			'blur': function() {
				if(this.value=='') 
					this.value = '********';			
			}
				
		});	
	}
	
	$$('.external').addEvent('click', function(ev){
		window.open(this.href); new Event(ev).stop(); return;
	});	
	
	//ReMooz.assign('.remooz');
	
	
	if( $('search') ) {
	
		var customTips = $$('.imgTip');
		var toolTips = new Tips(customTips);
		
		//toolTips.attach('#img1');

	}
	
	if( $('louer-hp') ) {
		
		$('louer-hp').addEvents({
			'mouseover' : function(){
				$('acheter-hp').fade(0.3);
			},
			'mouseout' : function(){
				$('acheter-hp').fade(1);
			}
		});
			
		$('louer-hp-texte').addEvent('mouseover', function(){
				$('acheter-hp').fade(0.3);
		});
		$('proprietaire-hp-texte').addEvent('mouseover', function(){
				$('acheter-hp').fade(0.3);
		});
		
		$('acheter-hp').addEvents({
			'mouseover' : function(){
				$('louer-hp').fade(0.3);
			},
			'mouseout' : function(){
				$('louer-hp').fade(1);
			}
		});
		$('acheter-hp-texte').addEvent('mouseover', function(){
				$('louer-hp').fade(0.3);
		});
	}
	
	
	if( $('annonces') ) {
		if( !$('annonces').hasClass('alerte') ){
			if( $('annonces').hasClass('location') ){
				$('acheter-bandeau').fade(0.3);
			}else {
				$('louer-bandeau').fade(0.3);
			}
		}
	}
	
	if( $('acheter-bandeau') ) {
		
		$('acheter-bandeau').addEvents({
			'mouseover' : function(){
				$('acheter-bandeau').fade(1);
				$('louer-bandeau').fade(0.3);
			},
			'mouseout' : function(){
				//$('louer-bandeau').fade(1);
				if( $('annonces') ) {
					if( $('annonces').hasClass('location') ){
						$('acheter-bandeau').fade(0.3);
						$('louer-bandeau').fade(1);
					}
				}else {
					$('louer-bandeau').fade(1);
				}
			}
		});
		
		$('louer-bandeau').addEvents({
			'mouseover' : function(){
				$('louer-bandeau').fade(1);
				$('acheter-bandeau').fade(0.3);
				
			},
			'mouseout' : function(){
				if( $('annonces') ) {
					if( !$('annonces').hasClass('location') ){
						$('louer-bandeau').fade(0.3);
						$('acheter-bandeau').fade(1);
					}
				}else {
					$('acheter-bandeau').fade(1);
				}
				
			}
		});
		
	}
	
	
	
	// Effet RollOver sur les coordonnées d'agence de la page contact
	$$('.agenceItem').addEvents({
			'mouseover' : function(){
				this.addClass('itemover');
				/*
				var popupUrl = this.getFirst('a').getProperty('href');
				window.open(, '_self', 'rel="lightbox"');
				*/
			},
			'mouseout' : function(){
				this.removeClass('itemover');
			}
	});
	
	// Afficher loyer maxi ou budget maxi
	//$$('.inputMaxi').addClass('inputToHide');
	
	
	if( $('annonces') ) {
		if( $('annonces').hasClass('location') ) {
			if( $('terrain') ) {
				$('terrain').addClass('inputToHide');
			}
		}
	}
	
	if( $('home') || $('annonces') || $('formAlerteWrapper') ) {	
		if( $('type_prestation_location') ) {
			if( $('type_prestation_location').checked ){
				$('loyer_maxi').removeClass('inputToHide');	
				$('budget_maxi').addClass('inputToHide');
				if( $('terrain') ) {
					$('terrain').addClass('inputToHide');
				}
			}
			$('type_prestation_location').addEvent( 'click', function() {
				$('loyer_maxi').removeClass('inputToHide');	
				$('budget_maxi').addClass('inputToHide');
				if( $('terrain') ) {
					$('terrain').addClass('inputToHide');
				}
			});
		}
		
		if( $('type_prestation_vente') ) {
			if( $('type_prestation_vente').checked ){
				$('budget_maxi').removeClass('inputToHide');
				$('loyer_maxi').addClass('inputToHide');
				if( $('terrain') ) {
					$('terrain').removeClass('inputToHide');
				}
			}
			$('type_prestation_vente').addEvent( 'click', function() {
				$('loyer_maxi').addClass('inputToHide');
				$('budget_maxi').removeClass('inputToHide');
				if( $('terrain') ) {
					$('terrain').removeClass('inputToHide');
				}
			});
		}
	}
		
	if( $('formAlerteWrapper') ) {
		$('villeSelect').addEvent( 'domready', function() {
			if( this.options[this.selectedIndex].value != 0 ) {
				$('etendre').removeClass('inputToHide');
			}else {
				$('etendre').addClass('inputToHide');
			}
		});
		$('villeSelect').addEvent( 'change', function() {
			
			if(	this.options[this.selectedIndex].value != 0 ) {
				$('etendre').removeClass('inputToHide');
			}else {
				$('etendre').addClass('inputToHide');
			}
		});
	}
	
	//Effets RollOver sur la carte de la page d'accueil
	
	if ($('carte_zoom')) {
	
		var areas = ['rennes', 'vannes', 'nantes', 'la-rochelle'];
		areas.each(function(item){
			if ($('zoom_' + item)) {
				$('zoom_' + item).addEvents({
					'mouseover': function(){
						bloc = 'zoom_' + item;
						//alert(bloc);
						$(bloc).setProperty('z-index', '5');
						$(bloc).getFirst('a').addClass('hover');
						
					},
					'mouseout': function(){
						bloc = 'zoom_' + item;
						$(bloc).getFirst('a').removeClass('hover');
					}
				});
			}
		});
		
	}
	
	// Changement de page si critère acheter est coché
	
	if( $('hpForm') ) {
		if( $('home') ) {
			if( $('type_prestation_vente') ) {
				$('type_prestation_vente').addEvent( 'click', function() {
					//alert('test');
					$('hpForm').setProperty('action', BASEURL+'annonces/achat/'+region+'/liste/');
				});
			}
			if( $('type_prestation_location') ) {
				$('type_prestation_location').addEvent( 'click', function() {
					//alert('test');
					$('hpForm').setProperty('action', BASEURL+'annonces/location/'+region+'/liste/');
				});
			}
		}else if( $('annonces') ) {
			if( $('type_prestation_vente') ) {	
				$('hpForm').setProperty('action', BASEURL+'annonces/achat/'+region+'/liste/');
			}
			if( $('type_prestation_location') ) {	
				$('hpForm').setProperty('action', BASEURL+'annonces/location/'+region+'/liste/');
			}
		}
	}
	if( $('criteresForm') ) {
		if( $('type_prestation_vente').checked ) {
			$('criteresForm').setProperty('action', BASEURL+'annonces/achat/'+region+'/liste/');
		}
		
		$('type_prestation_location').addEvent( 'click', function() {
            $('criteresForm').setProperty('action', BASEURL+'annonces/location/'+region+'/liste/');
        });
		
		$('type_prestation_vente').addEvent( 'click', function() {
			//alert('test');
			$('criteresForm').setProperty('action', BASEURL+'annonces/achat/'+region+'/liste/');
		});
	}
	
	if(	$('registerSubmit') ) {
		$('registerSubmit').addEvents ({
			'mouseover' : function() {
				this.addClass('hover');
			},
			'mouseout' : function() {
				this.removeClass('hover');
			}
		});
	}
	
	if(	$('editAlerte') ) {
		$('editAlerte').addEvents ({
			'mouseover' : function() {
				this.addClass('hover');
			},
			'mouseout' : function() {
				this.removeClass('hover');
			}
		});
	}
	
	var myTips = new Tips('.toolTip', {
		className: 'tipWrapper'				  
	});
	
	
	if( $('detail')) {
		pop();
	}
});

/* FONCTIONS */

function pop() {
	
	var pop = $('popup-outter') || '';
	if( pop!='' ) {
		var mask = pop.getElement('#popup-outter-mask');
		mask.setOpacity(.8);
		mask.addEvent('click', function(){ 
			//$('criteresForm').setStyle('visibility', 'visible'); 
			pop.setStyle('display', 'none'); 
		});

		var close = pop.getElement('#closeBtn');
		close.addEvent('click', function(e){ 
			e.preventDefault(); 
			//$('criteresForm').setStyle('visibility', 'visible');  
			pop.setStyle('display', 'none'); 
		});

		$('btnCallMe').addEvent('click', function(e) { 
			e.preventDefault();
			
			window.scrollTo(0,0);
			//$('criteresForm').setStyle('visibility', 'hidden');
			pop.setStyles({
				'display': 'block',
				'height': window.getScrollSize().y
			});

			mask.setStyle('height', window.getScrollSize().y);

			_gaq.push(['_trackPageview', this.href]);
		});
	}

}

