function loadPage(url){
	document.location.href = url;
}

function swapImage(image){
	$("largeImage").src = "images/" + image;
	$("imageEnlarge").href = "lgimages/" + image;
	Shadowbox.setup();
	//TODO: fix shadowbox initialization somehow. - maybe add load.gif type deal
}

function linkInit(imageArrays,use){
	//sets the wheels in motion.  calls galleryCreation with the default (use=0) or selected gallery (use=#).
	if (typeof use == "undefined") {
    	use = 0;
  	}
  	
	arrayUse = imageArrays[use];
	textLinks = "";
	if(imageArrays.length>1){
		textLinks = makeTextLinks(imageArrays.length,use);	
	}
	galleryCreation(arrayUse,textLinks);
	setGalleryBackground(cssBackground,use);
}

function galleryCreation(images,textLinks){
	//creates image links for galleries, first through 8th image
	divs = "";
	preloads = "";
		
	//start off by making the first image show up
	swapImage(images[1]);
	
	//now make the DIVS that are links on the right
	//starts at 1 because first entry in arrays is blank.
	for(i=1;i<images.length;i++){
		divi = i;
		if(i==8){
			divs += "<a id='link8' class='galleryLink'> </a>";
			divi=9;
		}
		divs += "<a id='link" + divi + "' class='galleryLink' onclick='swapImage(\"" + images[i] + "\");windowImage = " + i + ";' href='#'> </a>";
		preloads += "<img src='images/" + images[i] + "' style='display:none'/>";
	}
	divs += textLinks;
	
	//document.write(divs + preloads);
	divContent = divs + preloads;
	document.getElementById('menuArea').innerHTML = divContent;
}

function makeTextLinks(length,active){
	//creates text links when there are more than 1 array
	textLinks = "<div class='textLinks'><div class='textLinkSpacer'>";
	separator = " | ";
	activeClass = "";
	a = 1;
	
	for(i=0;i<length;i++){
		if(i==(length-1)){
			//if this is the last in the list, don't add the seperator
			separator = "";
		}
		if(i==active-1){
			//indicates this is the gallery being viewed
			activeClass = " activeGallery";
		}
		
		textLinks += "<a onclick='linkInit(imageArrays," + i + ")' href='#' class='moreText" + activeClass + "'>" + a + "</a>" + separator;
		
		a++;
	}
	textLinks += "</div></div>";
	
	return textLinks;
}

function setGalleryBackground(filename,imgnumber){
	//changes css background of gallery links on right side
	imgnumber++;
	//alert(imgnumber + "img");
	for(i=1;i<9;i++){
		if(i==8){
			i++;
		}
		bgfilename = "url('menus/" + filename + imgnumber +".jpg')";
		currentDiv = document.getElementById("link" + i);
		currentDiv.style.backgroundImage=bgfilename;
	}
	
}