/*****************************	SLIDERS	*/
var posicoes = new Array('jfs-a','jfs-b','jfs-c');
var posicoesPx = new Array('-466','57', '585');
var move = false;
function jfSliderStart(){
	move = true;
	$('#'+posicoes[0]).animate({top: posicoesPx[0]+'px'}, {queue:false,duration:300});
		if(chaveAtual > 0)
			$('#'+posicoes[0]+' .jfs_sobre').html('<span class="anterior">'+nomeslist[chaveAtual-1]+'</span>');
		else
			$('#jfs-controle-top').fadeOut(500);

	$('#'+posicoes[1]).animate({top: posicoesPx[1]+'px'}, 300,function(){
		jf_loadTCI();
	});
		
		
	$('#'+posicoes[2]).animate({top: posicoesPx[2]+'px'},{queue:false,duration:300});
		if(chaveAtual < ultimaChave)
			$('#'+posicoes[2]+' .jfs_sobre').html('<span class="proximo">'+nomeslist[chaveAtual+1]+'</span>');
		else
			$('#jfs-controle-bottom').fadeOut(500);
		
	jfsFree = true;
}

function jfSliderProximo(){
	if(chaveAtual < ultimaChave && move == false){
		move = true;
		$('#'+posicoes[0]).css({'z-index': '100'});
		$('#'+posicoes[1]).css({'z-index': '200'});
		$('#'+posicoes[2]).css({'z-index': '300'});
		
		chaveAtual++;
	
		
		$('#'+posicoes[1]).animate({top: posicoesPx[0]+'px'},700, function(){
			$(this).children('.jfs_load').html('');
		});
		$('#'+posicoes[1]+' .jfs_sobre').html('<span class="anterior">'+nomeslist[chaveAtual-1]+'</span>');
			$('#'+posicoes[1]+' .jfs_sobre').fadeIn(1000);
			
		
		$('#'+posicoes[2]).animate({top: posicoesPx[1]+'px'}, 700,function(){
			jf_loadTCI();
		});						
		
		$('#'+posicoes[0]).animate({top: posicoesPx[2]+'px'},{queue:false,duration:700});
			

			if(chaveAtual < ultimaChave)
				$('#'+posicoes[0]+' .jfs_sobre').html('<span class="proximo">'+nomeslist[chaveAtual+1]+'</span>');
			else
				$('#jfs-controle-bottom').fadeOut(500);
			
			
		posicoes = Array(posicoes[1], posicoes[2], posicoes[0]);
		$('#jfs-controle-top').fadeIn(500);
	}
}

function jfSliderAnterior(){
	if(chaveAtual > 0 && move == false){
		$('#'+posicoes[0]).css({'z-index': '200'});
		$('#'+posicoes[1]).css({'z-index': '200'});
		$('#'+posicoes[2]).css({'z-index': '100'});
		
		move = true;
		chaveAtual--;
		
		$('#'+posicoes[2]).animate({top: posicoesPx[0]+'px'},{queue:false,duration:700});
			if(chaveAtual > 0)
				$('#'+posicoes[2]+' .jfs_sobre').html('<span class="anterior">'+nomeslist[chaveAtual-1]+'</span>');
			else
				$('#jfs-controle-top').fadeOut(500);
			
		$('#'+posicoes[0]).animate({top: posicoesPx[1]+'px'}, 700,function(){
			jf_loadTCI();
		});
			
		$('#'+posicoes[1]).animate({top: posicoesPx[2]+'px'},700, function(){
			$(this).children('.jfs_load').html('');
		});	
		$('#'+posicoes[1]+' .jfs_sobre').html('<span class="proximo">'+nomeslist[chaveAtual+1]+'</span>');
			$('#'+posicoes[1]+' .jfs_sobre').fadeIn(1000);
			
		
		posicoes = Array(posicoes[2], posicoes[0], posicoes[1]);
		$('#jfs-controle-bottom').fadeIn(500);
	}
}

function jfSliderGoRight(){
	var width = imglist[chaveAtual].length*639;
	var left = parseInt($('#jfs_conteudo').css('left'));
	var validaPos = left-639;
	
	validaPos = validaPos%639 != 0 ? 639*parseInt(validaPos/639) : validaPos ;
	
	if(validaPos*-1 < width)
		$('#jfs_conteudo').animate({left: validaPos} , 300);
	else
		$('#jfs_conteudo').animate({left: 0} , 300);
}

function jfSliderGoLeft(){
	var width = imglist[chaveAtual].length*639;
	var left = parseInt($('#jfs_conteudo').css('left'));
	
	var validaPos = left+639;
	
	validaPos = validaPos%639 != 0 ? 639*parseInt(validaPos/639) : validaPos ;
	
	if(validaPos < 639)
		$('#jfs_conteudo').animate({left: validaPos} , 300);
	else
		$('#jfs_conteudo').animate({left: (width-639)*-1} , 300);
}

function jf_loadTCI(){	
	var htmlLoad = '<div id="jfs_conteudo" style="width: '+imglist[chaveAtual].length*639+'px">';
		for(x in imglist[chaveAtual]){
			htmlLoad += '<img src="uploads/tactos/'+pagLocal+'/'+imglist[chaveAtual][x]+'" />';
		}
	htmlLoad += '</div>';
	
	$('#'+posicoes[1]+' .jfs_load').html(htmlLoad);
	selecionaThumb(maplist[chaveAtual]);
	
	$('#'+posicoes[1]+' .jfs_sobre').fadeOut(1000);
	move = false;
}


/*****************************	MENU	*/
function tamanhoMenu(){
	var winW = $(window).width();
	var winH = $(document).height();
	
	var medida = ((winW - 960)/2)  + 180;

}

/*****************************	CARREGA	*/
$(document).ready(function(){
	tamanhoMenu();
});



/***************************************/
function array_search (needle, haystack, argStrict) {
    // Searches the array for a given value and returns the corresponding key if successful  
    // 
    // version: 1107.2516
    // discuss at: http://phpjs.org/functions/array_search    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
    // *     returns 1: 'surname'    // *     example 2: ini_set('phpjs.return_phpjs_arrays', 'on');
    // *     example 2: var ordered_arr = array({3:'value'}, {2:'value'}, {'a':'value'}, {'b':'value'});
    // *     example 2: var key = array_search(/val/g, ordered_arr); // or var key = ordered_arr.search(/val/g);
    // *     returns 2: '3'
    var strict = !!argStrict,        key = '';
    
    if (haystack && typeof haystack === 'object' && haystack.change_key_case) { // Duck-type check for our own array()-created PHPJS_Array
        return haystack.search(needle, argStrict);
    }    if (typeof needle === 'object' && needle.exec) { // Duck-type for RegExp
        if (!strict) { // Let's consider case sensitive searches as strict
            var flags = 'i' + (needle.global ? 'g' : '') +
                        (needle.multiline ? 'm' : '') +
                        (needle.sticky ? 'y' : ''); // sticky is FF only            needle = new RegExp(needle.source, flags);
        }
        for (key in haystack) {
            if (needle.test(haystack[key])) {
                return key;            }
        }
        return false;
    }
     for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            return key;
        }
    } 
    return false;
}
