var dom = function(s,c){
	if (c) return new dom(c).find(s);
	if (this==window) return new dom(s,c);
	if (s){
		if (s.constructor==String)
			return this.find(s,c);

		this.node = !s? []:s.constructor==Array?s:typeof s!="function"?[s]:this.ready(s);
	}
	if (this.node){
		this.length = 0;
		[].push.apply( this, this.node );
	}
	return this;
};
dom.fn = dom.prototype = {
	version:"1.0.1",
	node:null,
	length:0,
	ready:function(fn){
		dom(window).bind('load', fn);
	},
	find: function(select){
		select=select.split(" ",2);
		var s=select[0],s0=s.substring(0,1),n=this.node||[document];
		var d=new dom(s0=='#'? selectId(n) :
					s0=='.'? selectClass(n) :
					s0=='@'? selectAttr(n) :
					selectTag(n));

		if (select.length>1 && d.length){
			d=d.find(select[1]);
		}
		return d;

        function selectId(n){
			var nodes=[];
			s=s.substring(1);
			for (var i in n){select(n[i]);}
			function select(n){
                if (n.getElementById) nodes.push(n.getElementById(s));
				else{
				    if (n.id==s) nodes.push(n);
				    for ( var c = n.firstChild; c; c = c.nextSibling ){
					    if (c.tagName) select(c);
    				}
    		    }
			}
			return nodes;
        }
		function selectAttr(n){
			var nodes=[];
			s=s.substring(1).split("=");
			for (var i in n){select(n[i]);}
			function select(n){
				var a = n.getAttribute(s[0]); a=a?a.nodeValue:null;
				if (a && (s.length==1||a==s[1])) nodes.push(n);
				for ( var c = n.firstChild; c; c = c.nextSibling ){
					if (c.tagName) select(c);
				}
			}
			return nodes;
		};
		function selectClass(n){
			var nodes=[];
			s=s.substring(1);
			for (var i in n){select(n[i]);}
			function select(n){
				if (n.className==s) nodes.push(n);
				for ( var c = n.firstChild; c; c = c.nextSibling ){
					if (c.tagName) select(c);
				}
			}
			return nodes;
		};
		function selectTag(n){
			var nodes=[];
			for (var i in n){
				var e = n[i].getElementsByTagName(s);
				for (var j=0;j<e.length;j++)
					nodes.push(e[j]);
			}
			return nodes;
		};
	},
	hasClass:function(c){
		return this.node[0].className.indexOf(c)>=0;
	},
	parent:function(){
		return new dom(this.node[0].parentNode);
	},
	siblings:function(){
		var r = [],elem=this.node[0];
		for (var n=elem.parentNode.firstChild; n; n = n.nextSibling ) {
			if ( n.nodeType == 1 && n != elem )
				r.push( n );
		}return new dom(r);
	},
	css:function(k,v,n){
		for (var i in n=n==undefined?this.node:[this.node[n]]){
			if (v==undefined) return n[i].style[k];
			n[i].style[k]=v;
		}return this;
	},
	attr:function(k,v,n){
		for (var i in n=n==undefined?this.node:[this.node[n]]){
			if (v==undefined) return n[i].getAttribute(k);
			n[i].setAttribute(k,""+v);
		}return this;
	},
	// manipulation
	html: function(v) {
		if (v) this.node[0].innerHTML=v;
		return this.node[0].innerHTML;
	},
	append:function(elem){
		for (var i in this.node){
    	    this.node[i].appendChild(elem);
        }
        return this;
	},
	// form
	value:function(v){
		if (v) this.node[0].value=v;
		return this.node[0].value;
	},
	values:function(){
		var v={},n=this.find("type=text").node;
		for(var i in n){
			v[n[i].id]=n[i].value;
		}return v;
	},
	show: function(s,fn){
		return s? this.animate({height:1,width:1},s,fn):this.css("display","block");
	},
	hide: function(s,fn){
		return s? this.animate({height:-1,width:-1},s,fn):this.css("display","none");
	},
	slideDown: function(s,fn){
		return this.animate({height:1},s,fn);
	},
	slideUp: function(s,fn){
		return this.animate({height:-1},s,fn);
	},
	slideToggle: function(s,fn){
		return this.animate({height:0},s,fn);
	},
	fadeIn: function(s,fn){
		return this.animate({opacity:1},s,fn);
	},
	fadeOut: function(s,fn){
		return this.animate({opacity:-1},s,fn);
	},
	animate: function(prop,speed,fn){
		for (var i in this.node){
			var n=this.node[i],qid=dom.data.bind(n),q=dom.data.animate[qid],startq=!q||!q.length;
			if(startq){
				q=dom.data.animate[qid]=[];
			}
			q.push([function(n,q,v){
				var pc=0;
				for (var p in prop){
					pc++;
					(function(p,dir){
					var f=0,l=1,unit="",v=n.style.visibility,d=n.style.display,
					    h=v=="hidden"||d=="none"||!n.offsetHeight;

					if (dir<0&&h ||dir>0&&!h)
						return --pc?null:dequeue(n,q,1);
                    h=(dir<0||dir==0&&!h);
					var vn=n.style.visibility="hidden";
					var dn=n.style.display="block";
					if (/height|width/.test(p)){
						l=p=="height"? n.offsetHeight:n.offsetWidth;f=1;
						unit="px";
						d=h?"none":d="block";
					}
					else{
						l=n.style[p]||1;
						v=h?"hidden":"";
					}
					if(h) {f=l;l=0;dir=-1;};
					var s=f,o=n.style.overflow;if(o!=null)n.style.overflow="hidden";
					n.style[p]=s+unit;
					n.style.visibility="visible";
					var wait=speed=="fast"?10:!speed?20:speed=="slow"?30:speed/90;
					var step=(Math.abs(l-f)/wait)*(dir||1),i=setInterval(function(){
						s+=step;
						if (--wait<0||s<=0) {
							clearInterval(i);s=f>l?f:l;
							if (--pc==0){
								n.style.overflow=o;n.style.display=d;n.style.visibility=v;
								setTimeout(function(){dequeue(n,q,1);},0);
							}
						}
						n.style[p]=s+unit;
	    				if (p=="opacity" && dom.browser.msie)
            				n.style.filter = s==1?"":"alpha(opacity=" + parseInt(s * 100) + ")";
					},wait/2);
					})(p,prop[p]);		            
				}
			},n]);
			if(startq){
				dequeue(n,q,0)
			};
		}
		function dequeue(n,q,end){
			if (end) {
				q.shift();
				if (fn) fn.call(n);
			}
			if (q.length) {
				var qa=q.shift();
				q.unshift(qa);qa[0](qa[1],q,{});
			}
		}
		return this;
	}
}
var	undefined;
	
dom.extend=dom.fn.extend=function() {
	var prop,a=0;
	while (prop = arguments[a++])
		for ( var i in prop ) this[i] = prop[i];
}
dom.ua=navigator.userAgent.toLowerCase();

dom.extend({
	each: function( obj, fn) {
		if (!fn) {fn=obj;obj=this;}
		if ( obj.length == undefined )
			for ( var i in obj )
				fn.apply( obj[i], [i, obj[i]] );
		else
			for ( var i = 0, ol = obj.length; i < ol; i++ )
				if ( fn.apply( obj[i], [i, obj[i]] ) === false ) break;

		return this;
	},
	//browser:{(function x(){})[-5]=='x'?'FF3':(function x(){})[-6]=='x'?'FF2':/a/[-1]=='a'?'FF':'\v'=='v'?'IE':/a/.__proto__=='//'?'Saf':/s/.test(/a/.toString)?'Chr':/^function \(/.test([].sort)?'Op':'Unknown'},
	browser:{
		version: (dom.ua.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
		safari: /webkit/.test( dom.ua ),
		opera: /opera/.test( dom.ua ),
		msie: /msie/.test( dom.ua ) && !/opera/.test( dom.ua ),
		mozilla: /mozilla/.test( dom.ua ) && !/(compatible|webkit)/.test( dom.ua )
	},
	data:{
		uuid:0,
		event:{},
		animate:{},
		value:{},
		bind:function(obj){
			var id=obj["pdom"]=obj["pdom"]||++dom.data.uuid;
			return id;
		},
		unbind:function(obj){
			try {
				delete obj["pdom"];
			} catch(e){
				if ( obj.removeAttribute )
					obj.removeAttribute("pdom");
			}
			delete jQuery.cache[ id ];}
	},
	bind:function(obj,type,fn){
		var id=dom.data.bind(obj)+type+fn;
		var e=dom.data.event[id]={obj:obj,type:type,fn:null};
		if (obj.addEventListener){
			e.fn=function(e){
				if (!fn.apply(e.currentTarget,[e])){
					e.stopPropagation();e.preventDefault();
				}
			};
			obj.addEventListener( type, e.fn, false );
		}
		else if ( obj.attachEvent){
			e.fn=function(){
				var w={},we=window.event;w.currentTarget=obj;w.target=we.srcElement;
				if (!fn.apply(obj,[w])){
					we.cancelBubble=true;return false;
				}
			};
			obj.attachEvent( 'on'+type, e.fn);
		}
	},
	unbind:function( obj, type, fn) {
		if ( obj.detachEvent ) {
			obj.detachEvent( 'on'+type, fn );
		} else
			obj.removeEventListener( type, fn, false );
		dom.data.event[obj["pdom"]+type+fn] = null;
	}
});

dom.each(["prev","next"],function(i,o){
	dom.fn[o]=function(){var p=o+"Sibling";
		for (var n=this.node[0][p]; n; n = n[p] ) {
			if ( n.nodeType == 1)
				return new dom(n);
		}
		return this;
	}
})
.each(["bind","unbind"],function(i,o){
	dom.fn[o]=function(type, fn){
			for (var n in this.node){
				dom[o](this.node[n],type,fn);
		}
		return this;
	}
})
.each(("blur,focus,load,resize,scroll,unload,click,dblclick," +
	"mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
	"submit,keydown,keypress,keyup,error").split(","), function(i, o){
	dom.fn[o] = function(fn){
		return this.bind(o, fn);
	};
});

dom(window).bind("unload", function() {
	for (var o in dom.data.event){
		var e=dom.data.event[o];
		if (e) dom.unbind(e.obj,e.type,e.fn);
	};
	dom=null;
});

dom.extend({
	get:function(url,data,fn,type){
	    return dom.ajax({
			type:"GET",
			url:url,
			data:data,
			success:fn,
			dataType:type
	    });
	},
	getScript:function(url,fn) {
		return dom.get(url,null,fn,"script");
	},
	getJSON:function(url,data,fn) {
		return dom.get(url,data,fn,"json");
	},
	ajax:function(s){
		var xhr = window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
        xhr.open(s.type,s.url,true);
		if (s.data) xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xhr.setRequestHeader("If-Modified-Since","Thu, 01 Jan 1970 00:00:00 GMT" );
		xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
		xhr.onreadystatechange = function(){
		    var err=0;
			if (xhr.readyState == 4)try{
				var data=xhr.responseText;
				if (s.dataType=="json"){
					eval( "data = " + xhr.responseText);
					if (data.length==1) data = data[0];
				}
				else if (s.dataType=="script"){
			        var head = document.getElementsByTagName("head")[0] || document.documentElement,
				        script = document.createElement("script");

			        script.type = "text/javascript";
			        if (dom.browser.msie)
				        script.text = data;
			        else
				        script.appendChild(document.createTextNode(data));

			        head.insertBefore( script, head.firstChild );
			        head.removeChild( script );
				}

                err=!dom.httpSuccess(xhr);
				if (!err && s.success) s.success(data);
			    if (err&&s.error) s.error(err);

			    xhr=null;
		    }
			catch(err)
			{
			}
		}
		try {
			xhr.send(s.data);
		} catch(e) {
			
		}
		return xhr;
	},
	httpSuccess: function(xml) {
		try {
			return !xml.status ||
					( xml.status >= 200 && xml.status < 300 ) || xml.status == 304;
		} catch(e){}
		return false;
	},
	param: function( a ) {
		if (!a) return null;
		var s = [];
		// Serialize the key/values
		for ( var j in a )
			// If the value is an array then the key names need to be repeated
			if ( a[j] && a[j].constructor == Array )
				this.each( a[j], function(){
					s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
				});
			else
				s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );

		// Return the resulting serialization
		return s.join("&");
	}
});
dom.fn.extend({
	load:function(url,data,fn) {
	    url=url.split(" ");
	    var self=this;
	    return dom.get(url[0],data,function(data){
	        if (url[1]){
    	        var inner=dom(document.createElement("div")).html(data).find(url[1])[0];
    	        inner=null;
	        }
            self.html(url[1]?
                dom(document.createElement("div")).find(url[1])[0].outerHTML
                :data);
            if (fn) fn(data);
	    },"html");
	}
});
$ = dom;

