// klarejs10.js    13 jan 08  javascript for buttons, sliding, and scrolling
// klaregallery.js 15 jan 08  for gallery pages only (sliding, but no home page roundels)
//                 17 jan 08  switch sense of arrows round, left arrow now starts scrollright etc


if (document.images){  

	//precache images
	var offImgArray = new Array();
	offImgArray["button1"] = new Image (46,21);
	offImgArray["button2"] = new Image (138,21);
	offImgArray["button3"] = new Image (182,21);
	offImgArray["button4"] = new Image (109,21);
	offImgArray["button5"] = new Image (76,21);
	offImgArray["button1"].src = "img2/buttons/bhome_up.gif";
	offImgArray["button2"].src = "img2/buttons/bartist_up.gif";
	offImgArray["button3"].src = "img2/buttons/bcommunity_up.gif";
	offImgArray["button4"].src = "img2/buttons/bcommissions_up.gif";
	offImgArray["button5"].src = "img2/buttons/bcontact_up.gif"; 
	offImgArray["arrowleft"] = new Image (15,25);
	offImgArray["arrowright"] = new Image (15,25);
	offImgArray["arrowleft"].src = "img2/buttons/arrowleft_up.gif";
	offImgArray["arrowright"].src = "img2/buttons/arrowright_up.gif";
		
	
	var overImgArray = new Array();
	overImgArray["button1"] = new Image (46,21);
	overImgArray["button2"] = new Image (138,21);
	overImgArray["button3"] = new Image (182,21);
	overImgArray["button4"] = new Image (109,21);
	overImgArray["button5"] = new Image (76,21);
	overImgArray["button1"].src = "img2/buttons/bhome_over.gif";
	overImgArray["button2"].src = "img2/buttons/bartist_over.gif";
	overImgArray["button3"].src = "img2/buttons/bcommunity_over.gif";
	overImgArray["button4"].src = "img2/buttons/bcommissions_over.gif";
	overImgArray["button5"].src = "img2/buttons/bcontact_over.gif"; 
	overImgArray["arrowleft"] = new Image (15,25);
	overImgArray["arrowright"] = new Image (15,25);
	overImgArray["arrowleft"].src = "img2/buttons/arrowleft_over.gif";
	overImgArray["arrowright"].src = "img2/buttons/arrowright_over.gif";
	
	var downImgArray = new Array();
	downImgArray["button1"] = new Image (46,21);
	downImgArray["button2"] = new Image (138,21);
	downImgArray["button3"] = new Image (182,21);
	downImgArray["button4"] = new Image (109,21);
	downImgArray["button5"] = new Image (76,21);
	downImgArray["button1"].src = "img2/buttons/bhome_down.gif";
	downImgArray["button2"].src = "img2/buttons/bartist_down.gif";
	downImgArray["button3"].src = "img2/buttons/bcommunity_down.gif";
	downImgArray["button4"].src = "img2/buttons/bcommissions_down.gif";
	downImgArray["button5"].src = "img2/buttons/bcontact_down.gif";  
	downImgArray["arrowleft"] = new Image (10,21);
	downImgArray["arrowright"] = new Image (10,21);
	downImgArray["arrowleft"].src = "img2/buttons/arrowleft_over.gif";
	downImgArray["arrowright"].src = "img2/buttons/arrowright_over.gif";
		
}

/* functions for Main (top) buttons */
function mOver (imgName) {   // highlight when mouse over (except if current page), and hide Focus
	document.images[imgName].src = overImgArray[imgName].src;
	document.images[imgName].parentNode.hideFocus = true;
	window.status = " ";
	return true;
	
}
	
function mOut (imgName) {    // revert to normal when mouse out 
	document.images[imgName].src = offImgArray[imgName].src;
	document.images[imgName].parentNode.hideFocus = true;
	window.status = "";
	return true;
}

function mDown (imgName) {   // highlight   - then page changes anyway
	document.images[imgName].src = downImgArray[imgName].src;
	document.images[imgName].parentNode.hideFocus = true;
	window.status = " ";
	return true;
}

// functions for left/right arrows and to scroll gallery images
var scrollIntervalID;
var imageDivID;  
var nImageDivLeft = 0;   // number governing left of imagediv, must be numeric, have to set it first time
var nLeftLimit;            // leftpos of ImageDiv (px) when last pic on display (ie stop scrolling left)

function arrowLeftOver (nPictures) {   
	document.images["arrowleft"].src = overImgArray["arrowleft"].src;
	document.images["arrowleft"].parentNode.hideFocus = true;
	window.status = " ";
	startScrollRight();
	return true;
}

function arrowRightOver () {  
	document.images["arrowright"].src = overImgArray["arrowright"].src;
	document.images["arrowright"].parentNode.hideFocus = true;
	window.status = " ";
	startScrollLeft();
	return true;
}
	
function arrowOut (imgName) {    // revert to normal when mouse out 
	document.images[imgName].src = offImgArray[imgName].src;
	document.images[imgName].parentNode.hideFocus = true;
	window.status = "";
	stopScroll();
	return true;
}

// nPictures used to know when to stop sliding left
function pageInit(nPictures) {
	document.getElementById("arrowleftdiv").style.visibility = "visible";  // only enable once page fully loaded to avoid errors
	document.getElementById("arrowrightdiv").style.visibility = "visible";
	imageDivID = document.getElementById("imagediv");
	imageDivID.style.clip = "rect(0px 950px 325px 0px)"; // must set first or it's null ! 
	imageDivID.style.left = nImageDivLeft + "px";   // have to set style first (or else it's null)
	nLeftLimit = -(nPictures-3) * 303;    // stop when get to end (300px per image), 3 pics on page
	if (nLeftLimit > 0) {
		nLeftLimit = 0;
	}
	//alert("nLeftLimit = " + nLeftLimit);
}
	
function startScrollLeft() {
	if (scrollIntervalID) {
		clearInterval(scrollIntervalID);
	}
	nImageDivLeft = parseInt(document.getElementById("imagediv").style.left);  
	scrollIntervalID = setInterval("scrollLeft()", 10);
}

function scrollLeft() {
	if (nImageDivLeft > nLeftLimit) {
		nImageDivLeft -= 2;
		imageDivID.style.left = nImageDivLeft + "px";
		imageDivID.style.clip = "rect(0px " + (950-nImageDivLeft) + "px 325px " + (0-nImageDivLeft) + "px)";
	}
}

function startScrollRight() {
	if (scrollIntervalID) {
		clearInterval(scrollIntervalID);
	}
	nImageDivLeft = parseInt(document.getElementById("imagediv").style.left);  
	scrollIntervalID = setInterval("scrollRight()", 10);
}

function scrollRight() {
	if (nImageDivLeft < 0) {
		nImageDivLeft += 2;
		imageDivID.style.left = nImageDivLeft + "px";
		imageDivID.style.clip = "rect(0px " + (950-nImageDivLeft) + "px 325px " + (0-nImageDivLeft) + "px)";
	}
}

function stopScroll() {
	clearInterval(scrollIntervalID);
}

