function ajouterGestionnaire()
{
	if ($('#dt_notre_offre'))
	{		
		$("#dt_notre_offre").mouseenter(function() { montre('#notre_offre')});
		$("#dt_notre_offre").mouseleave(function() { montre('')});
		$("#notre_offre").mouseenter(function() { montre('#notre_offre')});
		$("#notre_offre").mouseleave(function() { montre('')});
	
		$("#dt_avant_premiere").mouseleave(function() { montre('');});
			
		$("#dt_nos_conseils").mouseenter(function() { montre('#nos_conseils');hideSelect(false, 2);});
		$("#dt_nos_conseils").mouseleave(function() { montre('');hideSelect(true, 2);});
		$("#nos_conseils").mouseenter(function() { montre('#nos_conseils');hideSelect(false, 2);});
		$("#nos_conseils").mouseleave(function() { montre('');hideSelect(true, 2);});
		
		$("#dt_references").mouseenter(function() { montre('#references');hideSelect(false, 3);});
		$("#dt_references").mouseleave(function() { montre('');hideSelect(true, 3);});
		$("#references").mouseenter(function() { montre('#references');hideSelect(false, 3);});
		$("#references").mouseleave(function() { montre('');hideSelect(true, 3);});
		
		$("#dt_budget").mouseenter(function() { montre('#budget');hideSelect(false, 4);});
		$("#dt_budget").mouseleave(function() { montre('');hideSelect(true, 4);});
		$("#budget").mouseenter(function() { montre('#budget');hideSelect(false, 4);});
		$("#budget").mouseleave(function() { montre('');hideSelect(true, 4);});
		
		$("#dt_newsletter").mouseenter(function() { montre('#newsletter');hideSelect(false, 4);});
		$("#dt_newsletter").mouseleave(function() { montre('');hideSelect(true, 4);});
		$("#newsletter").mouseenter(function() { montre('#newsletter');hideSelect(false, 4);});
		$("#newsletter").mouseleave(function() { montre('');hideSelect(true, 4);});
		
		$("#dt_espace_perso").click(function() { montre('#espace_perso');});
		$("#fermerEspacePerso").click(function() { fermerEspacePerso();});
		
		$("#header").mouseenter(function() { montre('');});
		
		//Initialisation du menu
		montre('');
	}
	/*
	if ($("#menuNavTranversale")) {
		$("#navTransversale .navTransMenuLvl1").mouseenter(function() { montreNavTransversaleMenu($(this))});
	}*/
	
	//Lien pour la carte
	
	/*
	
	Vieille carte des programmes
	
	if ($("#afficherCarte"))
	{
		//Event.observe($('afficherCarte'), "click", afficheCarte, false);
		$("#afficherCarte").click(function() { afficheCarte();});
	}
	*/
	/*if ($('contenuResultat'))
	{
		var newHeight=$('gaucheResultat').offsetHeight;
	//	newHeight+=189+189+7;
		newHeight =621;
		$('contenuResultat').style.height=newHeight + "px";
		//alert(newHeight);	
	}*/
	
	
	//Redimensionnement des pages programmes
	redimensionne();
	
	/*
	Chargement des flash dynamiquement.
	Corrige le problème sur IE pour charger le contenu
	Plus d'informations sur : http://wiki.mediabox.fr/documentation/swfobject
	*/
	
	//chargerFlash();
	
	//Chargement du diaporama si on est sur la page présentration
	/*if ($('page_presentation'))
	{
		doPanorama();
	}
	if (($('recherche')) || ($('recherche_en')))
	{
	   specialOnLoad();
	   
	   //window.open("http://www.cogedim-logement.com/pub/pop-up-video2.html","COGEDIM_Grenoble_Portes_Ouvertes","width=672, height=565, scrollbars=yes");
	}*/
	
	
}

// Liste des id a cacher
var aSelectToHide = [null, null, ['#type_log','#sel_region','#sel_ville1','#sel_ville2','#sel_ville3','#sortingColumn'], ['#type_log'], ['#sortingColumn'], null, null, ['#type_log'], ['#type_log','#sel_region','#sel_ville1','#sel_ville2','#sel_ville3','#type_commercialisation','#typeLogement']];

function hideSelect(bAction, iId) {
	if (aSelectToHide[iId]) {
		for (var i = 0 ; i < aSelectToHide[iId].length ; i++ ) {
			if ($(aSelectToHide[iId][i]).length > 0) {
				if (bAction) {
					$(aSelectToHide[iId][i]).css('visibility','visible');
				}
				else {
					$(aSelectToHide[iId][i]).css('visibility','hidden');
				}
			}
		}
	}
}

function montre(id){
	
	var d = $(id);
	var doChange = true;
	$('#notre_offre').css("display", "none");
	$('#nos_conseils').css("display", "none");
	$('#references').css("display", "none");
	$('#budget').css("display", "none");
	$('#newsletter').css("display", "none");
	
	if (d && doChange) {
		d.css("display", "block");
		
	}
}

function montreNavTransversaleMenu(id) {
	var doChange = true;
	
	$('#navTransversale .menuNavTransversale_on').each(function() {
		//$(this).css("display", 'none');
		$(this).removeClass("menuNavTransversale_on").addClass("menuNavTransversale_off");
	});
	//d.css("display", 'block');
	id.find(".menuNavTransversale_off").each(function() {
		$(this).removeClass("menuNavTransversale_off").addClass("menuNavTransversale_on");
	});
}
function fermerEspacePerso()
{
	$("#espace_perso").css("display","none");
}


function redimensionne()
{
	var divGauche = $("#DivGaucheProgramme");
	var divDroite = $("#DivDroitePresentationProgramme");
	var divDroite2 = $("#DivDroitePresentationProgramme2");
	var divCentre = $("#DivCentrePresentationProgramme");
	
	var divAvantPremiereGauche = $("#avantPremiereGauche");
	var divCentral = $("#contenuCentral");
	var divEncartGaucheLogement = $("#encartGaucheLogement");
	var divContenuLogement = $("#contenuLogement");
	var gaucheResultat = $("#gaucheResultat");
	var contenuResultat = $("#listeResultatsContenu");
	
	var heightGauche = 0;
	var heightDroite = 0;
	var heightCentre = 0;
	var heightGaucheResultat = 0;
	var heightContenuResultat = 0;
	
	if ( 0 < divCentre.size() || 0 <divCentral.size())
	{
		if (0 < divCentre.size())
		{
			heightCentre = divCentre.height();
		}
		if (0 < divCentral.size())
		{
			var heightCentral = divCentral.height();
		}
	}
	else if (0 < divContenuLogement.size())
	{
	   heightCentre = divContenuLogement.height();
	}
	else if (0 < gaucheResultat.size() && 0 < contenuResultat.size())
	{
	
	}
	else
	{
		return;
	}
	
	
	
	
	if (0 < divGauche.size() && 0 < divDroite.size())
	{
		heightGauche = divGauche.height();
		heightDroite = divDroite.height();
		if (heightGauche > heightCentre || heightDroite > heightCentre)
		{
			if (heightGauche > heightDroite)
			{
				heightDroite = heightGauche;
				heightCentre = heightGauche;
				divDroite.css("height",heightDroite + "px");
				divCentre.css("height",heightCentre + "px");
			}
			else
			{
				heightGauche = heightDroite;
				heightCentre = heightDroite;
				divGauche.css("height", heightGauche + "px");
				divCentre.css("height", heightCentre + "px");
			}
		} 
		if (heightCentre > heightGauche && heightCentre>heightDroite) {
                                heightDroite = heightCentre;
                                heightGauche = heightCentre;
                                divDroite.css("height", heightDroite + "px");
                                divGauche.css("height", heightGauche + "px");

                }
 
	}
	else if (0 < divGauche.size() && 0 < divDroite2.size())
        {
                heightGauche = divGauche.height();
                heightDroite = divDroite2.height()+115;//+150;
                if (heightGauche > heightCentre || heightDroite > heightCentre)
                {
                        if (heightGauche > heightDroite)
                        {
                                heightDroite = heightGauche-115;//-150;
                                heightCentre = heightGauche;
                                divDroite2.css("height", heightDroite + "px");
                                divCentre.css("height", heightCentre + "px");
                        }
                        else
                        {
                                heightGauche = heightDroite;
                                heightCentre = heightDroite;
                                divGauche.css("height", heightGauche + "px");
                                divCentre.css("height", heightCentre + "px");
                        }
                }
                if (heightCentre > heightGauche && heightCentre>heightDroite) {
                    heightDroite = heightCentre-115;//-150;
                    heightGauche = heightCentre;
                    divDroite.css("height", heightDroite + "px");
                    divGauche.css("height", heightGauche + "px");
                }

        }
	
	else if(0 < divGauche.size())
	{
		heightGauche = divGauche.height();
		if (heightGauche > heightCentre)
		{
			heightCentre = heightGauche;
			divCentre.css("height", heightCentre + "px");
		}
	}
	else if (0 < divAvantPremiereGauche.size())
	{
		heightGauche = divAvantPremiereGauche.height();
		if (heightGauche > heightCentral)
		{
			heightCentral = heightGauche;
			divCentral.css("height", heightCentral + "px");
		}
	}
	else if (0 < divDroite.size())
	{
		heightDroite = divDroite.height();
		if (heightDroite > heightCentre)
		{
			heightCentre = heightDroite;
			divCentre.css("height", heightCentre + "px");
		}
	}
	else if (0 < divDroite2.size())
        {
                heightDroite = divDroite2.height()-150;
				
                if (heightDroite > heightCentre)
                {
                        heightCentre = heightDroite;
                        divCentre.css("height", heightCentre + "px");
                }
        }

	else if (0 < divEncartGaucheLogement.size())
	{
	   heightGauche = divEncartGaucheLogement.height();
	   heightCentral = divContenuLogement.height();
	   if (heightGauche > heightCentral)
	    {
	      heightCentral = heightGauche;
	      divContenuLogement.css("height", heightCentral + "px");
	    }
	}
	else if (0 < gaucheResultat.size() && 0 < contenuResultat.size())
	{
		heightGaucheResultat = gaucheResultat.height();
		heightContenuResultat = contenuResultat.height();
		if (heightGaucheResultat > heightContenuResultat)
		{
			heightGaucheResultat = heightGaucheResultat + 35;			
			contenuResultat.css("height", heightGaucheResultat + "px");
		}
	}
	
}




function afficherDetails(id)
{
	var src_image = "";
	var tab_image;
	var real_name_image = "";
	if ($('#tr_listLot_' + id).size()>0)
	{
		if ($('#tr_listLot_' + id).attr("class") === "special")
		{
			$('#tr_listLot_' + id).attr("class","special2");
			src_image = $('#image_listLot_'+ id).attr("src");
			tab_image = src_image.split("/");
			real_name_image = tab_image[tab_image.length - 1];
			if (real_name_image == "fleche.png")
			{
				tab_image[tab_image.length - 1] = "flecheDepliee.png";
			}
			else
			{
				tab_image[tab_image.length - 1] = "flechegrisDepliee.png";
			}
			src_image = tab_image.join("/");
			$('#image_listLot_'+ id).attr("src", src_image);
		}
		else
		{
			$('#tr_listLot_' + id).attr("class", "special");
			src_image = $('#image_listLot_'+ id).attr("src");
			tab_image = src_image.split("/");
			real_name_image = tab_image[tab_image.length - 1];
			if (real_name_image == "flecheDepliee.png")
			{
				tab_image[tab_image.length - 1] = "fleche.png";
			}
			else
			{
				tab_image[tab_image.length - 1] = "flechegris.png";
			}
			src_image = tab_image.join("/");
			$('#image_listLot_'+ id).attr("src", src_image);
		}
	}
}

function changerFlash(src_flash, texte_flash)
{
	var url_serveur = "http://www.cogedim-logement.com";
	var Exp = new RegExp(url_serveur);
	
	// si l'url du serveur est déjà dans le param src_flash, alors on ne l'ajoute pas
	if( Exp.test( src_flash ) ){	
		var url_flash = src_flash;
	}
	else{
		var url_flash = url_serveur + src_flash;
	}
	
	var flashvars = null;	
	var params = {
		  loop: "true",
		  allowScriptAccess: "sameDomain",
		  align : "middle",
		  wmode : "opaque"
		};
	var attributes = null;
	
	swfobject.embedSWF(url_flash, "c_est_beau", "781", "420", "7", '', flashvars, params, attributes);
	
	/*var so_cest_beau = new SWFObject(url_flash, "c_est_beau", "781", "420", "7", "#094F82");
	so_cest_beau.addParam("loop", "true");
	so_cest_beau.addParam("allowScriptAccess", "sameDomain");
	so_cest_beau.addParam("align", "middle");
	so_cest_beau.addParam("wmode", "opaque");
	so_cest_beau.write("contenu_flash_cest_beau");*/
	
	if(texte_flash!=''){
		$('#contenu_text_cest_beau').html(texte_flash);
	}
	
	
	return false;
}

var broswer = {};
var userAgent = navigator.userAgent.toLowerCase();
broswer.version = (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1];
broswer.safari = /webkit/.test( userAgent );
broswer.opera = /opera/.test( userAgent );
broswer.msie = /msie/.test( userAgent ) && !/opera/.test( userAgent );
broswer.mozilla = /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent );

function initFlashTrans() {
	hideSelect(false, 8);
	$('#flashTransparent').css('marginLeft', Math.floor((parseInt($('#flashTransparent').attr('width'), 10) / 2) * (- 1)) + 'px');
	window.onresize = fixFlashTrans;
}

function getViewport() {
	return {width: $(window).width(), height: window.innerHeight ? window.innerHeight : $(window).height()};
}

function fixFlashTrans() {
	/* N'est plus necessaire
	if ($('#flashTransparent').length > 0) {
		var iDocumentWidth = getViewport().width;
		var iAnimationWidth = parseInt($('#flashTransparent').attr('width'), 10);
		if (iAnimationWidth > iDocumentWidth) {
			if (broswer.mozilla) {
				$('#flashTransparent').attr('width', Math.floor(iAnimationWidth  - ((iAnimationWidth - iDocumentWidth) / 2 ) - 8));
			}
			else {
				$('#flashTransparent').attr('width', Math.floor(iAnimationWidth  - ((iAnimationWidth - iDocumentWidth) / 2 )));
			}
		}
		else {
			$('#flashTransparent').attr('width', iAnimationWidth);
		}
	}
	*/
}

/**
 * Ferme l'intertitiel et montre a nouveau les selects (sinon ils sont devant le flash IE6 - IE7)
 */
function endFlashTrans() {
	$('#flashTransparent').css('display','none').remove();
	hideSelect(true, 8);
}

function doPanorama()
{
	//new PeriodicalExecuter(function() {nextImg(); }, 5);
}

/*

// Gestion de la vieille carte des programmes

function afficheCarte(event)
{
	var carte = $("#carte");
	var src_flash_carte = $("#src_flash_carte");
	if (carte && src_flash_carte)
	{
		var so_carte = new SWFObject(src_flash_carte.value, "carte_flash", "700", "470", "8", "#FFFFFF");
		so_carte.addParam("wmode", "opaque");
		so_carte.write("carte");
		carte.style.display = "block";
		
//		$('type_log').style.display = "none";
		$("#type_log").css("display","none");
//		$('budg_min').style.display = "none";
//		$('budg_max').style.display = "none";
		$('sel_region').style.display = "none";
		$("#type_log").css("display","none");
		$('sel_ville1').style.display = "none";
		$("#type_log").css("display","none");
		$('sel_ville2').style.display = "none";
		$("#type_log").css("display","none");
		$('sel_ville3').style.display = "none";
		$("#type_log").css("display","none");
	}
}

function fermeFlash(){
	$('carte').innerHTML="";
	$('carte').style.display = "none";
	$('type_log').style.display = "inline";
//	$('budg_min').style.display = "inline";
//	$('budg_max').style.display = "inline";
	$('sel_region').style.display = "inline";
	$('sel_ville1').style.display = "inline";
	$('sel_ville2').style.display = "inline";
	$('sel_ville3').style.display = "inline";
}


function leChoixProg(x){
	var base = "http://www.cogedim-logement.com/immobilier/";
	var temp = "a" + x;
	if (tabListeProgramme[temp])
	{
		document.location = base + tabListeProgramme[temp];
	}
}

function leChoixDep(x){
	var temp="http://www.cogedim-logement.com/immobilier/recherche_immobilier_departement_" + x + "_fr.html";
	document.location=temp;
}
*/
//Event.observe(window, "load", ajouterGestionnaire, false);
$(document).ready(function(){
	ajouterGestionnaire();
});


