// JavaScript Document
//var intSubNavInterval = 350;
//var intSubNavHeroWidth = 428;
//var intSubNavID = -1;
var intSubNavBG = 1;//skip the first image (it's shown through php)
var arSubNavBG = new Array();
//arSubNavBG[0] = 'home1.jpg';
//arSubNavBG[1] = 'home2.jpg';
//arSubNavBG[2] = 'home3.jpg';

function InitSubNav() {
	/*
	//remove href with javascript (keep optimised for SEO and disabled javascript users)
	$("#divSubNav .item").removeAttr("href");
	
	//ExpandSubNavWindow();
	$("#divSubNav .item").mouseover(
		function() {
			var intid = GetID($(this),6);
			SubNavHover(intid);
		}
	);
	$("#divSubNav .item").click(
		function() {
			var intid = GetID($(this),6);
			if(blGoogle)	SubNavClickedGoogle(intid);
			else			SubNavClicked(intid);
		}
	);
	//preload background images
	var pic0 = new Image(1000,227);
	pic0.src =strRoot+'img/subnav/'+arSubNavBG[0];
	var pic1 = new Image(1000,227);
	pic1.src =strRoot+'img/subnav/'+arSubNavBG[1];
	var pic2 = new Image(1000,227);
	pic2.src =strRoot+'img/subnav/'+arSubNavBG[2];
	*/
	//start background animation (if there are multiple images in loop)
	if(arSubNavBG.length>1) var t = setTimeout("UpdateSubNavBG()",4000);
}

function UpdateSubNavBG() {
	//fade out current image
	$('#imgSubNavBG').stop();
	$("#imgSubNavBG").animate(
		{opacity:0},1000, function() {
			//fade in next image
			$(this).attr('src',strRoot+'img/subnav/'+arSubNavBG[intSubNavBG]);
			$(this).animate({opacity:1},1000);
			var t = setTimeout("UpdateSubNavBG()",4000);
			
			//increment image loop
			intSubNavBG++;
			//reset image loop (if the end has been reached)
			if(intSubNavBG>(arSubNavBG.length-1)) intSubNavBG = 0;
		}
	);
}
/*
function SubNavHover(intid) {
	//move the arrow and hero image to the relevant sub nav menu item
	//get position/width
	var arNewPos	= $("#divSubNav #SNitem"+intid).position();
	var intWidth	= $("#divSubNav #SNitem"+intid).width();
	var intArrowLeft= arNewPos.left+(intWidth/2)-40;
	//move arrow
	$('#imgSubNavArrow').stop();
	$('#imgSubNavArrow').animate({left:(intArrowLeft)},intSubNavInterval);
	
	//increase font size
	$("#divSubNav .item:not(.current)").css("fontSize",10);
	if(intSubNavID!=intid) $("#divSubNav #SNitem"+intid).animate({fontSize:12},100);
}

function SubNavClickedGoogle(intid) {
	if(intSubNavID!=intid) {
		//change map position
		SetMapPosition(intid);
		//update content
		UpdateContent(arPageIDs[intid]);
		//move .current class
		$("#divSubNav .current").removeClass("current");
		$("#divSubNav #SNitem"+intid).addClass("current");
		//update id
		intSubNavID = intid;
	}
}
function SubNavClicked(intid) {
	if(intSubNavID!=intid) {
		//update content
		if(blGallery)	UpdateGallery(arPageIDs[intid]);
		else			UpdateContent(arPageIDs[intid]);
		//fade main image bg to grey
		$("#divSubNavGrey").animate({opacity:.8},intSubNavInterval);
		//get width
		var intWidth	= $("#divSubNav #SNitem"+intid).width();
		if(intSubNavID<0) setTimeout("ExpandSubNavWindow()",intSubNavInterval);
		else {
			//get old item position
			var arOldPos	= $("#divSubNav #SNitem"+intSubNavID).position();
			//close/revert hero window
			$('#divSubNavHero').stop();
			$('#divSubNavHero').animate({
				left:(arOldPos.left+(intWidth/2)),
				width:0
			},intSubNavInterval, function() {
				//expand new window
				ExpandSubNavWindow();
			});
		}
		
		//move .current class
		$("#divSubNav .current").removeClass("current");
		$("#divSubNav #SNitem"+intid).addClass("current");
		
		//fade out image and maintain centred position
		$('#divSubNavHero div').animate({
			left:-(intWidth/2),
			opacity:0
		},intSubNavInterval);
		//update id
		intSubNavID = intid;
	}
}

function ExpandSubNavWindow() {
	//expand the sub nav window using the most recent mouse over id (immediately after the previous/existing one has closed)
	var arNewPos = $("#divSubNav #SNitem"+intSubNavID).position();
	var intWidth = $("#divSubNav #SNitem"+intSubNavID).width();
	var intLeft	 = arNewPos.left+(intWidth/2);
	
	$('#divSubNavHero').show();//hidden to start with on home page as border messes main BG image alignment
	$('#divSubNavHero').css("left",intLeft);
	$('#divSubNavHero').animate({
		left:(intLeft-(intSubNavHeroWidth/2)),
		width:intSubNavHeroWidth
	},intSubNavInterval);
	//change image
	$('#divSubNavHero div').css("top",-(227*intSubNavID));
	//fade in image and maintain centred position
	$('#divSubNavHero div').animate({
		left:0,
		opacity:1
	},intSubNavInterval);
}
*/

function GetID(obj, intPos) {
	var strID = obj[0].id;
	return strID.substring(intPos);
}

