$(document).ready(function() {

    //Inicializa Menu Principal
    setaMenuPrincipal();

    //Seta clique Abas. Página empresa
    setaCliqueAbasEmpresa();

    //Inicializa Slide do Portfolio
    setaSlidePortfolio();

    //Seta Clique ver mais depoimentos
    setaCliqueVerMaisDepoimentos();

    //Estiliza Titulos
    estilizaTitulos();
    
    //Animação - Banner Topo
    animacaoBannerTopo();
    
    //Animação - Clientes
    animacaoMarcasClientes();    
    
    //Corrige o Bug do Background no I.E
    backgroundFlickr();
    
    //Seta Scroll
    setaScrol();
    
    //Mostra Portfólio
    mostraPortfolioAoCarregar();
       
});

/* --------------------------- Mostra Portfólio --------------------------- */

function mostraPortfolioAoCarregar() {
    
     window.onload = function() {
        mostraPortfolio();
    }
    
}

function mostraPortfolio() {
    $('#slidePortfolio').css('visibility', 'visible');
    $('#pgPortfolio .carregando').hide();
}

/* --------------------------- Executa Função --------------------------- */

function executaFn(nomeFn) {
    if ((window[nomeFn] instanceof Function) == true) {
      window[nomeFn]();
    };
}

/* --------------------------- Seta Scroll  --------------------------- */

function setaScrol() {
    $('.scroll-pane').jScrollPane({scrollbarWidth:10, scrollbarMargin:25, dragMaxHeight: 20});
}

/* --------------------------- Corrige o Bug do Background no I.E  --------------------------- */

function backgroundFlickr() {
    
    try {
      document.execCommand('BackgroundImageCache', false, true);
    }
    catch(e) {}
    
}

/* --------------------------- Abrir Popup  --------------------------- */

var popWin = "";

function abrirPopup(url, largura, altura, esquerda, topo) {

    propriedades = "resizeable=no,toolbar=no,menubar=no,scrollbars=no,statusbar=no,height="+altura+",width="+largura+",left="+esquerda+",top="+topo+"";
    popWin = window.open(url,'newWin',propriedades);
}

/* --------------------------- Animação - Banner Topo --------------------------- */

function animacaoBannerTopo() {

    $('#bannerPrincipal .banners img:first').show();
    $('#bannerPrincipal .banners').cycle({ 
        fx:     'fade', 
        speed:   800, 
        timeout: 4000, 
        pause:   0 
    });

}


/* --------------------------- Animação - Clientes --------------------------- */

function animacaoMarcasClientes() {

    $('#pgClientes .colunaDireida').cycle({ 
        fx:     'fade', 
        speed:   1000, 
        timeout: 5000, 
        pause:   0 
    });

}

/* --------------------------- Inicializa Menu Principal --------------------------- */

function setaMenuPrincipal() {

    $('#geral .container .menuAnimado').show();

	$('.home #fisheye').Fisheye(
		{
			maxWidth: 14,
			items: 'a',
			itemsText: 'span',
			container: '.menuAnimado',
			itemWidth: 102,
			proximity: 100,
			halign : 'center'
		}
	)


	$('.internas #fisheye').Fisheye(
		{
			maxWidth: 11,
			items: 'a',
			itemsText: 'span',
			container: '.menuAnimado',
			itemWidth: 85,
			proximity: 95,
			halign : 'center'
		}
	)
	
}

/* --------------------------- Inicializa Abas - Página Empresa --------------------------- */

function setaCliqueAbasEmpresa() {

	$('#pgEmpresa .textos .botoes a').click(function() {
	
		var idElemento = $(this).attr('id');
		
		$('#pgEmpresa .textos .aba').each(function() {
			
			if (this.className == 'aba ' + idElemento)
				$(this).show();
			else
				$(this).hide();
			
		});
		
	});

}

/* --------------------------- Inicializa Abas - Página Empresa --------------------------- */

function setaSlidePortfolio() {

	$("#slidePortfolio").jCarouselLite({
		btnNext: ".setaAvancar",
		btnPrev: ".setaVoltar",
		scroll: 3
	});
	

}

function setaSlideLinks() {

	$("#pgLinks #geral .container .conteudo .rolagem").jCarouselLite({
		btnNext: ".setaAvancar",
		btnPrev: ".setaVoltar",
		scroll: 1,
		visible: 3
	});

}

function setaSlideLinksUnico(visiveis) {

	$("#pgLinks #geral .container .conteudo .rolagem").jCarouselLite({
		btnNext: ".setaAvancar",
		btnPrev: ".setaVoltar",
		scroll: 1,
		visible: visiveis
	});
	
	$('.setaAvancar, .setaVoltar').css('visibility', 'hidden');

}

/* --------------------------- Seta Clique ver mais depoimentos --------------------------- */

function setaCliqueVerMaisDepoimentos() {

    $('#pgClientes .colunaEsquerda .linkMaisDepoimentos').click(function() {

        //Exibe todas as colunas
        $('#pgClientes .colunaEsquerda .coluna').show();

    });

}

/* --------------------------- Estiliza Titulos --------------------------- */

function estilizaTitulos() {
    
    if (typeof sIFR == "function") {
        sIFR.replaceElement("#pgServicos .coluna h2", "swf/freestyle_script.swf", "#75C5F0", null, null, null, 0, 0, 0, 0);
        sIFR.replaceElement("#pgVerServicos .coluna h1", "swf/freestyle_script.swf", "#75C5F0", null, null, null, 0, 0, 0, 0);
        sIFR.replaceElement("#pgProdutos .coluna h2", "swf/freestyle_script.swf", "#75C5F0", null, null, null, 0, 0, 0, 0);
        sIFR.replaceElement("#pgVerProdutos .coluna h1", "swf/freestyle_script.swf", "#75C5F0", null, null, null, 0, 0, 0, 0);
        sIFR.replaceElement("#pgLinks h1", "swf/freestyle_script.swf", "#75C5F0", null, null, null, 0, 0, 0, 0, "textalign=center");
    };

}
