function Swap( showTabId, hideTabId, showDivId, hideDivId )
{
	$( "#" + showDivId ).show();
	$( "#" + hideDivId ).hide();

	$( "#" + showTabId ).addClass( "selected" );
	$( "#" + showTabId ).removeClass( "normal" );

	$( "#" + hideTabId ).addClass( "normal" );
	$( "#" + hideTabId ).removeClass( "selected" );
}

function InitVideoWindow()
{
	debug( "InitVideoWindow" );

	var url = window.location.href;

	//verify that we are on the correct page (video page)
	if( url.indexOf( "video/watch" ) > -1 )
	{
		if( url.indexOf( "#ot" ) > -1 )
		{
			ClickOuttakesTab();
		}
		else
		{
			ClickVideoTab();
		}
	}
}

function ClickVideoTab()
{
	debug( "ClickVideoTab" );

	RememberTitle();

	ShowVideoWindow();

	if( window.isOuttakeVideo == 1 )
	{
		HideDescription();
		ShowDuringOuttakeButtons();
	}
	else
	{
		ShowDescription();
		HideDuringOuttakeButtons();
	}

	ResetTitle();

	return false;
}

function ClickOuttakesTab()
{
	debug( "ClickOuttakesTab" );

	RememberTitle();

	ShowOuttakesWindow();

	ShowDescription();
	HideDuringOuttakeButtons();

	ResetTitle();

	return false;
}

function ShowVideoWindow()
{
	debug( "ShowVideoWindow" );

	Swap( "navitem0", "navitem1", "videoclip", "outtakes" );
}

function ShowOuttakesWindow()
{
	debug( "ShowOuttakesWindow" );

	Swap( "navitem1", "navitem0", "outtakes", "videoclip" );
}

function ShowDescription()
{
	debug( "ShowDescription" );

	$( "div.info div.description" ).show();
}

function HideDescription()
{
	debug( "HideDescription" );

	$( "div.info div.description" ).hide();
}

function ShowDuringOuttakeButtons()
{
	debug( "ShowDuringOuttakeButtons" );

	$( "div.info div.buttonsduringouttake" ).show();
}

function HideDuringOuttakeButtons()
{
	debug( "HideDuringOuttakeButtons" );

	$( "div.info div.buttonsduringouttake" ).hide();
}

function BackToVideo( obj )
{
	RememberTitle();

	window.isOuttakeVideo = 0;

	ClickOuttakesTab();

	WritePlayer( obj.file, obj.image );

	ResetTitle();

	return false;
}

function ShowOuttakeVideo( obj )
{
	RememberTitle();

	window.isOuttakeVideo = 1;

	ClickVideoTab();

	WritePlayer( obj.file, obj.image );

	ResetTitle();

	return false;
}

function InitPostComment()
{
	var url = window.location.href;

	//verify that we are on the correct page (video page with comments)
	if( url.indexOf( "video/watch" ) > -1 )
	{
		//window.origPCBGColor = $( ".post_comment" ).css( "background-color" );
		window.origPCBGColor = "#f6f6f6";	//forced to do this because of IE7
	}
}

function PostComment()
{
	$( "#post_name" ).focus();

	$( ".post_comment" ).stop();
	$( ".post_comment" ).css( "background-color", "#bbbbbb" );
	$( ".post_comment" ).animate( { backgroundColor: window.origPCBGColor }, 500 );

	$( ".post_comment" ).queue (

		function()
		{
			$( "#post_name" ).focus();
			$( "#post_name" ).dequeue();
		}
	);

	return false;
}

function ParseNav( navId )
{
	$( "div." + navId ).find( "li" ).each(

		function( i )
		{
			$( this ).hover(

				function()
				{
					$( this ).addClass( "over" );
				},

				function()
				{
					$( this ).removeClass( "over" );
				}

			);
		}
	);
}

function RememberTitle()
{
	window.origTitle = document.title;
}

function ResetTitle()
{
	document.title = window.origTitle;
}

function debug( value )
{
	//$( "div.debug" ).html( $( "div.debug" ).html() + "<br>" + value );
}

$( document ).ready(

	function()
	{
		window.isOuttakeVideo = 0;
		window.origPCBGColor = 0;

		InitVideoWindow();
		InitPostComment();

		ParseNav( "nav" );
		ParseNav( "subnav" );
	}

);