// JavaScript Document


//if (jQuery.browser.msie) {
if (jQuery.browser.msie) {	
	
	jQuery(window).load(function(){
		
		$(document).ready(function(){
			
		// ajout -- avec style="display:none;" dans <div id="bkgallery">
		// cache le div au début ( image peut êtr décalée si plus large que fenêtre)
		// puis le montre uniquement quand bien positionné
		$('#bkgallery').fadeIn('slow');
								   	
		// ajout
		$('.loading').css('display','none');
		$('body').css('overflow','hidden');

	// MENU AUTO HIDE
	/*var auto_hide = true; //Set to false to disable menu auto hide
	var footer = true; //Set to false to hide footer bar
	var active = true;
	
	function movemenu(action){
		if(action == 'hide'){
			$('#footer-wrapper').animate({ marginBottom: "-50px" }, 500 );
			$('#header-wrapper').animate({ marginTop: "-75px" }, 500 );
			active = false;
		}else if(action == 'show'){
			$('#footer-wrapper').animate({ marginBottom: "0px" }, 500 );
		 	$('#header-wrapper').animate({ marginTop: "0px" }, 500 );
			active = true;
		}
	}
	if(footer == false ){ $('#footer-wrapper').hide(); }
	$(function() {
		setInterval(function() {		
							 
			if(active&&auto_hide){
				active = false;
				movemenu('hide');
			}
		}, 1000);
	});				 
	$(document).mousemove( function(e) {
		 if(auto_hide){
		 movemenu('show');
		 active = true;
		 }
	});*/
		
	


	 // MY BKGALLERY SCRIPT TO MANAGE BACKGROUND IMAGES
	
	var actualimg = 1;
	var totalimages = jQuery('#bkgallery img').length;
   	var skip_transition = false;
    var imagewidth = jQuery('#bkgallery #im1').width();
    var imageheight = jQuery('#bkgallery #im1').height();
	var ratio = imageheight/imagewidth;
	   
	if(totalimages == 1){jQuery('#bkgallery a').hide();}
	 
    supersizeImage(jQuery('#bkgallery #im1'), ratio);
	
    
    jQuery(window).resize(function() {
			imagewidth = jQuery('#im'+actualimg).width();
       		imageheight = jQuery('#im'+actualimg).height();
			ratio = imageheight/imagewidth; 
			
			supersizeImage(jQuery('#im'+actualimg), ratio);
    });
	

	
	function fadeImage(action){
		if(skip_transition == false){
			
			jQuery('#bkgallery img').fadeOut(1500);
			if(action == "prev"){
				actualimg = actualimg-1;
				if(actualimg < 1 ){
					actualimg = totalimages;
				}
			}else if(action == "next"){
				actualimg = actualimg+1;
				if(actualimg > totalimages){ actualimg = 1;}
			} 
			imagewidth = jQuery('#im'+actualimg).width();
       		imageheight = jQuery('#im'+actualimg).height();
			ratio = imageheight/imagewidth; 
			
			supersizeImage(jQuery('#im'+actualimg), ratio);
			jQuery('#im'+actualimg).fadeIn(1500);	
		}
		skip_transition = false; 
	}
	
	function fadeImageTarget(target){
		if(skip_transition == false){	 
			targetimg = parseInt(target.substr(2));// retrieve the image number in "imXXX"
			jQuery('#bkgallery img').fadeOut(1500);
			imagewidth = jQuery('#'+target).width();
       		imageheight = jQuery('#'+target).height();
			ratio = imageheight/imagewidth; 
			supersizeImage(jQuery('#'+target), ratio);
			jQuery('#'+target).fadeIn(1500);
			actualimg = targetimg; // for next/prev buttons
		}
		skip_transition = false;
	}
	
	function resetArrows(){
		 $('.prev').removeClass('disabled');
		  $('.next').removeClass('disabled');
	}
   
    jQuery(function() {
        if(totalimages >1 && skip_transition == false && autogallery == true ){
            setInterval(function() {   
				fadeImage( 'next');
            }, 3000);
        } 
    });
	
	jQuery('.bkgallery-nav a').click(function(){
		resetArrows();
		skip_transition = false; 
		var action = ($(this).attr('class'));
		fadeImage(action);
		skip_transition = true;
		return false;
	});
	
	jQuery(document).keydown(function(event) {
		 
	  	if (event.keyCode == '39') { //NEXT
		 	jQuery('.bkgallery-nav .next').click();
	   	}else  if (event.keyCode == '37') { //PREV
		 	jQuery('.bkgallery-nav .prev').click();
	   	}
	   	 
	});
	
	

	// SUPERSIZE FUNCTION TO MANAGE SCREEN RATIO FIT FOR BACKGROUND IMAGE  

    function supersizeImage(image, ratios) {
		
	   
	   //alert(imagewidth + " - "+imageheight);
       var browserwidth = jQuery(window).width();
       var browserheight = jQuery(window).height();
 	   if(imageheight == 0){imageheight = jQuery(image).attr('height');}
       
	
       if ((browserheight/browserwidth) >= ratios){//si la pantalla es mas alta que ancha (respecto al ratio
               jQuery(image).height(browserheight);
               jQuery(image).width(browserheight / ratios); 
       } else { 
	   			 
               jQuery(image).width(browserwidth);
               jQuery(image).height(browserwidth * ratios);    
       }
     
       jQuery(image).css('left', (browserwidth - jQuery(image).width())/2);
       if(jQuery(image).height()>0){
       		jQuery(image).css('top', (browserheight - jQuery(image).height())/2);
       }
	}
	
	function supersizeHeaderImage(image, ratios) {
  
	   //alert(imagewidth + " - "+imageheight);
       var browserwidth = jQuery(window).width();
       var headerheight = jQuery('#header-image').height();
 	   if(imageheight == 0){imageheight = jQuery(image).attr('height');}  
		
       if ((headerheight/browserwidth) >= ratios){//si la pantalla es mas alta que ancha (respecto al ratio
               jQuery(image).height(headerheight);
               jQuery(image).width(headerheight / ratios); 
       } else { 
	   			 
               jQuery(image).width(browserwidth);
               jQuery(image).height(browserwidth * ratios);    
       }
     
       jQuery(image).css('left', (browserwidth - jQuery(image).width())/2);
       if(jQuery(image).height()>0){
       		jQuery(image).css('top', (headerheight - jQuery(image).height())/2);
       }
	}
	 
});  
	   


});

}else{

$(document).ready(function(){
	
	jQuery(window).load(function(){	
	// ajout -- avec style="display:none;" dans <div id="bkgallery">
	// cache le div au début ( image peut êtr décalée si plus large que fenêtre)
	// puis le montre uniquement quand bien positionné
	$('#bkgallery').fadeIn('slow');	
	// ajout
	$('.loading').css('display','none');
	$('body').css('overflow','hidden');
								 
	
	// MENU AUTO HIDE
	// ca bugge
	/*var auto_hide = true; //Set to false to disable menu auto hide
	var footer = true; //Set to false to hide footer bar
	var active = true;
	
	function movemenu(action){
		if(action == 'hide'){
			$('#footer-wrapper').animate({ marginBottom: "-100px" }, 500 );
			$('#header-wrapper').animate({ marginTop: "-100px" }, 500 );
			active = false;
		}else if(action == 'show'){
			$('#footer-wrapper').animate({ marginBottom: "0px" }, 500 );
		 	$('#header-wrapper').animate({ marginTop: "0px" }, 500 );
			active = true;
		}
	}
	if(footer == false ){ $('#footer').hide(); }
	$(function() {
		setInterval(function() {						 
			if(active&&auto_hide){
				movemenu('hide');
			}
		}, 3000);
	});
					 
	$(document).mousemove( function(e) {
		 if(auto_hide){
		 movemenu('show');
		 }
	});*/
	

	
	// FADE EFFECTS
 
	//portfolio thumb fadein fadeout
	$(".image img").css("opacity",.7); 
	$(".image").hover(function(){
		$(this).find("img").fadeTo("slow", 1);
		$(this).find("span.title,div.description").fadeTo("slow", 1); 

	}, function(){
		$(this).find("img").fadeTo("slow", .7);
		$(this).find("span.fadeout,div.description").fadeTo("slow", 0); 
	});
	
	//blog thumb fadein fadeout
	$(".post img").css("opacity",1); 
	
	$(".show").css("opacity",0);
	$(".post").hover(function(){
		$(this).find("div.extract, div.extract p").fadeTo("slow", 1);
		$(this).find("div.postdata,div.postdata span").fadeTo("slow", 0); 

	}, function(){
		$(this).find("div.extract, div.extract p").fadeTo("slow", 0);
		$(this).find("div.postdata, div.postdata span").fadeTo("slow", 1); 
	});
	
	
	
	 // MY BKGALLERY SCRIPT TO MANAGE BACKGROUND IMAGES
	
	var actualimg = 1;
	var totalimages = jQuery('#bkgallery img').length;
   	var skip_transition = false;
    var imagewidth = jQuery('#bkgallery #im1').width();
    var imageheight = jQuery('#bkgallery #im1').height();
	var ratio = imageheight/imagewidth;
	   
	if(totalimages == 1){jQuery('#bkgallery a').hide();}
	
	
	 
    supersizeImage(jQuery('#bkgallery #im1'), ratio);
	
	supersizeHeaderImage(jQuery('#header-image img'), ratio);
    
	
    jQuery(window).resize(function() {
			imagewidth = jQuery('#im'+actualimg).width();
       		imageheight = jQuery('#im'+actualimg).height();
			ratio = imageheight/imagewidth; 
			
			supersizeImage(jQuery('#im'+actualimg), ratio);
    });
	
	

	function fadeImage(action){
		if(skip_transition == false){
			
			jQuery('#bkgallery img').fadeOut(1500);
			if(action == "prev"){
				actualimg = actualimg-1;
				if(actualimg < 1 ){
					actualimg = totalimages;
				}
			}else if(action == "next"){
				actualimg = actualimg+1;
				if(actualimg > totalimages){ actualimg = 1;}
			} 
			imagewidth = jQuery('#im'+actualimg).width();
       		imageheight = jQuery('#im'+actualimg).height();
			ratio = imageheight/imagewidth; 
			supersizeImage(jQuery('#im'+actualimg), ratio);
			jQuery('#im'+actualimg).fadeIn(1500);	
		}
		skip_transition = false; 
	}
	
	function fadeImageTarget(target){
		if(skip_transition == false){	 
			targetimg = parseInt(target.substr(2));// retrieve the image number in "imXXX"
			jQuery('#bkgallery img').fadeOut(1500);
			imagewidth = jQuery('#'+target).width();
       		imageheight = jQuery('#'+target).height();
			ratio = imageheight/imagewidth; 
			supersizeImage(jQuery('#'+target), ratio);
			jQuery('#'+target).fadeIn(1500);
			actualimg = targetimg; // for next/prev buttons
		}
		skip_transition = false;
	}
	
	function resetArrows(){
		 $('.prev').removeClass('disabled');
		  $('.next').removeClass('disabled');
	}
   
    jQuery(function() {
        if(totalimages >1 && skip_transition == false && autogallery == true ){
			
            setInterval(function() {    
				fadeImage( 'next');
            }, 3000);
        } 
    });
	
	jQuery('.bkgallery-nav a').click(function(){
		resetArrows();
		skip_transition = false; 
		var action = ($(this).attr('class'));
		fadeImage(action);
		skip_transition = true;
		return false;
	});
	
	jQuery(document).keydown(function(event) {
		 
	  	if (event.keyCode == '39') { //NEXT
		 	jQuery('.bkgallery-nav.next').click();
	   	}else  if (event.keyCode == '37') { //PREV
		 	jQuery('.bkgallery-nav.prev').click();
	   	}
	   	 
	});
	
	

	// SUPERSIZE FUNCTION TO MANAGE SCREEN RATIO FIT FOR BACKGROUND IMAGE  

	

    function supersizeImage(image, ratios) {
  
	   //alert(imagewidth + " - "+imageheight);
       var browserwidth = jQuery(window).width();
       var browserheight = jQuery(window).height();
 	   if(imageheight == 0){imageheight = jQuery(image).attr('height');}
	
       if ((browserheight/browserwidth) >= ratios){//si la pantalla es mas alta que ancha (respecto al ratio
               jQuery(image).height(browserheight);
               jQuery(image).width(browserheight / ratios); 
       } else { 
	   			 
               jQuery(image).width(browserwidth);
               jQuery(image).height(browserwidth * ratios);    
       }
     
       jQuery(image).css('left', (browserwidth - jQuery(image).width())/2);
       if(jQuery(image).height()>0){
       		jQuery(image).css('top', (browserheight - jQuery(image).height())/2);
       }
	}
	
	function supersizeHeaderImage(image, ratios) {
  
	   //alert(headerimagewidth + " - "+headerimageheight);
       var browserwidth = jQuery(window).width();
       var headerheight = jQuery('#header-image').height();
 	   if(imageheight == 0){imageheight = jQuery(image).attr('height');}  
		
       if ((headerheight/browserwidth) >= ratios){//si la pantalla es mas alta que ancha (respecto al ratio
               jQuery(image).height(headerheight);
               jQuery(image).width(headerheight / ratios); 
       } else { 
	   			 
               jQuery(image).width(browserwidth);
               jQuery(image).height(browserwidth * ratios);    
       }
     
       jQuery(image).css('left', (browserwidth - jQuery(image).width())/2);
       if(jQuery(image).height()>0){
       		jQuery(image).css('top', (headerheight - jQuery(image).height())/2);
       }
	}
	
	
	

 	});	
});  
	   


 
}

