//JSON banner content array

/*
* fonctions pour animations maps
*
*/ 
var temp;
function country_mouseover(country) {
	var element = country.split(' '); 
	country = element[0];

	$('#'+country+'_hover').fadeIn('fast');
	//alert($('#'+country+'_hover').css('top'));
	temp = getCountryToCss(country);
	country = country.replace('_',' ');
	
	
	//console.info(country);
	//$('ul#country_list li:contains(' + country + ')').addClass('hover');
}
function country_mouseout(country) {
var element = country.split(' '); 
	country = element[0];
	$('#'+country+'_hover').fadeOut('slow');
	country = country.replace('_',' ');
	//$('ul#country_list li:contains(' + country + ')').removeClass('hover');
}
function afterRender() {
	//render_ads(2);
}
function getCountryToCss(country){
	return country;
	
}



	
	
/*
* fin fonctions
*/

//var banner_data = {
//	//Tooltips
//	"tooltips" : [
//		//Remember that the count starts at zero
//		
//		{
//			//Array ID -> 0
//			"Title"   : "io lele", 
//			"Content" : "otran desin be",
//			"ImageURL"   : "yellow-bg.jpg"
//		},
//		
//		{
//			//Array ID -> 1
//			"Title"   : "Nice", 
//			"Content" : "You found link number 2",
//			"ImageURL"   : "orange-bg.jpg"
//		}
//		
//	] 
//}



// Image Preloader via http://www.innovatingtomorrow.net/2008/04/30/preloading-content-jquery
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

//Actual jQuery starts here on document ready
$(document).ready(function() {
	
	/*
	*	animations map area
	*
	*/
	$('area').live('mouseover',function(e) {
		var clicked = e.target;
		var country = $(clicked).attr('class');
	
		country_mouseover(country);
	}).live('mouseout',function(e) {
		var clicked = e.target;
		var country = $(clicked).attr('class');
		country_mouseout(country);
	});
	/*
	* fin animations
	*/
	
	//Goes through each tooltip's image URL
	for(var i = 0; i < banner_data.tooltips.length; i++){
		
		image_location = banner_data.tooltips[i].ImageURL;
		
		//Preload if location exists
		if (image_location != ''){
			$.preloadImages(image_location);
		};
		
	};
	
	
	$('area.tooltip').click(function(){ 
		//when hover starts
		
		//Get the ID of the current tooltip
	active_tooltip = $(this).attr('rel');
		
	top_ = $('#'+temp+'_hover').css('top');
	left = $('#'+temp+'_hover').css("margin-left");	
	top_ = top_.replace('px',' ');
	left = left.replace('px',' ');
	top_ = top_ - 80;
	left = left -40;
	
	
		//Replace the HTML in the header with data from JSON array
		$('#banner span.titreBanner').html(banner_data.tooltips[active_tooltip].Title);
		$('#banner p').html(banner_data.tooltips[active_tooltip].Content);
		
		$('#banner').css("display","block");
		$('#banner').css("margin-left",left+"px");
		$('#banner').css("top",top_+"px");
		//positioningTooltip(top,left);
		//$('#banner img').show().attr('src', banner_data.tooltips[active_tooltip].ImageURL);
        $('#info_contact').html(banner_data.tooltips[active_tooltip].Contact);
		
	
	//alert($('#'+country+'_hover').css('top'));
	//	alert(banner_data.tooltips[active_tooltip].Contact);
	
		
	
		
	},
	function(){ //When hover ends
		
		//Reset banner to defaults
		$('#banner h1').html("");
		$('#banner p').html("");
		$('#banner').css("");
        $('#info_contact').html('&nbsp;');
		
		//$('#banner img').hide().attr('src', '');
		
	});
	
});

