// JavaScript Document
var currentLink = 1;
var previouslyClickedThumb;

function onLoad() {
	checkFooterButtons();
	showPic(currentLink);
}

function checkFooterButtons() {
	if(numLinks == 0) {
		document.getElementById("nextButton").style.display = "none";
		document.getElementById("previousButton").style.display = "none";
	} else if(currentLink == 1) {
		document.getElementById("previousButton").style.display = "none";
		document.getElementById("nextButton").style.display = "block";
	} else if(currentLink == numLinks){
		document.getElementById("nextButton").style.display = "none";	
		document.getElementById("previousButton").style.display = "block";
	} else {
		document.getElementById("nextButton").style.display = "block";
		document.getElementById("previousButton").style.display = "block";
	}		
}

function showPic (obj) {	
	if (document.getElementById) {
		currentLink = obj;		
		var linkId = getLinkId(obj);
		var whichpic = document.getElementById(linkId);
		
		if(whichpic != null) {
			var picStr = whichpic.toString();
			var filetype = picStr.substr(picStr.length - 3, picStr.length - 1);
			
			if(filetype != "swf") {
				document.getElementById('workImage').src = whichpic.href;
			} else {
				writeFlash(whichpic.href);
			}
			
			checkFooterButtons();
			
			// changes clicked thumb's style
			changeThumbStyle(previouslyClickedThumb, whichpic);
			
			// comment out if need to title image
			/*
			if (whichpic.title) {
				document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
			} else {
				document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
			}
			*/
		}
		
		return false;
	} else {
		
		alert("why??");
		return true;
	}
}

function changeThumbStyle(previousThumb, currentThumb) {
	var suffix = "Active";
	var currentPrefix = currentThumb.className;
		
	currentThumb.className = currentPrefix + suffix; 
	
	if(previousThumb != null) {
		var previousClass = previousThumb.className;
		var newClass = previousClass.substr(0 , previousClass.length - suffix.length);
		previousThumb.className = newClass; 		
	}
	
	previouslyClickedThumb = currentThumb;
}

function getLinkId(num) {
	var prefix = "link";
	if(num < 10)
		return prefix + "0" + num;
	else
		return prefix + num;
}

function writeFlash(path) {
	var so = new SWFObject(path, "mymovie", "640", "480", "7", "#ffffff");
	so.write("flashcontent");
}