// JavaScript Document

var feature = {
	tabs: ['product_finder', 'catalog', 'reorder'],
	current: 0,
	interval: 0,
	starter: 0,
	
	init: function(){
		var that = this;
//
		$('#welcome_reorder').hide();
//		
		// attach events
		$('div.feature > div.tabs > div.tab').each(function(i){
			$(this).bind('mouseover', {index: i}, function(e){
				clearTimeout(that.starter);
				feature.stop();
				feature.go(e.data.index);
			}).mouseout(function(){
				//that.starter = setTimeout("feature.start()", 150);
			});
		});
		
		// stop feature when user mouses over welcome area
		/*$('div.feature > div.welcome').mouseover(function(){
			clearTimeout(that.starter);
			feature.stop();
		}).mouseout(function(){
			//that.starter = setTimeout("feature.start()", 150);
		});*/
		
		// preload images
		/*for(var i = 0; i < this.tabs.length; i++)
		{
			jQuery("<img>").attr("src", 'images/feature-main-' + this.tabs[i] + '.jpg');
			jQuery("<img>").attr("src", 'images/feature-button-sign-up-now-' + this.tabs[i] + '.jpg');
			jQuery("<img>").attr("src", 'images/feature-link-' + this.tabs[i] + '-over.jpg');
		}*/
	},
	
	start: function(){
		this.interval = setInterval("feature.go()", 3500);
	},
	
	stop: function(){
		clearInterval(this.interval);
	},
	
	go: function(tab){
		if (arguments.length === 0){
			var prev = this.current++;
			
			if (this.current === this.tabs.length)
				this.current = 0;
		} else {
			var prev = this.current;
			this.current = tab;
		}
		
		thisTab = this.tabs[this.current];
		prevTab = this.tabs[prev];
		
		// change the tab
		$('div.feature > div.tabs > div#tab_' + prevTab).removeClass('current');
		$('div.feature > div.tabs > div#tab_' + thisTab).addClass('current');
	
		// change the welcome
		$('div.feature > div.welcome > div#welcome_' + prevTab).hide();
		$('div.feature > div.welcome > div#welcome_' + thisTab).show();
	}
};

$(document).ready(function(){
	feature.init();
	//feature.start();
});
