 $(document).ready(function() {


	adapterphoto(photow,photoh);


	$("#rubmap").hide();

	$(window).resize(function () { 
      
      adapterphoto(photow,photoh);
      
    });
    

	var t=setTimeout("readapter()",500);
	
	//readapter();
	
	function estompefoto(){
	var thisMovie= (navigator.appName.indexOf("Microsoft") != -1)?  window["imagehome"]: document["imagehome"];
    thisMovie.goHome();			 
	}
	
	
	$(function(){ 
    $("ul#thenews").liScroll({travelocity: 0.05});

   // alert($("ul#thenews"));
	});

	
	/*
	var shownewshere =  false;
	
	try{
		shownewshere = shownews ? shownews : false;
	}
	catch(err){
		// pas de var shownews dans la page
	}
	
	if($("#li9") && shownewshere){//news
	
		showlinews("li9");
		setTimeout("hidelinews()",3000);

	}
	*/
	var lishowed ;
	
	function showlinews(lid){
	
			if(lishowed) hideli(lishowed);
	
			lishowed = lid;

			$("#"+lid).children().filter(".sousmenu").css("left",(-400+($("#"+lid).innerWidth()))+"px");
			$("#"+lid).children().filter(".sousmenu").css("display","block");
			
			
			if($("#"+lid).attr("class")=="sel"){
			
			monfond = $("#"+lid).css("background-color");
			
			}
			$("#"+lid).css("background-color","#000");	
			$("#"+lid).children().filter("a").css("color","#929292");
			//alert($("#"+lid).children().filter("a").css("color"));
	}
	
	function hidelinews(){
	
	 hideli("li9")
	
	
	}
	
	function showli(lid){
	
			if(lishowed) hideli(lishowed);
	
			lishowed = lid;
	
			//if(window["imagehome"] || document["imagehome"]){
			if(false){
				var thisMovie= (navigator.appName.indexOf("Microsoft") != -1)?  window["imagehome"]: document["imagehome"];
			
				try
				  {
				  var callResult = thisMovie.extalphafoto(50);
				  }
				catch(err)
				  {
				  /*txt="There was an error on this page.\n\n";
				  txt+="Error description: " + err.description + "\n\n";
				  txt+="Click OK to continue.\n\n";
				  alert(txt);*/
				  }
				
			}else{
			
				$("#photo").animate({opacity: '0.5'}, 100);
			}

			//alert($("#"+lid).outerWidth());
			$("#"+lid).children().filter(".sousmenu").css("left",(-400+($("#"+lid).outerWidth()))+"px");
			$("#"+lid).children().filter(".sousmenu").css("display","block");
			
			
			if($("#"+lid).attr("class")=="sel"){
			
			monfond = $("#"+lid).css("background-color");
			
			}
			$("#"+lid).css("background-color","#000");	
			$("#"+lid).children().filter("a").css("color","#929292");
	}
	
	function hideli(lid){
	
			//if(window["imagehome"] || document["imagehome"]){
			if(false){
			var thisMovie= (navigator.appName.indexOf("Microsoft") != -1)?  window["imagehome"]: document["imagehome"];
			
				try
				  {
				  var callResult = thisMovie.extalphafoto(100);
				  }
				catch(err)
				  { }



			}else{
			
				$("#photo").animate({opacity: '1'}, 100);
			}
    				//alert(callResult);
			$("#"+lid).children().filter(".sousmenu").css("display","none");
			
			if($("#"+lid).attr("class")=="sel"){
			
				$("#"+lid).css("background-color",monfond);
				$("#"+lid).children().filter("a").css("color","#000");
			}else{
			
				$("#"+lid).css("background-color","transparent");
				$("#"+lid).children().filter("a").css("color","#000");
			}
			
			lishowed = false;
	
	}
	
	
	
	
	var monfond;
     $("#menu li").hover(
     
     
		function() {
		
		
			showli( $(this).attr("id") );
			
			
		}	,
		function() {
		
			hideli( $(this).attr("id") );
		}	
	
	);
	
	
	
     $("#menu .repolist").hover(
		function() {
		
			var imid = "vign"+$(this).attr("id");
			
			$("#"+imid).show();
			
			
    		//alert(imid);

		}	,
		function() {

			var imid = "vign"+$(this).attr("id");
			
			$("#"+imid).hide();

		}	
	
	);	
	
	
	
	

});

function adapterphoto(w,h){

	if(widthpage){
	
		$("#page").css("width",widthpage+"px");
		
		if(heightpage){
			$("#photo").css("height",heightpage+"px");
		}
		
	}else{
	
		var minWidt = 800;
	
		var top = $("#top").outerHeight() + parseInt($("#top").css("margin-bottom")) ;
		//alert();
		var legende = $("#legend").outerHeight();
	
		var wp = getPageSize();
	
	//	alert(top+" "+legende+" "+wp[1]+" "+hc);
	
	//	hc = wp[1]>hc ? wp[1] : hc;
	
		var spaceH = wp[1] - top - legende - 2* parseInt($("#page").css("margin-top"));
		var spaceW = wp[0] ;
		
		//alert(photow+" "+photoh);
		var radio = ( ( photow / spaceW ) > (photoh / spaceH ) )? photow / spaceW : photoh / spaceH ;
		
		photohnw = parseInt(photoh/radio);
		photownw = parseInt(photow/radio);
		
		if(photownw<minWidt){
		
			radio = photow / minWidt;
			
			photohnw = parseInt(photoh/radio);
			photownw = parseInt(photow/radio);
			
		
		
		
		}
		
	
	
		$("#page").css("width",photownw+"px");
		$("#photo").css("height",photohnw+"px");
		sendwidth(photownw,photohnw);
	
	}

}


function sendwidth(w,h){

					jQuery.ajax({
					   type: "GET",
					   url: "savew.php",
					   data: "WIDTHPAGE="+w+"&HEIGHTPAGE="+h,
					   success: function(msg){
					   
						//alert(msg);
					   
						
					   },
					   
					   error: function(XMLHttpRequest, textStatus, errorThrown){
					   
							//jQuery("#alerteno").show();
							//jQuery("#formulaire").hide();
							
							//alert("caca");
					   
					   
					   }
					   
					   
					 });
					 


}


function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}
function hidelinews(){
	
	 //hideli("li9");
	 lid="li9";
	 if($("#"+lid).children().filter(".sousmenu").css("display") != "none"){
	 		
			$("#"+lid).children().filter(".sousmenu").hide("slow");
			
			$("#"+lid).css("background-color","transparent");
			$("#"+lid).children().filter("a").css("color","#000");

			lishowed = false;
	}
	
}



jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.05
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).width();
				});
				$strip.width(stripWidth);			
				var defTiming = stripWidth/settings.travelocity;
				var totalTravel = stripWidth+containerWidth;								
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};

	
    function readapter(){
    
    	 adapterphoto(photow,photoh);
    	 //alert(photow,photoh);
    }



