var varUrl,TimeID;
function shareSocial(tipo) {
	var formulario = document.forms['aspnetForm'];
	varTitulo = document.title;
	varUrl = document.location;
	if(varUrl == 'http://www.territorioanimal.com.br/index.php'){
		varUrl = 'http://www.territorioanimal.com.br/';
	}
	varDesc = document.getElementsByName('description')[0].getAttribute('content');
	//alert(varTitulo+"\n"+varUrl+"\n"+varDesc);
	
	varOrkutDesc = varDesc.substr(0, 220);
	varUrlOri = decodeURIComponent(varUrl);
	switch (tipo) {
		case 't':
			var janela = window.open('http://twitter.com/share?url=' + varUrlOri + '&text=' + encodeURIComponent(varTitulo) + '&via=TerritorioAnimal', 'shareTwitter', 'top=200,left=40,width=500,height=280,scrollbars=0,statusbar=1,menubar=0');
			break;
		case 'f':
			var janela = window.open('http://www.facebook.com/sharer.php?u=' + varUrlOri, 'shareFace', 'top=200,left=40,width=660,height=485,scrollbars=0,statusbar=1,menubar=0');
			break;
		case 'o':
			var janela = window.open('http://promote.orkut.com/preview?nt=orkut.com&tt=' + varTitulo + '&du=' + varUrlOri + '&cn=' + varDesc, 'shareOrkut', 'top=200,left=40,width=660,height=485,scrollbars=0,statusbar=1,menubar=0');
			break;
	}
}

function fill_info(evt,w,h,info){
	varCamada = document.getElementById('camada_info');
	if(varCamada.style.display == 'block'){
		varCamada.style.display = 'none';
	}else{
		if(evt.pageX){
			varScrW = window.innerWidth;
			varCamada.style.top = (evt.pageY-16)+'px';
			varCamada.style.left = evt.pageX-(w/2)+'px';
		}else{
			varScrW = evt.clientX;
			varCamada.style.top = (evt.y+134)+'px';
			varCamada.style.left = evt.x+(varScrW/2)+'px';
		}		
		varCamada.style.width = w+'px';
		varCamada.style.height = h+'px';
		varCamada.innerHTML = info;
		varCamada.style.display = 'block';
	}
}

function trocaImg(imagem,credito,legenda){
	if(credito != ''){
		varNewCont = '<b>Crédito da Foto:</b> '+credito+'<br/>';
	}else{
		varNewCont = '';
	}
	if(legenda != ''){
		varNewCont = varNewCont + '<b>Legenda:</b> '+legenda+'<br/>';
	}
	document.getElementById('img_main').innerHTML = '<img src="img/img_'+imagem+'" border="0" style="max-width:612px;" /><br/>'+varNewCont;
}

function mostraImg(arrId){
	document.body.style.overflowY= "hidden";
	document.getElementById('camada_overlay').style.height = (document.body.clientHeight+136)+'px';
	document.getElementById('camada_overlay').style.display = 'block';
	document.getElementById('camada_innerPic').innerHTML = '<img src="img/img_'+arrImg[arrId]['img']+'" border="0" />';
	document.getElementById('over_desc').innerHTML = arrImg[arrId]['legenda'];
	document.getElementById('over_count').innerHTML = '<span style="font-size:16px;color:#dddddd;"><b>'+(arrId+1)+'</b>/</span>'+(arrImg.length);
	document.getElementById('camada_innerlay').style.display = 'block';
	/* Checa quem deve aparecer */
	if(arrId > 0){
		document.getElementById('over_left').setAttribute('onclick','mostraImg('+(arrId-1)+')');
		document.getElementById('over_left').style.display = 'block';
	}else{
		document.getElementById('over_left').style.display = 'none';
	}
	if(arrId < (arrImg.length-1)){
		document.getElementById('over_right').setAttribute('onclick', 'mostraImg('+(arrId+1)+')');
		document.getElementById('over_right').style.display = 'block';
	}else{
		document.getElementById('over_right').style.display = 'none';
	}
}
function escondeImg(){
	document.getElementById('camada_innerlay').style.display = 'none';
	document.getElementById('camada_overlay').style.display = 'none';
	document.body.style.overflowY= "auto";
}

/* Globais para função de scroll */
var varPai;
var varLarg;
var varLeft;
var strCrop;
var strDist;
var marcaLoop;
marcaLoop = 0;
strDist = 0;
strCrop = 0;
function iniThumbs(){
	varPai = document.getElementById('in_thumbs');
	//varLarg = 600;
	varLarg = parseInt(varPai.style.width,10);
	varPai.style.display = 'block';
	varLeft = varPai.offsetLeft;
}

function slideLeft(){
	varPai = document.getElementById('in_thumbs');
	marcaLoop = marcaLoop + 10;
	varPai.style.left = -(marcaLoop-varLeft)+'px';
	varPai.style.clip = "rect(0px "+(marcaLoop + 580)+"px 80px "+(marcaLoop)+"px)";
	if((-marcaLoop) <= strDist){
		clearInterval(TimeID);
	}
}
function slideRight(){
	varPai = document.getElementById('in_thumbs');
	marcaLoop = marcaLoop - 10;
	varPai.style.left = (-marcaLoop)+varLeft+'px';
	varPai.style.clip = "rect(0px "+(marcaLoop + 580)+"px 80px "+(marcaLoop)+"px)";
	if((-marcaLoop) >= strDist){
		clearInterval(TimeID);
	}
}

function tmbLeft(){
		strDist = strDist - 600;
		strCrop = strCrop + 600;
	//if((-varLarg) <= (strDist - 600)){
		TimeID = setInterval(slideLeft,20);
	/* }else{
		clearInterval(TimeID);
		varNovoLeft = strDist + varLeft;
		varPai.style.left = varNovoLeft+'px';
		varPai.style.clip = "rect(0px "+(strCrop + 600)+"px 80px "+strCrop+"px)";
	} */
	if((-varLarg) >= (strDist - 600)){
		document.getElementById('thumb_right').style.display = 'none';
		document.getElementById('thumb_left').style.display = 'block';
		document.getElementById('thumb_left').setAttribute('onclick', 'tmbRight()');
	}else{
		document.getElementById('thumb_right').style.display = 'block';
		document.getElementById('thumb_left').style.display = 'block';
		document.getElementById('thumb_right').setAttribute('onclick', 'tmbLeft()');
		document.getElementById('thumb_left').setAttribute('onclick', 'tmbRight()');
	}
}
function tmbRight(){
		strDist = strDist + 600;
		strCrop = strCrop - 600;
	if(strDist <= 0){
		TimeID = setInterval(slideRight,20);
	}else{
		varNovoLeft = strDist + varLeft;
		varPai.style.left = varNovoLeft+'px';
		varPai.style.clip = "rect(0px "+(strCrop + 600)+"px 80px "+strCrop+"px)";
	}
	if(strDist >= 0){
		document.getElementById('thumb_left').style.display = 'none';
		document.getElementById('thumb_right').style.display = 'block';
		document.getElementById('thumb_right').setAttribute('onclick', 'tmbLeft()');
	}else{
		document.getElementById('thumb_left').style.display = 'block';
		document.getElementById('thumb_right').style.display = 'block';
		document.getElementById('thumb_left').setAttribute('onclick', 'tmbRight()');
		document.getElementById('thumb_right').setAttribute('onclick', 'tmbLeft()');
	}
}
