$('document').ready(function () {
    $('#sliderselecionado').nivoSlider({
        directionNav: false,
        directionNavHide: true,
        controlNav: true,
        effect: 'fade'
    });
    $('#slider').nivoSlider({
        directionNav: false,
        directionNavHide: true,
        controlNav: true,
        effect: 'fade'
    });
    ontabshandler('#linhadeprodutos');
    ontabshandler('#tabprodutoespecificado');
    ontabshandler('#busquepor');
    ontabshandler('#tabondeencontrar');

    showpicture();
    showmapa();
    showtooltip();
    //dropdown();

    //$(".wrapinp select, wrapsel select, .wrapinp input, .selwrap select").uniform();

    $("#tabdetalhestecnicos a").colorbox({ transition: "fade", width: "900px", height: "500px" });
});

function showpicture() {
    $('#gallistprodsel a').click(function () {
        $('#ctl00_ContentPlaceHolder1_galeriaimagemprodutoselecionado').attr('src', ($(this).attr('href')));
        console.info($(this).attr('href'));
        return false
    })
}

// Toggle produtos
$('h2.bnr_prod').click(function (e) {
    e.preventDefault();
    $(this).next('ul').slideToggle("200");
});

// Toggle revendas
$('.abre_rvnd').click(function (e) {
    e.preventDefault();
    $(this).next('.info_rvnd').slideToggle("200");
});


// Galeria Destaque Home
$('#dstq_home').ready(function () {

    var delay = 10000;
    var timeout = window.setInterval(homeTras, delay);

    $('.nav_bullet a', '#dstq_home').click(function () {
        $(this).blur();
        clearInterval(timeout);

        var id = this.hash;
        $('.destaque.dstq_atv', '#dstq_home').fadeOut(1200).removeClass('dstq_atv');
        $(id, '#dstq_home').fadeIn(1200).addClass('dstq_atv');

        $('.nav_bullet .dstq_atv', '#dstq_home').removeClass('dstq_atv');
        $(this).parent().addClass('dstq_atv');

        timeout = window.setInterval(homeTras, delay);
        return false;
    });

    function homeTras() {
        clearInterval(timeout);

        var next;
        if ($('.destaque.dstq_atv', '#dstq_home').next().is('.destaque')) {
            next = $('.destaque.dstq_atv', '#dstq_home').next('.destaque');
            nextControle = $('.nav_bullet .dstq_atv', '#dstq_home').next('li');
        }
        else {
            next = $('.destaque:eq(0)', '#dstq_home');
            nextControle = $('.nav_bullet li:eq(0)', '#dstq_home');
        }

        $('.destaque.dstq_atv', '#dstq_home').fadeOut(1200).removeClass('dstq_atv');
        $(next).fadeIn(1200).addClass('dstq_atv');
        $('.nav_bullet .dstq_atv', '#dstq_home').removeClass('dstq_atv');
        $('a', nextControle).parent().addClass('dstq_atv');

        timeout = window.setInterval(homeTras, delay);
    }

});
// Fim Galeria Destaque Home

// Redimensiona ct_fade
var tamanho = ($(window).height());
$("#ct_fade, #bg_fade").height(tamanho);

// Abre Esqueci minha Senha
$('.bt_esqcsenha').click(function (e) {
    e.preventDefault();
    $('#ct_fade, #esqc_senha').fadeIn(400);
    $('.ncadastrado').show();
});

// Fecha especificamente Esqueci minha Senha
$('#fechasenha').click(function (e) {
    e.preventDefault();
    $('#ct_fade, .mdl').fadeOut(400);
    $('.msg_alert').hide();
    $('#ctl00_email').attr("value", "");
    window.location="revendedor.aspx";
});

// Fecha modal revendedor
$('.hsubheader').click(function (e) {
    e.preventDefault();
    $('#bg_fade, .ct_revend').fadeIn(400);
});

// Fecha modal revendedor
$('.bt_fecharmdl').click(function (e) {
    e.preventDefault();
    $('#bg_fade, .modal').fadeOut(400);
});

// Valida email certo
/*$('.limpaenviado').click(function (e) {
    e.preventDefault();
    if ($('.ncadastrado').css("display", "block")) {
        $('.ncadastrado').css("display", "none");
    }
  

    $('.limpaenviando').submit();
});*/

// Abre Mensagem enviada com sucesso
function abreSucesso(e){
    e.preventDefault();
    $('.mdl').fadeOut(400);
    $('#ct_fade, #cadsucesso').fadeIn(400);
};

// Fecha modal
$('span.top_mdl a').click(function(e){
    e.preventDefault();
    $('#ct_fade, .mdl').fadeOut(400);
});

function ontabshandler(param) {
    var obj = {
        tabs: $(param + ' .thetabs'),
        firstTab: $(param + ' .thetabs:eq(0)'),
        linkTabs: $(param + ' .linktabs a'),
        firstLinkTab: $(param + ' .linktabs a:eq(0)')
    };
    obj.tabs.css({ display: 'none' });
    obj.firstTab.css({ display: 'block' });
    obj.firstLinkTab.addClass('activetab');

    obj.linkTabs.click(function () {
        if ($($(this).attr('href')).is(':hidden')) {
            obj.tabs.css({ display: 'none' });
            $($(this).attr('href')).fadeIn();

            obj.linkTabs.removeClass('activetab');
            $(this).addClass('activetab');
        }
        return false;
    })
}
function showtooltip() {
    var tooltip = $('.wrappercaracteristicas a').children('span');
    tooltip.css({ display: 'none' });
    //tooltip.css({opacity:0});
    $('.wrappercaracteristicas a').mouseenter(function () {
        $($(this).children('span')).css({ display: 'block' });
        //$($(this).children('span')).animate({opacity:1}, { queue: false, duration: 200 });
    })
    $('.wrappercaracteristicas a').mouseleave(function () {
        $($(this).children('span')).css({ display: 'none' });
        //$($(this).children('span')).animate({ opacity: 0 }, { queue: false, duration: 100 });
    })
}

function showmapa() {

    $('#Map area').mouseover(function () {
        //console.info($(this).attr('href')).addClass('uffront');
        $($('#Map area').attr('href')).removeClass('uffront');
        $($(this).attr('href')).addClass('uffront');
    });
    $('#Map area').mouseout(function () {
        $($(this).attr('href')).removeClass('uffront');
    });
}

var e = {
    d: document,
    id: function (event) { return this.d.getElementById(event); },
    tag: function (event) {
        for (var i = 0; i < this.d.getElementsByTagName(event).length; i++) {
            return this.d.getElementsByTagName(event[i]);
        }
    },
    cria: function (event) {
        try { return this.d.createElement(event); }
        catch (e) { e; }
    }
};
var linkexteno = e.id('external');
function urlHandler() {
    var url = window.location + "";
    var deletado = url.split('=').pop();

    //window.alert( deletado );
    //console.info( deletado );

    var videos = e.id('wrapsvideos');

    if (deletado === "BA") {
        videos.style.display = "none";
    }
}

window.onload = init;
function init() {
    fc.giveval();
}

var valor = {
    //namespace do valor para -texto
    texto: {
        cep: "Digite seu CEP",
        vazio: ""
    }
};
var field = {
    //cep onde encontrar
    cep: e.id('chegarcep')
};
var fc = {
    giveval: function () {
        var v;
        if (field.cep) {
            v = field.cep.value = valor.texto.cep;
            return v;
        }
    },
    onfocushandler: function () {
        field.cep.value = valor.texto.vazio;
    },
    onblurhandler: function () {
        if (field.cep.value === valor.texto.vazio) {
            field.cep.value = valor.texto.cep;
        }
    }
};
/*handler field
if (field.cep) { field.cep.onfocus = fc.onfocushandler; }
if (field.cep) { field.cep.onblur = fc.onblurhandler; }
*/






