var links; var pics; var slides; var opacity = 1; var stopShow;
function startShow() {
	slides = new slideshow("slides");
	links = document.getElementById("slideshow").getElementsByTagName("a");
	pics = document.getElementById("photo").getElementsByTagName("li");
	for(var q = 0; q < links.length - 1; q++) {slides.add_slide(new slide(links[q].src));}
	slides.transition(1);
	if(links.length > 1) {slides.play();}
}
function slide(src) {this.src = src;}
function slideshow(ssname) { //inspired by Patrick Fitzgerald - www.barelyfitz.com
	this.name = ssname; this.slides = new Array(); this.current = 0; this.prev = -1; this.timeoutid = 0; this.stopped = false; 
	this.add_slide = function(slide) {
		var i = this.slides.length;
		this.slides[i] = slide;
	}
	this.play = function() {
		this.pause(); this.stopped = false; this.timeoutid = setTimeout(this.name + ".loop()", 3000);
	}
	this.pause = function() { if(this.timeoutid != 0) { clearTimeout(this.timeoutid); this.timeoutid = 0; }	}
	this.fullStop = function() { this.pause(); this.stopped = true; }
	this.update = function() {
		links[this.current].parentNode.className += " active";
		pics[this.current].className = "active";
		if(!this.stopped) {
			if(this.current > 0) {this.prev = this.current - 1;}
			else {this.prev = this.slides.length - 1;}
		}
		if(this.prev != -1) {links[this.prev].parentNode.className = links[this.prev].parentNode.className.replace(/ active/g, "");}
		this.transition(1);
	}
	this.transition = function(i) {
		if (typeof i != 'undefined') {opacity = i;}
		if(opacity <= 10) {
			if(this.prev != -1) {pics[this.prev].style.opacity = ((10-opacity)*10)/100; pics[this.prev].style.filter = "alpha(opacity=" + (10-opacity)*10 + ")";}
			else if(this.prev == -1) {pics[this.current].className = "active";}
			pics[this.current].style.opacity = (opacity*10)/100; pics[this.current].style.filter = "alpha(opacity=" + opacity*10 + ")";
			++opacity;
			setTimeout(this.name + ".transition()", 75);
		}
		else {
			if(this.prev != -1) {pics[this.prev].className = "";}
			return true;
		}
	}
	this.next = function(n) {
		if(n < this.slides.length && n >= 0) {this.current = n;}
		this.update();
	}
	this.loop = function() {
		if(this.current < this.slides.length - 1) {next_slide = ++this.current;} else {next_slide = 0;} this.next(next_slide); this.play();
	}
	this.gotoSlide = function(n) {
		if((n < this.slides.length) && (n >= 0)) {
			this.fullStop();
			if(n != this.current) {
				this.prev = this.current;
				this.current = n;
			}
		}
		this.update();
	}
}

//startShow();