HOME_SITE = "/";

$(document).ready(function(){
	$('.icone_seta_menu').click(function(){
		if( $(this).hasClass('seta_baixo') )
			$(this).parent().find('ul').show();
		else
			$(this).parent().find('ul').hide();
		$(this).toggleClass("seta_baixo");
		return false;
	});
	//bannerImgs();
	$('#galleryLB a').lightBox({overlayBgColor:'#FFF'});
	barraPublicidade();
});
/*
$(document).ready(function(){
	$('.icone_seta_menu,.icone_seta_menu + a').click(function(){
		if(this.parentNode.lastElementChild.tagName == 'UL'){
			submenu = $((this).parentNode.lastElementChild);
			if(this.tagName == 'A')
				_this = this.previousElementSibling;
			else
				_this = this;
			if($(_this).hasClass("seta_baixo")){
				$(_this).removeClass("seta_baixo");
				submenu.show();
			}else{
				$(_this).addClass("seta_baixo");
				submenu.hide();
			}
		}
		return false;
	});
	//bannerImgs();
	$('#galleryLB a').lightBox({overlayBgColor:'#FFF'});
	barraPublicidade();
});
*/
var bannerAtv = 0;
var bannerQnt = 0;
bannerImgs = function(){
	var imgs = $('.banner_publicidade img');
	bannerQnt = imgs.length;
	for(i=0;i<bannerQnt;i++){
		if(i != 0){
			$(imgs[i]).slideToggle();
			bannerAtv = 0;
		}
	}
	setTimeout("trocaImg()",5000);
}
trocaImg = function(){
	var imgs = $('.banner_publicidade img');
	bannerAtv++;
	if(bannerAtv >= bannerQnt){
		bannerAtv = 0;
		$(imgs[bannerQnt-1]).slideToggle();
	}else
		$(imgs[bannerAtv-1]).slideToggle();
	$(imgs[bannerAtv]).slideToggle();
	setTimeout("trocaImg()",5000);
}

imprimir = function(){
	self.print();
	return false;
}

var textSize = 12;
function alteraTamanho(acao,alvo) {
	textSize = textSize + acao;
	if (textSize > 19) {
		textSize = textSize - acao;
		return false;
	} else if (textSize < 9) {
		textSize = textSize - acao;
		return false;
	}
	divAltera = document.getElementById(alvo);
	newSize = textSize+'px';
	divAltera.style.fontSize = newSize;
	return false;
}

popup = function(url,largura,altura){
	var x = (screen.width - largura) / 2;
	var y = (screen.height - altura) / 2;
	
	var popup = window.open(url, "popup", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, dependent, height=" + altura + ", width=" + largura + ", left=" + x + ", top=" + y);
	
	if (parseInt (navigator.appVersion)>=4)
		popup.window.focus();

}
changeFiltro = function(value,idDest){
	var url = HOME_SITE+'classificados/getfiltros';
	var destino = $('#'+idDest);
	
	destino.load(url+'/subcategoria/'+value);
}
mascData = function(obj){
	var a = obj.value;
	a=a.replace(/\D/g,"");
	a=a.replace(/^(\d\d)(\d)/g,"$1/$2");
	a=a.replace(/(\d{2})(\d)/,"$1/$2");
	obj.value = a;
}

/*JAVASCRIPT galeria HOME*/
fotoAtual = 0;
totalFotos = 0;
timeout = false;
escondeFotos = function(id,first){
	$('#'+id+' a').fadeOut();
	totalFotos = $('#'+id+' a').length;
	mostraFoto(first);
};
mostraFoto = function(id){
	$('#galeria_home_'+id).parent().find('a').css('display','none');
	$('#galeria_home_'+id).fadeIn();
	$('#galeria_manchete').html($('#galeria_home_'+id+' img').attr('title'));
	$('#galeria_manchete').attr('href',$('#galeria_home_'+id).attr('href'));
	fotoAtual = id;
	trocaTimeout();
};
proximaFoto = function(){
	if(fotoAtual >= totalFotos-1)
		fotoAtual = 0;
	else
		fotoAtual++;
	mostraFoto(fotoAtual);
}
anteriorFoto = function(){
	if(fotoAtual <= 0)
		fotoAtual = totalFotos-1;
	else
		fotoAtual--;
	mostraFoto(fotoAtual);
}
trocaTimeout = function(){
	if(timeout){
		clearTimeout(timeout);
		timeout = false;
	}
	timeout = setTimeout("proximaFoto();",5000);
}

/* Barra de publicidade */
openPublicidade = false;
barraPublicidade = function(){
//	$('.barraTitulo').mouseenter(function(){
//		barraOpen();
//	}).mouseleave(function(){
//		barraClose();
//	});
	$('#barraPublicidade').mouseenter(function(){
		setTimeout("barraOpen();",1000);
	}).mouseleave(function(){
		setTimeout("barraClose();",3000);
	});
}
barraOpen = function(){
	$('#barraPublicidade').css('width','180px');
	$('#barraFechada').css('display','none');
	$('#barraAberta').css('display','');
	//barraRestore();
}
barraClose = function(){
	$('#barraPublicidade').css('width','54px');
	$('#barraFechada').css('display','');
	$('#barraAberta').css('display','none');
}
function fazBusca() {
	var query = document.getElementById('query');
	document.location.href='/eng/busca/index/q/'+query.value;
}
openWindow = function(){
	window.open(document.location + "?imprimir=true");
}