var links; var pics; var slides; var opacity = 1; var stopShow; var items = new Array(); var http = getHTTPObject(); var t1; var t2; var t3; var newLink = new Array(); var newImg = new Array(); var border; var lastX; var lastY; var newX; var newY; var doneX; var doneY; var items = new Array(); var newItems = new Array();
window.onload = init;

function init() {
	if(!document.getElementById) {return false;}
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
	if(document.getElementsByTagName("body")[0]) {stopShow = document.getElementById("stopShow"); startShow();}
}
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) { 
	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;
		stopShow.parentNode.className = "pause";
		stopShow.title = "Pause slideshow";
		stopShow.onclick = function() {slides.fullStop();}
		stopShow.onmouseover = function() {window.status = "Pause slideshow"; return true;}
		this.timeoutid = setTimeout(this.name + ".loop()", 6000);
	}
	this.pause = function() {
		if(this.timeoutid != 0) {
			clearTimeout(this.timeoutid);
			this.timeoutid = 0;
		}
	}
	this.fullStop = function() {
		this.pause();
		this.stopped = true;
		stopShow.parentNode.className = "play";
		stopShow.title = "Play slideshow";
		stopShow.onmouseover = function() {window.status = "Play slideshow"; return true;}
		stopShow.onclick = function() {slides.transition(1); slides.play();}
	}
	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();
	}
}
function getHTTPObject() { 
	var xmlhttp; 

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { 
		try { 
			xmlhttp = new XMLHttpRequest();
				xmlhttp.overrideMimeType("text/xml");
		} catch (e) { 
			xmlhttp = false; 
		} 
	} 
	return xmlhttp; 
}
function doRollovers() {
	var images = document.getElementsByTagName("img");
	var buttons = document.getElementsByTagName("input");
	preloads = new Object();
	for(var i = 0; i < images.length; i++) {
		if(images[i].parentNode.nodeName == "A") {
			var imageOffSrc = images[i].src + "";
			if(imageOffSrc.indexOf("_off") != -1){
				var imageOverSrc = imageOffSrc.replace(/_off/g, "_over");
				preloads['imageOff_' + i] = new Image();
				preloads['imageOff_' + i].src = imageOffSrc;
				preloads['imageOver_' + i] = new Image();
				preloads['imageOver_' + i].src = imageOverSrc;
				images[i].parentNode.onmouseover = function(){this.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].src.replace(/_off/g, "_over");}
				images[i].parentNode.onmouseout = function(){this.getElementsByTagName("img")[0].src = this.getElementsByTagName("img")[0].src.replace(/_over/g, "_off");}
			}
		}
	}
	for (var i = 0; i < buttons.length; i++){
		if(buttons[i].src){
			var imageOffSrc = buttons[i].src + "";
			if(imageOffSrc.indexOf("_off") != -1){
				var imageOverSrc = imageOffSrc.replace(/_off/g, "_over");
				preloads['imageOff_' + i] = new Image();
				preloads['imageOff_' + i].src = imageOffSrc;
				preloads['imageOver_' + i] = new Image();
				preloads['imageOver_' + i].src = imageOverSrc;
				buttons[i].onmouseover = function(){this.src = this.src.replace(/_off/g, "_over");}
				buttons[i].onmouseout = function(){this.src = this.src.replace(/_over/g, "_off");}
			}
		}
	}
}

function doTransitions() {
	var images = document.getElementById("thumbs").getElementsByTagName("img");
	initBorder();
	for(var q = 0; q < images.length; q++) {
		newLink[q] = document.createElement("a");
		newLink[q].href = images[q].parentNode.href;
		newLink[q].title = images[q].parentNode.title;
		newLink[q].className = "overImg";
		newLink[q].style.left = findPosX(images[q]) + "px";
		newLink[q].style.top = findPosY(images[q]) + "px";
		newLink[q].opacity = 1;
		newImg[q] = document.createElement("img");
		newImg[q].src = images[q].src.replace(/_off/g, "_over");
		newLink[q].appendChild(newImg[q]);
		images[q].rel = newLink[q];
		document.body.appendChild(newLink[q]);
		newLink[q].onmouseover = function() {fade(this, 1); moveBorder(this);}
		newLink[q].onmouseout = function() {unfade(this, 1); hideBorder();}
	}
}
function fade(obj, i) {
	if (typeof i != 'undefined') {obj.opacity = i;}
	if(obj.opacity <= 10) {
		obj.style.opacity = (obj.opacity*10)/100; obj.style.filter = "alpha(opacity=" + obj.opacity*10 + ")";
		++obj.opacity;
		setTimeout(function(){fade(obj);}, 40);
	}
	else {return true;}
}
function unfade(obj, i) {
	if (typeof i != 'undefined') {obj.opacity = i;}
	if(obj.opacity <= 10) {
		obj.style.opacity = ((10-obj.opacity)*10)/100; obj.style.filter = "alpha(opacity=" + (10-obj.opacity)*10 + ")";
		++obj.opacity;
		setTimeout(function(){unfade(obj);}, 10);
	}
	else {
		obj.style.opacity = 0; obj.style.filter = "alpha(opacity=0)";
		return true;
	}
}
function initBorder() {
	border = document.getElementById("border");
	lastX = findPosX(document.getElementById("thumbs")) - 2;
	lastY = findPosY(document.getElementById("thumbs")) - 2;
	border.style.left = lastX + "px";
	border.style.top = lastY + "px";
}
function moveBorder(obj) {
	newX = findPosX(obj); newY = findPosY(obj);
	if((newX != lastX) || (newY != lastY)) {
		border.style.display = "block";
		move(lastX, lastY, newX, newY, 0, 0);
	}
}
function move(_lastX, _lastY, _newX, _newY, doneX, doneY) {
	if(_newX > _lastX) {_lastX += Math.ceil((_newX-_lastX)/2);}
	else if(_newX < _lastX) {_lastX += Math.floor((_newX-_lastX)/2);}
	else if(_newX == _lastX) {doneX = 1;}
	if(_newY > _lastY) {_lastY += Math.ceil((_newY-_lastY)/2);}
	else if(_newY < _lastY) {_lastY += Math.floor((_newY-_lastY)/2);}
	else if(_newY == _lastY) {doneY = 1;}
	border.style.left = _lastX + "px";
	border.style.top = _lastY + "px";
	if((doneX == 1) && (doneY == 1)) {lastX = _lastX; lastY = _lastY; return true;}
	else {setTimeout(function(){move(_lastX, _lastY, _newX, _newY);}, 25);}
}
function hideBorder() {
	border.style.display = "none";
}

function slideIt(x, newx) { 
	if (newx > x) {x += Math.ceil((newx-x)/2);}
	else if (newx < x) {x += Math.floor((newx-x)/2);}
	else if (newx == x) {return true;}
	var obj = document.getElementById("photo").getElementsByTagName("ul")[0].style.marginLeft = -x + 'px';
	var time = setTimeout('slideIt('+x+', '+newx+')', 75);
}
function fixFloats() {
	var divs = document.getElementById("entries").getElementsByTagName("div");
	var items = new Array(); var w = 0;
	for(var q = 0; q < divs.length; q++) {if(divs[q].className == "entry") {items[w] = divs[q]; w++;}}
	var col1 = findPosX(items[0]); var col2 = findPosX(items[1]);
	for(var q = 2; q < items.length; q++) {
		var total1 = 0; var total2 = 0;
		for(var w = 0; w < q; w++) {
			if(findPosX(items[w]) == col1) {total1 += items[w].offsetHeight;}
			else {total2 += items[w].offsetHeight;}
		}
		if(total2 > total1) {
			if(q%2) {var dif = total1 - total2 - 10;}
			else {var dif = total1 - total2 - 20;}
			items[q].style.marginTop = dif + "px";
		}
	}
 
}
function emailCloak() {
	var alltags = document.all? document.all : document.getElementsByTagName("*");
	for (i=0; i < alltags.length; i++) {
	  	if (alltags[i].className == "hide") {
			var oldText = alltags[i].firstChild;
			var emailAddress = alltags[i].firstChild.nodeValue;
			var user = emailAddress.substring(0, emailAddress.indexOf("("));
			var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
			var newText = user+"@"+website;
			var a = document.createElement("a");
			a.href = "mailto:"+newText;
			var address = document.createTextNode(newText);
			a.appendChild(address);
			alltags[i].replaceChild(a,oldText);
		}
	}
}
function findPosY(obj) {
	var posTop = 0;
	do {posTop += obj.offsetTop;} while (obj = obj.offsetParent);
	return posTop;
}
function findPosX(obj) {
	var posLeft = 0;
	do {posLeft += obj.offsetLeft;} while (obj = obj.offsetParent);
	return posLeft;
}
