//////////////////////////////////////////////////////
//
//	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");
		});
	}
	
	$("div.white_content div#news div:first").addClass("show");
	
	
	//gallery pages	
	if($('#contentHolder > div').length > 0)
	{
		$('#contentHolder > div').fadeOut(0);
		$('#nav_level3 li:first').addClass('selected');
		$('#contentHolder > div').load($('#nav_level3 li a')[0].href +  ' #pageBigContentHolder > div', function(){
			$(this).fadeIn('slow');
		});
	}
	
	$('#nav_level3 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"></div>');
		
		$(this).click(function(){
			var href = this.href;
			$(this).parent().addClass('selected');
			$(this).parent().siblings('.selected').removeClass('selected'); 
			//alert(href);
			$('#contentHolder > div').fadeOut('slow', function(){
				$(this).load(href + " #pageBigContentHolder > div", function(){
						$(this).fadeIn('slow');
				});
				
			});
			return false;
		});
		//fade screen out for IE
		$(this).children('.screen').fadeTo(0,1);
		$(this).hover(function(){			
			$(this).children('.screen').dequeue();
			$(this).children('.screen').fadeTo('slow',0);			
		}, function(){
			$(this).children('.screen').dequeue();
			$(this).children('.screen').fadeTo('slow', 1);
		});
	});
	
	$('.next_page').click(function(){
		var href = $('.items li.selected').next().children('a').attr('href');
		var next = $('.items li.selected').next();
		//if there is no next, do nothing
		if(next.length < 1)
			return false;
		var done = $('.items li.selected');
		
		done.removeClass('selected');
		next.addClass('selected');
		$('#contentHolder div').fadeOut('slow', function(){
			$(this).load(href + " #pageBigContentHolder > div", function(){
					$(this).fadeIn('slow');
			});	
		});
		return false;
	});
	
	$('.prev_page').click(function(){
		var href = $('.items li.selected').prev().children('a').attr('href');
		var prev = $('.items li.selected').prev();
		//if there is no previous, do nothing
		if(prev.length < 1)
			return false;
		var done = $('.items li.selected');
		done.removeClass('selected');
		prev.addClass('selected');
		
		
		$('#contentHolder div').fadeOut('slow', function(){
			$(this).load(href + " #pageBigContentHolder > div", function(){
					$(this).fadeIn('slow');
			});	
		});
		return false;
	});
	
});

