/***************************************************************************
****************************************************************************


[TABLE DES MATIÈRES]

	1.0	Déclaration des variables
	
	2.0	Création des fonctions
		2.1	Fonction du redimensionnement des image map
		2.2	Fonction du redimensionnement des image map
		
	3.0	Actions utilisateur
		3.1	Redimension de la fenêtre
		3.2	Rollover des boutons
 
 
****************************************************************************
***************************************************************************/



/* ========================================================================
 1.0 DÉCLARATION DES VARIABLES --------------------------------------------
========================================================================== */

var hfdif = $("#footerContent").height()+$("#headerContent").height()
$(document).ready(function(){	
	$("#map-bg-img").each(function(){
 		$(this).data({
	 		"originw"	:	$(this).width(),
	 		"originh"	:	$(this).height(),
	 		"ratio"		:	$(this).width()/$(this).height()	
	 	});
 	});	
 	
 	
 	$(".button-map").each(function() {
    position = $(this).position();
    $(this).data({
 			"originx":position.left,
 			"originy":position.top
 		});
	 	
	 	$("area", this).data({ 			 		
			"originshape":$("area", this).attr("coords")	 		
		}); 
	 	
	 	$("img", this).data({ 			 		
	 		"originw":$("img", this).width(),
	 		"originh":$("img", this).height() 		 		
		});    
	});
	
	
	var ratiodir = "";
	
})


		
		
/*========================================================================
 2.0 CRÉATION DES FONCTIONS -----------------------------------------------
==========================================================================*/


/*------- 2.1 Fonction du redimensionnement des image map ---------------*/
function mapresize(){
	var mpratio= $("#map-bg-img").width()/$("#map-bg-img").data("originw");
	//alert($("#map-bg-img").width())
	$(".button-map").each(function() {    
    
    $("area", this).each(function() {
		    var pairs = $(this).data("originshape").split(', ');
		    for(var i=0; i<pairs.length; i++) {
		        
		        var nums = pairs[i].split(',');
		        for(var j=0; j<nums.length; j++) {
		            nums[j] = parseFloat(nums[j]) *mpratio;
		        }
		        pairs[i] = nums.join(',');
		    }
		    $(this).attr("coords", pairs.join(', '));
		});
		
		$(this).css({
			left:	$(this).data("originx")*mpratio,
			top:	$(this).data("originy")*mpratio
		});
		
		
		$("img", this).each(function(){
			$(this).css({
				width:	$(this).data("originw")*mpratio,
				height:	$(this).data("originh")*mpratio
			});
		});
	});
}

/*------- 2.2 Fonction du redimensionnement de l'arrière-plan -----------*/
function bgresize(){

	var bgratio		=		$("#map-bg-img").data("ratio");
	var winratio	=		$(window).width()/$(window).height();
	var bgmaxh		=		800;		
	
	if (winratio > bgratio){ //Fenetre horizontale	
		$("#map-bg-img").css({
			width	:	$(window).width(),
			height:	$(window).width()/bgratio
		});
		if (winratio/bgratio <= 1.18 ){
			var diffh = ($(window).height()-$("#map-bg-img").height())-hfdif
		} else {
		
			var hh = ($("#map-bg-img").height()-$(window).width())/6
			var diffh = (($(window).height()-$("#map-bg-img").height())-hh)-hfdif
		}
		$("#debug").text(hh);
		
		$("#map-pos").css({ top: diffh })
		
	} else if (winratio < bgratio){ //Fenetre Verticale	
		if( ($(window).height() > bgmaxh) && ($(window).height() > $(window).width()) ){	
			$("#map-bg-img").css({
				width	:	bgmaxh*bgratio,
				height:	bgmaxh
			});
			
			if($(window).height() > $("#map-bg-img").height()){
				var diffh = ($(window).height()-$("#map-bg-img").height())-hfdif
				$("#map-pos").css({ top: diffh })
			}
			
		} else{
			$("#map-pos").css({ top: -hfdif })
			$("#map-bg-img").css({
				width	:	$(window).height()*bgratio,
				height:	$(window).height()
			});
			
			
		}		
	}
	
}



		
/*=========================================================================
 3.0 ACTIONS UTILISATEUR --------------------------------------------------
==========================================================================*/

$(document).ready(function(){		
	/* 3.1 Redimension de la fenêtre */
	$(window).resize(function(){		
		bgresize();	
		mapresize();	
	}).resize();
	
	/* 3.2 Rollover des boutons */	
})




