function getLocation() {
	if (google.loader.ClientLocation) {
			if (typeof(google.loader.ClientLocation.address) == 'undefined') {
				return 'SP';
			}
			var gLoc = google.loader.ClientLocation.address;
			if ((new String(gLoc.country_code)).toUpperCase() != 'BR') {
				return 'SP';
			}
			myUF = (new String(gLoc.region)).toUpperCase();
		} else {
			//o google não conseguiu pegar o estado, retorna SP
			myUF = "SP";
		}
		return myUF;
}

function getNameLocation( uf ) {
	switch (uf) {
			case "AC":
				return "Acre";
			case "AL":
				return "Alagoas";
			case "AM":
				return "Amazonas";
			case "AP":
				return "Amapá";
			case "BA":
				return "Bahia";
			case "CE":
				return "Ceará";
			case "DF":
				return "Distrito Federal";
			case "ES":
				return "Espírito Santo";
			case "GO":
				return "Goiás";
			case "MA":
				return "Maranhão";
			case "MG":
				return "Minas Gerais"; 
			case "MS":
				return "Mato Grosso do Sul";
			case "MT":
				return "Mato Grosso";
			case "PA":
				return "Pará";
			case "PB":
				return "Paraíba";
			case "PE":
				return "Pernambuco";
			case "PI":
				return "Piauí";
			case "PR":
				return "Paraná";
			case "RJ":
				return "Rio de Janeiro";
			case "RN":
				return "Rio Grande do Norte";
			case "RO":
				return "Rondônia";
			case "RR":
				return "Roraima";
			case "RS":
				return "Rio Grande do Sul";
			case "SC":
				return "Santa Catarina";
			case "SE":
				return "Sergipe";
			case "SP":
				return "São Paulo";
			case "TO":
				return "Tocantins";
	}
}

$(document).ready(function(){
	if(jQuery.cookie('uf')) {
		uf = jQuery.cookie('uf').toUpperCase();
	} else {
		uf = getLocation();
		jQuery.cookie('uf', uf);
	}
	$('#nome-estado').html( getNameLocation( uf ) + " - " );
	if( uf != 'RJ' && uf != 'SP') {
		uf = 'OUTROS';
	}
	//alert( '#estado-' + uf );
	//alert( $('#estado-' + uf ).html() );
	$('#lancamento').html($('#estado-' + uf ).html());
	
	$('[class=volumedasemana] a').attr('href', '/volume-da-semana.php?uf=' + uf);
	
	if( $('body').hasClass('home') ) {
		if( uf == 'OUTROS' ) {
			swf = 'homeFase2.swf';
		} else {
			swf = 'homeFase1.swf';
		}
		var flashParams = {scale: "noscale", allowfullscreen: "true", wmode: "transparent" }
		swfobject.embedSWF('/' + swf, "homeflash", "720", "447", "8", "#000000", null, flashParams);
	}
	
});
