function using(b, e) {
	b = (b || "").split(/\s*\.\s*/g);
	var a = window,
	h,
	g;
	for(var f = 0, c = b.length; f < c; f++) {
		g = b[f];
		if(h) {
			h += "." + g
		} else {
			h = g
		}
		if(!a[g]) {
			a[g] = {
			}
		}
		if(e !== true && !a[g].$name) {
			a[g].$name = h
		}
		a = a[g]
	}
	return a
}

(function(c) {
		var d = function(e) {
			return typeof e === "function"
		},
		a = function(e) {
			return Object.prototype.toString.apply(e) === "[object Array]"
		};
		function b() {
		}
		b.prototype = {
			find : function(l, k) {
				if(!l) {
					return
				}
				if(typeof l != "string") {
					this.obj = l
				} else {
					var h = l.split(/\s*\.\s*/g),
					e = k || window;
					for(var g = 0, f = h.length; g < f; g++) {
						if(e[h[g]]) {
							e = e[h[g]]
						} else {
							break
						}
					}
					if(g == f) {
						this.obj = e
					}
				}
				return this
			},
			run : function(e, f) {
				if(!f) {
					f = []
				}
				if(this.obj && a(f) && d(this.obj[e])) {
					this.obj[e].apply(this.obj, f)
				}
				return this
			},
			exec : function(e) {
				if(this.obj && d(e)) {
					e(this.obj)
				}
				return this
			},
			end : function() {
				delete this.obj;
				return this
			}
		};
		this.$O = function() {
			var e = new b();
			e.find.apply(e, arguments);
			return e
		};
		if(!c.Depender) {
			c.Depender = {
				Lib : {
				},
				Queue : [],
				isFunc : d,
				isArray : a,
				saveMemory : true,
				msgtype : {
					exists : "module exists:",
					need : "need module:",
					load : "load module:"
				},
				runlog : function(e, f) {
					$O("ConsoleSys").run("log", [this.msgtype[e] + f])
				},
				load : function(g, h) {
					var e = this.find(g),
					f = this;
					if(e.inited) {
						return
					}
					if(e.construct && d(e.construct)) {
						e.construct(using(g));
						e.inited = true;
						if(this.saveMemory) {
							delete e.construct
						}
						this.runlog("load", g);
						this.Queue.push(g)
					} else {
						this.runlog("need", g)
					}
				},
				find : function(e) {
					this.Lib[e] = this.Lib[e] || {
					};
					return this.Lib[e]
				},
				ModuleLoaded : function() {
				},
				AddModule : function(g, f) {
					var e = this.find(g);
					if(e.inited || e.construct) {
						return this.runlog("exists", g)
					}
					e.construct = f
				},
				Require : function(h, l) {
					var g = this,
					k = [];
					if(!a(h)) {
						return
					}
					for(var f = 0, e = h.length; f < e; f++) {
						this.load(h[f]);
						k.push(using(h[f]))
					}
					if(d(l)) {
						l.apply(this, k)
					}
				}
			}
		}
		c.Add = function(e, f, g) {
			if(d(f)) {
				g = f;
				f = []
			} else {
				f = f || []
			}
			if(f.length <= 0) {
				c.Depender.AddModule(e, function(h) {
						g(h);
						c.Ready(h.$name)
					})
			} else {
				c.Depender.AddModule(e, function(h) {
						c.Require(f, function() {
								var i = Array.prototype.slice.call(arguments);
								i.unshift(h);
								g.apply(null, i);
								c.Ready(h.$name)
							})
					})
			}
		};
		c.Require = function() {
			c.Depender.Require.apply(c.Depender, arguments)
		};
		c.Ready = function() {
			c.Depender.ModuleLoaded.apply(c.Depender, arguments)
		}
	})(using("AT"));
(function() {
		var b = {
			enable : true
		},
		c = window.location.href,
		a = function() {
		};
		b.open = function() {
			b.check = function() {
				if(!b.enable) {
					return true
				}
				if(window.console == undefined) {
					alert("This browser do not support console. ");
					b.enable = false;
					return true
				}
				return false
			};
			b.log = function() {
				if(b.check()) {
					return
				}
				console.log.apply(console, arguments)
			};
			b.logf = function() {
				if(b.check()) {
					return
				}
				console.debug.apply(console, arguments)
			};
			b.debug = function(d, e) {
				if(typeof d != "function" || !b.enable) {
					return
				}
				if(e) {
					d.apply(b, e)
				} else {
					d.apply(b)
				}
			}
		};
		b.close = function() {
			b.check = b.log = b.logf = b.debug = a
		};
		if(c.search(/debugmode/i) >= 0) {
			b.open()
		} else {
			b.close()
		}
		this.ConsoleSys = b
	})();
AT.Add("AT.UI", function(a) {
		a.clsBase = new Class({
				Implements : [Options, Events],
				options : {
					cont : "",
					autoDestroy : true
				},
				initialize : function(b) {
					this.setOptions(b);
					this._init(this.options)
				},
				_init : function(b) {
					this.cont = $(b.cont);
					if(b && b.initialize) {
						b.initialize.call(this)
					}
					if(this.build) {
						this.build(b)
					}
					if(b.autoDestroy) {
						window.addEvent("beforeunload", this.destroy.bind(this))
					}
				},
				setEvent : $empty,
				attach : function() {
					this.setEvent("add")
				},
				detach : function() {
					this.setEvent("remove")
				},
				destroy : function() {
					if(this.detach) {
						this.detach()
					}
				},
				els : function(b) {
					if(this.cont) {
						return this.cont.getElements(b)
					} else {
						return $$(b)
					}
				}
			});
		a.create = function(c, b) {
			return function(e, d) {
				return new b[c]($merge({
							name : e,
							cont : e + "cont"
						}, d))
			}
		}
});


AT.Add('MooTools.More.Fx.Scroll',function($ns){
	Fx.Scroll = new Class({
		Extends: Fx,
		options: {
			offset: {x: 0, y: 0},
			wheelStops: true
		},
	
		initialize: function(element, options){
			this.element = this.subject = document.id(element);
			this.parent(options);
			var cancel = this.cancel.bind(this, false);
	
			if ($type(this.element) != 'element') this.element = document.id(this.element.getDocument().body);
	
			var stopper = this.element;
	
			if (this.options.wheelStops){
				this.addEvent('start', function(){
					stopper.addEvent('mousewheel', cancel);
				}, true);
				this.addEvent('complete', function(){
					stopper.removeEvent('mousewheel', cancel);
				}, true);
			}
		},
	
		set: function(){
			var now = Array.flatten(arguments);
			if (Browser.Engine.gecko) now = [Math.round(now[0]), Math.round(now[1])];
			this.element.scrollTo(now[0], now[1]);
		},
	
		compute: function(from, to, delta){
			return [0, 1].map(function(i){
				return Fx.compute(from[i], to[i], delta);
			});
		},
	
		start: function(x, y){
			if (!this.check(x, y)) return this;
			var scrollSize = this.element.getScrollSize(),
				scroll = this.element.getScroll(), 
				values = {x: x, y: y};
			for (var z in values){
				var max = scrollSize[z];
				if ($chk(values[z])) values[z] = ($type(values[z]) == 'number') ? values[z] : max;
				else values[z] = scroll[z];
				values[z] += this.options.offset[z];
			}
			return this.parent([scroll.x, scroll.y], [values.x, values.y]);
		},
	
		toTop: function(){
			return this.start(false, 0);
		},
	
		toLeft: function(){
			return this.start(0, false);
		},
	
		toRight: function(){
			return this.start('right', false);
		},
	
		toBottom: function(){
			return this.start(false, 'bottom');
		},
	
		toElement: function(el){
			var position = document.id(el).getPosition(this.element);
			return this.start(position.x, position.y);
		},
	
		scrollIntoView: function(el, axes, offset){
			axes = axes ? $splat(axes) : ['x','y'];
			var to = {};
			el = document.id(el);
			var pos = el.getPosition(this.element);
			var size = el.getSize();
			var scroll = this.element.getScroll();
			var containerSize = this.element.getSize();
			var edge = {
				x: pos.x + size.x,
				y: pos.y + size.y
			};
			['x','y'].each(function(axis) {
				if (axes.contains(axis)) {
					if (edge[axis] > scroll[axis] + containerSize[axis]) to[axis] = edge[axis] - containerSize[axis];
					if (pos[axis] < scroll[axis]) to[axis] = pos[axis];
				}
				if (to[axis] == null) to[axis] = scroll[axis];
				if (offset && offset[axis]) to[axis] = to[axis] + offset[axis];
			}, this);
			if (to.x != scroll.x || to.y != scroll.y) this.start(to.x, to.y);
			return this;
		},
	
		scrollToCenter: function(el, axes, offset){
			axes = axes ? $splat(axes) : ['x', 'y'];
			el = $(el);
			var to = {},
				pos = el.getPosition(this.element),
				size = el.getSize(),
				scroll = this.element.getScroll(),
				containerSize = this.element.getSize(),
				edge = {
					x: pos.x + size.x,
					y: pos.y + size.y
				};
	
			['x','y'].each(function(axis){
				if(axes.contains(axis)){
					to[axis] = pos[axis] - (containerSize[axis] - size[axis])/2;
				}
				if(to[axis] == null) to[axis] = scroll[axis];
				if(offset && offset[axis]) to[axis] = to[axis] + offset[axis];
			}, this);
			if (to.x != scroll.x || to.y != scroll.y) this.start(to.x, to.y);
			return this;
		}
	
	});

});



(function (a) {
	var d = "http://",
	b = "asktest.com",
	c = {
		root : d + b,
		www : d + "www." + b,
		user : d + "user." + b,
		imgCode : d + "check." + b + "/checkEncodeCodes",
		js : d + "js." + b,
		image : d + "image." + b
	};
	$each(c, function (f, e) {
			a[e] = f;
			a["_" + e] = f.replace(/^http(s?):\/\//i, "")
		})
})(using("AT.Urls"));

AT.Add("AT.UI.Editor", ["AT.UI"], function($ns, UI){
	$ns.clsEditor = new Class({
		Extends:UI.clsBase,
		options: {
			cont: '#editor',
			buttons: ['url','html','js','css','img'],
			altinfo: ['插入URL: [url]http://url[/url] 或 [url=http://url]URL文字[/url]']
		},
		build: function(opt){
			this.cont = document.getElement(opt.cont);
			this.codeArr = [];
			this.bound = {
				click : this.addUbb.bindWithEvent(this),
				mouseover: this.showInfo.bindWithEvent(this),
				keyup: this.preview.bind(this)
			};
			this.addButton();
			
			this.attach();
			
		},
		addButton: function(){
			var self = this, 
				opt = self.options,
				toolbar = this.toolbar = new Element('div', {'id': 'toolbar',class:'clearfix'}),
				infobar = this.infobar = new Element('div', {
					'id': 'infobar',
					'text': '提示：选择您需要装饰的文字, 按上列按钮即可添加上相应的标签'
				});
			toolbar.inject(self.cont, 'before');
			infobar.inject(self.cont, 'before');
			

			opt.buttons.each(function(item, index){
				var ele = new Element('a', {
					'class': item,
					'html': '<span>'+item+'</span>',
					'title': '插入' + item + '代码',
					'name': opt.altinfo[index] 
							|| '插入' + item + '代码: [code=' + item + ']...[/code]'
				});
				ele.inject(self.toolbar);
			});
		},
		setEvent: function(add){
			var e = add + 'Event',
				bound = this.bound;
			this.toolbar[e]('click', bound.click);
			this.toolbar[e]('mouseover', bound.mouseover);
			this.cont[e]('keyup', bound.keyup);
		},
		attach: function(){
			this.setEvent('add');
		},
		showInfo: function(e){
			var ele = document.id(e.target),
				info = ele.get('name');
			if(info){
				this.infobar.set('html', info);
			}
		},
		preview: function(){
			var text = this.ubb();
			$('precontent').set('html', text);
		},
		addUbb: function(e){
			var ele = document.id(e.target),
				info = ele.get('class') || ele.getParent().get("class");
			if(!info) return;
			switch (info){
			case 'url' :
				this.wrapSelection('['+info+']','[/'+info+']');
			break;
			default:
				this.codeArr.include(info);
				this.wrapSelection('[code='+info+']','[/code]');
			break;
			};
			$('editor').fireEvent('keyup');
		},
		getSelection:function(){
			if(!!document.selection)
			return document.selection.createRange().text;
			else if(!!this.cont.setSelectionRange)
			return this.cont.value.substring(this.cont.selectionStart,this.cont.selectionEnd);
			else
			return false;
		},
		replaceSelection:function(text){
			var scrollTop=this.cont.scrollTop;
			if(!!document.selection){
			this.cont.focus();
			var old=document.selection.createRange().text;
			var range=document.selection.createRange();
			range.text=text;
			range-=old.length-text.length;
			}else if(!!this.cont.setSelectionRange){
			var selection_start=this.cont.selectionStart;
			this.cont.value=this.cont.value.substring(0,selection_start)+text+this.cont.value.substring(this.cont.selectionEnd);
			this.cont.setSelectionRange(selection_start+text.length,selection_start+text.length);
			}
			this.cont.focus();
			this.cont.scrollTop=scrollTop;
		},
		wrapSelection:function(before,after){
			this.replaceSelection(before+this.getSelection()+after);
		},
		cuturl: function(url){
			var length = 65;
			var urllink = '<a href="' + (url.toLowerCase().substr(0, 4) == 'www.' ? 'http://' + url : url) + '" target="_blank">';
			if (url.length > length) {
				url = url.substr(0, parseInt(length * 0.5)) + ' ... ' + url.substr(url.length - parseInt(length * 0.3));
			}
			urllink += url + '</a>';
			return urllink;
		},
		ubb: function(){
			var self = this, text = this.cont.get('value').replace(/\</g,'&lt;').replace(/\>/g,'&gt;');
		if(text.match(/\[(\w+)([^\[\]\s]*)\]([\s\S]+?)\[\/\1\]/)){
				text = text.replace(/\[url\]\s*(www.|https?:\/\/|ftp:\/\/|gopher:\/\/|news:\/\/|telnet:\/\/|rtsp:\/\/|mms:\/\/|callto:\/\/|bctp:\/\/|ed2k:\/\/){1}([^\[\"']+?)\s*\[\/url\]/ig, function ($1, $2, $3) {return self.cuturl($2 + $3);});
				text = text.replace(/\[url=www.([^\[\"']+?)\](.+?)\[\/url\]/ig, '<a href="http://www.$1" target="_blank">$2</a>');
				text = text.replace(/\[url=(https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k){1}:\/\/([^\[\"']+?)\]([\s\S]+?)\[\/url\]/ig, '<a href="$1://$2" target="_blank">$3</a>');
				
				text = text.replace(/\[code=(html|css|js){1}\]([\s\S]+?)\[\/code\]/igm,"<pre class=\"brush:$1;\">$2</pre>");
				text = text.replace(/\[code=img\]([\s\S]+?)\[\/code\]/igm,"<p class=\"center\"><img src=\"$1\"/></p>");
				
			}
			return text;
		}
	});

	$ns.create = UI.create('clsEditor',$ns);

});




var digg = function(rid, tid, ele){
	if(config.uid){
		if(ele.name=='digged'){
			alert('你已经咱过了！');
			return false;
		}
		new Request({
			method: 'post', 
			url: AT.Urls['www']+"/ajax/digg",
			onSuccess: function(msg){
				var msg = eval("("+msg+")");
				if(msg['error']){
					alert(msg['msg']);
				} else {
					var pre = ele.previousSibling,text=parseInt(pre.innerHTML);
					pre.innerHTML = text+1;
					alert(msg['msg']);
					ele.name = 'digged';
				}
			}
		}).send("resource_id=" + rid +"&resource_type="+tid);
	} else {
		location.href="http://www.asktest.com/login/";
	}
}



















