var flag = false;
var intervalo;

function acende(classe) {
	if(typeof classe == 'object') obj = classe
	else obj = $('#lights .'+classe);
	
	obj.css('backgroundPosition', '0 0');
	
}

function apaga(classe) {

	if(typeof classe == 'object') obj = classe
	else obj = $('#lights .'+classe);
	
	obj.css('backgroundPosition', '900px');
	
}

function acendeApaga(classe) {
	acende(classe);
	setTimeout('apaga("'+classe+'")', 1000);
}

function sobe() {
	var scroll = $('#content .text').scrollTop();
	$('#content .text').scrollTop(scroll-10);
}

function desce() {
	var scroll = $('#content .text').scrollTop();
	$('#content .text').scrollTop(scroll+10);
}


$(function() {
	
	$('#content .down').hover(function() {
		intervalo = setInterval("desce()", 50);
	}, function() {
		clearInterval(intervalo);
	})
	
	$('#content .up').hover(function() {
		intervalo = setInterval("sobe()", 50);
	}, function() {
		clearInterval(intervalo);
	})	
	
	$('#lights div').not('#lights div div').each(function(i) {
		$(this).css('backgroundPosition', '0 0');
		$(this).css('backgroundPosition', '900px');
	})
		
	$('#lights div').not('#lights div div').hover(function() {
		var classe = $(this).attr('class');
		$('#icon .bg li').hide();
		$('#icon .bg .'+classe).show();
		$(this).find('.menu').show();
		acende($(this));
	}, function() {
		$('#icon .bg li').hide();
		$('#icon .bg .main').show();
		$(this).find('.menu').hide();
		apaga($(this));
	})
	
	$('#footer').hover(function() {
		if(!flag) {
			flag = true;
			$(this).find('.content').slideToggle('fast', function() { flag = false });
		}
	}, function() {
		if(!flag) {
			flag = true;
			$(this).find('.content').slideToggle('fast', function() { flag = false });
		}
	})
	
	setTimeout('acendeApaga("empresa")', 1000);
	setTimeout('acendeApaga("contato")', 2000);
	setTimeout('acendeApaga("solucoes")', 3000);
	setTimeout('acendeApaga("produtos")', 4000);
	setTimeout('acendeApaga("servicos")', 5000);
	
	$('.coletanea a').hover(function() {
		$(this).stop().animate({width: '83px'})
	}, function() {
		$(this).stop().animate({width: '20px'})
	})
	
	var scrollNode = document.querySelector("#content .text");
	var scroller = new TouchScroll(scrollNode, {elastic: false});
	     	
});
