﻿var valeurDefault = '';

function getBaseURL(){
	var url = location.host;
	return "http://"+url + "/";
}

function switchImg(obj){
   var src = $('.bloc_detail_photo_gm').children('img').attr('src');
   var oldSrc = src.split("/");
   oldSrc.pop();
   var prefix = oldSrc.join('/');
   var miniSrc = obj.src;
   var tab2Src = miniSrc.split("/");
   var newImg = tab2Src.pop();
   var newSrc = prefix + "/" +newImg
   $('.bloc_detail_photo_gm').children('img').attr('src', newSrc);
}
/*
 * a voir
 */
 
 function showDivn(button, id){
	$('.bottom_modules_contenu').hide();
	$('.actived').removeClass();
	var elem = document.getElementById(id);
	if(elem == null){
		var url = getBaseURL() + "immobilier/tabsn"
		$.get(url, { tab: id},
		   function(data){
			 $(button).parent().next().after(data);
		});
	}
	$(button).attr('class', 'actived');
	$(elem).show();
}
function switchImgMulti(obj,module){
   var parent = obj.parentNode;
   var src = $('.bloc_' + module + '_detail_photo_gm').children('img').attr('src');
   var oldSrc = src.split("/");
   oldSrc.pop();
   var prefix = oldSrc.join('/');
   var miniSrc = obj.src;
   var tab2Src = miniSrc.split("/");
   var newImg = tab2Src.pop();
   var newSrc = prefix +"/"+newImg
   $('.bloc_' + module + '_detail_photo_gm').children('img').attr('src', newSrc);
   getMediaInfo('#' + parent.id);
}

function getMediaInfo(id){
	var divMedia = $(id).find('div');
	$('.titre_photo').html(divMedia.find('span').html() + '&nbsp;');
	$('.description_photo').html(divMedia.find('div').html() + '&nbsp;');
}

$(function(){
   /*
	*rechereche
	*/
	$('#TRI').change(function(){
		var urlBase = getBaseURL();
		var cible = location.pathname;
		var htmlTest = cible.indexOf('.html')
		if(htmlTest){
			var tab = cible.split('/', 2);
			cible = tab[1];
		}
		else{
			cible = 'references.html';
		}
		var selected = $(this).children('option:selected').val();
		var url = urlBase + cible +'/ordre/' + selected; 
		$(location).attr('href',url);
	});
	$('.bottom_modules_contenu').hide();
	/*
	* vide input
	
	$('input:text').focusin(function(){
		valeurDefault = $(this).val();
		$(this).val('');
	});
	$('input:text').focusout(function(){
		var valeurNew = $(this).val();
		if(valeurNew == '')
			$(this).val(valeurDefault);
	});
	*/

   /*
	*	animation menu gard-transports
	*/
	var hLiO = $("#header").children('div').children('ul').children("li").height();
	var anime_actived = 0;
	$("#header").children('div').children('ul').children(".informations").hover(function(){
			setTimeout("",10)
			$("#header").children('div').children('ul').children("li").height(hLiO);
			setTimeout("",10)
			if(anime_actived == 0){
				var hUl = $("#header").children('div').children('ul').children(".informations").children("ul").height();
				anime_actived = 1;
				$("#header").children('div').children('ul').children(".informations").animate({
					height: hUl+hLiO
				  }, 700,
					function() {
					anime_actived = 0;
				  });
			}
	},function(){
			setTimeout("",1000);
			$("#header").children('div').children('ul').children(".informations").stop();
			anime_actived = 0;
			$("#header").children('div').children('ul').children(".informations").animate({
					height: hLiO
		}, 350);
	});
	$("#header").children('div').children('ul').children(".activites").hover(function(){
		setTimeout("",10)
		$("#header").children('div').children('ul').children("li").height(hLiO)
		setTimeout("",10)
		if(anime_actived == 0){
			setTimeout("",10)
			var hUl = $("#header").children('div').children('ul').children(".activites").children('ul').height();
			setTimeout("",10)
			anime_actived = 1;
			$("#header").children('div').children('ul').children(".activites").animate({
				height: hUl+hLiO
			  }, 700,
				function() {
				anime_actived = 0;
			  });
		}
	}
	,
	function(){
	setTimeout("",1000);
	
	$("#header").children('div').children('ul').children(".activites").stop();
	anime_actived = 0;
	$("#header").children('div').children('ul').children(".activites").animate({
			height: hLiO
		  }, 350);

	})
	
	var anime_actived = 0;
	var hLi = $(".informations").height();
	$(".informations").hover(function(){
		if(anime_actived == 0){
		var hUl = $(".informations >ul").height();
		anime_actived = 1;
		$('.informations').animate({
			height: hUl+hLi
		  }, 700,
				function() {
				anime_actived = 0;
			  });
		}
	},function(){
		$(".informations").stop();
		anime_actived = 0;
		$('.informations').animate({
			height: hLi
		  }, 350);
	});
	
});

