$(function () {
	Ecpel.igniteAll();
});
var Ecpel = {
	'autor':'Adrian Neuhaus < a.neuhaus@gmail.com >',
	'igniteAll':function(){
		this.splashRoll.ignite();
		this.stripTabs.ignite();
	},
	'splashRoll':{
		'selItem': 0,
		'maxItens': 0,
		'timerInterval':{},
		'timerDelay': 9463,
		'startTimer':function () {
			this.stopTimer();
			this.timerInterval = setInterval(this.changeDest, this.timerDelay);
		},
		'stopTimer':function () { clearInterval(this.timerInterval) },
		'changeDest' : function () {
			var nextSelItem = Ecpel.splashRoll.selItem == Ecpel.splashRoll.maxItens-1 ? 0 : Ecpel.splashRoll.selItem + 1;
			$('#navItem_'+nextSelItem).triggerHandler('click');
		},
		'ignite':function(){
			this.maxItens = $('.splashHolder').length;
			this.startTimer();
			$('div.navItem').each(function(i){
				$(this).attr('id','navItem_'+i)
			});
			$('div.splashHolder').each(function(i){
				$(this).attr('id','splashHolder_'+i)
			});
			$('.navItem').click(function () {
				var id 	= $(this).attr('id'), q	= id.substr(id.lastIndexOf('_')+1,id.length);
				if(q != Ecpel.splashRoll.selItem){
					$('.navItem').removeClass('navItemSel');
					$(this).addClass('navItemSel');
					$('#splashHolder_'+Ecpel.splashRoll.selItem).fadeOut('fast',function(){
						if($(this).hasClass('hiddenSplash')) $(this).removeClass('hiddenSplash');
						$(this).hide();
						$('#splashHolder_' + Ecpel.splashRoll.selItem).fadeIn('slow');
					});
					Ecpel.splashRoll.selItem = parseInt(q);
				}
				Ecpel.splashRoll.startTimer();			
			});
		}
	},
	'stripTabs':{
		'ignite':function(){
			$(".stripTab*").click(function () {
				var tab = $(this), seta = $('#stripSeta'),
					id = tab.attr('id'),
					sPos = tab.position().left + (tab.width()/2) + (seta.width()/2),
					q = id.substr(id.lastIndexOf('_'),id.length);
		    	$('div[id*="stripPosts"]').not('#stripPosts'+q).hide();
		    	$('div[id*="stripTab"]').not('#stripTab'+q).css({'background-color':'#DDD'});
		    	$('#stripTab'+q).css({'background-color':'#FFDC00'});
		    	$('#stripSeta').css({'left':sPos+'px'});
		    	$('#stripPosts'+q).show();
		    });
		}
	}
}

