$(document).ready(function(){
	fixIe6BackgroundHeight();
	setInterval( fixIe6BackgroundHeight, 2000 );
	fixIE6Png();
	fixLeftMenu();
	testOverlayAndGoogleMaps();
	$( ".header" ).pngFix();
});

$(document).load(function(){
	fixIe6BackgroundHeight();
});

$( window ).resize(function(){
	fixIe6BackgroundHeight();
});


/* Script reparar a altura das faixas laterais no Iternet Explorer versões 6 e 7.
--------------------------------------------------------*/
function fixIe6BackgroundHeight()
{
	//return;
	if ( $.browser.msie && $.browser.version=="6.0" )
	{
		$( ".bgLeft, .bgRight" ).height( $("body").height() );
	}
}


/* Script para animar a altura do widget de programação.
--------------------------------------------------------*/
function getFlashMovie(movieName) 
{   
	var isIE = navigator.appName.indexOf("Microsoft") != -1;   
	return (isIE) ? window[movieName] : document[movieName];  
}  

function expandir()
{
	var flash = $("#boxProgramacaoWidget");
	
	if ( flash.height() == 400 )
	{
		animateToHeight( flash, "140px" );
	}
	else
	{
		animateToHeight( flash, "400px" );	
	}
}

function animateToHeight( flash, value )
{
	var flashObject = getFlashMovie( "boxProgramacaoWidget" );
	if ( jQuery.browser.mozilla )
	{
		flash.css( { height:value } );
		flashObject.fixScrollPosition();
	}
	else
	{
		flash.animate( { height:value }, { queue:false, duration:500 } );
		setTimeout( function(){ flashObject.fixScrollPosition(); }, 600 );
	}
}

/* Script de MouseOver para os menus da esquerda.
--------------------------------------------------------*/
function fixLeftMenu()
{
	$( "ul.boxMenuCima a" ).hover( fixLeftMenuOver, fixLeftMenuOut );	
	$( "ul.boxMenuBaixo a" ).hover( fixLeftMenuOver, fixLeftMenuOut );
}

function fixLeftMenuOver()
{
	$( "img.stateUp", this ).css( { display:"none" } );
	$( "img.stateOver", this ).css( { display:"block" } );
}

function fixLeftMenuOut()
{
	$( "img.stateUp", this ).css( { display:"block" } );
	$( "img.stateOver", this ).css( { display:"none" } );
}

/* Script para abrir o overlay do Google Maps
--------------------------------------------------------*/
array = new Array();

function testOverlayAndGoogleMaps()
{
	// abre o mapa mostrando todos os hotéis.
	$( "#printGoogle, .boxGoogle a" ).click(function( evt ) {
		evt.preventDefault();											 	
		overlay = new AdjetivaOverlay();
		$("div#AdjetivaOverlay").pngFix();
		//overlay.show( "googleMapsTemplate.html" );
		overlay.show( SITE_URL + "/GoogleMaps" );
		
		$( document ).bind( "GOOGLE_MAPS_LOADED.AdjetivaOverlay", function() {
			var googleMapsWidget = getFlashMovie( "googleMapsWidget" );
			googleMapsWidget.showHotels( array );
		});
		
	});
	
	
	// abre o mapa mostrando um hotél em particular.
	$( ".verGoogleMaps" ).click(function( evt ) {
		evt.preventDefault();											 	
		overlay = new AdjetivaOverlay();
		$("div#AdjetivaOverlay").pngFix();
		//overlay.show( "googleMapsTemplate.html" );
		overlay.show( SITE_URL + "/GoogleMaps/index/hotel/" + this.id );
		
		$( document ).bind( "GOOGLE_MAPS_LOADED.AdjetivaOverlay", function() {
			var googleMapsWidget = getFlashMovie( "googleMapsWidget" );
			googleMapsWidget.showHotels( array );
		});
		
	});
}

/**
*
*	Prepara o overlay que conterá o iFrame de inscricoes
*
*/
function prepareOverlayInscricoes()
{
	// Abre o Iframe para inscriçõoes por terceiros.
	$( ".conteudoInscricoes a.indirect" ).click(function( evt ) {
		return;
		evt.preventDefault();											 	
		overlay = new AdjetivaOverlay();
		$("div#AdjetivaOverlay").pngFix();
		//overlay.show( "googleMapsTemplate.html" );
		overlay.show( SITE_URL + "/Inscricoes/getIframe" ); 
		
		var info = "<h1>Inscri&ccedil;&atilde;o via interlocutor no ENAI 2009</h1>";
		overlay.setTitleContent( info );
		
	});
	
	// Abre o Iframe para inscrição direta.
	$( ".conteudoInscricoes a.direct" ).click(function( evt ) {
		return;
		evt.preventDefault();											 	
		overlay = new AdjetivaOverlay();
		$("div#AdjetivaOverlay").pngFix();
		//overlay.show( "googleMapsTemplate.html" );
		overlay.show( SITE_URL + "/Inscricoes/getIframeDirect" );
		
		var info = "<h1>Inscri&ccedil;&atilde;o direta no ENAI 2009</h1>";
		overlay.setTitleContent( info );
	});
}

function setOverlayInfo( data )
{
	if( overlay )
	{
		var info = "<h1>" + data.name + "</h1>";
		info += "<p><strong>" + data.address + "</strong></p>";
		info += "<p><strong>" + data.phone + "</strong></p>";
		overlay.setTitleContent( info );
	}
}

function setOverlayDrivingInfo( data )
{
	if( overlay )
	{
		var info = "<h1>" + data.name + "</h1>";
		
		info += "<p><strong>" + "Rota de carro para " + data.name + "</strong></p>";
		info += "<p><strong>" + data.summaryHtml + "</strong></p>";
		overlay.setTitleContent( info );
	}	
}

function googleMapsLoaded()
{
	$( document ).trigger( "GOOGLE_MAPS_LOADED" );
}


/* Script para corrigir transparência para o IE6
--------------------------------------------------------*/
function fixIE6Png()
{
	$( "div.tituloContainer, div.faixaFooterConteiner, .transpItemContainer" ).pngFix();
}


/* Script para direcionar para âncora após carregamento AJAX */
function navigateToAnchor()
{
	/*
	location = window.location.href;
	if( window.location.href.indexOf( "#" ) != -1 )
	{
		window.location.href = location;
	}
	*/
	
	a = window.location.href;
	if( a.indexOf( '#' ) != -1 )
	{
		a = a.substring( a.indexOf( '#' ) + 1 );
		
		if (document.anchors[ a ])
		{
			document.anchors[ a ].focus();
		}
		//$( "a[name=" + a + "]" ).focus();
	}
}

/* Abre a janela de impressão de programação */
function printProgramacao()
{
	janela = window.open( SITE_URL + "/Programacao/print", "printWindow", 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=600' );
}
