var slide;
var thumb;
var maxslides, maxThumbs;
var slideWidth, slideHeight;
var currentslide;
var maxDescriptions;
var grande;

function redimensionaBoxes()
{
  var menor, maior;
  var anun = document.getElementById('anunciante');
  var desc = document.getElementById('descricao');
  
  if (anun.offsetHeight < desc.offsetHeight)
  {
    menor = anun;
    maior = desc;
  }
  else
  {
    menor = desc;
    maior = anun;
  }
  
  menor.style.height = maior.offsetHeight-1 + 'px';
}

function CarregarSlides(width, height)
{
	var a = CarregarSlides.arguments;
	maxslides = a.length - 2; 
	currentslide = 0;

	slideWidth = width;
	slideHeight = height;

	slide = new Array(maxslides);

	for(var n=0; n <= maxslides; n++)
	{
		//slide[n] = new Image(302,346);
		slide[n] = new Image(width, height);
		slide[n].src = a[n+2];
	}
}

function CarregarThumbs(width, height)
{
	var a = CarregarThumbs.arguments;
	maxThumbs = a.length-2;
		
	thumb = new Array(maxThumbs);
	grande = new Array(maxThumbs);
	
	var x=0;
	for(var n=2; n <= maxThumbs; n = n+2)
	{
		//thumb[n] = new Image(265,180);
		thumb[x] = new Image(width, height);
		thumb[x].src = a[n];
		grande[x++] = a[n+1];
	}
}

function CarregarDescriptions()
{
	var a = CarregarDescriptions.arguments;
	maxDescriptions = a.length;
	
	descriptions = new Array(maxDescriptions);
	
	for(var i=0; i < maxDescriptions; i++)
	{
		//thumb[n] = new Image(265,180);
		descriptions[i] = a[i];
	}
}

function prevSlide() 
{
	var description = document.getElementById('slide_desc');
	
	if(document.images) 
	{
		currentslide--;
		
		if(currentslide<0) 
			currentslide = maxslides-1;
		
		document.images['slide'].src=slide[currentslide].src;
		description.innerHTML = descriptions[currentslide];
	}
}

function nextSlide() 
{
	var description = document.getElementById('slide_desc');
	
	if(document.images) 
	{
		currentslide++;
		
		if(currentslide>=maxslides) 
			currentslide=0;
			
		document.images['slide'].src= slide[currentslide].src;
		description.innerHTML = descriptions[currentslide];
	}
}

function showFullSize()
{
	//openPictureWindow(slide[currentslide].src, slideWidth, slideHeight, 'Imagem em Tamanho Grande');
	openPictureWindow(grande[currentslide], slideWidth, slideHeight, 'Imagem em Tamanho Grande');
}

function openPictureWindow(imageName,imageWidth,imageHeight,alt)
{
  var imagem = new Image();
  imagem.src = imageName;
  function resto()
  {
	  //newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight);
	  newWindow = window.open("","newWindow","width="+imagem.width+",height="+imagem.height +",scrollbars=1");
 	  newWindow.document.open();
	  newWindow.document.write('<HTML><TITLE>'+alt+'</TITLE><BODY bgcolor="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0" onBlur="self.close()">');
	  //newWindow.document.write('<IMG SRC='+imageName+' WIDTH='+imageWidth+' HEIGHT='+imageHeight+' ALT="'+alt+'">');
	  newWindow.document.write('<IMG SRC='+imageName+' ALT="'+alt+'">');
	  newWindow.document.write('</BODY></HTML>');
	  newWindow.document.close();
	  newWindow.focus();
	}
	imagem.onload = resto;
}
// end dHTML SlideShow Script
function swapImgRestore() 
{
	var i,x,a=document.sr; 
	
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
		x.src=x.oSrc;
}

function preloadImages() 
{
	var d=document; 
	
	if(d.images)
	{ 
		if(!d.p) 
		d.p=new Array();
		var i,j=d.p.length,a=preloadImages.arguments; 
		
		for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0)
			{ 
				d.p[j]=new Image; 
				d.p[j++].src=a[i];
			}
	}
}

function findObj(n, d) 
{
	var p,i,x;  
	
	if(!d) d=document; 
	
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
		
	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
		
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];

	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=findObj(n,d.layers[i].document);

	return x;
}

function swapImage() 
{
	var i,j=0,x,a=swapImage.arguments; 
	document.sr=new Array; 
	
	for(i=0;i<(a.length-2);i+=3)
		if ((x=findObj(a[i]))!=null)
		{
			document.sr[j++]=x; 
		
			if(!x.oSrc) 
				x.oSrc=x.src; 
		
			x.src=a[i+2];
		}
}

function mudaCidades(texto)
{
  document.getElementById('cidades').innerHTML = texto
  var biggest_pog_ever = texto.split("<!--")
  if (biggest_pog_ever.length > 1)
  {
    biggest_pog_ever = biggest_pog_ever[1].split("-->")
    eval(biggest_pog_ever[0])
  }
  clsEsconder('loading')
}

function mudaBairros(texto)
{
  document.getElementById('bairros').innerHTML = texto;
  clsEsconder('loading');
}
