// JavaScript Document
function parametros(url){
	var ret = new Object;
	var pos = url.indexOf("?");
	if(pos > 0) {
		url = url.substring(pos+1,url.length);
		var arraux = url.split("&");
		for(var i = 0; i < arraux.length; i++){
			var biv = arraux[i].split("=");
			ret[biv[0]] = biv[1];
		}
	}
	return ret;
}

function goto(href,target,historial){
	var hash = href;
	hash = hash.replace(/^.*#/, '');
	hash = (hash && hash.indexOf('?') == -1) ? hash + "?incluido=1" : hash + "&incluido=1";
	target.load(hash);
	
	if(typeof historial === 'undefined'){
		hash = base64Encode(hash);
		$.history.load(hash);
	}
	
	return false;
}

function gotoPagina(href,historial){
	var hash = href;
	hash = hash.replace(/^.*#/, '');
	hash = (hash && hash.indexOf('') == -1) ? hash + "?incluido=1" : hash + "&incluido=1";
	var param = parametros(hash);
	
	//escape for ie
	if(!(typeof param['donothing'] === 'undefined')){
		//hash = base64Encode(hash);
		//$.history.load(hash);
		return false;
	}
	
	if(!(typeof param['avance'] === 'undefined')){
		param['pagina'] = parseInt(param['pagina'],10);
		param['avance'] = parseInt(param['avance'],10);

		if(param['avance'] > 0) param['pagina'] = pagina + 1;
		if(param['avance'] < 0) param['pagina'] = pagina - 1;
		if(param['pagina'] < 1) param['pagina'] = 1;
		if(param['pagina'] > param['upagina']) param['pagina'] = param['upagina'];
	}
	if(!(typeof param['pagina'] === 'undefined')){
		$('[id^="pagina_"]').hide();
		
		$('#pagina_' + param['pagina'] + ' img.foto_thumb').each(function(n){
			if(this.src != this.alt){
				this.src = this.alt;
			}
		} ) ;

		
		$('#pagina_' + param['pagina']).show('slow');
		pagina = parseInt(param['pagina'],10);
		$("#paginacion td.sel").removeClass("sel");
		$('#paginacion td.paginacion_' + param['pagina']).addClass("sel");
		$(document).scrollTop(125);
	}
	
	if(typeof historial === 'undefined'){
		hash = base64Encode(hash);
		$.history.load(hash);
	}
	return false;
}

function volver_ficha(){
	if(contenido.length == 0){
		history.go(-1);
	}else{
		$('#contenido').html(contenido.pop());
		$('#contenido').activateJFrame();
	}		
}

function copa_popup(url){
	window.open("popup.php?url="+url, "", "location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=1,height=200,width=200");
}

function foto_popup(url){
	window.open("popup_foto.php?url="+url, "", "location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=1,height=200,width=200");
}

function cargar_chica(pos){
	if (pos > uchica) pos = 0;
	if (pos < 0) pos = uchica;
	chica = pos;
	/*
	$.blockUI({ message: $('#superloading'), 
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: '.5', 
			color: '#fff' 
		}		
	}); 
	*/
	$('#contenido').html("<div class='loading'></div>");
	goto("ficha.php?chica_id=" + chicas[pos] + "&indice=" + pos,$('#contenido'),true);
	
}

function cargar_chica_id(xchica_id){
	/*
	$.blockUI({ message: $('#superloading'), 
		css: { 
			border: 'none', 
			padding: '15px', 
			backgroundColor: '#000', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: '.5', 
			color: '#fff' 
		}		
	}); 
	*/
	$('#contenido').html("<div class='loading'></div>");
	goto("ficha.php?chica_id=" + xchica_id + "&indice=1",$('#contenido'),true);	
}

function mensaje_s(txt){
	$('#txtaviso').html(txt);
	$('#txtaviso').stop().animate({top:0},'fast','linear');
}
function mensaje_h(){
	$('#txtaviso').stop().animate({top:-17},'fast','linear');	
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
