/*
 * Google Config
 */
var IE 		= navigator.appName == 'Microsoft Internet Explorer';
//google_ad_channel 	= "8763501942";
//google_ad_type 		= "text";
//google_color_border	= "FADC47";
//google_color_bg 	= "FADC47";
//google_color_link 	= "8BA2E2";
//google_color_url 	= "8BA2E2";
//google_color_text 	= "8BA2E2";
var last_fotos = [];
dominio 		= "flogme.com.br";
url_static_img	= "http://static."+dominio+"/img/";

/*
 * comum
 */
function limpa_select(id_select){
	elem_trab = get(id_select);
	tot_in_select = elem_trab.options.length;
	for(x=tot_in_select;x>-1;x--){
		elem_trab.remove(x);
	}
}
function adiciona_opt(elem_trab, texto, valor){
	elem_trab = get(elem_trab);
	elem_trab.options[elem_trab.options.length] = new Option(texto, valor, false, false);
}

function verifica_radio_valor(radio_name){
	var elementos = document.getElementsByName(radio_name);
	var valor_radio = false;
	for(i=0;i<elementos.length;i++){
		if(elementos[i].checked) valor_radio = elementos[i].value;
	}
	return valor_radio;
}

/*
 *  thumb flutuante
 */
function get(elem){
	return document.getElementById(elem);
}

function mostra_tf(elementoReferencia,url_thumb, cidade, uf){
	var anteriores	= new Array();
    var elemento_ini= elementoReferencia.offsetParent;
	var tmpX 		= 0;
	var tmpY 		= 0;
	while(tem_parent = elemento_ini.offsetParent){
		tmpX = tmpX +  tem_parent.offsetLeft;
		tmpY = tmpY +  tem_parent.offsetTop;
		elemento_ini = tem_parent;
	}
	tmpX = tmpX +  elementoReferencia.offsetLeft;
	tmpY = tmpY +  elementoReferencia.offsetTop;
	var cor_uf  = retorna_cor(uf);
	var thumbTF = get('thumbFlutuante');
	thumbTF.style.marginTop = "7px";
	thumbTF.innerHTML = '<img src="'+url_thumb+'" onLoad="ajustaThumb2(this);" style="border: 3px solid '+cor_uf+';">';
	thumbTF.innerHTML += '<div id="legendaTF" class="legenda" style="margin-top: -30px; width: 0px; background-color: '+cor_uf+'"><div style="font-size: 9px;">'+unescape(cidade)+'</div>'+uf+'</div>';
	thumbTF.style.rigth = '1px';
	thumbTF.style.display = 'block';
/*
	document.title = tmpY+" - "+tmpX;
	thumbTF.style.top = tmpY+'px';
	tfTimer = setTimeout('mataTf()',3500);
*/
}

regioes = {
	'norte'			: ["AC","AM","RO","RR","AP","PA","TO"],
	'nordeste'		: ["MA","PI","BA","CE","RN","PB","PE","AL","SE"],
	'centrooeste'	: ["MT","MS","GO","DF"],
	'sudeste'		: ["SP","MG","ES","RJ"],
	'sul'			: ["PR","SC","RS"]
};

function retorna_cor(uf){
 	if(in_array(uf, regioes['sudeste'])){
		return "#FF6666";
	} else if(in_array(uf, regioes['nordeste'])){
		return "#996699";
	} else if(in_array(uf, regioes['sul'])){
		return "#FF9900";
	} else if(in_array(uf, regioes['norte'])){
		return "#66CC66";
	} else if(in_array(uf, regioes['centrooeste'])){
		return "#6666FF";	
	} else {
		return "#CCCCCC";
	}
}

function in_array(valor,tal_da_array){
	var retorno = false;
	for(var i=0;i<tal_da_array.length;i++){
		if(tal_da_array[i] == valor){
			retorno = true;
		}
	}
	return retorno;
}

function mataTf(){
	get('thumbFlutuante').style.display = 'none';
}



/*
 * Debugggg
 */
function aff(akjskdajdas,campo){
	var akjskdajdas_ = "[\n<br>"
	for (var prop in akjskdajdas){
		if(prop != 'selectionStart' && prop != 'selectionEnd'){
			//akjskdajdas_w.document.writeln(prop+' - '+'<br>');
			akjskdajdas_ += "<strong>" + prop + "</strong> = "+akjskdajdas[prop][campo]+";\n<br>";
		}
	}
	akjskdajdas_ += "]<br>";
	winJsDebuger = window.open('','winJsDebuger', 'width=500,height=400,scrolls=yes');
	winJsDebuger.document.body.innerHTML = '';
	winJsDebuger.document.write("<div><h1>JS Debug Tabaja</h1>"+akjskdajdas_+"</div>");
	winJsDebuger.focus();
}
 
 
/*
 * últimas
 */
var dadosTab = new Array(
	{ 'url':'/index.php', 'ajax':'last_jpg', 	'img':'tab_fotos', 	'title':'Veja as últimas fotos enviadas' },
	{ 'url':'/index.php', 'ajax':'last_videos', 'img':'tab_videos', 'title':'Veja os últimos SWFS enviados' },
	{ 'url':'/index.php', 'ajax':'last_gifs', 	'img':'tab_gifs', 	'title':'Veja os últimos GIFS enviados' },
	{ 'url':'/index.php', 'ajax':'last_swfs', 	'img':'tab_swfs', 	'title':'Veja os últimos VÍDEOS enviados' }
);

function selecionaTab(tabSelecionada){
	for(i=0;i<dadosTab.length;i++){
		arrayTab  = dadosTab[i];
		get('a'+arrayTab['img']).style.marginTop	= (arrayTab['img'] == tabSelecionada) ? '1px' : '0px';
		get('img'+arrayTab['img']).src				= (arrayTab['img'] == tabSelecionada) ? url_static_img+'ncapa/'+arrayTab['img']+'.jpg' : url_static_img+'ncapa/'+arrayTab['img']+'_off.jpg';
		if(arrayTab['img'] == tabSelecionada){
			var ajqs = arrayTab['ajax'];
		}
	}

	get_url("/conector.php?acao="+ajqs,"populaTab");
}

function populaTab(codigo){
	/*
	{
	'login':'kroner',
	'apelido':'%7E%5E%7EThissa%7E%5E%7E',
	'id_foto':'2972210',
	'url_thumb':'http://t1.xxxxxxxxx/asdasds',
	'cor_uf':'#6666FF'
	}
	*/
	html = "";
	eval(codigo);
	if(last_fotos.length){
		for(x=0; x<last_fotos.length; x++){
			html += '<div style="border: 1px solid '+last_fotos[x]['cor_uf']+'"><a href="http://'+last_fotos[x]['login']+'.'+dominio+'/?id_foto='+last_fotos[x]['id_foto']+'">';
			html += '<img border=0 src="'+last_fotos[x]['url_thumb']+'" onLoad="ajustaThumb(this);" onMouseOver="efeitoThumb(this, false);" onMouseOut="efeitoThumb(this, true);"/><br>';
			html += unescape(last_fotos[x]['apelido'])+'</a></div>';
		}
		get('ultimasCorpo').innerHTML = html;
	}
}

function efeitoThumb(elemento, out){
	if(out == true){
		elemento.width  = (parseInt(elemento.width)-4);
		elemento.height = (parseInt(elemento.height)-4);
	} else {
		elemento.width  = (parseInt(elemento.width)+4);
		elemento.height = (parseInt(elemento.height)+4);
	}
}

function ajustaThumb(elemImg){
	var tot = (100 - parseInt(elemImg.height)) / 2;
	elemImg.style.marginTop = tot+"px";
}

function ajustaThumb2(elemImg){
	get('legendaTF').style.width = elemImg.width+"px";
	if(!IE){
		var tot = (100 - parseInt(elemImg.width)) / 2;
		get('legendaTF').style.marginLeft = (tot+3)+"px"; 
	}
	var tot = (100 - parseInt(elemImg.height)) / 2 + 13;
	get('thumbFlutuante').style.marginTop = tot+"px";
}
