/**
 *  General utilities for FLS
 * 
 *  @author    Viknesk Kumarr Muniandy
 *  @updated  24-01-2009
 */

// Auto hover-state image switcher
var AutoHover = {
	label: 'auto-hover',
	init: function (label) {
		if (!window.jQuery) { return; }
		label = label || AutoHover.label;
		$('img.'+label+', input[type=image].'+label).each (function () {
			var src = $(this).attr('src');
			var src_hover = '';
			var match = null;
			if (match = src.match(/^(.+)\.(jpg|jpeg|png|gif)$/))
			{
				src_hover = match[1] + '-hover.' + match[2];
				$(this).hover (
					function () { $(this).attr('src', src_hover); },
					function () { $(this).attr('src', src); }
				);
			}
		});
	}
}

// Contact Us overlay
var HearFromUs = {
	triggerBtn: '#hear-from-us',
	overlayDiv: '#hear-from-us-overlay',
	closeBtn: '.close-overlay',
	init: function (overlay, openBtn, closeBtn) {
		return; // Disabled at client's request
		overlayEl = $(overlay || HearFromUs.overlayDiv);
		openBtnEl = $(openBtn || HearFromUs.triggerBtn);
		closeBtn = closeBtn || HearFromUs.closeBtn;
		var offset = openBtnEl.offset();
		overlayEl
			.css({
				'position': 'absolute',
				'top': offset.top,
				'left': offset.left + openBtnEl.width() - overlayEl.width()
			}).appendTo($('body'));
		openBtnEl.click (function () {
			var offset = $(this).offset();
			overlayEl
				.css ({
					'position': 'absolute',
					'left': offset.left + $(this).width() - overlayEl.width(),
					'top': offset.top,
					'visibility': 'visible'
				})
				.find (closeBtn).click(function () {
					overlayEl.css({'visibility':'hidden'});
					return false;
				});
			return false;
		});
	}
}

// Left Menu highlight, based on current section
var LeftMenuHighlight = {
	selClass: 'selected',
	liIdPrefix: 'lm-',
	init: function () {
		if (window.$section) $('#' + LeftMenuHighlight.liIdPrefix + $section).addClass (LeftMenuHighlight.selClass);
	}
}

// Anchor highlighting
var AnchorHighlight = {
	focusClass: 'focus',
	init: function () { 
		if (location.hash && location.hash.length) 
			try { $(location.hash).addClass (AnchorHighlight.focusClass); } catch (e) {}
		
	}
}

function FirstArticleHighlight() {
	$(location.hash).removeClass ('focus');
	$('#article-6').addClass ('focus');
	window.location.hash="#article-6"; 
} 

var prevHighlight;

function IndicatorHighlight(id) {

	$(prevHighlight).removeClass ('focus');
	//$(location.hash).removeClass ('focus');
	$(id).addClass ('focus');	
	window.location.hash=id; 
	if(location.hash != "#top")
		prevHighlight = id;
	
}

var tVar;
var timer_is_on=0;

function timedCount()
{
	//tVar=setTimeout("location.reload(true)",60000);
	if(window.location.href.indexOf("?")==-1)
		tVar=setTimeout("window.location.href = window.location.href + '?refresh=1'",60000);
	else
		tVar=setTimeout("window.location.href = window.location.href.substr(0, window.location.href.indexOf('?')) + '?refresh=1'",60000);

}

function startTimer()
{
	document.getElementById('timerToggle').innerHTML = '<strong>Turn Auto-refresh</strong>&nbsp;<a href="javascript:stopCount()"><img src="/assets/images/buttons/btn_TimerOff.gif" alt="" border="0" style="vertical-align:middle;"></a>';
	if (!timer_is_on)
  	{
  	timer_is_on=1;
  	timedCount();
  	}
}

function stopCount()
{
	clearTimeout(tVar);
	timer_is_on=0;
	document.getElementById('timerToggle').innerHTML = '<strong>Turn Auto-refresh</strong>&nbsp;<a href="javascript:startTimer()"><img src="/assets/images/buttons/btn_TimerOn.gif" alt="" border="0" style="vertical-align:middle;"></a>';
}

