//////////////////////////////////////////////////////
//
//	The purpose of this file is to
//	apply a hover class on mouseover
//	on the <li> elements in the nav.
//	This is because IE doesn't put
//	the pseudo class :hover on <li> elements
//
//	This is code that uses the
//	jquery javascript library (http://jquery.com/)
//
//////////////////////////////////////////////////////
$(window).load(function() {

		if (document.all&&document.getElementById) {
		// this is needed for the IE 6 pseudo hover class bug
		$(".navtop > li").hover(function() {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
		// this adds flyout support for IE 6
		$(".navtop > li li ").hover(function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
		
	} else {
		// this is need for safari when nav covers flash
		$(".navtop li ul").hover(function () {
			$(this).addClass("redraw");
		},
		function () {
			$(this).removeClass("redraw");
		});
	}
	
		
	
	//gallery pages
	if($('#gallery p').length > 0)
	{
		$('#gallery p').fadeOut(0);
		$('#gallery p').load($('#imageNav li a')[0].href +  ' #pageContentHolder img', function(){
			$(this).fadeIn('slow');
		});
	}
	
	var href = "";
	$('#imageNav li:first a').addClass('chosen');
	$('#imageNav li a').each(function(){	
		var img = $(this).children('img')[0];
		var w =  img.width;
		var h =  img.height;
		var screen = $(this).append('<div class="screen" style="width: ' + w + 'px;height: ' + h +  'px;"></div>');
		$(this).click(function(){
			$('#imageNav li a.chosen').removeClass('chosen');
			$(this).addClass('chosen');
			var myAnchor = this;
			$('#gallery p').fadeOut('slow', function(){
				$(this).load(myAnchor.href + ' #pageContentHolder img', function(){
						$(this).fadeIn('slow');
				});
				
			});
		return false;
		});	
		
		$(this).children('.screen').fadeTo(0,0.5);
		$(this).hover(function(){
			href = this.href;
			//$('#testOut').append('<p>' + href + '</p>');
			$(this).children('.screen').dequeue();
			$(this).children('.screen').fadeTo('slow',0);
			//$('#testOut').append('<p>hover</p>');
			$('#pageContentHolder p').fadeOut('slow', function(){
				$(this).load(href + " #pageContentHolder img", function(){
						$(this).fadeIn('slow');
				});
				
			});
			
		}, function(){
			$(this).children('.screen').dequeue();
			$(this).children('.screen').fadeTo('slow', 0.5);
		});
	});
	
	
	// next button
	$('a.right').click(function(){
		$('#imageNav li a.chosen').parent('li').next().children('a').trigger('click');	
	});
	
	// previous button
	$('a.left').click(function(){
		$('#imageNav li a.chosen').parent('li').prev().children('a').trigger('click');	
	});
	
	
	// Remove default form text on focus
	$(".emptytext").focus( function(){
		if ( $(this).val() == $(this)[0].defaultValue ) {
			$(this).val("");
		}
	});
	// Replace default form text on blur if input is empty
	$(".emptytext").blur( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this)[0].defaultValue );
		}
	});
	
	
});

