/* home.js */

var features = [];
var current_feature = 0;
var feature_interval;
var feature_time = 10000;
var feature_tween;


/* initial actions */
window.addEvent('domready', function() {
	
	var feature_images = [];
	features.each(function(feature) {
		feature_images.push(feature.image);
	});
	new Asset.images(feature_images, {
		onComplete: function() {
			playFeatures.delay(feature_time, false, 1);
		}
	});
	
});


/* features */
function playFeatures(i) {
	showFeature(i || current_feature);
	feature_interval = rotateFeature.periodical(feature_time, false, 'next');
}
function stopFeatures(i) {
	$clear(feature_interval);
	if (i) showFeature(i);
}
function rotateFeature(type) {
	var top = features.length;
	var btm = -1;
	if (type == 'next') {
		var i = (current_feature + 1 == top) ? btm + 1 : current_feature + 1;
	} else if (type == 'prev') {
		var i = (current_feature - 1 == btm) ? top - 1 : current_feature - 1;
	}
	showFeature(i);
}
function showFeature(i) {
	feature_tween = new Fx.Tween('home-feature', {
		onComplete: function() {
			$('feature-title').set('html', features[i].title ? features[i].title : '&nbsp;');
			$('feature-image').set('src', features[i].image);
			$('feature-link').set('href', features[i].link);
			$('feature-body').set('html', features[i].body ? features[i].body : '&nbsp;');
			current_feature = i;
			feature_tween = new Fx.Tween('home-feature').start('opacity', 1);
		}
	}).start('opacity', 0);
	
}





