function Arrumar() {
    var home = 0;
    if(HOME){
        home = 450;
    }

    $('#conteudo').css({
        'height':$('#iframeconteudo').css('height')
    });

    $('table#fundo').css({
        'height':(parseInt($('#iframeconteudo').height()))+'px'
    });


    var tamanhominimo = 800;


    var divfundo = 200+parseInt($('#iframeconteudo').height())+home+parseInt($('div#foot').height());
    divfundo = (divfundo<tamanhominimo)?tamanhominimo:divfundo;
    // alert(divfundo);
    //alert(parseInt($('#iframeconteudo').height()));
    //if(divfundo<900) divfundo=900;
    $('div#fundo').css({
        'height':(divfundo)+'px'
    });
    //alert(parseInt($('#iframeconteudo').css('top')));
    $('#foot').css({
        'top':(divfundo-150)+'px'
    });

    $('#desenvolvedor').css({
        'top':(divfundo+50)+'px'
    });

    //$(document).pngFix();

    $('html, body').css({
        'visibility':'visible'
    });
}

$(document).ready(function(){


    $('img').load(function(){
        Arrumar();
    });

    //sCSS('layout_home');
    PrepararLinks();
    //OUTROS LINKS
    $('#atendimentoonlineX').click(function(){
        loadScript(REALPATH+"/sistema/jq/js/jquery-ui-1.7.1.custom.min.js");
        var src = "http://www.dellos.com.br/adere4/";
        loadCSS(src+"sistema/jq/css/smoothness/jquery-ui-1.7.1.custom.css");
        loadCSS(src+"sistema/css.css");
        loadCSS(src+"chat2/css/chat.css");
        loadCSS(src+"chat2/css/screen.css");
        loadCSS(src+"chat2/css/screen_ie.css");
		
        if($('div#dialog').length==0)
            $('body').append('<div id="dialog" title="Atendimento Online"><form id="form1"><table width="100%" border="0" cellspacing="5" cellpadding="0">  <tr>    <td>Nome</td>    <td><input name="nome" type="text" id="nome" class="inputchat"></td>  </tr>  <tr>    <td>Email</td>    <td><input name="email" type="text" id="email" class="inputchat"></td>  </tr>  <tr>    <td>Assunto</td>    <td><input name="assunto" type="text" id="assunto" class="inputchat"></td>  </tr>  <tr>    <td>J&aacute; &eacute; cliente? </td>    <td><input name="jaecliente" type="radio" value="s">      Sim         <input name="jaecliente" type="radio" value="n">N&atilde;o </td>  </tr></table></form></div>');
		
        $('#dialog').dialog({
            modal:false,
            autoOpen: false,
            width: 230,
            height:300,
            open:function(){
                $(this).css({
                    'z-index':900000000
                });
            },
            buttons: {
                "Entrar":function(){
                    Entrar();
                },
                "Fechar": function() {
                    $(this).dialog("close");
                }
            }
        });
		
        $('#dialog').dialog('open');
    });
	
    $('.setidioma').click(function(){
								  
        });
	
    //BUSCAS
    $("#campo_busca_produto").keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
        {
            document.location = REALPATH + IDIOMA.split("_").join("") +"/busca/"+$('#campo_busca_produto').val().split(" ").join("-")+".html";
        }
    });

    $('#btcampobusca').click(function(){
									  
        document.location = REALPATH + IDIOMA.split("_").join("") +"/busca/"+$('#campo_busca_produto').val().split(" ").join("-")+".html";
    });
    $('#mercado_aplicacao').change(function(){
        document.location = REALPATH + IDIOMA.split("_").join("") +"/mercado/"+$(this).val()+'.html';
    });
    $('#tipo_produto').change(function(){
        document.location = REALPATH + IDIOMA.split("_").join("") +"/familia/"+$(this).val()+'.html';
    });
	
    $('.setidioma').click(function(){
        document.location  = REALPATH + $(this).attr('id') +'/home/home.html';
    });

    $('div#recursoshumanos').click(function(){
        document.location = REALPATH + IDIOMA.split("_").join("") +"/contato/vagas.html";
    });


    Arrumar();

});


function buscaProduto(cp,valor){
    postOnIframe('#iframeconteudo','./buscaproduto.php',{
        'cp':cp,
        'valor':valor
    },null);
    setLayout($(this).attr('layout'));
/*
	$.ajax({
		   global:false,
		   url:'buscaproduto.php',
		   data:{
			   'cp':cp,
			   'v':valor
		   },
		   type:'POST',
		   success:function(){
		   }
		   });*/
}

function loadScript(src) {
    $('head').append(
        $(document.createElement('script'))
        .attr({
            type: 'text/javascript',
            src: src + "?_" + parseInt((Math.random()*1000000))
        })
        );
}

function loadCSS(src) {
    media_css='screen';
    $('head').append(
        $(document.createElement('link'))
        .attr({
            rel: 'stylesheet',
            type: 'text/css',
            media: media_css || 'screen,projection',
            href: src + "?_" + parseInt((Math.random()*1000000))
        })
        );
}

function setLayout(layout)
{
	
    switch(Number(layout))
    {
        case 0: //normal
            sCSS('layout_home');
            break;
        case 1://grande
            sCSS('layout_home');
            break;
        case 2://pequeno
            sCSS('layout_home');
            break;
        default://home
            sCSS('layout_internas');
            break;
    }
}

function postOnIframe(div, src, dados, fncallback){
    $.post(src,
        dados,
        function(data){//alert(data);
            $(div).show().empty().html(data);
            if(typeof(fncallback)=="function")
                fncallback.call(this,data);
        });
}

function Entrar(){
    var dados = $('#form1').serialize()+'&submit=entrar';
    $.post('logar.php',
        dados,
        function(data){
            //alert(data);
            src="./chat2/js/chat.js";
            $('head').append(
                $(document.createElement('script'))
                .attr({
                    type: 'text/javascript',
                    src: src + "?_" + parseInt((Math.random()*1000000))
                })
                );

            chatWith('ADERE');
            //window.location.reload();
            $('#dialog').dialog('close');
						
        });
}



function switchStylestyle(styleName) {
    $('link[rel*=alternate][title*=layout]').each(function(i)
    {
        this.disabled = true;
        document.selectedStyleSheetSet = styleName;
        if (this.getAttribute('title') == styleName)
        {
            this.disabled = false;
        }
    });
}


function sCSS(styleName) {
    switchStylestyle(styleName) ;
}

function PrepararLinks()
{
    //LINKS INTERNOS
    $('.artigo').click(function(){
        //$('#iframeconteudo').attr('src','./artigo.php?t='+$(this).attr('xhref'));
        postOnIframe('#iframeconteudo','./ler_artigo.php',{
            id:$(this).attr('xhref')
        },null);
        setLayout($(this).attr('layout'));
    });
    $('.lista').click(function(){
        //$('#iframeconteudo').attr('src','./artigo.php?t='+$(this).attr('xhref'));
        postOnIframe('#iframeconteudo','./artigo.php',{
            s:$(this).attr('xhref')
        },null);
        setLayout($(this).attr('layout'));
    });
    //LINKS EXTERNOS
    $('.linkexterno').click(function(){
        $(document).attr('location',$(this).attr('xhref'));
        setLayout($(this).attr('layout'));
    });
	
    //LINKS ESPECIAIS
    $('.linkespecial').click(function(){
        //$('#iframeconteudo').attr('src',$(this).attr('xhref'));
        postOnIframe('#iframeconteudo',$(this).attr('xhref'),{},null);
        setLayout($(this).attr('layout'));
    });
}

$('body').ready(function(){
    $('#carregandosite').hide();
});



