//slimstat functions. This script use prototype.js, and prototype.js must be loaded before.

//filter submit load
function filterAjaxUpdater() {
	if ($("fi").value == ''){	alert('No Filter Resource'); } else {
		var url = $('slimstat_filter').action + "/panel.php?ajax=true";
		var pars = Form.serialize($('slimstat_filter'));
		new SlimLoading('slim_main', url, pars);
	}
}
//table reload
function tableAjaxUpdater(id, fi, t, len, me, p) {
	var el = "twraper_"+ t;
	var url = $('ajax_request').href + "/module.php?ajax=true&len=" + len;
	var pars = "panel="+p+"&ajt=true&moid="+ id + fi;
	if($('slm9').className.indexOf("slm_current") > -1) pars += "&feed=1";
	var c = new Array();
	c = document.getElementsByClassName("md_current", "module_" + t);
	for(i = 0; i < c.length; i++) {
		$(c[i]).className = $(c[i]).className.replace(" md_current", "");
	}
	new SlimLoading(el, url, pars);
	$(me).className += " md_current";
}
//panel(filtered) load
function SlimajaxUpdater(p,fi) {
	var me = $("slm" + p);
	var c = new Array();
	c = document.getElementsByClassName("slm_current", "slim_menu");
	for(i = 0; i < c.length; i++) {
		$(c[i]).className = $(c[i]).className.replace("slm_current", "slm");
	}
	var url = $('ajax_request').href + "/panel.php?ajax=true";
	var par = "panel=" + p + fi;
	new SlimLoading('slim_main', url, par);
	me.className = me.className.replace("slm", "slm_current");
}

//ajax request
var SlimLoading = Class.create();
SlimLoading.prototype = {
	initialize: function(el, url, par){
		this.url = url;
		this.par = par;
		this.tid = $(el);
		this.tid.fader = new fx.Opacity(this.tid, {duration: 200, onComplete: this.request.bind(this) });
		this.before();
	},
	before: function(){
		this.tid.fader.custom(0.99, 0.4);
		this.tid.parentNode.className = "slim_working";
	},
	request: function(){
		this.tid.fader.options.onComplete = this.reset.bind(this);
		new Ajax.Request(this.url, {method: 'get', parameters: this.par, onComplete: this.get.bind(this) });
	},
	get: function(request){
		this.tid.innerHTML = request.responseText;
		this.after();
	},
	reset: function(){
		this.tid.parentNode.className = "";
	},
	after: function(){
		this.tid.fader.custom(0.4, 0.99);
	}
};

//smooth navigation
function SmoothScroll(el) {
	new fx.Scroll({duration: 400, transition: fx.sineOut }).scrollTo(el); 
	return false;
}