$(document).ready(function(){
	//top nav tooltips
	if (!$.browser.msie || jQuery.browser.version > 6){
		$('ul.top-nav li:not(.active) a').each(function(){
			jA = $(this);
			jA.append('<div class="toptip-top"><div class="toptip-bot2"><div class="toptip-mid"><div class="toptip-bot1"><div class="toptip">'+ jA.attr('title') +'</div></div></div></div></div>'
					).removeAttr('title'
					).mouseover(function(){$('.toptip-top',this).css('left',Math.round(($(this).width() / 2)-104.5)+'px').show();}
					).mouseout(function(){$('.toptip-top',this).hide();})
		});
		$('ul.top-nav li.active a').removeAttr('title');
	}
	
	//read-more hide/show divs
	$('div.read-more').hide().each(function(i){
		jEl = $(this);
		bInline = jEl.hasClass('inline');
		bOneOff = jEl.hasClass('oneoff');
		strId = jEl.attr('id');
		if (!strId || !strId.length || strId.length == 0) {
			strId='divReadMore-'+i;
			jEl.attr('id',strId);
		}
		strTitle = jEl.attr('title');
		strOneOff = (bOneOff) ? ' oneoff' : '';
		jEl.removeAttr('title');
		strTitle = (strTitle && strTitle.length && strTitle.length > 0) ? strTitle : ((bInline) ? 'more...' : 'Read More...');
		strAltTitle = ((bInline) ? '...less' : '...Read less');
		strHTML = '<a href="#'+strId+'" class="read-more'+strOneOff+'" title="'+strTitle+'" alttitle="'+strAltTitle+'">'+strTitle+'</a>';
		if (bInline) {
			jEl.prev().append(' '+ strHTML);
		} else {
			jEl.before('<p>'+ strHTML +'</p>');
		}
	});
	$('a.read-more').click(function(){
		jEl = $(this);
		if (jEl.hasClass('open')){
			$(this.hash).slideUp('slow');
			jEl.removeClass('open');
			try{pageTracker._trackEvent('ReadMoreLess', 'Less', this.hash);}catch(e){}
		} else {
			$(this.hash).slideDown('slow');
			jEl.addClass('open');
			try{pageTracker._trackEvent('ReadMoreLess', 'More', this.hash);}catch(e){}
		}
		if (jEl.hasClass('oneoff')) {
			jEl.remove();
			return false;			
		}
		strTitle = jEl.attr('alttitle');
		jEl.html(strTitle);
		jEl.attr('alttitle',jEl.attr('title'));
		jEl.attr('title',strTitle);
		return false;
	});
	
	//ie only links
	if (!$.browser.msie){
		$('a.ieonly').attr('href','javascript:void(0);').addClass('disabled').append(' (unavailable in this browser, requires Internet Explorer)');
	}
	
	$('.anti-scroll').each(function(){
		var iOffset = $(this).offset().top;
		$(this).attr('iOffset',iOffset);
	});
	
	$(window).bind('scrollstop',function(){
		var iWindowScrollTop = $(window).scrollTop();
		$('.anti-scroll').each(function(){
			var jThis = $(this);
			var iScrollTo = (iWindowScrollTop - jThis.attr('iOffset')) + 15;
			if (iScrollTo <= 0) {
				jThis.animate({top:'0px'},100,null,function(){jThis.css('position','static');});
			} else {
				var strScrollTo = iScrollTo + 'px';
				jThis.css('position','relative').animate({top:strScrollTo},100);
			}
		});
	});
	
	toScrolling = null;
	$(window).scroll(function(){
		if (toScrolling) window.clearTimeout(toScrolling);
		toScrolling = window.setTimeout('$(window).trigger("scrollstop")',250);
	});
	
	$('div.slides a').click(function(){
		if ($(this).hasClass('active')) return false;;
		$('div.slides div.slide.active').fadeOut().trigger('slide-end').removeClass('active');
		$('div.slides a.active').removeClass('active');
		$(this).addClass('active');
		$(this.hash).fadeIn('slow').trigger('slide-start').addClass('active');
		return false;
	});
	
});

function fnNextLI(strContext){
	jCurLI = $('li.active',$(strContext));
	jNextLI = jCurLI.next();
	if (jNextLI.length == 0) jNextLI = $('li:first',$(strContext));
	$(strContext)[0].toNext = setTimeout('fnNextLI("div#action-plan");',3000);
	$('img',jCurLI).fadeOut();
	jCurLI.removeClass('active');
	jNextLI.addClass('active');
	$('img',jNextLI).fadeIn();
}

// script adapted from Josh Fraser (http://www.onlineaspect.com)
function getLocalGMTOffset() {
	var rightNow = new Date();
	var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
	var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
	var temp = jan1.toGMTString();
	var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	temp = june1.toGMTString();
	var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
	var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
	var dst;
	if (std_time_offset == daylight_time_offset) {
		dst = "0"; // daylight savings time is NOT observed
	} else {
		// positive is southern, negative is northern hemisphere
		var hemisphere = std_time_offset - daylight_time_offset;
		if (hemisphere >= 0)
			std_time_offset = daylight_time_offset;
		dst = "1"; // daylight savings time is observed
	}
	return fnConvertTimeToOffset(std_time_offset)+","+dst;
}

function fnConvertTimeToOffset(value) {
	var hours = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var mins = parseInt(value);
   	value -= parseInt(value);
	value *= 60;
	var secs = parseInt(value);
	var display_hours = hours;
	// handle GMT case (00:00)
	if (hours == 0) {
		display_hours = "00";
	} else if (hours > 0) {
		// add a plus sign and perhaps an extra 0
		display_hours = (hours < 10) ? "+0"+hours : "+"+hours;
	} else {
		// add an extra 0 if needed 
		display_hours = (hours > -10) ? "-0"+Math.abs(hours) : hours;
	}
	mins = (mins < 10) ? "0"+mins : mins;
	return display_hours+":"+mins;
}