
// ========================================================================== //
// ========================================================================== //

// -------------------------------------------------------------------------- //
/*	initialize

*/
// -------------------------------------------------------------------------- //
var		main_menu = null;

jQuery( function ()
{
	var		base_len = 0;
	
	$('#nav_main a').each( function()
	{
		if( base_len == 0 )	// The first link is just for the home page.
			base_len = this.href.length;
		else
		{					// Remove home page base URL from main menu address.
//			var		menu = $( '#dd_' + this.href.substr( base_len, 100 ) );
			
//			if( menu.length > 0 )
			{	// Set the id of the other menu component into the drop-down and link portions.
//				$(this).parent().get(0).dd_other_half = menu.get(0).id;
//				menu.get(0).dd_other_half = $(this).parent().attr('id');
				
				// Assign functions for handling open and close.
				$(this).parent().hover( open_menu, close_menu );
//				menu.hover( open_menu, close_menu );
			}
		}
	} );
	
	// Enable all forms on the page since javascript is present
	lz_enable_forms();
	
	if( $('#splash_main').length )
	{
		$('#splash_main').data( 'current', $('#splash_main img').eq(0) );
		$('#splash_main a').mouseenter( im_splash_switch );
		$('#splash_main img').click( im_splash_catch_click );
	}
} );

function open_menu()
{
	$(this).addClass('hovered');
//	$('#' + this.dd_other_half).addClass('hovered');
}

function close_menu()
{
	$(this).removeClass('hovered');
//	$('#' + this.dd_other_half).removeClass('hovered');
}


// -------------------------------------------------------------------------- //
/*	Drop_Down_Menus

*/
// -------------------------------------------------------------------------- //

function Drop_Down_Menus( menu_id, timeout )
{
	this.menu_id = id;		/* Full menu ul */
	this.timeout = timeout;
	this.timer = null;
	this.open_item = null;
	
	$(document).ready( function()
	{
		$('#' + this.id + ' > li').hover( main_menu.open, main_menu.delayed_close );
		$(document).click( main_menu.close );
		var menus = $('#nav_main li a');
		var menu_count = menus.length;
		
		for( var i = 0; i < menu_count; i++ )
		{
			var	menu_body_id = '#ddm_' + menus.get(i).href;
			var menu_body = $(menu_body_id);
			
			if( menu_body.length == 1 )
			{
				var		top = 1;
			}
		}
		
	} );
	
	this.open = function ()
	{
		this.cancel_close();
		this.close();
		this.open_item = $('#ddm_'+ this.id).css( 'display', 'block' );
	}
	
	this.close = function ()
	{
		if( this.open_item )
			this.open_item.css( 'display','none' );
	}
	
	this.delayed_close = function ()
	{
		this.timer = setTimeout( main_menu.close, this.timeout );
	}
	
	this.cancel_close = function ()
	{
		if( this.timer )
		{
			clearTimeout( this.timer );
			this.timer = null;
		}
	}
}


// -------------------------------------------------------------------------- //
/*	im_setup_multi_ad

	If n > 3, it assumes it's just 3.
	
*/
// -------------------------------------------------------------------------- //

function im_setup_multi_ad( base_id, n )
{
	n = parseInt( n );
	if( n <= 1 )
		return;
	
	if( $('#' + base_id) != undefined )
	{
		if( $('#' + base_id + '_2').length > 0 )
		{
			$('#' + base_id).get(0).next_spot = base_id + '_2';
			
			if( n > 2 )
			{
				if( $('#' + base_id + '_3').length > 0 )
				{
					$('#' + base_id + '_2').get(0).next_spot = base_id + '_3';
					$('#' + base_id + '_3').get(0).next_spot = base_id;
				}
			}
			else
				$('#' + base_id + '_2').get(0).next_spot = base_id;
		}
	}		
}


// -------------------------------------------------------------------------- //
/*	im_cycle_spot

*/
// -------------------------------------------------------------------------- //

function im_cycle_spot( id )
{
	var				visible_spot = id;
	
	if( $('#' + id).hasClass('hidden') )
	{
		if( $('#' + id + '_2').hasClass('hidden') )
			visible_spot = id + '_3';
		else
			visible_spot = id + '_2';
	}
	
	$('#' + visible_spot).addClass( 'hidden' );
	$( '#' +  $('#' + visible_spot).get(0).next_spot ).removeClass('hidden');
}



// -------------------------------------------------------------------------- //
/*	im_cycle_spot_with_timer

*/
// -------------------------------------------------------------------------- //

function im_cycle_spot_with_timer( id )
{
	var				visible_spot = id;
	
	if( $('#' + id).hasClass('hidden') )
	{
		if( $('#' + id + '_2').hasClass('hidden') )
			visible_spot = id + '_3';
		else
			visible_spot = id + '_2';
	}
	
	$('#' + visible_spot).addClass( 'hidden' );
	$( '#' +  $('#' + visible_spot).get(0).next_spot ).removeClass('hidden');
	
	var			timeout = $( '#' +  $('#' + visible_spot).get(0).next_spot + ' input' ).val();
	if( typeof( timeout ) === 'undefined' )
		timeout = 5000;
	
	$('#colin').html( timeout );
	setTimeout( function(){ im_cycle_spot_with_timer( "welcome_spots_extra_1" ); }, timeout );
}


// -------------------------------------------------------------------------- //
/*	im_splash_switch

*/
// -------------------------------------------------------------------------- //

function im_splash_switch()
{
	var			next = $( '#' + $(this).attr('id') + '_img' );
	var			main = $('#splash_main');
	var			current = main.data('current');
	
	if( !next.length || current.attr('id') === next.attr('id') )
		return;
	
	current.fadeOut( 400 );
	next.fadeIn( 400 );
	main.data( 'current', next );
}

// -------------------------------------------------------------------------- //
/*	im_splash_catch_click

*/
// -------------------------------------------------------------------------- //

function im_splash_catch_click()
{
	var		id = $(this).attr('id');
	var		link_id = id.substr( 0, id.length - 4 );
	
	document.location = $('#' + link_id).attr('href');
}


