var elOpen = null;
var headers = Array();
var curimage = -1;
var first = true;
fncAnimate = function()
{
	
	curimage++;
//	console.log(headers);
	
	if(curimage >= headers.length) curimage = 0;
	var foo = headers[curimage];
	
	
	$('img.photo').attr('src', foo.image);
	$('img.photo').attr('height', foo.height);

	if(!first) $('img.photo').fadeIn(4000);
	
	$('img.photo').animate({
		marginTop: '-' + (foo.height - 214) + 'px'
	}, 7000).fadeOut(4000).animate({
		marginTop: '0px'
	}, 1);

	if(first) setTimeout('fncAnimate()', 11000);
	else setTimeout('fncAnimate()', 15000)
	
	first = false;
	
};

resizeWindow = function() {
	//alert(($('.contentwrapper').height() + $('.contentwrapper').height()) + "px");
	//alert($(document).height() + "px");
	$('div.contentshade').css('height', ($('.contentwrapper').height() + $('.headerwrapper').height()) + "px");
	//$('body').css('height', ($('.contentwrapper').height() + $('.headerwrapper').height() + 40) + "px");
	
//	$('body').css('height', $(document).height());
};

$(document).ready(function(){
	var resizeTimer = null;
	
	$('.preloadedHeaderImage').each(function() {
		headers[headers.length] = { image : $(this).attr('src'), height : parseInt($(this).attr('imageheight')) } 
	});
	
	
	
	$(document).bind('resize', function() {
		if (resizeTimer) clearTimeout(resizeTimer);
		
		resizeTimer = setTimeout(resizeWindow, 100);
	});

	
	var blnFoundSelect = 0;
	
	resizeWindow();
	
	$('.content .menu li').each(function() {
		if(blnFoundSelect && blnFoundSelect == 1)
		{
			elOpen = $(this);
			blnFoundSelect = 2;
		}
		if($(this).hasClass('selected') && blnFoundSelect == 0)
		{
			blnFoundSelect = 1;
		}
		if($(this).hasClass('selected') && blnFoundSelect == 2)
		{
			elOpen.show();
			elOpen = null;
		}
		
	});
	
	if(elOpen)
	{
		
		setTimeout('elOpen.slideDown(1000); resizeWindow();', 500);
	}
	
	
	
	
	
	$("a.album_image").fancybox({
		'overlayShow'			: false,
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'			: 500,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack'
	});
	
	if(headers.length > 1)
	{
		setTimeout('fncAnimate()', 1000);
	}
	
});
