window.addEvent('domready', function(){
	var g = $('dindex');
	if(g)
	{
		var as=g.getElements("a");
		$each(as,function(a){
			a.addEvent('click', function(){
				getLst(this.innerHTML,1);
				return false;
			});
		});
	}
	if($('dfontlist')){
	var lis = $('dfontlist').getElements("li");
	if(lis.length > 12)
		$('dfontlist').style.overflowY = 'scroll';

	$('dfontlist').addEvent('mouseleave', function(){
		if(_ise)	_ise.className = '';
	});
	}
	if($('oimgs'))
	$('oimgs').addEvent('mouseleave', function(){
		if(_irse)	_irse.className = '';
	});
});

_ise=null;
function iselect(id)
{
	var fx = new Fx.Scroll($('dimgs'),{duration:300, onComplete:sadd.pass(e)});
	if(_ise)	_ise.className = '';
	var e = $('i'+id);
	if(e){
		e.className = 'iselect';
		_ise = e;
		fx.scrollTo(0, e.getPosition().y - 340 + (window.ie ? - 20 : 0));
	}
}
var _mad=false;
function sadd(e)
{
	(function(){
		if(!_mad)
		{
			_mad=true;
			var fx = new Fx.Styles('dad', {duration: 200, transition: Fx.Transitions.Cubic.easeOut, onComplete:function(){_mad=false}});
			fx.start({'top': [$('dad').style.top, e.getSize().scroll.y]});
		}
	}).delay(1);
}
_irse=null;
function irselect(id)
{
	var nid=id.substr(1,id.length)
	if(_irse)	_irse.className = '';
	var e = $(nid);
	if(e){
		e.className = 'iselect';
		_irse = e;
		var fx = new Fx.Scroll($('dfontlist'),{duration:300});
		fx.scrollTo(0, e.getPosition().y - 340 + (window.ie ? - 20 : 0));
	}
}

function getLst(l,p)
{//loadings
	_lastquery = new Array(l, p);
	var data = "page=" + p;
	new Ajax('/dyn/list/'+l, {
	method: 'post',
	data: data,
	onComplete: function(htm){
		$('dfontlist').innerHTML = htm;
		$('dfontlist').style.overflowY = 'hidden';}
	}).request();

	new Ajax('/dyn/pics/'+l, {
	method: 'post',
	data: data,
	onComplete: function(htm){
		$('oimgs').innerHTML = htm;
		var fx = new Fx.Scroll($('dimgs'),{duration:700});
		fx.toTop();
		}
	}).request();

	new Ajax('/dyn/pages/'+l, {
	method: 'post',
	data: data,
	onComplete: function(htm){
		$('dpagesnum').innerHTML = htm;
		$('dpages').style.display = 'block';
	}
	}).request();
	return false;
}

function getTTF(i){
	new Ajax('/dyn/'+i, {
	method: 'get',
	onComplete: function(htm){
		if(htm != "")	document.location = htm;
	}
	}).request();
	return false;
}

_lastquery=null;
_strproc = "";
function fsrch(){
	if($('iquery') && $('iquery').value != "")
	{
		if(_strproc != "")
			_strproc = $('perror').innerHTML
		$('perror').style.display = 'block';
		$('perror').className = 'loading';
		$('perror').innerHTML = _strproc;

		var data = "query=" + $('iquery').value;
		new Ajax('/dyn/qlist/process', {
		method: 'post',
		data: data,
		onComplete: function(htm){
			if(htm.substring(0,1)!="0")
			{
				$('dfontlist').innerHTML = htm;
				$('dfontlist').style.overflowY = 'hidden';
				$('perror').style.display = 'none';
			}
			else
			{//not found
				$('perror').className = '';
				$('dfontlist').innerHTML = '';
				$('perror').innerHTML = htm.substring(1, htm.length);
			}
		}}).request();

		new Ajax('/dyn/qpics/process', {
		method: 'post',
		data: data,
		onComplete: function(htm){
			$('oimgs').innerHTML = htm;
			var fx = new Fx.Scroll($('dimgs'),{duration:700});
			fx.toTop();
			}
		}).request();
	}
}
