$(document).ready(function(){
$('#content .info .links ul:last-child, #menu ul li:last-child').addClass('last');
});

/* Global Functions */
/* Class: SlideShowClass
		Creates a fade-in and out slide show.
*/
function SlideShowClass(objList) {
	this.objList = objList;
	this.current = 0;
	this.fps = 30;
	this.pause = 3000;
	this.fade = 2000;
	this.zIndex = 15;
}

SlideShowClass.prototype.start = function() {
	// go to next after pause
	var self = this;
	setTimeout(function(){self.next(self);}, self.pause);
};

SlideShowClass.prototype.next = function(self) {
	// start fade out and in
	
	var a = self.current;
	var b = a + 1;
	if (b >= self.objList.length) {
		b = 0;
	}
	self.current = b;
	
	var objA = self.getID(self.objList[a]);
	var objB = self.getID(self.objList[b]);
	
	// make sure A is in front of B
	objA.style.zIndex = self.zIndex + 0;
	objB.style.zIndex = self.zIndex + 1;
	
	// set starting opacity
	self.setOpacity(objA, 99);
	self.setOpacity(objB, 1);
	
	// make both visible
	self.setVisible(objA, true);
	self.setVisible(objB, true);
	
	// start fade
	self.fadeStep(self, objA, objB, 0);
	
};

SlideShowClass.prototype.fadeStep = function(self, objA, objB, alpha) {
	// step through fade until complete
	
	var delay = 1000 / self.fps;
	var step = 100 / self.fade * delay;
	
	alpha = Math.min(alpha + step, 100);
	
	// set alpha
	self.setOpacity(objA, (100 - Math.floor(alpha)));
	self.setOpacity(objB, Math.floor(alpha));
	
	if (alpha >= 100) {
		// done
		self.setVisible(objA, false);
		setTimeout(function(){self.next(self);}, self.pause);
	} else {
		// continue step
		setTimeout(function(){self.fadeStep(self, objA, objB, alpha);}, delay);
	}
	
};		

SlideShowClass.prototype.getID = function(objname) {
	return document.getElementById(objname);
};

SlideShowClass.prototype.setVisible = function(obj, v) {
	if (v) {
		obj.style.display = "block";
	} else {
		obj.style.display = "none";
	}
};
SlideShowClass.prototype.setOpacity = function(obj, alpha) {
	try { obj.style.opacity = (alpha / 100); } catch (e) { }
	try { obj.style.MozOpacity = (alpha / 100); } catch (e) { }
	try { obj.style.KhtmlOpacity = (alpha / 100); } catch (e) { }
	try { obj.style.filter = "alpha(opacity=" + alpha + ")"; } catch (e) { }
};
SlideShowClass.prototype.debug = function(s) {
	var obj = document.getElementById("debug");
	obj.value = s + "\n" + obj.value; 
};


function cropMenu(x1, x2) {
	var obj = this.document.getElementById("menuClip");
	obj.style.visibility = 'visible';
	obj.style.clip = "rect(0px," + x2 + "px,30px," + x1 + "px)";
}
function cropMenuOut() {
	var obj = this.document.getElementById("menuClip");
	obj.style.clip = "rect(0px, 0px, 0px, 0px)";
}

function initSlideshow(ids) {
	
	var SS = new SlideShowClass(ids);
	SS.pause = 3000; // 3s
	SS.fade = 1000; // 1s
	
	// start slideshow
	SS.start();
	
}

