/*
 * Pega todos os links que tenham o destino de http:// e manda abri los em outra aba
 */
//(function($) {
//    $(function(){
//        $("a[href^=http://]").click(function(){
//            window.open($(this).attr("href"))
//            return false
//        })
//    })
//})(jQuery);
/*
 * Tira o pontilhado dos elementos
 */
(function($) {
    $(function(){
        $('a').click(function() {
            $(this).blur();
        });
        if($('.tweets').length > 0){
            twitterAPI({
                'Utilizador':TWITTER_NOME,
                'Tweets':TWITTER_VIEWS,
                'containerID':'.tweets'
            });
        }

    })

})(jQuery);


/*
 *
 * Javascriptque faz as imagens do bloco Cases
 * Do crosscontent passar automatico.
 *
 */
(function($) {
    $(function(){
        var tempo = startCrossCases();
    });
})(jQuery);
function startCrossCases(){
    var time = window.setInterval('passaCrossCases()', 4000);
    return time;
}
var busy1 = false;
function passaCrossCases(){
 if(busy1 == true) return false;
    busy1 = true;
    var elemento = $('#div-conteiner-cross-cases .conteudo-casos:last');
    var novoElemento = elemento.clone();
    novoElemento.css('width', '169px');
    novoElemento.css('margin-left','-175px');
    $('#div-conteiner-cross-cases').prepend(novoElemento);
    elemento.remove();
    $('#div-conteiner-cross-cases .conteudo-casos:first').animate({marginLeft: '0px'},500, function(){busy1 = false;});
    return false;
}
/*
 *
 * Fim do javascript do bloco de cases
 *
 *
 *
 * Cuida do submit do formulario de newsletter
 */
(function($) {
    $(function(){
        $('#bt_submit_newsletter').click(function(){
            $('#form-newsletter').submit()
            return false;
        })
    });
})(jQuery);
/*
 *
 * Fim do javascript do formulario de newsletter
 *
 *
 *
 *
 */
(function($) {
$(function() {
   $("a.favoritos").click(function(e) {
     e.preventDefault();
     // aqui deve definir o endereço do site
     var url = URL_ATUAL;
     // aqui deve definir o titulo do site
     var title = 'Bem-vindo ao Portal da Sances Sistemas';
     //verifica se o navegador que você está usando é o chrome
     var navegadorChrome = navigator.appVersion;
     var nChrome = navegadorChrome.indexOf('Chrome');

     if(nChrome != -1){
         window.sidebar.addPanel(title, url, '');
         return false;
     }else{
         // mozilla firefox
         if ($.browser.mozilla == true) {
           window.sidebar.addPanel(title, url, '');
           return false;
         // internet explorer
         } else if($.browser.msie == true) {
             window.external.AddFavorite( url, title);
             return false;
         // outros navegadores
         } else {
             alert('Pressione as teclas CTRL + D para adicionar aos favoritos.');
         }
     }
   });
    $('.interagir-bt').click(function(){

        $('.div-final').hide();
        $('.bt_subimit_itens_Inter_div').show();
        if($(this).attr('rel') == 'indique'){
            $('.conteudo-coment').hide();
            $('.conteudo-indique').show();
            $('.bt_subimit_itens_Inter').attr('id','bt_submit_indique');
            $('.bt_subimit_itens_Inter_div').find('#bt_submit_indique').each(function(){
                $(this).bind('click', function(){
                    $('#form-indique').submit();
                    return false;
                });
            });
        }else{
            $('.conteudo-coment').show();
            $('.conteudo-indique').hide();
            $('.bt_subimit_itens_Inter').attr('id','bt_submit_coments');
            $('.bt_subimit_itens_Inter_div').find('#bt_submit_coments').each(function(){
                $(this).bind('click', function(){
                    $('#form-coments').submit();
                    return false;
                })
                return false
            })
        }
        $(this).blur();
        return false;
    })
    $('#bt_submit_coments').click(function(){
        $('#form-coments').submit();
        return false;
    })
});
})(jQuery);
/*
 *
 * Javascriptque faz as imagens do bloco Clientes
 * Do crosscontent passar automatico.
 *
 */
(function($) {
    $(function(){
        var tempo = startCrossClientes();
    });
})(jQuery);
function startCrossClientes(){
    var time = window.setInterval('passaCrossClientes()', 4000);
    return time;
}
var busy2 = false;
function passaCrossClientes(){
 if(busy2 == true) return false;
    busy2 = true;
    var elemento = $('#div-conteiner-cross-clientes .conteudo-clientes:last');
    var novoElemento = elemento.clone();
    novoElemento.css('width', '169px');
    novoElemento.css('margin-left','-175px');
    $('#div-conteiner-cross-clientes').prepend(novoElemento);
    elemento.remove();
    $('#div-conteiner-cross-clientes .conteudo-clientes:first').animate({marginLeft: '0px'},500, function(){busy2 = false;});
    return false;
}
/*
 *
 * Fim do javascript do bloco de cases
 *
 *
 * Abre a popup de rss
 *
 *
 */
jQuery(function(){
    jQuery('.bt-rss').each(function(){
       jQuery(this).bind('click', function(){
            var left = cauculaWigth(460);
            jQuery('#div-conteiner-pop').hide();
            jQuery('#loading').show();
            jQuery.blockUI({ message: jQuery('#div-loading'),css: { width:'460px', left: left+'px', top:'20%',border:'0;'} });
            jQuery.get(BASE_URI+'noticias/popuprss', null, function(result){
               jQuery('#loading').hide();
               jQuery('#div-conteiner-pop').show();
               jQuery('#div-conteiner-pop').html(result);
            });
            return false;
        })
    })
});

/*
 *
 * ==================================================
 *
 * pega os valores do tamalnho da tela....
 */
function f_clientWidth() {
    return f_filterResults (
        window.innerWidth ? window.innerWidth : 0,
        document.documentElement ? document.documentElement.clientWidth : 0,
        document.body ? document.body.clientWidth : 0
    );
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function cauculaWigth(widthPop)
{
    var widthPop = widthPop;
    var widthJanela = f_clientWidth();
    var resultato = (widthJanela-widthPop)/2;
    return resultato;
}
/*
 *
 * ==================================================
 *
 * Controlador da paginação dos banner na home
 */
var imgInativa = BASE_URI+'application/themes/sances/img/icones/banner_paginacao.png';
var imgAtiva = BASE_URI+'application/themes/sances/img/icones/banner_paginacao-a.png';
$(function(){
    window.setInterval('passarBannerHome()', 10000);
})
function passarBannerHome()
{
    var daVez = '';
    daVez = $('.conteiner-banners-resto').find('.disaparecer:first');

    if(daVez.html() == null){
        daVez = $('.conteiner-banners-resto').find('.banners_home:first');
    }
    $('.banners_home').hide();
    $('.banners_home').removeClass('disaparecer');
    daVez.show();
    daVez.next().addClass('disaparecer');

    trocaPagina(daVez.attr('rel'));
}
function trocaPagina(pagina)
{
    $('.img-page-controller').attr('src', imgInativa);
    $('.'+pagina).attr('src', imgAtiva);
}
$(function(){
    $('.controler-banner').click(function(){
        $('.banners_home').hide();
        $('.banners_home').removeClass('disaparecer');
        $('.banner_top'+$(this).attr('rel')).show();
        $('.banner_top'+$(this).attr('rel')).next().addClass('disaparecer');

        $('.img-page-controller').attr('src', imgInativa);
        $(this).find('img').attr('src', imgAtiva);

        return false;
    })
})
/*
 *
 * ==================================================
 *
 * Controlador o menu de noticias.
 */
$(function(){
    $('.abrir-submenu').click(function(){
        var offset = $(this).next().offset();
        var height = offset.height;
        $(this).next().toggle(function(){

        });
        $(this).blur();
        return false;
    });
});



