/*
 *	jQuery Timer plugin v0.1
 *		Matt Schmidt [http://www.mattptr.net]
 *
 *	Licensed under the BSD License:
 *		http://mattptr.net/license/license.txt
 */
 
 jQuery.timer = function (interval, callback)
 {
	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };


$(document).ready(function(){
	var itemcount = $("#index_feature_inner").children().size();
	var switcher = $("#index_feature_switcher");
	var i=1;
	for (i=1;i<=itemcount;i++) {
		switcher.append("<li>"+i+"</li>");
	}
	var currentitem = (Math.ceil(itemcount*Math.random()))-1;
	switchfeature(currentitem, false);

	function switchfeature(index, fade) {
		if (index >= itemcount) {
			index = 0;
		}
		switcher.children("li").removeClass("active").eq(index).addClass("active");
		if(fade==true) {
			$("#index_feature_inner li").eq(index).fadeIn('slow').end()
			.not($("#index_feature_inner li").eq(index)).fadeOut('slow');
		} else {
			$("#index_feature_inner li").hide().eq(index).show();
		};
		currentitem = index;
	}
	
	var switcher_timer = $.timer(5000, function (timer) {
  		switchfeature(currentitem+1, true);
  	});

	switcher.children("li").each(function(z){
		$(this).bind("click", function(){
			switchfeature(z, true);
			switcher_timer.stop();
		});
	});
	
	$(".exitbutton").click(function(){
		$(".ie6_warning").fadeOut('slow');
		return false;
	});

});