var url = window.location;
url = url.toString(); url = url.split('/'); url = url[2];
var server_name = "";
if (url == "localhost") server_name = "http://localhost/clientes/telmaster/site/";
//else server_name = "http://192.168.0.171/clientes/telmaster/site/";
else server_name = "http://www.telmaster.com.br/";

jQuery(document).ready(function() {

//conteudos show and hide
    $(".method-show").children("li .el").mouseover(function() {
        methodshow_over(this);
        //$(this).not("#el_on").attr("id","el_hover");
    }).mouseout(function() {
        methodshow_out(this);
        //$(this).not("#el_on").removeAttr("id");
    }).click(function() {
        methodshow_click(this);
        //$("#conteudo_detalhado_subitem span[id=el_on]").removeAttr("id");
        //$(this).attr("id","el_on");
        //var id = $(this).attr("showID");
        //$("#conteudo div").hide();
        //$('.'+id).show();
    });
    methodshow_over = function(e) { $(e).not("#el_on").attr("id","el_hover"); }
    methodshow_out = function(e) { $(e).not("#el_on").removeAttr("id"); }
    methodshow_click = function(e) {
            $("#conteudo_detalhado_subitem span[id=el_on]").removeAttr("id");
            $(e).attr("id","el_on");
            var id = $(e).attr("showID");
            $("#conteudo div").hide();
            $('.'+id).show();

    }
//conteudos load and remove
    $(".method-load").children("li .el").mouseover(function() {
        $(this).not("#el_on").attr("id","el_hover");
    }).mouseout(function() {
        $(this).not("#el_on").removeAttr("id");
    }).click(function() {
        $("#conteudo_detalhado_subitem span[id=el_on]").removeAttr("id");
        $(this).attr("id","el_on");
//        var id = $(this).attr("showID");
//        $("#conteudo div").hide();
        $("#conteudo iframe").remove();
        var x= $(this).attr("showID");
        $("#conteudo").append("<iframe id='testeiframe' onload='iframeAutoHeight(this)' src=galeria_siemens.php?s="+x+" border=0 ></iframe>");
    });

/* carousel */

    mycarousel_initCallback = function(carousel,st) {
        var els = $('#galeria li').length;
        if (els <7) {
            var elsW = els*90;
            $('.jcarousel-clip').width(elsW).css('left','50%').css('margin-left','-'+((elsW)/2)+'px');
        }
 
    }
    mycarousel_itemFirstInCallbackBefore = function(carousel, item, idx, state) {
        $('li[jcarouselindex = '+(idx+2)+']').children('.item_galeria').children('div,img').removeAttr('id').removeAttr('destaque');
        $('li[jcarouselindex = '+(idx+4)+']').children('.item_galeria').children('div,img').removeAttr('id').removeAttr('destaque');
    }
    mycarousel_itemFirstInCallbackAfter = function(carousel, item, idx, state) {
        $('li[jcarouselindex = '+(idx+3)+']').children('.item_galeria').children('div,img').attr('id','item_galeria_destaque').attr('destaque','central');
    }


    galMouseOver = function(o) {
        $(o).children('div,img').not("#item_galeria_ativo").attr('id','item_galeria_destaque');

    }
    galMouseOut = function(o) {
        //div[destaque != central],img[destaque != central]

        $(o).children('div,img').not("#item_galeria_ativo").removeAttr('id');

    }
    galClick = function(o) {

        $('div#item_galeria_ativo').attr('id','');
        $('img#item_galeria_ativo').attr('id','');
        $(o).children('div,img').attr('id','item_galeria_ativo');
        $("#detalhado").load('carregar_detalhe.php', { s: $(o).attr('showID') }, function() {
        });

    }

    carregarCarousel = function(elStarter) {

        jQuery('#carousel').jcarousel({
            scroll: 7,
            initCallback: mycarousel_initCallback,
            start:1
        });
    }

/* /carousel */

/* acesso rapido */

    $("#acessorapido_botoes div").children("img").mouseover(function(){
            $(this).parent().children("span").attr('class', 'hover');
        }).mouseout(function(){
            if ($(this).parent().children("span").attr('class') != 'on') {
            $(this).parent().children("span").attr('class', 'off');
        }
        }).click(function() {
            var alt = $(this).attr("alt");
            var ar_url = "";
            if (alt == "home") { ar_url = server_name; }
            if (alt == "news") { ar_url = server_name+"secao/noticias"; }
            if (alt == "mapadosite") { ar_url = server_name+"secao/mapa_do_site/"; }
            if (alt == "cases") { ar_url = server_name+"secao/cases/"; }
            if (alt == "restrict") { ar_url = server_name; }
            $("#acessorapido_botoes span").attr('class','off');
            $(this).parent().children("span").attr('class','on');
            location.href=ar_url;
    });
    //ativar icones window location

    var url = window.location;


    if (url == server_name) $("#acessorapido_botoes div").children("img[alt=home]").parent().children("span").attr('class','on');
    if (url == server_name+"secao/mapa_do_site/") $("#acessorapido_botoes div").children("img[alt=mapadosite]").parent().children("span").attr('class','on');
    if (url == server_name+"secao/noticias/") $("#acessorapido_botoes div").children("img[alt=news]").parent().children("span").attr('class','on');
    if (url == server_name+"cases/") $("#acessorapido_botoes div").children("img[alt=cases]").parent().children("span").attr('class','on');

    //search

    $("#search_lupa").click(function() {
            redirSearch();

    });

    redirSearch = function() {
            if ($("#search_text").val() == "" || $("#search_text").val() == "O que desejas?" ) {
                $("#search_text").val("O que desejas?");
            }
            else {
                url = server_name+"secao/pesquisa/index.php?t="+$("#search_text").val().replace(/\s/g,"+");
                location.href=url;
        }
    }
    $("#search_text").focus(function() {
        if ($("#search_text").val() == "O que desejas?") $("#search_text").val("");
    }).keypress(function (e) { if (e.which == 13) { redirSearch(); } });

/* /acesso rapido */




        /*
        $("#fundo_pagina_inicial").hide();
        $("#fundo_conteudo_instantaneo").show();

        var url = posdir+'class/getFrame.php';
        $.get( url,
            {secao:s,
                subsecao:ss},function(data){
                if (data>=0 ) {
                    cInstFrame(data);
              }
            }
        );      
    }
    */

// Ativação da seção pelo flash

    goSecao = function(s,ss,sss) {
        if (s == 'institucional') {
            location=server_name+'secao/'+s+'/index.php?i='+ss;
        }
        if (s == 'produtos' || s == 'servicos') {
            if (ss == 'outros_produtos') {
                 location=server_name+'secao/'+s+'/'+ss+'/'+sss+'/index.php';
            }
            else {
                if (sss) location=server_name+'secao/'+s+'/'+ss+'/index.php?i='+sss;
                else location=server_name+'secao/'+s+'/'+ss+'/index.php';
            }
        }
        if (s == 'noticias') location=server_name+'secao/'+s+'/index.php';
        if (s == 'fale_conosco') location=server_name+'secao/'+s+'/index.php';
        if (s == 'clientes') location=server_name+'secao/'+s+'/index.php?i='+ss;
    }
    ativarLightBox = function(este) {
        $(este).fancybox({ 'zoomSpeedIn': 400, 'zoomSpeedOut': 400, 'imageScale':true });
    }

});

function chimg(este) {
    var src_img_fb = $(este).attr('src');
    var alt_img_fb = $(este).attr('alt');
    $(este).wrap("<a id='single_image' onMouseOver='ativarLightBox(this);' href='"+src_img_fb+"'></a>");

}
function iframeAutoHeight(quem){
    //by Micox - elmicox.blogspot.com - elmicox.com - webly.com.br
    if(navigator.appName.indexOf("Internet Explorer")>-1){ //ie sucks
        var func_temp = function(){
            var val_temp = quem.contentWindow.document.body.scrollHeight + 5
            quem.style.height = val_temp + "px";
            alert(val_temp)        }
        setTimeout(function() { func_temp() },100) //ie sucks
    }else{
        var val = quem.contentWindow.document.body.parentNode.offsetHeight + 5
        quem.style.height= val + "px";
    }
}


