var toLoad = "";
$(document).ready(function() 
{
/*
	var hash = window.location.hash.substr(2);
	var href = $('#nav li a').each(function()
	{
		var href = $(this).attr('href');
		if(hash==href.substr(1))
		{
			toLoad = hash;
			$('#content').load('/views/'+toLoad+'.php', showContent());
		}
	});

	$('#nav li a').click(function()
	{
		toLoad = $(this).attr('href').substr(1);
		
		$('#content').hide('fast',closePage);
		window.location.hash = $(this).attr('href');		
		return false;
	});
	*/
	init();
});

function loadContent()
{
	$('#content').load('/views/'+toLoad+'.php','',showNewContent())
}

function showPageContent()
{
	$('#main-header').fadeIn(100, function()
	{
		$('#main-header').animate({"left": "600"}, 750, "easeInCirc", function(){
			$('#bio-nav').fadeIn(800, function()
			{
				$('#buzzsaw-logo-small').fadeIn(800);
				$('#small-nav').fadeIn('fast');
			});
		});
	});
}


function showBioDetails()
{
	$('#bio').fadeIn('fast');
	$('.scroll-pane').show().jScrollPane();
}

function closeBioDetails()
{
	$('#bio').fadeOut('fast');
	$('.scroll-pane').hide().jScrollPane();
}

function showDirectorDetails()
{
	$('#main-header').animate({ left: 600, opacity: 1.0},750, "easeInCirc", function()
	{
		$('#bio-nav').fadeIn(800, function()
		{
			$('#clips').fadeIn(800, function()
			{
				$('#buzzsaw-logo-small').fadeIn(800);
				$('#small-nav').fadeIn('fast');
			});
		});
	});
}





function showClientLogin()
{
	$('#clientlogin-header').animate({ top: 250, opacity: 1.0},1050, "easeInCirc", function()
	{
		$('#clientLogin-display').fadeIn(800, function()
		{
			$('#buzzsaw-logo-small').fadeIn(800);
			$('#small-nav').fadeIn('fast');
		});
	});
}
function showContact()
{
	$('#contact-header').animate({ bottom: 490, opacity: 1.0},1050, "easeInCirc", function()
	{
		$('#contact-display').fadeIn(800, function()
		{
			$('#buzzsaw-logo-small').fadeIn(800);
			$('#small-nav').fadeIn('fast');
		});
	});
}
function showAboutContent()
{
	$('#about-header').animate({ right: 850, opacity: 1.0},1050, "easeInCirc", function()
	{
		$('#content-disp').fadeIn(800, function()
		{
			$('#buzzsaw-logo-small').fadeIn(800);
			$('#small-nav').fadeIn('fast');
		});
	});
}
function showTheBuzz()
{
	$('#thebuzz-header').animate({ left: 800, opacity: 1.0},1050, "easeInCirc", function()
	{
		$('#content-disp').fadeIn(800, function()
		{
			$('#buzzsaw-logo-small').fadeIn(800);
			$('#small-nav').fadeIn('fast');
		});
	});
}
function showNewContent() 
{
	$('#content').show('normal', function(){
		$('#page-header').fadeIn(800, function()
		{
			$('#page-header').animate({"left": "750"}, 750, "easeInCirc", function(){
				$('#director-list').fadeIn(800, function()
				{
					$('#buzzsaw-logo-small').fadeIn(800);
					$('#small-nav').fadeIn('fast');
				});
			});
		});	
	});
}

function showDirectorsPage() 
{

	$('#strip').animate({ top: 70, opacity: 1.0},750, "easeInCirc", function()
	{
		$('#directors-header').animate({ bottom: 280, opacity: 1.0},550, "easeInCirc", function()
		{
			$('#director-list').delay(500).fadeIn(800, function()
			{
				$('#buzzsaw-logo-small').fadeIn(800, function()
				{
					playStrip();
				});
				$('#small-nav').fadeIn('fast');				
			});	
		});
	});
}


function showViewDetails()
{

	$('#view-header').animate({opacity: 1.0},550, "easeInCirc");
	$('#buzzsaw-logo-small-view').animate({ opacity: 1.0},750, "easeInCirc");
	$('#bio-nav').fadeIn(800);
	$('#player').delay(500).animate({ opacity: 1.0},750, "easeInCirc");
	
}

function showNowPlaying(mt)
{
	$('#now-playing').css('top', mt);
	$('#now-playing').fadeIn('fast');
}

function loadBuzzsawVideos(id, w, h)
{
	$("#video-content").html('<embed type="video/mp4" style="cursor:hand; cursor:pointer;" src="'+id+'" width="'+w+'" height="'+h+'" autoplay="true" target="myself" controller="true" loop="false" scale="aspect" bgcolor="#ffffff" pluginspage="http://apple.com/quicktime/download/"></embed>');

	$('#video-content').css('height', h);
	
}



function loadVideoContent(id,startVid, width, height)
{
	if(id == 'winstar_wedding')
	{
		$('#now-playing').fadeOut('fast');
	}
	jwplayer("video-content").setup(
	{
		flashplayer: "/assets/swf/player.swf",
		width: width,
		height: height,
		bufferlenght: 2,
		stretching: 'none',
		fullscreen:'false',
		autoStart: startVid,		
		file: id,
		events: {
			onComplete: function() 
			{
				showNowPlaying();
			}
		}
	});
}


function hideLoader() 
{
	$('#load').fadeOut('normal');
}	
function init()
{
	$('#content').load('/views/home.php', '');
}
function showContent()
{
	$('#container').fadeIn(1000, function(){
		$('#strip').fadeIn(800, function(){
			$('#strip').animate({"top": "50"}, 750, "easeInCirc", function()
			{
				$('#page-header').animate({ left: 750, opacity: .05},750, "easeInCirc", function()
				{		
					$('#director-list').fadeIn(800, function()
					{
						$('#buzzsaw-logo-small').fadeIn('fast');
					});
				});
			});
		});
	});
}

function loadHome()
{
	$('#loading-logo').fadeIn(1000, function(){
		$('#container').delay(2500).fadeIn(1000, function(){
			$('#loading-logo').fadeOut('fast');
			$('#logo').animate({ left: 750, opacity: 1.0},750, "easeInCirc", function()
			{
				$('#nav').fadeIn(800, function(){
					$('#strip').fadeIn(800, function(){
						playStrip();
						$('#fb-icon').fadeIn(500, function(){
							$('#twit-icon').fadeIn('fast');
							$('embed').remove();
						});
					});
				});
			});
		});
	});
}

function closePage()
{
	$('#twit-icon').fadeOut(50, function(){
		$('#fb-icon').fadeOut(100, function(){
			$('#logo').fadeOut(350, function(){
				$('#nav').fadeOut(500, function(){
					$('#strip').animate({"top": "50"}, 750, "easeInCirc", function(){
						$('#content').hide('fast',loadContent);
					});
				});
			});
		});
	});	
}

function playStrip()
{
	setTimeout(function()
	{
		$('#slider1').nivoSlider(
		{ 
			effect:'fade',
			animSpeed: 500,
			pauseTime:2000, 
			pauseOnHover:false, 
			directionNav:false, 
			directionNavHide: true, 
			controlNav: false 
		});
	}, 1000);
	setTimeout(function()
	{
		$('#slider2').nivoSlider(
		{
			effect:'fade',
			animSpeed: 500,		
			pauseTime:2500,
			pauseOnHover:false,
			controlNavThumbs:true,
			directionNav:false, 
			directionNavHide: true, 
			controlNav: false
		});
	}, 1000);
	setTimeout(function()
	{
		$('#slider3').nivoSlider({
			effect:'fade',
			animSpeed: 500,
			pauseTime:3000,
			pauseOnHover:false,
			boxCols: 8,
			boxRows: 4,
			 directionNav:false, directionNavHide: true, controlNav: false
		});
	}, 1000);
}


var open = false;
function showSmallNav()
{
	if(open = false || open == '')
	{
		$('#small-nav').fadeIn(50, function(){
			$('#small-nav').animate({"left": "200"}, 750, "easeInCirc");
		});
		open = true;
	}else{
		$('#small-nav').fadeOut(100, function(){
			$('#small-nav').animate({"left": "150"}, 750, "easeInCirc");
		});
		open = false;
	}
}

function showSmallViewNav()
{
	if(open = false || open == '')
	{
		$('#small-nav-view').fadeIn('fast');
		open = true;
	}else{
		$('#small-nav-view').fadeOut(100, function(){
			$('#small-nav-view').animate({"left": "300"}, 750, "easeInCirc");
		});
		open = false;
	}
}
