$(document).ready(function() {                  	

	//INDEX
	$('#txt_ski').hide();
	$('#txt_cheese').hide();
	
	// CUFON REPLACEMENT
	//Pour IE9
	Cufon.set('engine', 'canvas');
	Cufon.replace('#navbar li a, h1.name, #main h2, #navbar li a span', { fontFamily: 'Myriad Pro Light' }); 
	
	Cufon.replace('.post h3 a, a.read_more, #sidebar h3, #main h3, #main h4, #pagination a',  { fontFamily: 'Lacuna Regular' }); 
	
	Cufon.replace('a.button', {
	fontFamily: 'PT Sans',
	textShadow: '1px 1px #434343'
	});

	//DROPDOWN SCRIPT
	$('#navbar ul').css({display: "none"}); 
	$('#navbar li').hover(function(){
		$(this).find('ul:first').css({visibility: "visible", display: "none"}).fadeIn('fast');
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});	
	
		// IE navbar last child fix		
		$('#navbar li ul li:last-child').css('border-bottom', 'none');	

	
	//SHOW THE LOADER AND HIDE BACKGROUND IMAGE UNTIL IT IS LOADED
	$('#bg img').css('display', 'none');
	$('body').append('<span id="body_loader"></span>');	
	$('#body_loader').fadeIn();
	
	
	//RANDOM IMAGE ON PAGE LOAD 	
	$.randomImage = {
		defaults: {
			
			//you can change these defaults to your own preferences.
			path: '/images/interface/background/', //change this to the path of your images
			myImages: ['background1.jpg', 'background2.jpg', 'background3.jpg', 'background4.jpg', 'background5.jpg', 'background6.jpg', 'background7.jpg' ] //put image names in this bracket. 
			
		}			
	}
	
	$.fn.extend({
			randomImage:function(config) {	
				var config = $.extend({}, $.randomImage.defaults, config); 
				 return this.each(function() {		
						var imageNames = config.myImages;	
						//get size of array, randomize a number from this
						// use this number as the array index
						var imageNamesSize = imageNames.length;
						var lotteryNumber = Math.floor(Math.random()*imageNamesSize);
						var winnerImage = imageNames[lotteryNumber];
						var fullPath = config.path + winnerImage;
						//put this image into DOM at class of randomImage
						// alt tag will be image filename.
						$(this).attr( {
										src: fullPath,
										alt: winnerImage
									});	
				});	
			}
	});
	//RANDOM IMAGE ON PAGE LOAD 	
	$.randomImage2 = {
		defaults: {
			
			//you can change these defaults to your own preferences.
			path: '/images/interface/background-consulting/', //change this to the path of your images
			myImages: ['background1.jpg', 'background2.jpg', 'background3.jpg', 'background4.jpg', 'background5.jpg', 'background6.jpg', 'background7.jpg' ] //put image names in this bracket. 
			
		}			
	}
	
	$.fn.extend({
			randomImage2:function(config) {	
				var config = $.extend({}, $.randomImage2.defaults, config); 
				 return this.each(function() {		
						var imageNames = config.myImages;	
						//get size of array, randomize a number from this
						// use this number as the array index
						var imageNamesSize = imageNames.length;
						var lotteryNumber = Math.floor(Math.random()*imageNamesSize);
						var winnerImage = imageNames[lotteryNumber];
						var fullPath = config.path + winnerImage;
						//put this image into DOM at class of randomImage2
						// alt tag will be image filename.
						$(this).attr( {
										src: fullPath,
										alt: winnerImage
									});	
				});	
			}
	});
	
		
	//run the random script
	$('.random').randomImage();
	$('.random2').randomImage2();
	
	//random image script ends here



    //GALLERY IMAGES HOVER SCRIPT
		
		//add span that will be shown on hover on gallery item
		$(".gallery li a.image").append('<span class="image_hover"></span>'); //add span to images
		$(".gallery  li a.video").append('<span class="video_hover"></span>'); //add span to videos

		$('.gallery  li a span').css('opacity', '0').css('display', 'block') //span opacity = 0 
		
		// show / hide span on hover
		$(".gallery li a").hover(
			 function () {
				 $(this).find('.image_hover, .video_hover').stop().fadeTo('slow', .7); }, 
			function () {
		  		  $('.image_hover, .video_hover').stop().fadeOut('slow', 0);
		});
			
	
             
    //IF BODY HAS CLASS VIDEO_BACKGROUND, MAKE HTML HEIGHT 100% AND ABILITY TO HIDE AND SHOW NAVIGATION ON HOME PAGE
	if($('body').hasClass('video_background'))
	{
		$('html').css('height', '100%');		
		
		
	$('#hide_menu a').css('display', 'block');	
		                  	         
   //SHOWING MENU TOOLTIP ------ delete if you don't want it!                    
    $('#hide_menu a').hover( function(){
         $('.menu_tooltip').stop().fadeTo('fast', 1);            	
     },
     function () {
     	$('.menu_tooltip').stop().fadeTo('fast', 0);  
	});
             
	
	 
		            
    //HIDING MENU         
    
    //click on hide menu button (arrow points up)                            
    $('#hide_menu a.menu_visible').live('click',function(){	
		
	    	//add class hidden
	        $('#hide_menu a.menu_visible')
		        .removeClass('menu_visible')
		        .addClass('menu_hidden')
		        .attr('title', 'Show the navigation');
		   
		    // hide the tooltip     
	        $('.menu_tooltip').css('opacity', '0');
	          
	        //move navigation up, after replace the text                  
		    $('#menu_wrap').animate({top: "-=480px"}, "normal", function() {      	
		                $('.menu_tooltip p').text('Show the navigation');	//tooltip text in when menu is 'hidden' 
	        });
	                       	
            return false;
            
     	});
	          
     	       	
	//SHOWING MENU	
		//click on show menu button (arrow points down)                      	
		 $('#hide_menu a.menu_hidden').live('click', function(){	
		    
		     //add class visible	
		     $('#hide_menu a.menu_hidden')
			     .removeClass('menu_hidden')
			     .addClass('menu_visible');
		
			// hide the tooltip      
		      $('.menu_tooltip').css('opacity', '0');    
		        $('#menu_wrap').animate({ top: "+=480px"}, 'normal');  
		            $('.menu_tooltip p').text('Hide the navigation'); //tooltip text in when menu is 'visible' 
		            
		            return false;    
		 });

	};  

						

		
	/**** ACCORDION ****/
	$('#datacontent a').each(function () {
		$('<div class="fader" />').css('opacity', 0).prependTo(this);
	  }).hover(function () {
		$('img', this).stop().animate({
		  marginLeft : 5
		}, 250);
		
		$('.fader', this).stop().animate({
		  opacity : 0.15
		});
		
	  }, function () {
		$('img', this).stop().animate({
		  marginLeft : 10
		}, 250);
		
		$('.fader', this).stop().animate({
		  opacity : 0
		});
	  }).find('img').css('marginLeft', 10);
	  
	  $('#azerty').each(function () {
		var $links = $(this).find('a.accordion'),
		  panelIds = $links.map(function() { return this.hash; }).get().join(","),
		  $panels = $(panelIds),
		  $panelwrapper = $panels.filter(':first').parent(),
		  delay = 500,
		  heightOffset = 40; // we could add margin-top + margin-bottom + padding-top + padding-bottom of $panelwrapper
		  
		$panels.hide();
		
		$links.click(function () {
		  var link = this, 
			$link = $(this);
		  
		  // ignore if already visible
		  if ($link.is('.selected')) {
			return false;
		  }
		  
		  $links.removeClass('selected');
		  $link.addClass('selected');
		  
				  
		  if ($.support.opacity) {
			$panels.stop().animate({opacity: 0 }, delay);
		  }
		  
		  $panelwrapper.stop().animate({
			height: 0
		  }, delay, function () {
			var height = $panels.hide().filter(link.hash).css('opacity', 1).show().height() + heightOffset;
			
			$panelwrapper.animate({
			  height: height
			}, delay);
		  });
		});
		
		$links.filter(window.location.hash ? '[hash=' + window.location.hash + ']' : ':first').click();
	  });	
		
}); //document.ready function ends here

//WAIT UNTIL CONTENT IS LOADED
$(window).load(function() {
	 
	//hide loader
	$('#body_loader').hide().remove();
	
	//append grid if not on the home page
	if (!$('body').hasClass('body_home')) {	
	$('.grid_overlay, #bg').fadeTo('fast', .8).append('<div class="grid"></div>');
	}
	
	//fade in the image
	$('#bg img').fadeIn('normal');
	   	
});







	


