/**
 * Penlee House Gallery
 */


var Penlee = {
	
	/**
	 * Start the Javascript implementations
	 * 
	 * @return void
	 */
	start: function() {
		
		$('#q').focus(function() {
			if($(this).val() == 'Search') {
				$(this).val('');
			}
		}).blur(function() {
			if($(this).val() == '') {
				$(this).val('Search');
			}
		});

                artistPortfolio.init();
		
	}
	
};


var artistPortfolio = {
	
	init: function() {
		
		var locationhash = location.hash;
		
		$('.portfolio-mainimage-overlay').html('');
		
		$('.portfolio-images img').fadeTo('fast', 1);
		
		$('.portfolio-images img:first').addClass('selected-image').fadeTo('fast', 0.3);
		
		$('.portfolio-images a').click(function() {
			var src = $(this).attr('href');
			var h4  = $(this).find('span').attr('title');
			var p   = $(this).attr('title');
			var hash= $(this).attr('rel');
			
			if(hash) {
				location.hash = hash;
			}
			
			$('.portfolio-images img').removeClass('selected-image').fadeTo('fast', 1);
			$(this).find('img').fadeTo('fast', 0.3).addClass('selected-image');
			
			$('.portfolio-mainimage-overlay').stop().fadeIn('fast', function() {
				$('.top-image-text-area h4').html( h4 );
				$('.top-image-text-area p').html( p );
				$('#main-image').attr('src', src ).load(function() {
					$('.portfolio-mainimage-overlay').stop().fadeOut('fast');
				});
			});
			
			return false;
		});
		
		if(locationhash) {
			$(".portfolio-images a[rel='" + locationhash + "']").trigger('click');
		}
		
	}
	
};

/**
 * When the DOM is ready run the method Penlee.start()
 */

$(document).ready(Penlee.start);