$(document).ready(function() {		

	$(".mainScroller").addClass("scrollable").addClass("vertical");
	$(".mainNavItem").attr("href","#");
	$(".vertical").css("overflow","hidden");
	$(".tabbedNavHolder").css("float","left");
	$(".items").css("height","3000em").css("position","absolute");
	$(".slides").addClass("minHeight");
	$(".btt").remove();
	

	// initialize scrollable with mousewheel support
	$(".scrollable").scrollable({ vertical: true, speed: 600/*, mousewheel: true */}).navigator(".tabbedNav");	
	$(".vertical").each(function() {
		$(this).css('height', $(this).find('section:first').outerHeight(true));
	});
	$('.tabbedNav li:first').addClass('active');
	$(".tabbedNav").append('<li class="current"></li>');
	$(".tabbedNav .current").each(function() { $(this).addClass('top' + $(this).position().top); });
	$(".mainNavItem").click(function(){
		if($(this).parent().hasClass('active')) return;
		var self = this;
		var obj = (!$.browser.msie && !parseInt($.browser.version) < 9) ? $(this).parent().parent().parent().next() : $(this).parent().parent().parent().next().next();
		var nav = $(this).parent().parent();
		var navItemPos = $(this).position().top-nav.find(".current").attr('class').replace(/[A-z_\s-]*/, '');
		var itemClicked = nav.find("li a").index(self);
		var slideHeight = obj.find(".slides").eq(itemClicked).outerHeight(true);
		nav.find(".current").animate({top: navItemPos  }, 600);
		obj.animate({height: slideHeight}, 600);
	});
	
	// IE upgrade prompt
	if($.browser.msie && parseInt($.browser.version) < 8 && getCookie('ie6warning') != 'off') {
		setTimeout(function() {
			$('body').prepend('<div id="iealert"><a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home">In order to view this website correctly we recommend that you download the latest version of Internet Explorer.  A free update is available here...</a><a class="close" href="#close">Close</a></div>');
			$('#iealert').slideDown();
			$('#iealert a').hover(function() { $('#iealert a').addClass('hover'); $('#iealert .close').addClass('closehover'); }, function() { $('#iealert a').removeClass('hover'); $('#iealert .close').removeClass('closehover'); });
			$('#iealert a').click(function() { $('#iealert').slideUp(); });
			$('#iealert .close').click(function() { setCookie('ie6warning', 'off', 1); });
		}, 1000);
	}
	
	$('.slideshow').slideshow();
	
	$('form.lib').labelsInside();

	if(typeof($(document).pngFix) == 'function') $(document).pngFix();
	
});


function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
