
/**
 * The number of millisecond that a menu item
 * should continue to appear for.
 * This value should not be lower then 500 (1/2 a second)
 * (1000 millisecond = 1 second)
 */

	_hideDelay = 300;

/**
 * HideInfoBox
 * @param {jQuery Selector Object} div.expand-info
 */
function hideInfoBox(selector)
{
	var $infoBox = $(selector);
	
	if( $infoBox.hasClass('in-print') || $('body').hasClass('more-info-page') ) return;

	$infoBox
		.data('showState',1)
		.fadeOut(function(){
			$(this).data('showState',0);
		})
	;
}

function expandBoxInfo(domElement)
{
	var $this = $(domElement);
	var index = $('div.leftcontentblue',$this.parent()).index($this);
	var itemNumber = parseInt(index) + 1;
	var $popUp = $('#expand-info-'+itemNumber);
	var showState = $popUp.data('showState');
	
	return {
		 $this:			$this
		,index: 		index
		,itemNumber: 	itemNumber
		,showState: 	showState
		,$popUp:		$popUp
	};
}

/**
 * JQUERY
 * The follow code runs once the DOM has loaded
 */
$(function(){
	
	$('div.leftcontentblue')
		/*
		 * Append "More Info" link
		 * Link is not clickable as the hovering effect of the box will have the
		 * side information box appear.
		 */
		.append('<div class="more-info">*<a href="#More-Info" target="_blank">More Info</a> &#187;</div>')
		/*
		 * Mouse Control over Left Sidebox
		 * On MouseOver, Show ExpandInfo Box
		 * On MouseOut , Set Box to disappear
		 */
		.hover(
			function(e)
			{
				var ebi = expandBoxInfo(this);
				
				clearTimeout( ebi.$popUp.data('hideTimer') );
				if(ebi.showState) return;
				
				ebi.$popUp
					.data('showState',1)
					.fadeIn(function(){
						$(this).data('showState',2);
					})
					.css('top', ebi.$this.offset().top )
					.css('left', parseInt(ebi.$this.outerWidth()) + parseInt(ebi.$this.css('margin-left')) - 1 )
				;
			}
			,
			function(e)
			{
				var ebi = expandBoxInfo(this);
				
				ebi.$popUp.data('hideTimer', setTimeout('hideInfoBox("#expand-info-'+ebi.itemNumber+'");', _hideDelay) );
				return;
			}
		);
	
	$('.more-info a').click(function(){
		$this = $(this);
		var ebi = expandBoxInfo($this.parent().parent());
		$this.attr('href', '/more-info-'+ebi.itemNumber+'.html');
		return true;
	});
	
	
	/*
	 * Mouse Control over Expand Box
	 * On MouseOver, Prevent box from disappearing
	 * On MouseOut , Set Box to disappear
	 */
	$('div.expand-info').hover(
		function(e)
		{
			var $this = $(this);
			clearTimeout( $this.data('hideTimer') );
		}
		,
		function(e)
		{
			var $this = $(this);
			$this.data('hideTimer', setTimeout('hideInfoBox("#'+$this.attr('id')+'");', _hideDelay) );
		}
	);
	
	/*
	 * 
	 */
	$('.print-bar-print').click(function(e){
		window.print();
		return false;
	});
	
});

