Event.observe ( window, 'load', function ()
{
	var Query = new Object ();
	var Tester = new RegExp ( /[\?&]([^&$]*)/ );
	var QueryString = window.location.search;
	var CurrentMatch = Tester.exec ( QueryString );
	while ( CurrentMatch != null )
	{
		Query [ CurrentMatch [ 1 ].slice ( 0, CurrentMatch [ 1 ].indexOf ( '=' ) ) ] = CurrentMatch [ 1 ].slice ( CurrentMatch [ 1 ].indexOf ( '=' ) + 1 );
		QueryString = QueryString.replace ( CurrentMatch [ 0 ], '' );
		CurrentMatch = Tester.exec ( QueryString );
	}

	var AdBlockSet = false;

	if ( Query.DefaultTab != null )
	{
		$( 'TabList' ).getElementsBySelector ( 'a' ).each ( function ( Item )
		{
			if ( Item.hasClassName ( Query.DefaultTab ) )
			{
				ShowAd ( Query.DefaultTab );

				AdBlockSet = true;
			}
		} );
	}

//	if ( !AdBlockSet )
//		ShowAd ( 'Hockey' );

	var LoginFormSet = false;

	if ( Query.DefaultLoginForm != null )
	{
		$( 'LoginTabs' ).getElementsBySelector ( 'a' ).each ( function ( Item )
		{
			if ( Item.hasClassName ( Query.DefaultLoginForm ) )
			{
				ShowLoginForm ( Query.DefaultLoginForm );

				LoginFormSet = true;
			}
		} );
	}

//	if ( !LoginFormSet )
//		ShowLoginForm ( 'NormalLogin' );

	$( 'TabList' ).getElementsBySelector ( 'a' ).each ( function ( Item )
	{
		Item.observe ( 'click', TabClick );
	} );

	$( 'LoginTabs' ).getElementsBySelector ( 'a' ).each ( function ( Item )
	{
		Item.observe ( 'click', LoginTabClick );
	} );
} );

function TabClick ( EventObject )
{
	ShowAd ( $w ( Event.element ( EventObject ).className ) [ 0 ] );
}

function ShowAd ( CurrentTab )
{
	$( 'AdContainer' ).getElementsBySelector ( 'div.Ad' ).each ( function ( Item )
	{
		if ( Item.hasClassName ( CurrentTab ) )
			Item.show ();
		else
			Item.hide ();
	} );

	$( 'TabList' ).getElementsBySelector ( 'a' ).each ( function ( Item )
	{
		if ( Item.hasClassName ( CurrentTab ) )
			Item.addClassName ( 'Active' );
		else
			Item.removeClassName ( 'Active' );
	} );
}

function LoginTabClick ( EventObject )
{
	ShowLoginForm ( $w ( Event.element ( EventObject ).className ) [ 0 ] );
}

function ShowLoginForm ( CurrentTab )
{
	$( 'LoginContainer' ).getElementsBySelector ( 'div.LoginForm' ).each ( function ( Item )
	{
		if ( Item.hasClassName ( CurrentTab ) )
			Item.show ();
		else
			Item.hide ();
	} );

	$( 'LoginTabs' ).getElementsBySelector ( 'a' ).each ( function ( Item )
	{
		if ( Item.hasClassName ( CurrentTab ) )
			Item.addClassName ( 'Active' );
		else
			Item.removeClassName ( 'Active' );
	} );
}
