function exeIs(cmd, page)
{
    var u = self.location.href;
    return u.indexOf(exeGetKey(cmd)) > -1;
}

function exeGetKey(cmd)
{
    return "#cmd_"+ cmd;
}

function exeSave(cmd)
{
    self.location.href += exeGetKey(cmd);
}

function faqDoEvents()
{
    $( '.a5_info' ).css( 'cursor', 'pointer' ).click(function()
	{
		// se o ativo não for o este
		if( $( '.ativo' ).get(0) != $( this ).get(0) )
		{
			// fecha o ativo
			$( '.ativo' ).toggleClass( 'ativo', 'inativo' ).children( 'p' ).slideToggle();
		}
		// fecha/abre o atual
		$( this ).children( 'p' ).slideToggle();
		$( this ).toggleClass( 'ativo', 'inativo' );
	});
	$( '.a5_info' ).css( 'cursor', 'pointer' ).mouseover(function()
	{
		$( this ).removeClass( 'out' );
		$( this ).addClass( 'hover' );
	});
	$( '.a5_info' ).css( 'cursor', 'pointer' ).mouseout(function()
	{
		$( this ).removeClass( 'hover' );
		$( this ).addClass( 'out' );
	});
}

// depois que terminar de ler toda a pagina (document), executa a funo
$(document).ready(function() {
    if (!isCookieEnabled()) {
        $(".messagebox_text").html("Aten&#231;&#227;o! Foi detectado que seu navegador n&#227;o est&#225; aceitando cookies. " +
            "A Bancorbras utiliza cookies para identificar voc&#234; ao longo das sess&#245;es em nossos sistemas " +
            "(marca&#231;&#227;o de reserva online, por exemplo). Para evitar problemas, habilite os cookies em seu " +
            "navegador para o dom&#237;nio BANCORBRAS.COM.BR.");
    }

    /* mensagem de erro no login */
    $(".messagebox").hide();
    if ($(".messagebox_text") != null && $(".messagebox_text").html() != "") {
        if (!exeIs("msg") && $(".messagebox").length > 0) {
            $(".messagebox").show();
            $(".formlogin").hide();
            $(".rodapelogin").hide();
            $("#ctl00_ContentPlaceHolder1_divLinks").hide();
            $("#btok").click(function() {
                $(".messagebox").hide();
                $(".formlogin").show();
                $(".rodapelogin").show();
                $("#ctl00_ContentPlaceHolder1_divLinks").show();
                return false;
            });
            exeSave("msg");
        }
    }

    // $("img[alt=Brasil Cap]").parent().attr("href", "javascript:;");
    // $("img[alt=Brasil Cap]").parent().click(function() {
			
			// var openpage = '/site/gambi/reg.htm';
			// var srcimage = $(this).find('img').get(0).src;
			
			// if(srcimage.indexOf('arq634060550061450986.jpg') != -1){
				// window.open('http://www.bancorbras.com.br/_storage/regulamento2.html', 'regulamento', 'width=680,height=450,menubar=no,status=no,scrollbars=yes,resizable=yes');
			// } else if(srcimage.indexOf('arq634060550061450986.jpg') != -1)	{
				// window.open('/site/gambi/reg.htm', 'regulamento', 'width=680,height=450,menubar=no,status=no,scrollbars=yes,resizable=yes');
			// }
			
			
        // return false;
    // });
	
	//pop up em iframe
	$(document).ready(function(){
		
		var endereco = (("https:" == document.location.protocol) ? "https://" : "http://") + "www.bancorbras.com.br/";
		var endereco_servico= endereco + "site/servico/popup_handler.ashx";

		$('a[href$=jpg],a[href$=png],a[href$=gif],a[href$=jpeg]').each(function(){
			var reflink = $(this);
			reflink.click(function(){
				tb_pathToImage = "/site/img/load.gif";
				var srclink = reflink.attr('href');
				var endereco_servico_final= endereco_servico + '?action=write_javascript' + '&img=' + encodeURIComponent(srclink);
				$.getScript(endereco_servico_final, function() {
					openPopUp();
				});
				
				return false;
			});
		});
	});

    /* Avisos de formulários em geral pelo site */
    $(".warning").hide();
    var warn_html = $(".warning").html();
    if (warn_html == null) warn_html = "";
    if (warn_html != "" && !exeIs("warning")) {
        $(".warning").show();
        //exeSave("warning");
    }

    $('ul.fotos li a').click(function() {
        $(this).abreFoto();
        return false;
    });
    // depois que "clicar" no meu elemento que tenha o seletor #header h3 a, execulta a funcao
    // tmb pode ser quando passar o mouse ( mouseover )

    // para mais, http://docs.jquery.com/Events
    $("#oQueDeseja h3 a").click(function() {
        $(this).toggleClass('ativo');

        //$('#iframe-flash-workround').toggleClass('iframeRedusido');    
        $('#oQueDeseja #linksrapidos').toggleAnim('toggle');

        return false;
    });
    // controla o hover no botão de abrir
    // se clicar e tirar o mouse, fecha o menu em X milissegundos
    $("#oQueDeseja h3 a").hover(
		function() {
		    if (typeof (time) != 'undefined') {
		        clearTimeout(time);
		    }
		}
		, function() {
		    time = setTimeout(oQueDesejaHide, 2000);
		});
    // controla o hover no menu
    // se tirar o mouse, fecha o menu em X milissegundos
    $("#linksrapidos").unbind().hover(
		function() {
		    if (typeof (time) != 'undefined') {
		        clearTimeout(time);
		    }
		}
		, function() {
		    time = setTimeout(oQueDesejaHide, 1000)
		}
	);

    // Botao voltar
    $("#botaoVoltar").click(function() { history.back() });

    $("#turismo").click(function() {
        $('#turismoLista').toggleAnim('toggle');

    });

    $("#busque").focus(function() {
        if ($(this).attr("value") == "Busca") {
            $(this).attr("value", "");
        }
    });

    $("#busque").blur(function() {
        if ($(this).attr("value") == null) {
            $(this).attr("value", "Busca");
        }
    });

    // A5 Faq		
    faqDoEvents();

    /*  MENU LATERAL */

    $("#secundario > #menu > li > a.seta").click(function() {
        var visible = $("#menu > li").children("ul:visible");
        var li = $(this).parent("li");

        if (visible.get() != "" && visible.html() != $(this).children("ul").html()) {
            visible.toggleAnim('hide');
            visible.parent('li').toggleClass('ativo');
        }
        setSubmenu('slow', li);
    }
	);
    // se a página for um subitem, abre o menu automagicamente
    setSubmenu(50, "#menu > li.ativo");
});

function oQueDesejaHide()
{
	if( $( "#linksrapidos" ).is( ":visible" ) == true )
	{
		$( "#linksrapidos" ).toggleAnim( 'hide' );
		$( "#oQueDeseja h3 a" ).removeClass( 'ativo' );
	}
}

// configura os submenus
// recebe a levocidade (number ou string) de animacao
function setSubmenu( vel, elm )
{
	var li = $( elm );
	if ( li.children( "ul" ).get() != "" )
	{
		if( li.children( 'ul:visible' ).get() == "")
		{
			li.children( 'ul' ).slideDown( vel, function()
				{
					$( "#menu > li > ul > li" ).hover(
						function()
						{
							$( this ).children( "ul" ).show();
						}
						,function()
						{
							$( this ).children( "ul" ).hide();	
						}
					)
				}
			);
			
			li.addClass( 'ativo' );
		}
		else
		{
			//li.children( 'ul' ).hide( "slow" );
			li.removeClass( 'ativo' );
		}
				
		if ( li.attr("initEv") != "1" )
		{
			li.attr("initEv", "1");
			
			menuLiHoverClass();
		}
	}
}

$( "#botaoVoltar" ).click( function() { history.back() });

function menuLiHoverShow()
{
	$( "#menu > li > ul > li" ).hover(
		function()
		{
			$( this ).children( "ul" ).slideDown();
		}
		,function()
		{
			$( this ).children( "ul" ).slideUp();	
		}
	)
}

function menuLiHoverClass()
{
	$( "#menu > li > ul > li > ul" ).hover(
		function()
		{
			$( this ).parent( "li" ).addClass( 'ativo' );	
		}
		,function()
		{
			$( this ).parent( "li" ).removeClass( 'ativo' );	
		}
	);	
}

//Funo que exibe contedo de itens de publicador para outros elementos HTML na pgina
function mostraConteudo(id, objeto)
{
    document.getElementById(id).innerHTML = objeto;
}

// Funo reponsavel pela animao de mostrar/esconder elementos
jQuery.fn.toggleAnim = function( value, callBack )
{
	this.each( function()
	{
		jQuery( this ).animate(
			{ height: value },
			'slow',
			callBack
		);
	});
}

jQuery.getClasses = function( obj )
{
	// pega todas as classes do img atual
	var cssClasses = obj.className.split(' ');
	return cssClasses;
}

jQuery.fn.abreFoto = function( )
{
	var fotosGeral = $( this ).parents( "div" ).children( ".imgdesc ").children( ".prinimg" );
	var link = $( this );

	fotosGeral.attr('src', link.attr( "href" ) );
	fotosGeral.attr('alt', link.attr( "href" ) );
	$('.descr').html( link.title );
}

//$( function()
//{
//	$('ul.fotos li a').click(function()
//	{
//		$( this ).abreFoto( );
//		return false;
//	});
//});

$( function()
{
	//inserir o flahs no html
	var flashTag = retMapa();
	if( $('#contmapa').length )
	{
		//controla interao do select de regies
	$(".regioes").change( function() 
		{ 
			//var mapa = $.browser.msie ? window["mapaFlash"] : document["mapaFlash"];
			var mapa = $('#mapaFlash').get(0);
			mapa.destacaArea( this.value );			
		});
		$('#contmapa').get(0).innerHTML = flashTag;
	}
	
	var flashTag = flashHome();
	if( $('#flashome').length && self.location.href.indexOf("noflash") == -1)
	{
		$('#flashome').get(0).innerHTML = flashTag;
	}
});



function retMapa()
{
	return( '<object id="mapaFlash" type="application/x-shockwave-flash" data="../../swf/mapa_brasil.swf" width="315" height="315"><param name="movie" value="../../swf/mapa_brasil.swf" /><param name="wmode" value="transparent" /></object>' );
}

norte = new String();
nordeste = new String();
centrooeste = new String();
sul = new String();
suldeste = new String();

function indRegiao ( reg )
{
	//coloca o link de acordo com a regio selecionada
	if( reg == 'norte' )
	{
		window.location.href = norte;
	}
	else if( reg == 'nordeste' )
	{
		window.location.href = nordeste;
	}
	else if( reg == 'centrooeste' )
	{
		window.location.href = centrooeste;
	}
	else if( reg == 'sul' )
	{
		window.location.href = sul;
	}
	else if( reg == 'suldeste' )
	{
		window.location.href = suldeste;
	}

}

function flashHome()
{
	if( $('#flashome').length )
	{
		var ses = session; // se mudar a casa cai
		var flashtag = getFlashTag("/site/swf/carregahome.swf", "retorno="+ ses);
		return flashtag;
	}
}

function getFlashTag(swfUrl, flashVars)
{
    return '<object id="homeflash" type="application/x-shockwave-flash" data="'+ swfUrl +'" '+
        'width="100%" height="100%"><param name="movie" value="'+ swfUrl +'" />'+
        '<param name="wmode" value="transparent" /><param name="scale" value="noscale" />'+
        '<param name="salign" value="t" />'+
        '<param name="flashVars" value="'+ flashVars +'" /></object>';   
}

function isCookieEnabled()
{
   document.cookie = "__cookieEnabled=true";
   return document.cookie.indexOf("__cookieEnabled=true") != -1;
}

function popup(url, largura, altura, supressAlert)
{
    var x = (screen.availWidth - largura) / 2;
    var y = (screen.availHeight - altura) / 2;
    var opcoes = "resizable=yes,scrollbars=no,menubar=no,statusbar=no";
    
    opcoes += ",width="+ largura +",height="+ altura +",top="+ y +",left=" + x;
    
    var w = window.open(url, "_blank", opcoes, true);

    if (w == null && !supressAlert)
    {
        alert("Seu bloqueador de popup inibiu a abertura da janela. " +
            "Desative-o e tente novamente.");
        return;
    }
    else
    {
        w.focus();
    }
}

