//<![CDATA[

$(function() {

	new RotationBanners(true).startStop();

});

var RotationBanners = function() {
	this.initalize.apply(this, arguments);
}

RotationBanners.prototype = {
	autoplay: true,
	timer : null,
	delay :5000,
	currentPage : 1,
	pageCount : 4,
	initalize: function(playing)
	{
		this.autoplay = playing;
		
	},
	gotoPage: function(page)
	{
		if (typeof(page) == 'undefined' || page == null) {
			page = 1;
			this.currentPage = 1;
		}
		if (page > this.pageCount) { page -=  this.pageCount; }
		if (page < 0) { page = 1; }
		
		var inst = this;
		$('#mv0' + this.currentPage).fadeOut(700, (function (inst) {
			return function() {
				$('#slideshow ul li:nth-child(' + inst.currentPage + ') a img').attr('src', 'img/index/slide0' + inst.currentPage + '.png');
				$('#slideshow ul li:nth-child(' + page             + ') a img').attr('src', 'img/index/slide0' + page             + '_on.png');
			};
		})(inst));
		$('#mv0' + page).fadeIn(1000, (function (inst) {
			return function() {
				inst.currentPage = page;
			}
		})(inst));
	},
	goForward: function () {
		this.gotoPage(this.currentPage + 1);
	},
	clearTimer : function()
	{
		if (this.timer) window.clearInterval(this.timer);
	},
	startStop : function()
	{
		if (this.autoplay === true) {
			this.clearTimer();
			var func = this.goForward;
			var inst = this;
			this.timer = window.setInterval((function(inst) { return function() { inst.goForward(); };})(inst), this.delay);
		} else {
			this.clearTimer();
		}
	}
};

//]]>
