// JavaScript Document

//////////////////////////////////////////////////////
//
//	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/)
//
//////////////////////////////////////////////////////

$(document).ready(function() {
	//comment this out if you have no png images
    $('img[@src$=.png]').ifixpng(); 
});

$(window).load(function() {
	
	//animated cream logo
	$('#cream a').hover(function(){
			$('#cream').animate({backgroundColor: '#eb9e29'}, 'slow');
		}, function(){
			$('#cream').animate({backgroundColor: '#bebebe'}, 'slow');
	});
	
	//homepage slideshow
	if($('#slideShow').length > 0)
	{
		$('#slideShow').serialScroll({items: 'div.slide', next:  'a.next', prev: 'a.prev', target: '#boogie', constant: false, duration: 300, easing: 'swing'});
	
		$('#slideShow a.next,#slideShow a.prev').hover(
			function(){ 
				$(this).dequeue();
				$(this).animate({width: "22px"}, "fast");
			},
			function(){
				$(this).animate({width: "16px"}, "fast");
			}
		);
	}
	
	if($('#c1').length > 0)
	{
		var divs = $('#c1 > div');
		var n = divs.length;
		if(n > 0) 
			$(divs[Math.floor(n*Math.random())]).css({display: 'block'});

	}
	
	if($('#c3').length > 0)
	{
		var ps = $('#c3 p');
		var n = ps.length;
		if(n > 0)
			$(ps[Math.floor(n*Math.random())]).css({display: 'block'});

	}
	
	if($('#gallery').length > 0)
	{
		var defaultDescription = "";
		defaultDescription = $('#titleDesc .description').html();
		$('#gallery li a').each(function(){
			var screen = $('<div class="screen"></div>').appendTo(this);
			$(this).children('.screen').animate({opacity: 0.7}, '1');
			$(this).hover(
				function(){
					if($(this).parent().hasClass('selected'))
						return;
					$(this).children('.screen').dequeue();
					$(this).children('.screen').animate({opacity: 0}, 'fast');
					$('#titleDesc .description').html($(this).siblings('span.description').html());
				}, 
				function(){
					if($(this).parent().hasClass('selected'))
						return;
					$(this).children('.screen').animate({opacity: 0.7}, 'fast');
					$(this).children('.screen').dequeue();
					$('#titleDesc .description').html(defaultDescription);
			});
		});
		
		/*var scrollWidth = Math.ceil($('#gallery ul li').length / 6 ) * (882);*/
		var scrollWidth = Math.ceil($('#gallery ul li').length / 6 ) * (882);
		scrollWidth = scrollWidth + 1;
		var excludeValue = $('#gallery ul li').length - 1;
		$('#gallery ul').width(scrollWidth + 'px');
		$('#gallery').serialScroll({items: 'li', next:  'a.next', prev: 'a.prev', target: '#slider', constant: true, duration: 1000, easing: 'easeOutQuart', step: 6, cycle: true, lock: false, exclude: 5});
	
		$('#gallery ul li.selected a .screen').animate({opacity: 0}, 'fast');
		$('#gallery ul li a').click(function(){
			var mrA = this;
			if($(this).parent().hasClass('selected'))
			{
				return false;
			}
			defaultDescription = $(this).siblings('span.description').html();
			$('#gallery ul li.selected').removeClass('selected').find('.screen').animate({opacity: 0.7}, 'fast');
			$(this).parent().addClass('selected');
			$('#galleryContent').animate({height: '20px', opacity: 0},'slow', function(){
				$('#galleryContent #target').css({display: "none"});
				$('#galleryContent #target').load(mrA.href + ' #galleryContent div' , function(){
					$('#galleryContent #target').css({display: "block"});
					$('#galleryContent').animate({height: '570px', opacity: 1},'slow');
				}); 
			});
			/*$('#galleryContent').animate({opacity: 0},'slow', function(){
				$('#galleryContent #target').css({display: "none"});
				$('#galleryContent #target').load(mrA.href + ' #galleryContent div' , function(){
					$('#galleryContent #target').css({display: "block"});
					$('#galleryContent').animate({opacity: 1},'slow');
				}); 
			});*/
			return false;
		});
	
		$('#gallery a.next,#gallery a.prev').hover(
			function(){ 
				$(this).dequeue();
				$(this).animate({width: "22px"}, "fast");
			},
			function(){
				$(this).animate({width: "16px"}, "fast");
			}
		);
	}
});
