var timeTabs;

var Application = {
	changeTabs: true,
	listeners: function() {
		$('#navServices li a').live('click',function(){
			var tabRel = $(this).attr('rel');
			Application.changeTabServices(tabRel);
			Application.changeTabs = false;
			window.clearInterval(timeTabs);
			/*$('#navServices li.active').removeClass('active');
			$('#nav-'+tabRel).addClass('active');
			$('.bn').addClass('dnone');
			$('#bn-'+tabRel).removeClass('dnone');*/
		});
		
		$('.select a').live('click',function(){
			var rel = $(this).attr('rel');
			Application.toggleSelect(rel,'block');
			Application.changeTabs = false;
			window.clearInterval(timeTabs);
		});
		
		$('.select_content a').live('click',function(){
			
			var element = $(this).parent().parent().attr('id');
			$('a.value[rel='+element+']').text($(this).attr('rel'));
			//$('a.value[rel='+element+']').parent().find('input[type=hiden]').val(element);
			$('#hidden_'+element).val($(this).attr('rel'));
			//$(this).parent().parent().parent().find('input[type=hiden]').val($(this).attr('rel'));
			Application.changeTabs = false;
			window.clearInterval(timeTabs);
			Application.toggleSelect(element,'none');
		});
		
		$('#bn *').live('focus',function(){
			Application.changeTabs = false;
			window.clearInterval(timeTabs);
		});
		
		Shadowbox.init();
		if($('body').hasClass('home')){
			timeTabs = setInterval("Application.changeTabServices('10')",8000);
		}
	},
	toggleSelect: function(who,display){
		if($('#'+who).css('display') == 'none') {
			$('#'+who).css('display','block');
		}else{
			$('#'+who).css('display','none');
		}
	},
	changeTabServices: function(tabRel){
	
		if(tabRel == '10' && Application.changeTabs == false){
			return false;
		}
	
		if(tabRel == '10'){
			var rel = $('#navServices li.active a').attr('rel');
			if(rel == 'andaimes'){
				tabRel = 'plataformas';
			}else if(rel == 'plataformas'){
				tabRel = 'energia';
			}else{
				tabRel = 'andaimes';
			}
		}
		
		//alert(tabRel);
	
		$('#navServices li.active').removeClass('active');
		$('#nav-'+tabRel).addClass('active');
		$('.bn').addClass('dnone');
		$('#bn-'+tabRel).removeClass('dnone');
	}
};

$(document).ready(function(){
	Application.listeners();
});
