/*****************************/
/******** TIMEOUT RESOURCE ***/
/*****************************/
var timeout = '';

/*****************************/
/******** TIMEOUT RESOURCE ***/
/*****************************/
var total_extra_padding = 12;

/*****************************/
/********* MENU TIMEOUT ******/
/*****************************/
var menu_time_out = 500;

/*****************************/
/********* HTML HOLDER *******/
/*****************************/
var return_html = 'empty';

/*****************************************************************************************************************************************************************/
/*********************************** NAV ELEMENTS BEHAVIOUR ******************************************************************************************************/
/*****************************************************************************************************************************************************************/
$().ready(function(){
	
	/***************************************************************************/
	/**************** ONHOVER ACTIONS ******************************************/
	/***************************************************************************/
	$('li a', '#top_nav').click(function(){
		//add class to remember click
		$('.clickfocus').removeClass('active').removeClass('clickfocus');
		$(this).addClass('clickfocus').addClass('active');
		//first lets clear what was inside
		$('#submenu').html('');
		//get dimensions
		var window_width 	= $(window).width();
		var item_width 		= $(this).parent().width();
		var top_nav_pos		= $('#top_nav').position();
		var submenu 		= $('#submenu').width() + total_extra_padding - 0;
		var position 		= $(this).parent().position();
		//set the left position
		var left_pos		= position.left + ( item_width / 2) - ( submenu / 2 ) + top_nav_pos.left;
		//account for left border
		var left_pos 		= ( 0 <= left_pos ) ? left_pos : 0;
		//account for right border
		var left_pos 		= (left_pos < ( window_width - submenu )) ? left_pos : window_width - submenu;
		//get the menu id
		var menu_id 		= $(this).attr('id').substr(5);
		//build the nav
		$('#submenu').css({'left' : left_pos + 'px'}).html($(this).parents('li').find('.menu_holder').html()).show();
	});

	/***************************************************************************/
	/*************** ONHOVEROUT ACTIONS ****************************************/
	/***************************************************************************/	
	$('#submenu, #top_nav').hover(function(){
		//clear the timeout
		clearTimeout(timeout);
	}, 	function(){
		timeout = setTimeout(function(){
			$('.clickfocus').removeClass('active').removeClass('clickfocus');
			$('#submenu').hide();
		}, menu_time_out);
	});
	
});

/*****************************/
/********* PREVENT IFRAME ****/
/*****************************/
if(top.location != self.location){ top.location = self.location; }
