ee = new EAST_END();
$(document).ready(ee.init);


function EAST_END() {
	
	
	this.init = init;
	function init() {
		//$('.feature').hover(showBar, hideBar);
		
		curIndex = 0;
		fadeDuration = 2;
		container = $('#coop-features');
		features = [];
		timer = 0;
		
		container.find('.feature').each(function(i, div) {
			(i == 0) ? $(div).addClass('show') : $(div).removeClass('show');
			features.push($(div));
		});
		
		if ( features.length > 1 )
			play();
		
	} // init
	
	function hideBar() {
		$('.feature-bar').fadeOut();
		// resume autoplay
		
	} // hideBar
	
	function next() {
		var prevIndex = curIndex;
		curIndex = (curIndex + 1) % features.length;
		
		features[curIndex].stop().hide().addClass('show');
		features[prevIndex].fadeOut(fadeDuration * 1000, function() { $(this).removeClass('show'); });
		setTimeout(function() {
			features[curIndex].fadeIn(fadeDuration * 1000)
		}, fadeDuration * 0.8);
	} // next
	
	function play() {
		if ( features.length ) {
			clearInterval(timer);
			timer = setInterval(next, 7000);
			isPlaying = true;
		}
	} // play
	
	function showBar() {
		$('.feature-bar').fadeIn();
		// stop autoplay
		
	} // showBar
	
} // EAST_END
