// image rollover function
function initRollovers() {
	if (!document.getElementById) return
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');
	if (document.getElementById('ss_pic')) {
		firstpic = document.getElementById('ss_pic').src;
		firstpic = firstpic.substring(firstpic.indexOf('images/'));
		sshighlighter(firstpic);
	}
	for (var i = 0; i < aImages.length; i++) {
		if (aImages[i].className.match("rollover")) {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			if (src.indexOf('_over')==-1) {
				var hsrc = src.replace(ftype, '_over'+ftype);
			} else {
				var hsrc = src;
			}
			aImages[i].setAttribute('hsrc', hsrc);
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}
// changes the slideshow image based on the file given in the tag's onclick function
function slideshow (thisclick) {
	thispic = thisclick.id;
	document.getElementById('ss_pic').src = 'images/'+thispic;
	sshighlighter(thispic)
	return false;
}
// does the highlighting of the relevant slideshow button. Called by initRollovers, slideshow, and slidechange.
// This function conflicts with the Rollovers effect:
//      for now the numbered buttons in the slideshow are NOT to be given the class 'rollover'.
function sshighlighter (thispic) {
	thispic = thispic.replace('images/','');
	b = document.getElementById(thispic);
	bu = b.getAttribute('src');
	var images = document.getElementsByTagName('img');
	for (i=0;i<images.length;i++) {
		if (images[i].className.match('slideshow')) {
			if (images[i].getAttribute('id')!=thispic) {
				fred = images[i].getAttribute('src').replace('_over','');
				images[i].setAttribute('src',fred);
				images[i].className = images[i].className.replace('xover','rollover');
			} else {
				exty = bu.substring(bu.lastIndexOf('.'));
				if (bu.indexOf('_over')==-1) { newbu = bu.replace(exty,'_over'+exty); }
			//alert(newbu);
				b.className = b.className.replace('rollover','xover');
				b.setAttribute('src',newbu);
			}
		}
	}
}
// changes the slideshow image to next or previous
function slidechange (seq) {
	var sscount = 0;
	imagelist = new Array();
	var images = document.getElementsByTagName('img');
	for (i=0;i<images.length;i++) {
		if (images[i].className.indexOf('slideshow')!=-1) {
			imagelist[sscount] = images[i].getAttribute('src');
			sscount++;
		}
	}
	thisPic = document.getElementById('ss_pic');
	thisPicUrl = thisPic.src.substr(thisPic.src.indexOf('images'));
	oldNum = thisPicUrl.match(new RegExp('(\\d+)\\.jpg'))[1];
	if (seq=='prev') {
		newNum = Number(oldNum) - 1;
		if (newNum<1) { newNum = sscount; }
	} else {
		newNum = Number(oldNum) + 1;
		if (newNum>sscount) { newNum = 1; }
	}
	newPicUrl = thisPicUrl.replace(new RegExp('\\d+\\.jpg'),newNum+'.jpg');
	document.getElementById('ss_pic').src = newPicUrl;
	sshighlighter(newPicUrl);
	return false;
}

// launch everything at once! note that sequence of functions can matter.
function launchAll() {
	initRollovers();
//	slideplace();
}
window.onload = launchAll;
