$(document).ready(function(){
	
	// Função do click para histórico
	$("a[rel='history']").livequery('click',function(){
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		//trocar '?' por '!' do hash caso o navegador seja o Opera
		if(navigator.appName == "Opera"){hash = hash.replace('?','!')};
		$("#divLoading").slideDown('slow');
		$("#divConteudo").slideUp({
			duration: 300,
			easing: "easeInSine",
			complete: function(){ 
				$.historyLoad(hash);
			}
		});
		return false;
	});
	
	//Text Resize
	var originalFontSize = $('.divTextos').css('font-size');
	// Reset Font Size	
	$(".resetFont").livequery('click', function(){
		$('.divTextos').css('font-size', originalFontSize);
	});
	// Increase Font Size
	$(".increaseFont").livequery('click', function(){
		var currentFontSize = $('.divTextos').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		$('.divTextos').css('font-size', newFontSize);
		return false;
	});
	// Decrease Font Size
	$(".decreaseFont").livequery('click', function(){
		var currentFontSize = $('.divTextos').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		$('.divTextos').css('font-size', newFontSize);
		return false;
	});

	//remover pontilhado dos links depois do click
	$("a").livequery("focus",function(){
		this.blur();
	});
	
	//Adicionar return false a todos os links com href="#" para não adicionar nada ao histórico
	$('a[href*=#]').livequery('click', function(){
		return false;
	});
	
	//Imprimir
	$("a[rel='print']").livequery('click',function(){
		var content = $('#divConteudo').html();
		var pwin = window.open('','print_content','width=680,height=500');	
		pwin.document.open();
		pwin.document.write('<html><head><style type="text/css">body{font-family:Arial, Helvetica, sans-serif; font-size:12px; text-align:justify;} img{border:0px;}</style></head><body onload="window.print()">'+content+'</body></html>');
		pwin.document.close();	
		setTimeout(function(){pwin.close();}, 1000);
	});
	
	$('#body').css('overflowX', 'hidden');
	
	$.insertSWF('#flexWebLogo','http://flexwebsites.com.br/modelos/swf/logo-flexweb-'+logo+'.swf','100','50');
	
});

//Preload
function mostraCorpo(){	
	setTimeout(function(){
	$('#corpo').css({visibility: 'visible'});
	$("#divConteudo").hide();
	$('#preload').fadeOut('slow');
		$.historyInit(pageload);
	}, 100);
}

//Histórico
function pageload(hash) {
	// hash doesn't contain the first # character.
	if(hash) {
		// restore ajax loaded state
		$("#divConteudo").load(hash.replace('!','?'));
	} else {
		// start page
		$("#divConteudo").load(paginaInicial.replace(/&amp;/g,'&'));
	}
}


//Flash Content
jQuery.extend({
	insertSWF: function(div, file, width, height){
	$(div).html('<object width="'+width+'" height="'+height+'" type="application/x-shockwave-flash" data="'+file+'" menu="false"><param name="movie" value="'+file+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="menu" value="0" /></object>');
	}
})

//Função para funcionar o link AJAX pelo Flash
function linkFlash(url){
	var hash = url;
	//trocar '?' por '!' do hash caso o navegador seja o Opera
	if(navigator.appName == "Opera"){hash = hash.replace('?','!')};
	$("#divLoading").slideDown('slow');
	$("#divConteudo").slideUp({
		duration: 300,
		easing: "easeInSine",
		complete: function(){ 
			$.historyLoad(hash);
		}
	});
}

//IE6 Validate
isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
isIE7 = navigator.userAgent.toLowerCase().indexOf('msie 7') != -1;
isIE8 = navigator.userAgent.toLowerCase().indexOf('msie 8') != -1;
if(isIE6 == true && isIE7 == false && isIE8 == false){
	if(confirm("Caro usuário,\n\nA versão do seu navegador (Internet Explorer 6.0) é inadequada para acesso à este website.\n\nAtualizar agora para a versão 8.0? (Recomendado)")){document.location="http://www.microsoft.com/brasil/windows/internet-explorer/default.aspx";}
}