////////////////////////////////
// Navigation Menu Drop-downs //
////////////////////////////////
// These are called via the
// navigation menu rollovers
// below

var curDropDown = "none";

function dropDownShow(dropDownName, clickEvent, objLink){
	
	dropDownID='mnu'+dropDownName;
	curDropDownID='mnu'+curDropDown;
	
	if(typeof doHide != "undefined"){
		clearTimeout(doHide);
	}
	
	if(curDropDown!="none"&&curDropDown!=dropDownName){
		objDropDown = document.getElementById(curDropDownID);
		objDropDown.style.visibility = "hidden";
	}
	
	objDropDown = document.getElementById(dropDownID);
	objDropDown.style.visibility = "visible";
	objDropDown.onmouseout = function () { navOff(dropDownName); };
	objDropDown.onmouseover = function () { navOn(dropDownName, clickEvent, objLink); };
	objLink.onmouseout = function () { navOff(dropDownName); };
	objLink.onmouseover = function () { navOn(dropDownName, clickEvent, objLink); };
	
	curDropDown=dropDownName;
	
}

function dropDownHide(dropDownName){
	//
	dropDownID='mnu'+dropDownName;
	objDropDown = document.getElementById(dropDownID);
	doHide = setTimeout("objDropDown.style.visibility = 'hidden'",250);
}



///////////////////////////////
// Navigation Menu Rollovers //
///////////////////////////////

//Preload Images

var d=document;

var imgHome_off = new Image();
imgHome_off.src="/images/navigation/home.gif";
var imgEvents_off = new Image();
imgEvents_off.src="/images/navigation/events.gif";
var imgRoty_off = new Image();
imgRoty_off.src="/images/navigation/roty.gif";
var imgMembership_off = new Image();
imgMembership_off.src="/images/navigation/membership.gif";
var imgJobs_off = new Image();
imgJobs_off.src="/images/navigation/jobs.gif";
var imgEducation_off = new Image();
imgEducation_off.src="/images/navigation/education.gif";
var imgCharity_off = new Image();
imgCharity_off.src="/images/navigation/charity.gif";
var imgSponsorship_off = new Image();
imgSponsorship_off.src="/images/navigation/sponsorship.gif";

var imgHome_on = new Image();
imgHome_on.src="/images/navigation/home_on.jpg";
var imgEvents_on = new Image();
imgEvents_on.src="/images/navigation/events_on.jpg";
var imgRoty_on = new Image();
imgRoty_on.src="/images/navigation/roty_on.jpg";
var imgMembership_on = new Image();
imgMembership_on.src="/images/navigation/membership_on.jpg";
var imgJobs_on = new Image();
imgJobs_on.src="/images/navigation/jobs_on.jpg";
var imgEducation_on = new Image();
imgEducation_on.src="/images/navigation/education_on.jpg";
var imgCharity_on = new Image();
imgCharity_on.src="/images/navigation/charity_on.jpg";
var imgSponsorship_on = new Image();
imgSponsorship_on.src="/images/navigation/sponsorship_on.jpg";


//might want to stop browser getting the click later on
function navOn(name, clickEvent, objLink)
{
	imgName='img'+name;
	d.images[imgName].src = eval(imgName + "_on.src");
	dropDownShow(name, clickEvent, objLink);
}

function navOff(name)
{
	imgName='img'+name;
	d.images[imgName].src = eval(imgName + "_off.src");
	dropDownHide(name);
}



///////////////////
// Fading Images //
///////////////////

//check how to add event listener - we don't want to start the fading until it's all loaded up
window.addEventListener?window.addEventListener("load",init_fade,false):window.attachEvent("onload",init_fade);

var img = new Array(), thisImg=0, modify='div', co=1;

function init_fade() {
	
	//quit if getelement fn not exist
	if(!d.getElementById)return;
	
	//load the images in here - theres no point loading the images if we cant even use them!
	
	//This should be src of imgFading
	img[0] = new Image();
	img[0].src = "/images/fading/img1.jpg";
	
	//These are the other images
	img[1] = new Image();
	img[1].src = "/images/fading/img7.jpg";
	
	img[2] = new Image();
	img[2].src = "/images/fading/img5.jpg";
	
	img[3] = new Image();
	img[3].src = "/images/fading/img3.jpg";
	
	img[4] = new Image();
	img[4].src = "/images/fading/img6.jpg";
	
	img[5] = new Image();
	img[5].src = "/images/fading/img2.jpg";
	
	img[6] = new Image();
	img[6].src = "/images/fading/img8.jpg";
	
	img[7] = new Image();
	img[7].src = "/images/fading/img9.jpg";
	
	img[8] = new Image();
	img[8].src = "/images/fading/img10.jpg";
	
	img[9] = new Image();
	img[9].src = "/images/fading/img11.jpg";
	
	setTimeout(fade_do,1000);
	
}

function fade_do() {

	if(modify=='div'){
		//
		thisImg++;
		if(thisImg==img.length){thisImg=0;}
		d.getElementById("imageFader").style.backgroundImage = 'url(' + img[thisImg].src + ')';
		modify='img';
		//we've changed the divs background, so fade the image out to show it
		setTimeout(fade_out,1000);
	}else{
		//
		thisImg++;
		if(thisImg==img.length){thisImg=0;}
		d.getElementById("imgFading").src = img[thisImg].src;
		modify='div';
		//we've changed the image so fade it in to show it
		setTimeout(fade_in,1000);
	}
	
}
	
function doOpacity(image) {
	if(image.doOpacity>1) {
		image.doOpacity = 1;
	}else{
		image.style.MozOpacity = image.doOpacity;
		image.style.filter = "alpha(opacity=" + ( image.doOpacity * 100 ) + ")";
		image.style.opacity = image.doOpacity;
	}
}

function fade_out() {
	if(co>0){
		co-=0.05;
		d.getElementById("imgFading").doOpacity = co;
		doOpacity(d.getElementById("imgFading"));
		setTimeout(fade_out,50);
	}else{
		//image is already invisible so do fade_do next
		d.getElementById("imgFading").style.visibility='hidden';
		setTimeout(fade_do,1000);
	}
}

function fade_in() {
	if(co<1){
		d.getElementById("imgFading").style.visibility='visible';
		co+=0.05;
		d.getElementById("imgFading").doOpacity = co;
		doOpacity(d.getElementById("imgFading"));
		setTimeout(fade_in,50);
	}else{
		//image is already visible so do fade_do next
		setTimeout(fade_do,1000);
	}
}