$(document).ready(function(){
	
	// MENU
	$("div.menu ul").superfish(); 
	
	if ($('.current_page_item').length)
	{
		var bk = $('.menu ul li.current_page_item').css('background-image').replace('/off','/on');
		$('.menu ul li.current_page_item').css('background-image',bk);
	}
	
	$('.menu ul li').hover(
		function(){
			if (!$(this).hasClass('current_page_item')) {
				var bk = $(this).css('background-image').replace('/off','/on');
				$(this).css('background-image',bk);
			}
		},
		function(){
			if (!$(this).hasClass('current_page_item')) {
				var bk = $(this).css('background-image').replace('/on','/off');
				$(this).css('background-image',bk);		
			}
		}
	);
	
	// GALLERY
	$('#gallery_images img:first').css('border','1px solid white');
	
	$('#gallery_images img').live('mouseover',function(){
		var src_l = $(this).attr('data-src');
		var src_c = $(this).attr('data-content');
		$('#gallery_images img').css('border','none');
		$(this).css('border','1px solid white');
		$('#loader').addClass('loading');
		$('#loader img').fadeOut('fast');
		var img = $('#loader img');
		   
		$(img)
			// once the image has loaded, execute this code
		  .load(function () {
		  
			  // set the image hidden by default    
			  $(this).hide();
			    
			  // with the holding div #loader, apply:
			  $('#loader')
			  	// remove the loading class (so no background spinner), 
			  	.removeClass('loading')
			    
			  	// fade our image in to create a nice effect
			    $(this).fadeIn('slow');
		  })
		    
		  // If there was an error loading the image, react accordingly
		  .error(function () {
		  	$('#loader').text('Sorry, this image could not be loaded.');
		  })
		    
		  // Set the src attribute of the new image to our image
		  .attr('src', src_l);
		    
		  // If there is content, show... else hide
		  if (src_c.length > 0) {
		  	$('.image_content').show();
		    $('.image_content').html(src_c);
		  } else {
		  	$('.image_content').hide();
		  }
	});
			
	
	// PRELOAD
	$.fn.preload = function() {
    	this.each(function(){
    		var url = '/wp-content/themes/di/images/menu/on/' + this;
        	$('<img/>')[0].src = url;
    	});
	}

	$(['home.jpg','about.jpg','services.jpg','projects.jpg','contact.jpg']).preload();

});
