$(window).load(function(){
	$("#preloader").fadeOut(500,function(){$(this).remove();});
});



//FADES
function fadingElements(){
    $(".thumb_holder .overlay, .ngg-gallery-thumbnail .overlay").fadeTo("fast", 0.0);
	$(".thumb_holder .overlay, .ngg-gallery-thumbnail .overlay").hover(function(){
	$(this).fadeTo(250, 0.6);},

	function(){
		$(this).fadeTo(400, 0.0);
	});
}


function buttonFades(){
	var animDuration = 250; //time in milliseconds
	
	$("button.orange").hover(function() {
		$(this).animate({ backgroundColor: "#ea7500" }, animDuration);
	}, function() {
      	$(this).animate({ backgroundColor: "#cc6600" }, animDuration);
	});
}


//EQUAL HEIGHTS
function equalDivs(){
	$(".equal_one").equalHeight();
	$(".equal_two").equalHeight();
	$(".equal_three").equalHeight();
}


//ACCORDION
function paneAccor(){
	$( "#accordion" ).accordion({ header: '.opener', collapsible: true, active: false, autoHeight: false });
	$( "#accordionArchive" ).accordion({ header: '.opener', collapsible: true, active: false, autoHeight: false });
}


//FORM STYLING
function customForms(){
	$("select, input:checkbox, input:radio, input:file, input:text, textarea").uniform();
}


function evenOddClasses(){
	$("ul li:even").addClass("even");
	$("ul li:odd").addClass("odd");
}

function orderOverlay(){
	$("div.publications button.order_trigger").live('click', function(){
			var id = $(this).attr('id'); // get the link
			$('div.order_overlay#'+id).fadeIn(500);
			$("div.order_overlay#"+id+" .preloader").fadeOut(500);
			customForms();
			return false;
	});
	
	
	$('div.order_overlay .close').click(function(){
		var id = $(this).attr('id');
		$('div.order_overlay#'+id).fadeOut(500);
		return false;
	});
}

//940 MEDIA SLIDER ON EVENTS SINGLES
function mediaAutoSlider() {
	// Trigger mouse move event over the 'menu_holder'.
	$(".thumbnails").mousemove(function(e) {
		// Enable scroll function only when the height of the 'slider' or menu is greater than the 'menu_holder'.
		if($(this).width() < $(".slide_content").width()) {
			// Calculate the distance value from the 'menu_holder' y pos and page Y pos.
			var distance = e.pageX - $(this).offset().left;
			// Get the percentage value with respect to the Mouse Y on the 'menu_holder'.
			var percentage = distance / $(this).width();
			// Calculate the new Y position of the 'slider'.
			var targetX = -Math.round(($(".slide_content").width() - $(this).width()) * percentage);
			// With jQuery easing funtion from easing plugin.
			$('.slide_content').animate({left: [targetX+"px", "easeOutCirc"]}, { queue:false, duration:200 });
			// Without easeing function. by default jQuery have 'swing'.
			//$('#slider').animate({top: [targetY+"px", "easeOutCirc"]}, { queue:false, duration:200 });
		}
	});
	
	
	
	$("div#full_images div.image_container:first-child").fadeIn( function() {
    	$(this).addClass('active');
    });
    
    
    
	$('.thumbnails a.trigger').click(function () {
    	
    	var linkID = $(this).attr('id');
    	var mediaPane = linkID.replace("link_","pane_");

    	$('#full_images div.image_container').fadeOut(
    	
    	function() {
    	$(this).removeClass('active');
    	});
    	
		$('div#'+mediaPane).delay(800).fadeIn(
		
			function() {
    		$(this).addClass('active');
    	});
    	return false;

	});
}


function galleryMasonry(){
	$('.ngg-galleryoverview').masonry({
  		singleMode: true, 
  		itemSelector: '.grid_4'
  	});
}

$(function() {
	fadingElements();
	buttonFades();
	equalDivs();
	paneAccor();
	customForms();
	evenOddClasses();
	orderOverlay();
	galleryMasonry();
	mediaAutoSlider()
});


$(function() {
   var zIndexNumber = 1000;
   $('div').each(function() {
       $(this).css('zIndex', zIndexNumber);
       zIndexNumber -= 10;
   });
});

