/** Finetip Website Javascript
 * by WebOutreach 2008 **/

/* Declarations */
var homepageLinkZindexes=new Array();
var maxHomepageLinkZindex=0;

/* Load-time stuff */
$(document).ready(function() {
	//Make external links target a new window
	externalLinks();
	
	//Lightbox-enable the lightbox images
	$(".lightbox").lightbox();
	
});

/**
 * Make all external links target correctly
 */
function externalLinks() {
	if (!document.getElementsByTagName) return;
 	var anchors = document.getElementsByTagName("a");
 	for (var i=0; i<anchors.length; i++) {
 		var anchor = anchors[i];
 		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
 	}
}

/**
 * Make hovering over menu links work
 *
 * @param object The link object
 * @param bool Bring forward (true) or send back (false)
 */
function linkHover(objLink,direction) {
	//alert($(objLink).attr('href'));
	if (direction) {
		//Bring to front
		$(objLink).css('zIndex',maxHomepageLinkZindex);	
	} else {
		//Drop back
		$(objLink).css('zIndex',homepageLinkZindexes[$(objLink).attr('href')]);	
	}
}

/**
 * Log the z-indexes of the homepage links
 */
function logHomepageLinks() {
	$('.homepageLink').each(function() {
		homepageLinkZindexes[$(this).attr('href')]=$(this).css('zIndex');

		
		//Is it a max? If so, update it
		if ($(this).css('zIndex')>maxHomepageLinkZindex) {
			maxHomepageLinkZindex=$(this).css('zIndex');	
		}
		
	});
	//Add 1 to the z-index for later use	
	++maxHomepageLinkZindex;


}
function scrollToElement(objElement) {
	if (!((jQuery.browser.opera && jQuery.browser.version>=9.5) || (jQuery.browser.msie && jQuery.browser.version<6))) {
		if (objElement) {
			//Work out what to scroll to
			scrollEl=$('#'+$(objElement).attr('href').substr(1));
			$.scrollTo(scrollEl,1000);
		} else {
			$.scrollTo(0, 1000);
		}
		return false;	
	} else {
		//Invalid browser! Degrade gracefully
		return true;
	}
}