$(document).ready(function() {
	
	// Remove 'Search' value from search field when focused.
	$(".query").focus(function () {
		$(this).attr("value", "");
  });
	
	// Remove top margin of first project entry in Asset Maintenance and Legal/Insurance.
	if (window.location.pathname == "/projects/category/asset-maintenance") {
		$('h2:first').addClass('top');
	};
	
	if (window.location.pathname == "/projects/category/legal-insurance") {
		$('h2:first').addClass('top');
	};
	
	// Remove right-hand margin on .projectitem class.
	$('.project img:last').load(function() {
		$('.project').fadeIn(1000);
		$('.project > .item:nth-child(3n)').css('margin-right', '0px');	
	});
	
	// Remove bottom margin of last paragraph in .rightcolumn.
	$('.rightcolumn p:last, .newsitem:last').addClass('bottom');

	// Navigation dropdown.
	$('li.dropdown').hover(
		function() { //Display.
			$('ul', this).css('display', 'block'); },
		function() { // Hide
			$('ul', this).css('display', 'none')
	});
	
	$('li.dropdown').bind('mouseenter mouseleave', function() {
		$(this).toggleClass('hover');
	});
	
	// Animated loading gif.
	var image = $(".images img:first");
	$(image).one("load", function() {
		$(".projectimageload").fadeOut(1000);
	 }).each(function() {
		if (this.complete) $(this).trigger("load");
	});
	
	var thumb = $('.thumb img');
	$('.thumb').each(function() {
		$(thumb).one("load", function() {
			$('.projectthumbload').fadeOut(1000);
		 }).each(function() {
			if (this.complete) $(this).trigger("load");
		});
	});
		
	// Page images cycle.
	$(function() {
		$(".pageimages img:first, .image:first").fadeIn(1000, function() {
			$('.pageimages, .images').cycle({
				fx: 'fade',
				speed: 2000,
				timeout: 6000,
				next: '.frame, .image'
			});
		});
	});
		
});
