// JavaScript Document
var intervalTvFlash = null;
var valorIntervalo = 30000; //em ms = 30s
$(function () {
	//começo função ocultar box de nichos

	$('#conteudo01,#conteudo02,#conteudo03,#conteudo04,#conteudo05,#conteudo06').hide();

	$("#menu-canais-educacao.tabs li a").click(function (e) {
		var i = 0;
		switch (this.id) {
			case "pagamento":
				i = 1;
				break;
			case "recebimento":
				i = 2;
				break;
			case "capital":
				i = 3;
				break;
			case "antecipacao":
				i = 4;
				break;
			case "financiamento":
				i = 5;
				break;
			case "investimento":
				i = 6;
				break;
		}

		if (i > 0) {
			e.preventDefault();
			$("#menu-canais-educacao.tabs li").removeClass("ui-tabs-selected");
			$(this).parent().addClass("ui-tabs-selected");
			$('#conteudo0' + i).parent().find("> :visible").hide();
			$('#conteudo0' + i).show();
		}
	});
	//fim função ocultar box de nichos


	$("div.pager ul li a").die("click").live("click", function (e) {
		e.preventDefault();
		var context = $(this).closest('.container-pager');
		var autoRotate = context.data('autoRotate');

		if (autoRotate)
			clearInterval(intervalTvFlash);

		if (!$(this).parent().hasClass("on")) {
			var parent = $(this).closest(".container-pager");
			$(".pager-item.visible", parent).removeClass("visible");
			$(".pager ul li.on", parent).removeClass("on");

			var index = $(".pager ul li", parent).index($(this).parent());
			$(".pager-item:eq(" + index + ")", parent).addClass("visible");
			$(this).parent().addClass("on");
		}

		if (autoRotate)
			intervalTvFlash = setInterval(function () {
				var item = $("div.pager ul li.on", context).next().length > 0 ? $("div.pager ul li.on", context).next() : $("div.pager ul li:eq(0)", context);
				item.find('a').click();
			}, valorIntervalo);
	});

	$("div.pagerSolucoes ul li a").die("click").live("click", function (e) {
		e.preventDefault();
		if (!$(this).parent().hasClass("on")) {
			var parent = $(this).closest(".container-pager");
			$(".pager-item.visible", parent).removeClass("visible");
			$(".pagerSolucoes ul li.on", parent).removeClass("on");

			var index = $(".pagerSolucoes ul li", parent).index($(this).parent());
			$(".pager-item:eq(" + index + ")", parent).addClass("visible");
			$(this).parent().addClass("on");
		}
	});

	$("input[type=text]").focus(function () {
		if (this.value != '') {
			if (this.value == this.title) this.value = '';

			$(this).unbind("blur").blur(function () {
				if (this.value == '') this.value = this.title;
			});
		}
	});

	/*	$('#sub-menu div.nivel1').transform({		
	xml: "/pj/Empresas/Util/Xml/MenuPrincipal.xml", 
	xsl: "/pj/Empresas/Util/Xml/MenuPrincipal.xslt",
	erro: function() { alert('Ocorreu um erro ao carregar o XML'); },
	success: function() {
	var matchUrl = window.location.pathname.split("/");
	if(null != matchUrl && matchUrl[3] != undefined) {
	var submenu = matchUrl[3];
	var xsltSubMenu = "";
				
	switch (submenu.toLowerCase()) {
	case "solucoes":
	xsltSubMenu = "SubMenuSolucoes.xslt";
	break;
	}
				
	if(xsltSubMenu != "") {
	var url = window.location.pathname.match(/^\/([^\/]+)\//);

	$('#sub-menu div.nivel2').transform({
	xml: "/pj/Empresas/Util/Xml/MenuPrincipal.xml", 
	xsl: "/pj/Empresas/Util/Xml/"+ xsltSubMenu,
	//xsl: "/pj/Empresas/Util/Xml/SubMenuSolucoes.xslt",
	erro: function() { alert('Ocorreu um erro ao carregar o XML'); },
	success: function() {
	var suburl = window.location.pathname.substring(0, window.location.pathname.indexOf("/", url[0].lastIndexOf("/")+1)+1);
	if(null != suburl)
	{
	$("#sub-menu .nivel2 ul > li a[href="+ suburl +"]").parent().addClass("ativo");
	}
	}
	});
					
	if(null != url)
	{
	$("#sub-menu ul > li a[href="+ url[0] +"]").parent().addClass("ativo");
	}
	}
	}
			
	}
	});
	*/
	//FUNÇÃO PARA MIX XML/XSLT
	$('#sub-menu div.nivel1').transform({
		xml: "/pj/Empresas/Util/Xml/MenuPrincipal.xml",
		xsl: "/pj/Empresas/Util/Xml/MenuPrincipal.xslt",
		erro: function () { alert('Ocorreu um erro ao carregar o XML'); }
	});

	$('#box-voce-procura div.listaVoceProcura').transform({
		xml: "/pj/Empresas/Util/Xml/ComboVoceProcura.xml",
		xsl: "/pj/Empresas/Util/Xml/ComboVoceProcura.xslt",
		erro: function () { alert('Ocorreu um erro ao carregar o XML'); }
	});
    //id="seu-universo-itau-banner" class="box-generico"id="sidebar"	
    $('#sidebar #box-setor-atividade').transform({
		xml: "/pj/Empresas/Util/Xml/BoxSimulador.xml",
		xsl: "/pj/Empresas/Util/Xml/BoxSimulador.xslt",
		erro: function () { alert('Ocorreu um erro ao carregar o XML'); }
	});
    $('#sidebar-30horas').transform({
		xml: "/pj/Empresas/Util/Xml/Box30Horas.xml",
		xsl: "/pj/Empresas/Util/Xml/Box30Horas.xslt",
		erro: function () { alert('Ocorreu um erro ao carregar o XML'); }
	});	
	//FIM DA FUNÇÃO PARA MIX XML/XSLT	

	$('#box-voce-procura #inputBusca').autocomplete(cities, {
		container: $("#box-voce-procura .list-results")
	}).focus(function (e, ui) {
		$('#box-voce-procura .listaVoceProcura').show();
		$("body").bind("mouseover", function (e) {
			if ($(e.target).parents("#box-voce-procura").length == 0) {
				$('#box-voce-procura #inputBusca').blur();
				$('#box-voce-procura .listaVoceProcura').hide();
				$("body").unbind("mouseover")
			}
		});
	});

	$("#box-voce-procura form").bind("submit", function (e) {
		e.preventDefault();
		if ($('#box-voce-procura #inputBusca').val() == $('#box-voce-procura #inputBusca').attr("title"))
			$('#box-voce-procura #inputBusca').focus();
		else this.submit();
	});

	$('.selectUniversoItau a.select').bind("click", function (e) {
		e.preventDefault();
		$("#box-setor-atividade").slideToggle("normal", function () {
			if ($("#box-setor-atividade").is(":visible")) {
				$(document).bind('click', function (e) {
					var $clicked = $(e.target);
					if (!$clicked.parents().hasClass("dropdown")) {
						$(document).unbind("click");
						$("#box-setor-atividade").slideUp();
					}
				});
			}
		});
	});
	/*$('#box-voce-procura input[type=text]').focus(function(e){
	$(this).unbind("click").bind("click", arguments.callee);
	controlAutoComplete.show();
		
	})*/

	CarregarPager(false, true);
});

function CarregarPager(autoRotate, random, context) {
	
	var container = (context == undefined) ? $(".container-pager") : context;

	container.each(function () {
		var items = $(".pager-item", this);

		var box = $(this);
		var container = box;
		if (box.hasClass("box-generico")) {
			box = $(".miolo", this);
			container = $(".rodape", this);
		}

		if (items.length > 1) {
			var pager = $("<div class='pager' />");
			var ul = $("<ul />");
			ul.width(items.length * 15);
			for (var i = 0; i < items.length; i++) {
				ul.append('<li><a href="/">' + (i + 1) + '</a></li>');
			}
			//$("li:eq(0)", ul).addClass("on");
			pager.append(ul);
			$(container).append(pager);
		}


		if (autoRotate) {
			container.data('autoRotate', true);
		}

		var active = random ? Math.floor(Math.random() * items.length) : 0;
		$("ul li:eq("+ active +") a", container).click();
	});
}

function CarregarPagerSolucoes(context) {

	var container = (context == undefined) ? $(".container-pager") : context;

	container.each(function() {
		var items = $(".pager-item", this);
		
		var box = $(this);
		if(box.hasClass("box-generico")) box = $(".miolo", this);

		if(items.length > 1) {
			var pager = $("<div class='pagerSolucoes' />");
			var ul = $("<ul />");
			ul.width(items.length * 15);
			for(var i = 0; i < items.length; i++) {
				ul.append('<li><a href="/">'+ (i+1) +'</a></li>');
			}
			$("li:eq(0)", ul).addClass("on");
			pager.append(ul);
			$(box).append(pager);
		}
	});
}
$(document).ready(function(){
    $('#conteudo').hide();
    $('#mostrar').click(function(event){
        event.preventDefault();
        $("#conteudo").show("slow");
     });
     $('#ocultar').click(function(event){
        event.preventDefault();
        $("#conteudo").hide("slow");
     });
 });
 $( document ).ready( function() {   
    $("a[rel='pop-up']").click(function () {   
        var caracteristicas = "top=0,left=0,height=525,width=781,scrollTo,resizable=1,scrollbars=1,location=0";   
        nueva=window.open(this.href, 'Popup', caracteristicas);   
        return false;   
 }); 
 
 //começo função ocultar box de nichos
 $(document).ready(function(){
 });
});

$( document ).ready( function() {   
    $("a[rel='pop-upcentral']").click(function () {   
        var caracteristicas = "height=275,width=680,scrollTo,resizable=0,scrollbars=0,location=0,left=0,top=0;";   
        nueva=window.open(this.href, 'Popup', caracteristicas);   
        return false;   
 });   
});

$( document ).ready( function() {   
    $("a[relatorio='pop-upCatalogo']").click(function () {   
        var caracteristicas = "height=525,width=781,scrollTo,resizable=1,scrollbars=1,location=0,top=0,left=0";   
        nueva=window.open(this.href, 'Popup', caracteristicas);   
        return false;   
 });   
}); 

function fn_QC_seg_tecno() { // Programa Mais Segurança - tecnologia
    window.open('http://www.itau.com.br/itau/seguranca/ind_seg_tecseg.htm', 'itaumain');
}
function fn_QC_seg_fraudes() { // Programa Mais Segurança - fraudes
    window.open('http://www.itau.com.br/itau/seguranca/ind_seg_exemp_fraudes.htm', 'itaumain');
}
function fn_QC_itoken() { // IToken
    window.open('http://www.itau.com.br/itoken/index.htm', 'itaumain');
}

function fn_QC_ecpf() { //  Avaliacao de qualidade Febraban
    window.open('http://www.itau.com.br/itau/pessoa_juridica/ind_pj_ecpf.htm', 'itaumain');
   }


   /*-----------------------------------------------------------------------------*/
   // para esconder o combo
   /*function EM(evt) {
   	try {
   		if (document.all) {
   			if ((window.event.srcElement.id == 'inputBusca') || (window.event.srcElement.id == 'DivClicavelSubmit')) return false; //exceto
   			else {
   				fadeOut('divComboItens');
   				document.Form1.search.value = "O que voce procura?";
   			}
   		}

   		else  // FireFox
   		{
   			var aux = evt.target;

   			if ((aux.id == 'inputBusca') || (aux.id == 'DivClicavelSubmit')) return false; //exceto	 
   			else {
   				fadeOut('divComboItens');
   				document.Form1.search.value = "O que voce procura?";
   			}
   		}
   	}
   	catch (e) { }
   }*/
