	
	var interval = 4000;
	var imgs = '';
	var timeoutID;
	var cur_sub = '';
	
	function switchSRC(elt,mode){
		if(mode){
			elt.attr('src',	'images/'+elt.attr('id')+'_on.png');
		}else{
			elt.attr('src',	'images/'+elt.attr('id')+'.png');
		}
	}

	function initMenu(){
		
		var config = {    
			 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 0, // number = milliseconds for onMouseOver polling interval    
			 over: openSub, // function = onMouseOver callback (REQUIRED)    
			 timeout: 300, // number = milliseconds delay before onMouseOut    
			 out: closeSub // function = onMouseOut callback (REQUIRED)    
		};
		
		$('#menu li:has(ul)').hoverIntent( config )
		
		openPane();
		
	}
	
	function openSub(){
		$('#menu li ul').hide();
		$(this).toggleClass('on');
		var elt = $(this).find('ul');
		var str_padl = $(this).css('padding-left');
		var str_padr = $(this).css('padding-right');
		var padl = Number(str_padl.substr(0,str_padl.indexOf('p')));
		var padr = Number(str_padr.substr(0,str_padr.indexOf('p')));
		var new_width = $(this).width()+(padl+padr)+1;
		if(elt.width()<new_width){
			elt.css('width',new_width);
		}
		/*elt.css('width',$(this).width()+(padl+padr)+1);*/
		elt.css('top',$(this).position().top-elt.height()+2);
		elt.css('left',$(this).position().left-1);
		elt.show();
	}
	
	function closeSub(){
		cur_sub = '';
		$(this).toggleClass('on');
		$(this).find('ul').hide();
	}

	function closePane(callback){
		$('#pane').animate({ 
			marginTop: '472px'
		  }, 500,'easeOutExpo',callback);
	}

	function openPane(){
		$('#pane').animate({ 
			marginTop: $('#content').height()-$('#pane').height()
		  }, 2500,'easeOutExpo',function(){$('#tools').show()});
	}


	function showTarifs(){
		$('#tarifs').show();
	}
	function closeTarifs(){
		$('#tarifs').hide();
	}

	function closeObjects(){
		$('.object').hide();
		openPane();
	}
	
	

	function showMap(str){
		clearTimeout(timeoutID);
		$('#flash').empty();
		/*swfobject.embedSWF("plan.swf", "content", "760", "472", "9.0.0", "expressInstall.swf");*/
		var so = new SWFObject("plan.swf", "map", "759", "472", "9");
		so.addParam("allowScriptAccess","Always");
        so.useExpressInstall("expressinstall.swf");
        so.addVariable("elt", str); 
        so.write("flash");
		$('#flash').show();
	}

	function hideMap(){
		if(imgs!=''){
			initGallery();
		}
		/*swfobject.embedSWF("plan.swf", "content", "760", "472", "9.0.0", "expressInstall.swf");*/
		$('#flash').hide();
	}

	function initGallery(){
		timeoutID = window.setTimeout('showGallery()',interval);	
	}

	function showGallery(){
		$('#flash').empty();
		var so = new SWFObject("galerie.swf", "map", "759", height, "9");
		so.addParam("wmode","transparent");
		so.addParam("allowScriptAccess","Always");
        so.useExpressInstall("expressinstall.swf");
        so.addVariable("elt", imgs); 
        so.addVariable("interval", interval); 
        so.write("flash");
		$('#flash').show();
		$('#bt_gallery').html('<a href="javascript:showInsideGallery()">INTERIEUR</a>');
	}

	function showInsideGallery(){
		clearTimeout(timeoutID);
		$('#flash').empty();
		var so = new SWFObject("galerie_interieur.swf", "map", "759", height, "9");
		so.addParam("wmode","opaque");
		so.addParam("allowScriptAccess","Always");
        so.useExpressInstall("expressinstall.swf");
        so.addVariable("elt", inside_imgs);
        so.write("flash");
		$('#flash').show();
		$('#bt_gallery').html('<a href="javascript:showGallery()">EXTERIEUR</a>');
	}

	function hideGallery(){
		$('#flash').hide();
	}
	

	function showHierGallery(){
		clearTimeout(timeoutID);
		$('#flash').empty();
		var so = new SWFObject("galerie_interieur.swf", "map", "759", height, "9");
		so.addParam("wmode","opaque");
		so.addParam("allowScriptAccess","Always");
        so.useExpressInstall("expressinstall.swf");
        so.addVariable("elt", inside_imgs);
        so.write("flash");
		$('#flash').show();
		$('#bt_gallery2').find("a").attr("href","javascript:hideHier()");
	}
	
	function hideHier(){
		$('#flash').hide();
		$('#bt_gallery2').find("a").attr("href","javascript:showHierGallery()");
		showGallery()
	}
	
	function popup(page,largeur,hauteur,s){
		var top=(screen.height-hauteur)/2-20;
		var left=(screen.width-largeur)/2;
		options = 'toolbar=no,directories=no,status=no,scrollbars='+s+',resize=no,menubar=no,location=no';
		window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
	}

	$(document).ready(initMenu);
