// JavaScript Document
function rand (min, max) {
    // http://kevin.vanzonneveld.net
    // +   original by: Leslie Hoare
    // +   bugfixed by: Onno Marsman
    // %          note 1: See the commented out code below for a version which will work with our experimental (though probably unnecessary) srand() function)
    // *     example 1: rand(1, 1);
    // *     returns 1: 1
    
    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
    
    /*
    // See note above for an explanation of the following alternative code
    
    // +   reimplemented by: Brett Zamir (http://brett-zamir.me)
    // -    depends on: srand
    // %          note 1: This is a very possibly imperfect adaptation from the PHP source code
    var rand_seed, ctx, PHP_RAND_MAX=2147483647; // 0x7fffffff
 
    if (!this.php_js || this.php_js.rand_seed === undefined) {
        this.srand();
    }
    rand_seed = this.php_js.rand_seed;
 
    var argc = arguments.length;
    if (argc === 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
 
    var do_rand = function (ctx) {
        return ((ctx * 1103515245 + 12345) % (PHP_RAND_MAX + 1));
    };
 
    var php_rand = function (ctxArg) { // php_rand_r
        this.php_js.rand_seed = do_rand(ctxArg);
        return parseInt(this.php_js.rand_seed, 10);
    };
 
    var number = php_rand(rand_seed);
 
    if (argc === 2) {
        number = min + parseInt(parseFloat(parseFloat(max) - min + 1.0) * (number/(PHP_RAND_MAX + 1.0)), 10);
    }
    return number;
    */
}
function getAnchor(){
	var myFile = document.location.toString();
	if (myFile.match('#')) { // the URL contains an anchor
	  // click the navigation item corresponding to the anchor
	  var myAnchor = myFile.split('#')[1];
	  return myAnchor;
	} else {
	  return false;
	}
}
var randPublicidade = rand(1, 5);
var showPublicidade =false;
var totalExibidas  = 0;
var root_folder  = '/';

function loadThumb($idFoto,$idAlbum){
	var totalItens = $("ul#thumb-lista li").size();
	var posicao = $('ul#thumb-lista li').index( $('#foto-'+$idFoto) );
	if ($('#foto-'+$idFoto).html() == ''){
		$('#foto-'+$idFoto).html('<img src="'+root_folder+'img-thumbzoom/fotos/'+$idAlbum+'/71/56/img/'+$('#foto-'+$idFoto).attr('name')+'"/>');
	}
	if ($('#foto-'+$idFoto).next().html() == ''){
		$('#foto-'+$idFoto).next().html('<img src="'+root_folder+'img-thumbzoom/fotos/'+$idAlbum+'/71/56/img/'+$('#foto-'+$idFoto).next().attr('name')+'"/>');
	}
	if ($('#foto-'+$idFoto).next().next().html() == ''){
		$('#foto-'+$idFoto).next().next().html('<img src="'+root_folder+'img-thumbzoom/fotos/'+$idAlbum+'/71/56/img/'+$('#foto-'+$idFoto).next().next().attr('name')+'"/>');
	}
	if ($('#foto-'+$idFoto).next().next().next().html() == ''){
		$('#foto-'+$idFoto).next().next().next().html('<img src="'+root_folder+'img-thumbzoom/fotos/'+$idAlbum+'/71/56/img/'+$('#foto-'+$idFoto).next().next().next().attr('name')+'"/>');
	}
	if ($('#foto-'+$idFoto).next().next().next().next().html() == ''){
		$('#foto-'+$idFoto).next().next().next().next().html('<img src="'+root_folder+'img-thumbzoom/fotos/'+$idAlbum+'/71/56/img/'+$('#foto-'+$idFoto).next().next().next().next().attr('name')+'"/>');
	}
	if ($('#foto-'+$idFoto).prev().html() == ''){
		$('#foto-'+$idFoto).prev().html('<img src="'+root_folder+'img-thumbzoom/fotos/'+$idAlbum+'/71/56/img/'+$('#foto-'+$idFoto).prev().attr('name')+'"/>');
		$('#foto-'+$idFoto).prev().fadeIn(3000);
		
	}
	
	if(posicao < 5 || totalItens <= 8) {
		var leftItem = 0;
	} else if(posicao > totalItens-5) {
		var leftItem = 316-(79*(totalItens-5));
	} else {
		var leftItem = 316-(79*posicao);
	}
	$("ul#thumb-lista").animate({ left: leftItem+"px" },{ queue:false, duration:"slow" });
	//$('#album-fotos-view-img').fadeOut(100, function () {
		$('#estrelasFoto').html('');
		$('#albumPessoal').html('');
		$('#votosFoto').html('');
		$('#cliquesFoto').html('');
		$('#pessoasFoto').html('');
		totalExibidas++;
		if(showPublicidade == false & (randPublicidade == posicao || totalExibidas > 5)) {
			showPublicidade = true;
			$('#album-fotos-view-img').html('<img id="viewFoto" src="/publicidades.jpg"/>');
			$('.album-fotos-publicidade').hide();
		} else {
			$('#album-fotos-view-img').html('<img id="viewFoto" src="'+root_folder+'img-view/fotos/'+$('#foto-'+$idFoto).attr('album')+'/651/434/img/'+$('#foto-'+$idFoto).attr('name')+'"/>');
			$('.album-fotos-publicidade').show();
			xajax_loadFoto($idFoto);
			$("ul#thumb-lista li").removeClass("selecionado");
			$('li#foto-'+$idFoto).addClass("selecionado");
			if ($('#foto-'+$idFoto).prev().attr('alt'))
				$('#navPrevFoto').html("<a onclick=\"loadThumb('"+$('#foto-'+$idFoto).prev().attr('alt')+"','"+$('#foto-'+$idFoto).prev().attr('album')+"');\">&lt;</a>");
				else $('#navPrevFoto').html("");
			if ($('#foto-'+$idFoto).next().attr('alt'))
				$('#navNextFoto').html("<a onclick=\"loadThumb('"+$('#foto-'+$idFoto).next().attr('alt')+"','"+$('#foto-'+$idFoto).prev().attr('album')+"');\">&gt;</a>");
				else $('#navNextFoto').html("");
		};
		$('#viewFoto').load(function () {
			//$('#album-fotos-view-img').fadeIn(200);
		});
		
	//});
	
};