﻿/// <reference path="jquery-1.3.2.js" />

$(document).ready(function() {
    var cpMediaBox = $("#CpMediaBox");

    if (cpMediaBox.size() > 0) {
        $indice1 = cpMediaBox.find(".aba1");
        $indice2 = cpMediaBox.find(".aba2");
        $indice3 = cpMediaBox.find(".aba3");
        $indice4 = cpMediaBox.find(".aba4");

        $indicesMB = $("#botoes").children("div").children("div");

        ConfiguraNavegacaoMB();

        iMB = 1;
        stopMB = false;

        setTimeout(AlternaMB, 5000);
    }
});


function ConfiguraNavegacaoMB() {
    $indicesMB.click(function() {
        AtivaInativaElementosMB(this);
        stopMB = true;
    })
};

function AlternaMB() {
    if (stopMB === false) {
        AtivaInativaElementosMB($indicesMB[iMB]);

        if (iMB === 3) {
            iMB = 0;
        }
        else {
            iMB += 1;
        }
        setTimeout(AlternaMB, 5000);
    }
}

function AtivaInativaElementosMB(elemento) {
    $indicesMB.removeClass("AbaAtiva");
    $indicesMB.addClass("AbaInativa");
    var indice = $(elemento);
    
    indice.addClass("AbaAtiva");
    indice.removeClass("AbaInativa");

    switch (indice.attr("id")) {
        case "aba1":
            $indice2.hide();
            $indice2.children("div.txt").hide();
            
            $indice3.hide();
            $indice3.children("div.txt").hide();
            
            $indice4.hide();
            $indice4.children("div.txt").hide();

            $indice1.fadeIn(500);
            $indice1.children("div.txt").slideDown(500)
            break;
        case "aba2":
            $indice1.hide();
            $indice1.children("div.txt").hide();
            
            $indice3.hide();
            $indice3.children("div.txt").hide();
            
            $indice4.hide();
            $indice4.children("div.txt").hide();

            $indice2.fadeIn(500);
            $indice2.children("div.txt").slideDown(500)
            break;
        case "aba3":
            $indice1.hide();
            $indice1.children("div.txt").hide();
            
            $indice2.hide();
            $indice2.children("div.txt").hide();
            
            $indice4.hide();
            $indice4.children("div.txt").hide();

            $indice3.fadeIn(500);
            $indice3.children("div.txt").slideDown(500);
            break;
        case "aba4":
            $indice1.hide();
            $indice1.children("div.txt").hide();
            
            $indice2.hide();
            $indice2.children("div.txt").hide();
            
            $indice3.hide();
            $indice3.children("div.txt").hide();
            
            $indice4.fadeIn(500);
            $indice4.children("div.txt").slideDown(500)
            break;
    }
}