// Gallery
//                                         
// init                                    
//                                         

// variables
var globalVar = 0;
var nr = 0;
//var nrImg = 0;
var arr_img = new Array; // image array for rollover images
var initOk = false;


function initGallery() {	

	// initialize main functions
	a1ImgMenuPreload();
	initOk = true;
}
                                     
// preparation                             
//                                         

function a1ImgMenuPreload() {
	// preloading images from the arr_img
	// all images are loaded into arr_img[group][imageId][mouseover state]
	for (group in arr_img) {
		// go through each image group
		for (i=0; i<arr_img[group]["nrOfItems"]; i++) {
			arr_img[group][i] = new Array;
			arr_img[group][i][0] = new Image;
			arr_img[group][i][1] = new Image;
			// preload all image states
			if (i == arr_img[group]["activeItem"]) {
				arr_img[group][i][0].src = imgPath + group + "_" + i + "_" + "11" + arr_img[group]["fileType"]; // at ahl website we simply show the 
				arr_img[group][i][1].src = imgPath + group + "_" + i + "_" + "11" + arr_img[group]["fileType"]; // mouseover image for the active item!
			} else {
				arr_img[group][i][0].src = imgPath + group + "_" + i + "_" + "10" + arr_img[group]["fileType"];
				arr_img[group][i][1].src = imgPath + group + "_" + i + "_" + "11" + arr_img[group]["fileType"];
			}
		}
	}
}


function imgPreload(number, img){
	newImg = "img" + number;
	newImg = new Image;
	newImg.src = img;
}

function changeImg(imgNr, nrImg){
	
	globalVar = imgNr;
	//newImgSrc = document.getElementById(imgNr).src;
	newImgSrc = document.getElementById("i" + imgNr).src;
	document.getElementById('mainImg').src = newImgSrc;
	
	changeMenuColor(imgNr, nrImg);
}

function previousImg(nrImg){
	nr = globalVar;
	if(nr != 0){
		nr--;
		changeImg(nr, nrImg);
	}
}
function nextImg(size){
	nr = globalVar;
	if(nr != size){
		nr++;
		changeImg(nr, size);
	}
}

function changeMenuColor(nr, nrImg){
	for(var i=0; i<=nrImg; i++){
		id = "link" + i;
		document.getElementById(id).src = "../images/spB.gif"
	}
	id = "link" + nr;
	document.getElementById(id).src = "../images/spW.gif"
}

