$(function() {
	var showing = 0;
	var divs = $('#featured div.product');
	var nav = $('#nextproduct');
	var stop = divs.length;
	for (i = 2; i <= stop; i++) {
		var pad = (i >= 3) ? 'style="padding-left:6px;"' : ''; // Fix for extra offset on numbers 3 and up.
		nav.append('<a href="#"' + pad + '>' + i + '</a> ');
	}
	var buttons = nav.find('a');
	var effects = [];
	
	var intervalId = window.setInterval(function() {
		$(divs.get(showing)).fadeOut(); // Comment out this line, and un-comment the next line, to eliminate fading out.
		//$(divs.get(showing)).hide();
		$(buttons.get(showing)).removeClass('here');
		showing = (showing == divs.length - 1) ? 0 : showing+1;
		$(divs.get(showing)).fadeIn();  // Comment out this line, and un-comment the next line, to eliminate fading in.
		//$(divs.get(showing)).show();
		$(buttons.get(showing)).addClass('here');
		if (jQuery.browser.msie && jQuery.browser.version == '7.0') {
			$('div.quickadd').append(document.createElement('div'));
		}
	}, 4000);
	
	function stopRotating(e) {
		window.clearInterval(intervalId);
		var stop = divs.length;
		divs.stop(true, true);
		for (i = 0; i < stop; i++) {
			if (i==e.data.index) {
				$(divs.get(i)).fadeIn(); // Comment out this line, and un-comment the next line, to eliminate fading out.
				//$(divs.get(i)).show();
				$(buttons.get(i)).addClass('here');
			} else if (i==showing) {
				$(divs.get(i)).fadeOut();  // Comment out this line, and un-comment the next line, to eliminate fading in.
				//$(divs.get(i)).hide();
				$(buttons.get(i)).removeClass('here');
			} else {
				$(divs.get(i)).hide();
			}
		}
		if (jQuery.browser.msie && jQuery.browser.version == '7.0') {
			$('div.quickadd').append(document.createElement('div'));
		}
		showing = e.data.index;
	}
		
	buttons.each(function(index, b) {
		$(b).bind('click', {index: index}, stopRotating);
	});
	divs.each(function(index, d) {
		$(d).bind('click', {index: index}, stopRotating);
	});
});