
function scrollprog(id, tamanho, dir)
{
	var obj = document.getElementById(id);
	var top = obj.offsetTop;
	var height = obj.offsetHeight;
	var n = ($('#scroll li').length)/3;
	var pag = Math.ceil((n/3));

	if (id == 'scroll2')
		var pag = Math.ceil(($('#scroll2 li').length)/3)

	if (dir == "up")
		var marg = top-tamanho;
	else if (dir == "down")
		var marg = top+tamanho;

	var ab = (tamanho*pag)*-1;

	if (marg < 1 && marg > ab)
		$(obj).animate({top: marg+'px'}, 1000);

}

function scrolar(id, tamanho, dir)
{
	scrollprog(id, tamanho, dir);
}
var avanc;
function vai(inter)
{
		var pos = $('#foto').attr('key');
		var posat = parseFloat(pos)+1;
		
						$('#mini img').each(function(){
										avanc = setInterval('avanca()', 5000);
							 /*if ($(this).attr('key') == posat)
							 {
					var sss = $(this).attr('src').split('/');								 
				if ($(this).attr('src').split('/').length >= 7)
					var src = sss[3]+'/'+sss[4]+'/'+sss[5]+'/'+sss[6]+'/'+sss[7]+'/'+sss[8];
				else
					var src = $(this).attr('src');				
					var bla = this;
					$('#foto').animate({opacity: 0.0}, 100, false, function(){
					$("#foto").attr({src: src, key: $(bla).attr("key")}).animate({opacity: 1.0}, 1000);
								$('#span').html($(bla).attr("key"));
								});
							 }*/
						});
						
if ($('#span').html() == $('#total').html())
			pray('stop');
}

var int;
function pray(act)
{
		if(act == 'start' && $('#span').html() != $('#total').html())
		{
		avanca();
		int = setInterval('avanca()', 5000);
		$("#acct_stop").css({display: 'inline'});
		$("#acct_start").css({display: 'none'});		
		}
		else if (act == 'stop')
		{	
		clearInterval(int);
		clearInterval(avanc);		
		$("#acct_start").css({display: 'inline'});
		$("#acct_stop").css({display: 'none'});		
		}
}

function avanca()
{
if ($('#span').html() == $('#total').html())
			pray('stop');					
	
var pos = $('#foto').attr('key');
	var posat = parseFloat(pos)+1;
					$('#mini img').each(function(){
					   if ($(this).attr('key') == posat)
						 {
								var sss = $(this).attr('way').split('/');
								var bla = this;
							$('#foto').animate({opacity: 0.0}, 100, false, function(){
								/*if ($(bla).attr('src').split('/').length >= 7)
									var src = sss[3]+'/'+sss[4]+'/'+sss[5]+'/'+sss[6]+'/'+sss[7]+'/'+sss[8];
								else*/
									var src = $(bla).attr('way');
									var key = $(bla).attr('key');
								$("#foto").attr({src: src, key: key}).animate({opacity: 1.0}, 500);
									});
										$('#span').html($(this).attr("key"));					
						 }
					   if ($(this).attr('key') == parseFloat(posat)+1)
						 {
							 $('#carregando').attr({src: $(this).attr('way')});
						 }						 
					});
}

function volta()
{
	var pos = $('#foto').attr('key');
	var posat = parseFloat(pos)-1;
					$('#mini img').each(function(){
					   if ($(this).attr('key') == posat)
						 {
					var sss = $(this).attr('way').split('/');
					var bla = this;
				$('#foto').animate({opacity: 0.0}, 100, false, function(){
					/*if ($(bla).attr('src').split('/').length >= 7)
						var src = sss[3]+'/'+sss[4]+'/'+sss[5]+'/'+sss[6]+'/'+sss[7]+'/'+sss[8];
					else*/
						var src = $(bla).attr('way');
						var key = $(bla).attr('key');
					$("#foto").attr({src: src, key: key}).animate({opacity: 1.0}, 500);
						});
							$('#span').html($(this).attr("key"));					
						 }
					   if ($(this).attr('key') == parseFloat(posat)-1)
						 {
							 $('#carregando').attr({src: $(this).attr('way')});
						 }								 
					});
	
}

function doSaveAs(){
	window.open('download.php?url='+$("#foto").attr('src'), 'Download', 'width=0, height=0, resizable=0, scrollbars=0, statusbar=0, menubar=0');

}

function action(id, act)
{	
				$('#mini img').each(function(){
						if ($(this).attr('key') == id)
						{
								var sss= $(this).attr('way').split('/');
							/*if ($(this).attr('src').split('/').length >= 7)
								var caminho = sss[4]+'/'+sss[5]+'/'+sss[6]+'/'+sss[7]+'/'+sss[8]+'/'+sss[9];
							else*/
								var caminho = $(this).attr('way');
							$("#foto").attr({src: caminho, key: $(this).attr("key")});
							$('#span').html($(this).attr("key"));					
						}
						if ($(this).attr('key') == parseFloat(id+1))
						{
								var sss= $(this).attr('way').split('/');
							/*if ($(this).attr('src').split('/').length >= 7)
								var caminho = sss[4]+'/'+sss[5]+'/'+sss[6]+'/'+sss[7]+'/'+sss[8]+'/'+sss[9];
							else*/
								var caminho = $(this).attr('way');
							$("#carregando").attr({src: caminho, key: $(this).attr("key")});
						}						
					 });
						setTimeout(function(){
							document.getElementById("mostra").style.opacity=0;							
							document.getElementById("mostra").style.visibility=act;
							$('#mostra').animate({opacity: 1.0},1000);							
							if (act == 'visible')
								$('body').css({background: '#000'});
							else
								$('body').css({background: '#000 url(css/images/bg-body.jpg) repeat-y center center'});
							}, 500);
						
}

function scrollDiv(id, tamanhodiv, dir)
{
	var obj = document.getElementById(id);
	var height = obj.offsetHeight;
	var top = obj.offsetTop;
	var width = obj.offsetWidth;
	var left = obj.offsetLeft;
	if(dir == 'up')
	{
		if(top < 0)
		{
			novo = top+3;
			if(novo > 0)
				novo = 0;
			obj.style.top = novo + "px";
		}
	}
	if(dir == 'down')
	{
		if(top-top-top+tamanhodiv < height)
		{
			novo = top-3;
			if(novo-novo-novo+tamanhodiv > height)
				novo = top;
			obj.style.top = novo + "px";
		}
	}
	if(dir == 'left')
	{
		if(left < 0)
		{
			novo = left+3;
			if(novo > 0)
				novo = 0;
			obj.style.left = novo + "px";
		}
	}
	if(dir == 'right')
	{
		if(left-left-left+tamanhodiv < width)
		{
			novo = left-3;
			if(novo-novo-novo+tamanhodiv > width)
				novo = left;
			obj.style.left = novo + "px";
		}
	}
}
function scrolar(id, tamanho, dir, rate)
{
	scrolling = self.setInterval('scrollDiv(\''+id+'\', '+tamanho+', \''+dir+'\')', rate);
}
function descrolar()
{
	scrolling = window.clearInterval(scrolling);
}