/* Author: Magazine // J.Arsac
*/

$(function(){
	
	// Gestion des timestamps pour les exports (pb de cache JAHIA)
	function timestampExportLinks() {
		var timestamp = "&odrtimestamp=";
			
		$(".exportlinks a[href]")
		.click(timestampExportLinks)
		.each(function() { 
			if (this.href.indexOf(timestamp)<0)
				this.href+=timestamp+"0";
				
			this.href = this.href.replace(new RegExp(timestamp+".*$","g"), timestamp+new Date().getTime());
		});
	}
	
	// Gestion des timestamps pour les exports (pb de cache JAHIA)
	timestampExportLinks();
	
	/* gestion du bandeau mon compte*/
	$("#monCompte").click(function () {

		 if ($("div #header").is(":hidden")) {
			 	$("div #header").slideDown();
			 	$(this).removeClass("monCompte");
			 	$(this).addClass("monCompteOpen");
			 	
	      } else {
		    	$("div #header").slideUp();
			 	$(this).removeClass("monCompteOpen");
			 	$(this).addClass("monCompte");
	      }

	});
	
	$("#userConnecte").click(function () {

		 if ($("div #header").is(":hidden")) {
			 	$("div #header").slideDown();
			 	$(this).removeClass("userConnecte");
			 	$(this).addClass("userConnecteOpen");
			 	
	      } else {
		    	$("div #header").slideUp();
			 	$(this).removeClass("userConnecteOpen");
			 	$(this).addClass("userConnecte");
	      }

	});	
	
	$(".registerFields").focus(function () {
		$(this).val('');
		
	});
	
	$("#tableAnnonces tr.TabLineResult img").hover(function (){
			if($(this).attr('class')!='noimage'){
				var lelement = $(this)[0].offsetParent.offsetTop;
				var imageSrc = $(this).attr('src');
				imageSrc=imageSrc.replace("/thumbnail","");
	
				/* marche pas sous IE 
				var laPosition =  ($(this)[0].y) - 90;*/
				var laPosition = lelement - 90;
				$("div.resultZoom").css({ top : laPosition});
				$("div.resultZoom img").attr('src',imageSrc);
				$("div.resultZoom").show();
			}
			
	});
	
	$("#tableAnnonces tr.TabLineResult").hover('', function (){
		$("div.resultZoom").hide();
		
	});
	
	/*
	 * Page d'accueil
	 * 
	 * */
	function hasMoved(moodular) {
		var nbElement = $("#slideshowNav td div").size()-2;//Nombre de div - divs prec et next
		var lapuceactive = moodular.current + 1;
		for (i=1; i<=nbElement; i++){
			document.getElementById('puce_'+ i).className= "slideOff";
		}
		
		document.getElementById('puce_'+ lapuceactive).className= "slideOn";

	}
	
	
	
	var mood= $("#slideshowWrap ul").moodular({
        callbacks: [hasMoved],
        speed: 800,
        dispTimeout: 4000,
        api: true
	});
	
	$("#slideshowNav #slideNext").bind('click', function () { mood.next(); return false; });
	
	$("#slideshowNav #slidePrev").bind('click', function () { mood.prev(); return false; });
	
	$(".locationsTitle").click(function() {
        $("div#toggleAchLoc").removeClass("achatsOn");
        $("div#toggleAchLoc").addClass("locationsOn");
        $("div#toggleAchLoc #locationsContent").jScrollPane({showArrows: true});
	});	

	$(".achatsTitle").click(function() {
        $("div#toggleAchLoc").removeClass("locationsOn");
        $("div#toggleAchLoc").addClass("achatsOn");
        $("div#toggleAchLoc #achatsContent").jScrollPane({showArrows: true});
	});	
	
	
	$('.scroll-pane').jScrollPane({showArrows: true});
	/*
	 * Page recherche logement
	 * 
	 * */
	
	
	/*Gestion des Zoom via Fancybox*/
	

		/* This is basic - uses default settings */
		
	$("a.zoomable").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'hideOnContentClick' : true,
		onComplete	:	function() {
        	$('object').hide();
		},
		onCleanup	:	function() {
			$('object').show();
		}

		
	});
	
	$("a.sendToFriend").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200
	});
	
	$("#changePasswordLink").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'type'				: 'iframe',
		'width'				: '75%',
		'height'			: '36%',
		'titleShow'		: false

	});	
	
	$(".forgotPassword").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'type'				: 'iframe',
		'width'				: '75%',
		'height'			: '40%',
		'titleShow'		: false

	});		
	
	$("a.saveAlerteLink").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'type'				: 'iframe',
		'width'				: '75%',
		'height'			: '30%',
		'titleShow'		: false

	});	
	
	$("#repondreOffreLink").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'type'				: 'iframe',
		'width'				: '70%',
		'height'			: '100%',
		'titleShow'		: false

	});	
	
	$("#repondreOffreEmploiLink").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'type'			: 'iframe',
		'width'			: '70%',
		'height'		: '100%',
		'titleShow'		: false

	});		
	
	$("a.editAlerteLink").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'type'				: 'iframe',
		'width'				: '70%',
		'height'			: '100%',
		'titleShow'		: false

	});		
	
	$("a.reponseOffreDetail").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'type'				: 'iframe',
		'width'				: '75%',
		'height'			: '75%',
		'titleShow'		: false

	});			
	
	$("#achatPublicUrlLink").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'type'				: 'iframe',
		'width'				: '75%',
		'height'			: '35%',
		'titleShow'		: false

	});	
	function manageFormRechercheBien (typeLogement, locAchat)
	{
		/*LOGEMENT*/
		if (typeLogement==1){
			if (locAchat==1){ /*LOC*/
				window.location.replace('/cms/louer-acheter/location-logement');
			}
			else if (locAchat==2){ /*ACHAT*/
				window.location.replace('/cms/louer-acheter/vente-logement');
			}
		}

		/*STATIONNEMENT*/
		if (typeLogement==2){
			if (locAchat==1){/*LOC*/
				window.location.replace('/cms/louer-acheter/location-stationnement');			
			}else if (locAchat==2){/*ACHAT*/
				window.location.replace('/cms/louer-acheter/vente-stationnement');
			}
		}

		/*LOCAL COMMERCIAL*/
		if (typeLogement==3){
			if (locAchat==1){/*LOC*/
				window.location.replace('/cms/louer-acheter/location-local');
				
			}
			else if (locAchat==2){/*ACHAT*/
				window.location.replace('/cms/louer-acheter/vente-local');
			}
		}
	
	}

	

	$("#formRechercheLogement input[type=radio][name=type]").change(function() {


		var typeLogement = $("#formRechercheLogement input[type=radio][name=type]:checked").attr('value');
		var locAchat = $("#formRechercheLogement input[type=radio][name=loc]:checked").attr('value');

		if(locAchat > 0){
			manageFormRechercheBien(typeLogement, locAchat);
		}

		
	});
	
	$("#formChoixAccount input[type=radio][name=radioAccount]").change(function() {
		var typeAccount = $("#formChoixAccount input[type=radio][name=radioAccount]:checked").attr('value');
		window.location.replace(typeAccount);
		
	});
	
	$("#formRechercheLogement input[type=radio][name=loc]").change(function() {
		var typeLogement = $("#formRechercheLogement input[type=radio][name=type]:checked").attr('value');
		var locAchat = $("#formRechercheLogement input[type=radio][name=loc]:checked").attr('value');
		$("#formRechercheLogement #TRlocachattitre").show();
		$("#formRechercheLogement #TRlocachatvalue").show();		
		manageFormRechercheBien(typeLogement, locAchat);
		
	});	
	
	/*Tri sur les colonnes*/
	$("th.sortable").click(function () {
		var aSortable = $(this).children('a').first();
		if(aSortable){
			window.location.replace(aSortable.attr("href"));
		}
	});
	/*Tri sur les colonnes*/
	$("th.header").click(function () {
		var aSortable = $(this).children('a').first();
		if(aSortable){
			window.location.replace(aSortable.attr("href"));
		}
	});	
	
	/*Verification lecteur flash */
	if($("embed").html()!=null ||  $("object").html()!=null || $("a.videoplayer").html()!=null) {
		var playerVersion = swfobject.getFlashPlayerVersion();
		if(playerVersion  == null || playerVersion.major=='' || playerVersion.major < 9){
            $("a#flash_install").fancybox({
        		'width'			: '70%',
        		'height'		: '50%',
            	"hideOnContentClick": false
            }).trigger("click");
			
			//alert(playerVersion.major + "." + playerVersion.minor + "." +playerVersion.release);
		}	
	}
	
});

function changeLocataireFieldVisibility(){
	if($("#isLocataireParam").val()==0){
		$(".locataireFields").hide();
		$(".noLocataireFields").show();
	}else{
		$(".locataireFields").show();
		$(".noLocataireFields").hide();
	}
}










