/*
 *	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 = $("#feature").children().size();
	// var currentitem = (Math.ceil(itemcount*Math.random()))-1;
	var currentitem = itemcount-1;
	switchfeature(currentitem, false);
	// $("#index_feature_switcher li").each(function(z){
	// 	$(this).bind("click", function(){
	// 		switchfeature(z, true);
	// 	});
	// });
	function switchfeature(index, fade) {
		var speed=1000;
		if (index >= itemcount) {
			index = 0;
		}
		// $("#index_feature_switcher li").removeClass("active").eq(index).addClass("active");
		if(fade==true) {
			$("#feature li").eq(index).fadeIn(speed).end()
			.not($("#feature li").eq(index)).fadeOut(speed);
		} else {
			$("#feature li").hide().eq(index).show();
		};
		currentitem = index;
	}
	
	$.timer(5000, function (timer) {
  		switchfeature(currentitem+1, true);
  	});
	
	// $(".exitbutton").click(function(){
	// 	$(".ie6_warning").fadeOut('slow');
	// 	return false;
	// });

});
