/**
 * @author Shafiq
 */

Cufon.replace('span.header');
Cufon.replace('span.introtext');
Cufon.replace('span.green');

//leftmenu height calculation
$(window).load(function() {
	if($("#footer").offset().top + $("#footer").height() < $(window).height()) {
		footerheight = $("#footer").height();
		$("#footer").css('top',$(window).height() - $("#footer").offset().top - footerheight - 54);
	}
	$("#leftmenu").height($("#leftmenu ul").height() + 30);
	pcOffset = $("#pageContent").offset();
	lmOffset = ($("#leftmenu").offset())?$("#leftmenu").offset():{top: 0, left: 0};
	pcPadding = parseInt($("#pageContent").css("paddingTop"));
	lmPadding = parseInt($("#leftmenu").css("paddingTop"));
	pCTotalHeight = $("#pageContent").height() + pcPadding + pcOffset.top;
	//lmTotalHeight = $("#leftmenu ul").height() + lmPadding + lmOffset.top;
	if(pCTotalHeight < lmTotalHeight)
	{
		$("#pageContent").height(lmTotalHeight - pcPadding - pcOffset.top);
	} else {
		fOffset = $("#footer").offset();
		$("#leftmenu").height(fOffset.top - lmPadding - lmOffset.top);
	}

	//open PDFs in a new window
	$("a[href*='pdf']").each(function() {
		$(this).attr('target','_blank');
	});
});

$(document).ready(function () {

	//table colouring
	$("table:not(#email) tr:odd").addClass("evenrow");
	$("table:not(#email) tr:even").addClass("oddrow");
	$("table:not(#email) tr:first").addClass("firstrow");
	$("table:not(#email) tr:nth-child(2)").addClass("secondrow");
	$("table:not(#email) tr:last").addClass("lastrow");
	$("table:not(#email) td:nth-child(1)").addClass("firstcell");
	$("table:not(#email) td:nth-child(2)").addClass("secondcell");
	$("table:not(#email) td:nth-child(3)").addClass("thirdcell");
	$("table:not(#email).widetable td:nth-child(2)").removeClass("secondcell");
	$("table:not(#email).widetable td:nth-child(3)").removeClass("thirdcell");
	$("table:not(#email).widetable td:nth-child(2)").addClass("firstcell");



	//back to top bar logic for glossary section
	btt = $('#backtotopbar');
	lbtt = $('#lowerbacktotopbar');
	if(btt.css('display') == 'none') return false;
	btt.css('display','block');
	btt.css('margin-bottom','-40px');
	glossarypos = ($('#glossarynav').offset())?$('#glossarynav').offset():{top: 0, left: 0};
	footerpos = $('#footer').offset();
	$(window).bind('scroll resize', function(e) {
		scrollTop = $(window).scrollTop();
		if(scrollTop>glossarypos.top+10 && scrollTop + $(window).height() < footerpos.top){
			lbtt.css('display','none');
			if (btt.css('marginBottom') == '-40px') {
				if($.browser.webkit == true)
					btt.css('marginBottom', 0);
				else
					btt.animate({marginBottom: 0},'fast');
			}
		} else {
			if(scrollTop + $(window).height() > footerpos.top) {
				btt.css('marginBottom','-40px');
				lbtt.css('display','block');
			} else {
				if (btt.css('marginBottom') == '0px') {
				if($.browser.webkit == true)
					btt.css('marginBottom', -40);
				else
					btt.animate({marginBottom: -40},'fast');
				}
			}
		}
	});
});