hs.graphicsDir = 'css/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.dimmingOpacity = 0.0; //0.75
// define the restraining box
hs.useBox = true;
hs.width = 800;
hs.height = 600;
// Add the controlbar
hs.addSlideshow({
    //slideshowGroup: 'group1',
    interval: 5000,
    repeat: false,
    useControls: true,
    fixedControls: 'fit',
    overlayOptions: {
        opacity: 1,
        position: 'bottom center',
        hideOnMouseOut: true
    }
});
// colocar isso antes de aplicar display none nas sub ULS
function ajustaWidthLi(ul) {
    var maior = 0;
    $('> li', ul).each(function(){
        var tam = $(this).width();
        if(tam > maior)
            maior = tam;
        var ul = $('> ul', this);
        if($(ul).langth == 1)
            ajustaWidthLi(ul);
    });
    $('> li', ul).css({width: maior});
}
function getCidades(input, estado){
    $(input).html('')
    .next().find('ul')
    .append('<li rel="">Carregando...</option>')
    .load('Contato/getCidades/'+estado, function(){
        setSearchableInput(input);
    })
}
function verifEstado(select){
    var id = $('option:selected', select).attr('rel');
    if(id != '' && id != 'undefined')
        getCidades('#cidade', id);
}
function setSearchableInput(id){
    var busca, texto, div_ac;
    $(id).keyup(function() {
        busca = $(this).val();
        div_ac = $(this).next();
        if(busca == "" || busca == "undefined" || $('li[rel*='+busca+']', div_ac).length == 0) {
            $(div_ac).css({display: 'none'});
            return;
        }
        else
            $(div_ac).css({display: 'block'});
        $(div_ac).find('li').each(function(){
            if($(this).filter('li[rel*='+busca+']').length == 1) {
                texto = $(this).text().replace(busca, '<b>'+busca+'</b>');
                $(this).css({display: 'block'}).html(texto);
            }
            else
                $(this).css({display: 'none'});
        }).filter('li:hidden:gt(9)').css({display: 'none'});
    })
    .next().find('li')
    .css({cursor: 'pointer'})
    .hover(function(){
        $(this).css({'background-color': '#dddddd'});
    }, function(){
        $(this).css({'background-color': '#ffffff'});
    })
    .click(function(){
        $(id).val($(this).text());
        $(this).parent().parent().css({display: 'none'});
    });
}
$(document).ready(function(){
    verifEstado('#estado');
    $('#estado').change(function(){
        verifEstado('#estado');
    });

    $('a.vermais, a.voltar, a.vertodos, input.acessar, input.voltar, input.enviar').css({opacity: 0.7}).hover(function(){
        $(this).css({opacity: 1});
    }, function(){
        $(this).css({opacity: 0.7});
    });
    $('.menu > ul > li ul').css({opacity: 0});
    $('.menu li').hover(function(){
        $('> a', this).addClass('hover').parent().addClass('hover');
        var ul = $('> ul', this);
        if($(ul).parent().parent().parent().attr('class') != 'menu')
            $(ul).css({left: parseInt($(this).outerWidth(), 10)+'px'});
        $(ul).stop().css({display: 'block', opacity: 0}).animate({opacity: 1}, 'fast');
    }, function(){
        $('> a', this).removeClass('hover').parent().removeClass('hover');
        $('> ul', this).stop().animate({opacity: 0}, 'fast', function(){
            $(this).css({display: 'none'})
        });
    });
    $('.conteudo .texto .txt img').each(function(){
        if($(this).attr('src').substr(0, 4) != 'http')
            $(this).attr({src: 'http://sistema.midukan.com.br/'+$(this).attr('src')})
    });
    $('input, textarea, select').keyup(function(){
        var maxlength = parseInt($(this).attr('maxlength'), 10);
        var index = $('input, textarea, select').index(this);
        if(maxlength > 0 && this.selectionEnd == maxlength)
            $('input, textarea, select').eq(index+1).focus();
    });
});
