function navOnde() {
    $('.abas ul li').click(function() {
        var indice = $(this).prevAll().size() + 1;
        if ($('#tab' + indice).css('display') == 'none') {
            $('.abas ul li').removeClass('active');
            $('.tab #content').cycle('stop');
            $(this).addClass('active');

            $('.tab').css('display', 'none');
            $('#tab' + indice).css('display', 'block');
            $('#tab' + indice + ' #nav-banner').html("");

            animaBanner('#tab' + indice);
            mudaImagemBanner('#tab' + indice, indice - 1);
        }
    });
}

function animaBanner(quem) {
    $(quem + ' .img img').css('opacity', '0');
    $(quem + ' .img h2').css('left', '-228px');
    $(quem + ' .img img').animate({
        opacity: 1
    }, 1000, function() {
        $(quem + ' .img h2').animate({
            left: 4
        }, 500, function() {

        });
    });
}
function mudaImagemBanner(tab, id) {
    $(tab + ' #content').cycle({
        fx: 'fade',
        timeout: 3000,
        pager: tab + ' #nav-banner',
        pagerAnchorBuilder: function(idx, slide) {
            return '<li id="' + idx + '"><a href="#"><img src="imagens/img' + (idx + 1 + 4 * id) + '.jpg"></a></li>';
        }
    });
}

function overProdutos() {
    $('.section.loja ul li').hover(
		function() {
		    $(this).stop();
		    //if($(this + ':animated') != true){
		    $(this).animate({
		        marginTop: '-15px'
		    }, 200, function() { });
		    //}
		},
		function() {
		    $(this).stop();
		    $(this).animate({
		        marginTop: '0'
		    }, 200, function() { });
		}
	);
}

function initBanner() {
    var sorteia = Math.floor(Math.random() * $('.abas ul li').size());
    $('.abas ul li').removeClass('active');
    $('.abas ul li:eq(' + sorteia + ')').addClass('active');

    $('.tab').css('display', 'none');
    $('#tab' + (sorteia + 1)).css('display', 'block');
    animaBanner('#tab' + (sorteia + 1));
    mudaImagemBanner('#tab' + (sorteia + 1), sorteia);
}

function accordion(){
	$('.accordion dt:first-child').addClass('active');
	$('.accordion dt:first-child').next('dd').css('display', 'block');
	
	$('.accordion dt').click(function(){
		$('.accordion dt').removeClass('active');
		if($(this).next('dd').css('display') == 'block'){
			$(this).next('dd').slideUp('slow');
		}else{
			$(this).addClass('active');
			$('.accordion dd').slideUp('slow');
			$(this).next('dd').slideDown('slow');
		}
	});
}

$(document).ready(function() {
    navOnde();
    overProdutos();
    initBanner();
	accordion();
});
