﻿
// THIS IS THE MAIN GALLERY SCRIPT
// FOR RACHEL MOODY'S SITE
// 2007-2008 Levi DeKeyrel
// Hooray

var unColor = "#336699";
var avColor = "#3399CC";
var arNum = 1;
var fold;

var blast = new Array('One','Two','Three','Four','Five','Six','Seven','Eight'); //this is the pages cell IDs
var pNums = new Array (1,2,3,4,5,6,7,8,9);

function pLoads() {
	pNums.length = pages;
}


function loader(wrd) {
	fold = wrd;
	//alert(fold);
}



function blaster(arNum,pages) {		
	nameMaker(arNum);
	cellFiller();
	pageNavChange(arNum);
	arrowChange(arNum);
}

function cellFiller() {
	for (var f in blast) {
		colorChange(f);
		thumbChange(f);
	}
}

function pageNavChange(arNum) { // changes Page sub nav according to how many pages
	for (var g in pNums) {
		if (pNums[g] == arNum) {
			document.getElementById(pNums[g]).innerHTML = pNums[g] + " |";
		} else {

		document.getElementById(pNums[g]).innerHTML = '<a class="pg_num" title="Page ' + pNums[g] + '" href="javascript:jumpPage(' + pNums[g] + ');">' + pNums[g] + '</a> | ';
		}
	}
}

function arrowChange(arNum) {
	var bck = document.getElementById('pgBk');
	var fwd = document.getElementById('pgFw');
	if (arNum == 1) {
		bck.style.backgroundColor = unColor;
		bck.innerHTML = '&lt;&lt;';
	} else {
		bck.style.backgroundColor = avColor;
		bck.innerHTML = '<a title="Previous Page" href="javascript:PageBack();">&lt;&lt;</a>';
	}
	if (arNum == pages) {
		fwd.style.backgroundColor = unColor;
		fwd.innerHTML = '&gt;&gt;';
	} else {
		fwd.style.backgroundColor = avColor;
		fwd.innerHTML = '<a title="Next Page" href="javascript:PageForw();">&gt;&gt;</a>';
	}
	
}

function colorChange(f) { // chnges background color according to Availability
		if (pageN[f][1] == 'No' || pageN[f][1] == 'no' || pageN[f][1] == '') {
			document.getElementById(blast[f]).style.backgroundColor = unColor;
			//avl = 'No';
		} else {
			document.getElementById(blast[f]).style.backgroundColor = avColor;
		}	
}

function thumbChange(f) { // fills each of the cells in the BLAST array with thumbnail images and links
		if (pageN[f][0] == 'space' || pageN[f][0] == '') {
			document.getElementById(blast[f]).style.backgroundColor = unColor;		
			document.getElementById(blast[f]).innerHTML = '<img alt="Thumbnail" class="spaceThumb" src="images/spacer.gif"/>';
		} else {
			document.getElementById(blast[f]).innerHTML = '<a href="javascript:coll1(\'' + pageN[f][0] + '\');"><img id="' + pageN[f][0] + '" title="' + pageN[f][0] + '" alt="Thumbnail" class="thumb" src="images/thumbs/' + pageN[f][2] + '/' + pageN[f][0] + '.jpg"/></a>';
		}
}


function nameMaker(arNum) { //changes the name of the array to call

	if (arNum == 1) {
		pageN = stuff1;
	} else if (arNum == 2) {
		pageN = stuff2;	
	} else if (arNum == 3) {
		pageN = stuff3;
	} else if (arNum == 4) {
		pageN = stuff4;	
	} else if (arNum == 5) {
		pageN = stuff5;
	} else if (arNum == 6) {
		pageN = stuff6;
	} else if (arNum == 7) {
		pageN = stuff7;
	} else if (arNum == 8) {
		pageN = stuff8;
	} else if (arNum == 9) {
		pageN = stuff9;
	} 
	
	
}

function jumpPage(x) {
	cleaner();
	arNum = x;
	blaster(arNum);
}

function PageBack() {
	cleaner();
	arNum--;
	//alert(arNum);
	blaster(arNum);
	
}

function PageForw() {
	cleaner();
	arNum++;
	//alert(arNum);
	blaster(arNum);
}



function changer(titl,avl,prc,sett,desc) {	//changes all descriptions and image size
	
	if (avl == 'Yes' || avl == 'yes') {
		document.getElementById('avail').innerHTML = img + ", " + avl;	// if the piece is available, display item code
		document.getElementById('price').innerHTML = "$" + prc; 	// price of the piece
		document.getElementById('set').innerHTML = sett;	// is the piece a part of a set?
	//} else if (document.getElementById(titl).style.backgroundColor == unColor) {
	} else if (avl == 'No' || avl == 'no') {
		
		document.getElementById('avail').innerHTML = 'No'; 	// otherwise, display 'No'
		document.getElementById('price').innerHTML = 'N/A'; 	// set price to 0
		document.getElementById('set').innerHTML = 'N/A';	// not a part of a set		
	}
	document.getElementById('title').innerHTML = titl;	// name or short description of piece
	document.getElementById('full_desc').innerHTML = desc;	// longer description of the piece, materials, length, etc.
	
}

function cleaner() { // clears thumbnail cells, to get ready for filling
	for (var f in blast) {
		document.getElementById(blast[f]).style.backgroundColor = unColor;		
		document.getElementById(blast[f]).innerHTML = '<img alt="Thumbnail" class="spaceThumb" src="images/spacer.gif"/>';	
	}
	
	document.getElementById('avail').innerHTML = '<br\>'; 	
	document.getElementById('price').innerHTML = '<br\>'; 	
	document.getElementById('set').innerHTML = '<br/>';		
	document.getElementById('title').innerHTML = '<br/>';	
	document.getElementById('full_desc').innerHTML = '<br/>';	
	document.images.gallery.src= "images/info.gif";
	img = 'RM000';
}


function coll1(nm) {	// called when thumbnail is clicked, changes main image src, calls description changes
	document.images.gallery.src= "images/spacer.gif";
	img = nm;
	gutZ();
	changer(titl,avl,prc,sett,desc);
	//pageN[f][2] = sect;
	document.images.gallery.src= "images/gallery/" + sect + "/" + nm + ".jpg";
}

function gutZ() {	// gets name of image, calls corresponding description change (in other js file)
	var goob = img.substr(2,3); 	// strips 'RM' or first two items in the string
	var newGoob = ("r" + goob); 	// adds 'r' to the number code
	window[newGoob]();	// calls available function with desription changes (other js file)
}

function fullsize(grr) {
	//alert(fold);
	if (grr == 'RM000') {
		;
	} else {
	//window.open("images" + "/" + "fullsize" + "/" + sect + "/" + img + ".jpg");
	
	myWin= open();

	// open document for further output
	myWin.document.open();

	// create document
	myWin.document.write("<html><head><title>" + grr);
	myWin.document.write("</title></head><body bgcolor='#3399cc' background='images/bg1.jpg'>");
	myWin.document.write("<div align='center'><br/><br/>");
	
	myWin.document.write("<a href='javascript:window.close();'><img style='border:solid 1px white' src='images/portfolio/" + fold + "/" + grr + ".jpg' /></a><br/><br/>");
	
	//myWin.document.write("<a href='javascript:window.close();'>Close Window</a><br/><br/>")
	myWin.document.write("</div>");  
	myWin.document.write("</body></html>");

	// close the document - (not the window!)
	myWin.document.close();	
	}
}