( function() {
	var $UI = window.$UI = function(JSON) {
		return new $UI.effect(JSON);
	}
	$UI.effect = function(JSON) {
		// effect's type, currently supports focus and tabs;
		this.type = JSON.type;

		// tabs
		this.tabId = JSON.tabId || JSON.id;
		if (JSON.tabClass) {
			this.tabs = $UI.fn.getByClass(JSON.tabClass,this.tabId);
		} else {
			this.tabs = document.getElementById(this.tabId)
					.getElementsByTagName(JSON.tabTn || 'li');
		}

		// cons
		this.conId = JSON.conId || JSON.id;
		if (JSON.conClass) {
			this.cons = $UI.fn.getByClass(JSON.conClass, this.conId);
		} else {
			this.cons = document.getElementById(this.conId)
					.getElementsByTagName(JSON.conTn || 'div');
		}

		// start from??
		this.current = JSON.current || 0;

		// remember the className;
		this.cn = [];

		// check if the number of tabs equals of the cons;
		if (this.tabs.length != this.cons.length) {
			throw new Error("Match Failed");
			return;
		} else
			this.levels = this.tabs.length;

		var obj = this;
		for (var i = 0,l=this.levels;i<l;i++){
			( function() {
				var b = i;
				obj.cn[i] = obj.tabs[i].className;
				obj.tabs[i]['on'+(JSON.eType||'mouseover')] = function() {
					obj.current = b;
					clearTimeout(obj.run);
					obj.run = setTimeout(obj.start, 10);
				}
			})()
		}
		this.interval = JSON.interval || 3000;
		(this.start = function() {
			if (obj.current >= obj.levels)
				obj.current = 0;
			if (obj.current < 0)
				obj.current = obj.levels - 1;
			for (var i=0,l=obj.levels;i<l;i++){
				obj.tabs[i].className = (obj.current == i) ? obj.cn[i]+' current' : obj.cn[i];
				obj.cons[i].style.display = (obj.current == i) ? 'block' : 'none';
			}
			if(obj.type=='focus'){
				obj.current++;
				obj.run = setTimeout(obj.start, obj.interval)
			}
		})()
	}
	$UI.fn={
		hasClass : function(val, elem) {
			var re = new RegExp("(^|\\s)" + val + "(\\s|$)");
			if (re.test(elem.className))
				return true;
		},
		getByClass : function(cla, elem) {
			var ret = [],elem=document.getElementById(elem)||document,els=elem.getElementsByTagName('*');
			for ( var i = 0, l =els.length ; i < l; i++) {
				if ($UI.fn.hasClass(cla, els[i]))
					ret.push(els[i]);
			}
			return ret;
		}
	}
})()