// change font size & colour of current item
function jcarouselAfterEndCallBack(carouselLink) {
	var idNum = carouselLink[0].id.replace("carouselItem","");

	$("#jcarousel-control a").each(function(index){
		if (index == idNum) {
			$(this).css({"color":"#000000","fontSize":"140%","text-decoration":"none"});
		} else {
			$(this).css({"color":"#FFFFFF","fontSize":"100%","text-decoration":"underline"});
		}
	});
}

// pause the carousels when an item link is clicked
function pauseCarousel(clickedItem) {
	clickedItem.blur();
	if ($("#CarouselPlayPause").hasClass("paused") === false) {
		$("#CarouselPlayPause").click();
	}
}

// Do jQuery bits on document ready
$(document).ready(function() {
	// hide the menus apart from the cookied/1st one
	var showMenu = $.cookie('menu_cookie');
	if (isNaN(showMenu) || showMenu === null) {
		showMenu = 1;
	} else {
		showMenu = parseInt(showMenu,10);
		showMenu --;
	}
	
	$.each($("div.menu_body"), function(index){
		if (index == showMenu) {
			$("#firstmenu p.cola5:eq("+showMenu+")").css({backgroundImage:"url(/template_images/arrow_down.gif)"});
		} else {
			$(this).hide();
		}
	});

	//slides the element with class "menu_body" when paragraph with class "menu_head" is clicked 
	$("#firstmenu p.cola5").click(function() {
		if ($(this).next("div.menu_body").is(":hidden")) {
			$.cookie('menu_cookie', this.id.replace("menu",""));
			$(this).css({backgroundImage:"url(/template_images/arrow_down.gif)"});
		} else {
			$(this).css({backgroundImage:"url(/template_images/arrow.gif)"});
		}
		$(this).next("div.menu_body").slideToggle("slow").siblings("div.menu_body").slideUp("slow");
		$(this).siblings("p.cola5").css({backgroundImage:"url(/template_images/arrow.gif)"});
	});
	
	// create carousel item links (1 | 2 | 3 etc)
	var jcarouselBtnAry = new Array();
	$("#mycarousel li").each(function(i){
		var newID = "carouselItem" + i;
		$(this).attr("id",newID);
		var getLinks = "#carouselItem" + i + " a";
		var linkTitle;
		$(getLinks).each(function(){
			if ($(this).text().length > 0) {
				linkTitle = $(this).text();
				return false;
			}
		});
		$("#jcarousel-control").append('<a href="#" id="carouselLink' + (i) + '" class="' + i + ' sect3" title="' + 
			linkTitle + '" onclick="pauseCarousel(this);">' + (i+1) + '</a> | ');
		jcarouselBtnAry.push("." + i);
	});
	
	// create pause/play link
	$("#jcarousel-control").append('<span id="CarouselPlayPause">' +
		'<a href="#" class="sect3" onclick="return false" title="Pause the highlight scroller">Pause</a></span>');

	// highlight 1st item
	$("#carouselLink0").css({"color":"#000000","fontSize":"140%","text-decoration":"none"});
	
	// configure jCarouselLite
	$(".highlights").jCarouselLite({
		speed: 1500,
		vertical: true,
		visible: 1,
		auto: 15000,
		afterEnd: jcarouselAfterEndCallBack,
		btnGo: jcarouselBtnAry,
		pause: "#CarouselPlayPause"
	});

	// play/pause link
	$("#CarouselPlayPause").click(function() {
		if ($("#CarouselPlayPause").hasClass("paused")) {
			$(this).html('<a href="#" class="sect3" onclick="return false" title="Start the highlight scroller">Play</a>');
		} else {
			$(this).html('<a href="#" class="sect3" onclick="return false" title="Pause the highlight scroller">Pause</a>');
		}
	});
	
	$("#srch_fld").focus();
});