function ajax_error (msg, cls) {
	cls = cls || "error";
	this.addClass(cls).html(msg);
	return false;
}

function get_domain(url) {
	_url = url.toLowerCase(); 
    if (_url.indexOf("http://") >= 0) {
	    var _url = url.replace("http://", "");
	}
    if (_url.indexOf("/") >= 0) {
		var _domain_arr = _url.split("/");
		var _domain = _domain_arr[0];
	} else {
		var _domain = _url;
	}
	_domain = _domain.trim();
	_domain = _domain.replace(" ", "");
    return _domain;
}

(function( window, undefined ) {
	var T = function( type, data ) {
			
		};
	$.fn.extend({
		ac: function(cn) {
			cn = cn ? cn : "hover";
			this.addClass(cn);
			return this;
		},
		rc: function(cn) {
			cn = cn ? cn : "hover";
			this.removeClass(cn);
			return this;
		}
	});
	T.extend = $.extend;
	T.extend({
		prefix : "a5_quick_",
		history: function( type, append, options ) {
			type = this.prefix + type;
			options = $.extend( { expires:7, path: "/" }, options );
			
			var datas = $.cookie(type),
				items = datas ? datas.split("|") : [],
				cache = [];
			
			if(append !== undefined) {
				$.inArray(append, items) == -1  && items.push(append);
				items.length > 8 && items.shift();
				return $.cookie(type, items.join("|"), options);
			} 
			
			return items;
		},
		quick: function( type, selector ) {
			type = this.prefix + type;
			var datas = $.cookie(type),
				items = datas ? datas.split("|") : [];
				i = l = items.length, html = "";
				
			if( i ) {
				while( i ) {
					i--;
					html += '<li>' + items[i] + '</li>';
				}
				html = '<ul>' + html + '</ul>';
				
				var quick = $(selector || "#quick"),
					input = quick.siblings("input[name='q']");
				quick.html(html);
				!input.val() &&  input.val(items[l-1]);

				var list = $("ul li", quick),
					timeout;
				
				list.hover(
					function() {
						$(this).addClass("hover");
					}, 
					function() {
						$(this).removeClass("hover");
					}
				).click(function() {
					input.val($(this).html());
				});
				
				input.focus(function() {
					quick.fadeIn("fast");
				}).focusout(function(e) {
					timeout = setTimeout(function(){
						quick.fadeOut("fast");
					}, 101);		
				}).keydown(function(e) {
					if(e.keyCode == 38 || e.keyCode == 40) {
						var cur = list.filter(".hover"), act;
						if(e.keyCode == 40) {
							if(cur.length) {
								cur.rc();
								act = cur.next().ac();
							} else {
								act = list.first().ac();
							}
						} else {
							if(cur.length) {
								cur.rc();
								act = cur.prev().ac();
							} else {
								act = list.last().ac();
							}
						}
						input.val(act.html());
					}
				});
				
				
			}
		},
		jump: function(f, c, v) {
			var q = f.q.value,
				c = baseUrl + '/' + c + '/',
				v = v ? v.split(',') : [],
				i = v.length;
			f.b.disabled = true;
			window.location = c + q;
			return false;
		},
		forb: function(f, v) {
			f.b.disabled = true;
			if(v) {
				
			}
		},
		validate: {
			d: function() {
			},
			url: function() {
			}
		}
	});
	
	window.T = T;
})(window);

$.ajaxSetup({"timeout": 1000});

