largeur_site = 1004;

$(document).ready(function(){  

    $(window).resize(function(){
		afficheBandeauTop();
		changeLarSSMenu();
		redimensionnementBackgroundFull();
    });
	         manageRotation(); 
	redimensionnementBackgroundFull();
	afficheBandeauTop();
	changeLarSSMenu();
	
	manageFooterHome();
	manageMenu();
  	
	if($.browser.msie && $.browser.version=="6.0") {
	
		if($("body").hasClass("front")) {
			
			$("html").css("overflow","hidden");
			
		} else {
			
			//$("html").css("overflow-x","hidden");
			
		}
		
	}
	
});


	$(function () {
		//if($(document).find('.section-nous-rejoindre').length!=0) {
			$("#accordion").accordion({ active: 'none',clearStyle: true, collapsible: true });
		//}	
	});

/* Inspire de Alsacreations */
function redimensionnementBackgroundFull(){
	
    var image_width = 1200;  
    var image_height = 800;      
	
    var over = image_width / image_height;  
    var under = image_height / image_width;  
      
    var body_width = $(window).width();  
    var body_height = $(window).height();  
    
	if(!$.browser.msie && $.browser.version!="6.0") {
	
	    if (body_width / body_height >= over) {
		  $('#backgroundFull').css({  
			'width': body_width + 'px',  
			'height': Math.ceil(under * body_width) + 'px',  
			'left': '0px',  
			'top': Math.abs((under * body_width) - body_height) / -2 + 'px'  
		  });  
		} else {
		  $('#backgroundFull').css({
			'width': Math.ceil(over * body_height) + 'px',  
			'height': body_height + 'px',  
			'top': '0px',  
			'left': Math.abs((over * body_height) - body_width) / -2 + 'px'  
		  });  
		}
	
	} else {
		
		var haut = document.documentElement.clientHeight;
		
		var lar = document.documentElement.clientWidth;
		
		if(lar/haut >= over) {
			
			$('#backgroundFull').css({
				'width': lar,
				'height': Math.ceil(under * lar),  
				'top': '0px'
				//'left': eval(Math.ceil((body_width / 2) - over * haut / 2 ) ) + 'px'  
			});
		
		} else {
			
			$('#backgroundFull').css({
				'width': Math.ceil(over * haut),
				'height': haut, 
				'top': '0px',  
				'left': '0px'  
			});
		
		}
		
	}
	
}

function afficheBandeauTop() {
	
	var window_lar = $(window).width();
	var header_left = $('#page_header').offset().left
	var lar = window_lar - ( header_left + largeur_site ) + 32;
	
	if( ( window_lar > largeur_site )  ) {	
		
		if ($.browser.msie ) {
			
			header_left += 1;
			lar += 1;
			
		}
		
		/*header_left += 2;*/
		
		$('#bandeauTopLeft').css({
			'display' : 'block',
			'width' : header_left
		});
	
	} else {
		
		$('#bandeauTopLeft').css({
			'display' : 'none'
		});
		/*
		$('#bandeauTopRight').css({
			'display' : 'none'
		});*/
		
	}
	
	if(lar<36){ lar = 36; }
	
	$('#bandeauTopRight').css({
		'display' : 'block',
		'width' : lar
	});
	
}

var timerFooter;

function manageFooterHome() {
	
	$('#page_footer #acces_direct').bind('mouseenter', function() {
		
		clearTimeout(timerFooter);
		afficheFooterHome();
		
		
	});
	$('#page_footer #acces_direct').bind('mouseleave', function() {
		
		timerFooter = setTimeout("cacheFooterHome()",100);
		
	});
	$('#page_footer #acces_direct').bind('click', function() {
	return false;
	});
	
	
	$('#page_footer #block-rich_footer-rich_footer_level_2').bind('mouseenter', function() {
		clearTimeout(timerFooter);
		afficheFooterHome();
		
	});
	
	$('#page_footer #block-rich_footer-rich_footer_level_2').bind('mouseleave', function() {
		timerFooter = setTimeout("cacheFooterHome()",100);
		
	});
	
}

function afficheFooterHome() {
	
	$('#page_footer #block-rich_footer-rich_footer_level_2').fadeIn(150);
	
}

function cacheFooterHome() {
	
	$('#page_footer #block-rich_footer-rich_footer_level_2').fadeOut(100);
	
}

function changeLarSSMenu() {
	
	var lar = $(window).width() - ( $('#page_header').offset().left + 200 );
	
	if(lar%2 != 0) {
		
		//lar += 1;
		
	} 
	
	$('#page_header .ss-menu ').css({
		'width' : lar
	});
		
		
		  
}

function manageMenu() {
	
	if ( !$.browser.msie ) {
	
		$('#page_header li .ss-menu').css({
			opacity : 0,
			top : -50
		});
		
	}
	
	$('#page_header li.item').each(function(index) {
		
		$(this).bind('mouseenter', function() {
			
			$(this).find('a').addClass('over');
			
			menu_in = $(this).find('.ss-menu')
			
			$(menu_in).stop();
			
			if ( !$.browser.msie ) {
				
				$(menu_in).css('display','block');
				
				$(menu_in).animate({
					opacity: 1,
					top: 0
				}, 150, function() {
				});
				
			} else {
				
				$(menu_in).css('display','block');
				
			}
			
		});
		
		$(this).bind('mouseleave', function() {
			
			$(this).find('a').removeClass('over');
			
			menu_out = $(this).find('.ss-menu')
			
			$(menu_out).stop();
			
			if ( !$.browser.msie ) {
			
				$(menu_out).animate({
					opacity: 0,
					top: -50
				}, 0, function() {
					//alert($(this).find('a').html());
					$(menu_out).css('display','none');
				});
				
			} else {
				
				$(menu_in).css('display','none');
				
			}
		
		});
		
	});
	

	
}


var tab_Image = [0,1,2];
var actImgRotation = 0;

function manageRotation() {

	fisherYates(tab_Image);
	
	$('#background-container').append('<img id="backgroundFull" src="/sites/all/themes/gpn/img/fond_home_'+tab_Image[0]+'.jpg" width="1200" height="800" alt="" />');
	
	if($(document).find('.i18n-en').length!=0) { 
		$('#accroche').append('<img class="png" src="/sites/all/themes/gpn/img/accroche_home_en_'+tab_Image[0]+'.png" alt="">');
	} else {
		$('#accroche').append('<img class="png" src="/sites/all/themes/gpn/img/accroche_home_fr_'+tab_Image[0]+'.png" alt="">');
	}
		
}

function fisherYates ( myArray ) {
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}






