// JavaScript Document
/*CAIXA DE DETALHES CLIENTES*/
var vetCliente = new Array
var vetClienteLat = new Array
function cliente(nome,atividade,cidade,url) {
   this.nome = nome;
   this.atividade = atividade;
   this.cidade = cidade;
   this.url = url;   
}

var w=1
var h=1

if (document.getElementById || document.all)
document.write('<div id="trailimageid" style="position:absolute;visibility:hidden;z-index:2;"></div>')

function gettrailobj()
{
	if (document.getElementById) return document.getElementById("trailimageid").style
	else if (document.all) return document.all.trailimagid.style
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail()
{
	document.onmousemove=""
	document.getElementById('trailimageid').innerHTML = ""
	gettrailobj().visibility="hidden"
	gettrailobj().left=-500
	gettrailobj().top=0
}


function showtrail(posVet)
{
	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1)
	{
		//w=width
		//h=height
		
		followmouse()
		str = "<div class='caixaDetCliente'>"
		str += "<h3>" + vetCliente[posVet].nome +  "</h3>"
        str += "<p>"
		str += "<strong>Atividade:</strong> " + vetCliente[posVet].atividade + "<br>"
		str += "<strong>Cidade:</strong> " + vetCliente[posVet].cidade
        str += "</p>"
		if(vetCliente[posVet].url != "")
		{
			str += "<p><strong>Site:</strong> <a href='"+ vetCliente[posVet].url +"'>" + vetCliente[posVet].url + "</a></p>"
		}
        str += "</div>"
		
		document.getElementById('trailimageid').innerHTML = str;
		document.onmousemove=followmouse
		gettrailobj().visibility="visible"
		//gettrailobj().width=w+"px"
		//gettrailobj().height=h+"px"


	}
}


function followmouse(e)
{

	if(navigator.userAgent.toLowerCase().indexOf('opera') == -1)
	{

		var xcoord=20
		var ycoord=-80

		if (typeof e != "undefined")
		{
			xcoord+=e.pageX
			ycoord+=e.pageY
		}
		else if (typeof window.event !="undefined")
		{
			xcoord+=truebody().scrollLeft+event.clientX
			ycoord+=truebody().scrollTop+event.clientY
		}

		var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
		var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

		if (xcoord+w+3>docwidth)
		xcoord=xcoord-w-(20*2)

		if (ycoord-truebody().scrollTop+h>truebody().clientHeight)
		ycoord=ycoord-h-20;

		gettrailobj().left=xcoord+"px"
		gettrailobj().top=ycoord+"px"

	}

}
/*fim*/
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 200;	// maximum image size.

if (document.getElementById || document.all){
	//document.write('<div id="previewimageid" style="position:absolute;visibility:hidden;z-index:2;">');
	//document.write('</div>');
}

function getpreviewobj(){
if (document.getElementById)
return document.getElementById("previewimageid").style
else if (document.all)
return document.all.previewimageid.style
}

function getpreviewobjnostyle(){
if (document.getElementById)
return document.getElementById("previewimageid")
else if (document.all)
return document.all.previewimageid
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

//I <3 istockphoto.com


function showpreview(posVet){
	currentimageheight = 200;

	document.onmousemove=followmouse;

	str = "<div class='caixaDetCliente'>"
		str += "<h3>" + vetCliente[posVet].nome +  "</h3>"
        str += "<p>"
		str += "<strong>Atividade:</strong> " + vetCliente[posVet].atividade + "<br>"
		str += "<strong>Cidade:</strong> " + vetCliente[posVet].cidade
        str += "</p>"
		if(vetCliente[posVet].url != "")
		{
			str += "<p><strong>Site:</strong> <a href='"+ vetCliente[posVet].url +"'>" + vetCliente[posVet].url + "</a></p>"
		}
        str += "</div>"
	getpreviewobjnostyle().innerHTML = str;
	getpreviewobj().visibility="visible";
}

function showhints(texthint){
	currentimageheight = 20;

	document.onmousemove=followmouse;

	newHTML = '<div style="padding: 2px 4px; background: #CC0000;">';
	newHTML = newHTML + '<p>' + texthint + '</p>';
	newHTML = newHTML + '</div>';
	getpreviewobjnostyle().innerHTML = newHTML;
	getpreviewobj().visibility="visible";
}
function hidepreview(){
	getpreviewobj().visibility="hidden"
	document.onmousemove=""
	getpreviewobj().left="-500px"
}

function followmouse(e){
	var xcoord=20
	var ycoord=20

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	//if (document.all){
	//	getpreviewobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	getpreviewobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 150){
			xcoord = e.pageX - xcoord - 220; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 30)){
			ycoord += e.pageY - Math.max(0,(30 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 150){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 220; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 30)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(30 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	getpreviewobj().left=xcoord+"px"
	getpreviewobj().top=ycoord+"px"

}



var foto_atual,proxima_foto,id_foto_atual,id_label_atual;
var num_fotos = 2;
intervalo = new Object()

var arrayLink = new Array();

function mudar_foto(foto){
	
	
	id_proxima_foto = "#foto_"+foto;
	id_proximo_label = "#label_"+foto
	
	$(id_foto_atual).animate( {'opacity':'hide'},'slow');

	$(id_proxima_foto).animate( {'opacity':'show'},'slow',function(){
		foto_atual = foto
		id_foto_atual = id_proxima_foto;
		
		
	})
	
	$(id_label_atual).animate( {'opacity':'hide'},'slow');
	$(id_proximo_label).animate( {'opacity':'show'},'slow',function(){		
		id_label_atual = id_proximo_label;
		
		
	})
	
			
}
function setarFoto(foto)
{
	foto = foto.replace("n","")	
	mudarClassNum(foto)		
	clearInterval(intervalo)		
	mudar_foto(foto)
	intervalo = setInterval("fotoAuto()",3000)
}
function fotoAuto()
{
	if(foto_atual == num_fotos)
	{
		proxima_foto = 0;
	}
	else
	{
		proxima_foto = parseInt(foto_atual) + 1	
	}	
	
	mover("D")
	mudarClassNum(proxima_foto)
}
function mudarClassNum(proxima_foto)
{
	for(i=0;i<=num_fotos;i++)
	{
		idNum = "#n"+i
		if(i == proxima_foto )
		{
			$(idNum).addClass("numFundo")
			$(idNum).removeClass("semFundo")
		}
		else
		{
			$(idNum).addClass("semFundo")	
			$(idNum).removeClass("numFundo")
		}
	}	
}

function mover(tipo)
{
	if(tipo == "E")
	{
		proxima_foto=  parseInt(foto_atual) - 1	
		if(proxima_foto < 0)
		{
			proxima_foto = parseInt(num_fotos)-1
			
		}
	}
	else
	{
		proxima_foto =  parseInt(foto_atual) + 1	
		if(proxima_foto >= num_fotos)
		{
			proxima_foto = 0	
		}	
		
	}
	clearInterval(intervalo)		
	mudar_foto(proxima_foto)
	mudarClassNum(proxima_foto)
	if(proxima_foto == 0)
	{
		intervalo = setInterval("fotoAuto()",6000)
	}
	else
	{
		intervalo = setInterval("fotoAuto()",3000)
	}
	
	
}

function iniciarGaleria()
{
	foto_atual = 0;
	id_foto_atual = "#foto_0";
	id_label_atual = "#label_0"
	num_fotos = $("#imgCli .miniaturasGal").length
	
	if(num_fotos > 1)
	{
		for(i=0;i<=num_fotos;i++)
		{
			idNum = "#n"+i
			$(idNum).click(function () { 
			setarFoto(this.id)
			});
		}
		for(i=1;i<=num_fotos;i++)
		{
			$("#foto_"+i).hide()	
			$("#label_"+i).hide()
		}
		$("#btnDir").click(function () { 
			mover('E')
			});
		$("#btnEsq").click(function () { 
			mover('D')
			});
		
		
		intervalo = setInterval("fotoAuto()",6000)
	}
	
}

