(function() {
        var DomReady = window.DomReady = function(w, fn) {
                return new DomReady.prototype.init(w, fn);
        }

        DomReady.prototype = {
                init : function(w, fn) {
                        var d = w.document, D = 'DOMContentLoaded', u = w.navigator.userAgent.toLowerCase(), v = parseFloat(u.match(/.+(?:rv|it|ml|ra|ie)[\/: ]([\d.]+)/)[1]);

                        function init(e) {
                                if (!document.loaded) {
                                        document.loaded = true;
                                        // pass a fake event if needed
                                        fn((e.type && e.type == D) ? e : {
                                                type: D,
                                                target: d,
                                                eventPhase: 0,
                                                currentTarget: d,
                                                timeStamp: +new Date,
                                                eventType: e.type || e
                                        });
                                }
                        }

                        // safari < 525.13
                        if (/webkit\//.test(u) && v < 525.13) {

                                (function () {
                                        if (/complete|loaded/.test(d.readyState)) {
                                                init('khtml-poll');
                                        } else {
                                                setTimeout(arguments.callee, 10);
                                        }
                                })();

                        // internet explorer all versions
                        } else if (/msie/.test(u) && !w.opera) {

                                d.attachEvent('onreadystatechange',
                                        function (e) {
                                                if (d.readyState == 'complete') {
                                                        d.detachEvent('on'+e.type, arguments.callee);
                                                        init(e);
                                                }
                                        }
                                );
                                if (w == top) {
                                        (function () {
                                                try {
                                                        d.documentElement.doScroll('left');
                                                } catch (e) {
                                                        setTimeout(arguments.callee, 10);
                                                        return;
                                                }
                                                init('msie-poll');
                                        })();
                                }

                        // browsers having native DOMContentLoaded
                        } else if (d.addEventListener &&
                                (/opera\//.test(u) && v > 9) ||
                                (/gecko\//.test(u) && v >= 1.8) ||
                                (/khtml\//.test(u) && v >= 4.0) ||
                                (/webkit\//.test(u) && v >= 525.13)) {

                                d.addEventListener(D,
                                        function (e) {
                                                d.removeEventListener(D, arguments.callee, false);
                                                init(e);
                                        }, false
                                );

                        // fallback to last resort for older browsers
                        } else {
                                // from Simon Willison
                                var oldonload = w.onload;
                                w.onload = function (e) {
                                        init(e || w.event);
                                        if (typeof oldonload == 'function') {
                                                oldonload(e || w.event);
                                        }
                                };
                        }
                }
        }
})();

(function() {

        var Xhr = window.Xhr = function( options ) {
                return new Xhr.prototype.httpRequest( options );
        };

        if( typeof XMLHttpRequest === "undefined" ) {
                XMLHttpRequest = function() {
                        return new ActiveXObject(
                                ( navigator.userAgent.indexOf("MSIE 5") >= 0 ) ? "Microsot.XMLHTTP" : "Msxml2.XMLHTTP"
                        );
                }
        };

        function serializeData( data ) {

                var serialized = [];

                if( data.constructor == Array ) {
                        for( var i=0, j=data.length; i<j; i++ )
                                serialized.push( data[i].name + "=" + encodeURIComponent( data[i].value ) );
                } else {
                        for( var k in data )
                                serialized.push( k + "=" + encodeURIComponent( data[k] ) );
                }

                return serialized.join("&");
        };

        function httpData( req, type ) {

                var contentType = req.getResponseHeader("Content-Type");
                var data = !type && contentType && contentType.indexOf("xml") >= 0;

                data = type == "xml" || data ? req.responseXML : req.responseText;

                if( type === "script" ) {
                        eval.call( window, data );
                } else if ( type === "json" ) {
                        data = eval("(" + data + ")");
                } else if ( type === "html" ) {
                        var tempDiv = document.createElement("div");
                        tempDiv.innerHTML = data;
                        data = tempDiv.firstChild;
                        tempDiv = null;
                }

                return data;

        };

        function httpSuccess( req ) {

                try {
                        return !req.status && location.protocol === "file:" ||
                                ( req.status >= 200 && req.status < 300 ) ||
                                req.status === 304 ||
                                navigator.userAgent.indexOf("Safari") >= 0 && typeof req.status === "undefined";
                } catch(e) {}

                return false;
        };

        Xhr.prototype = {

                httpRequest: function( options ) {

                        var options = {
                                async: options.async || true,
                                cache: options.cache === false ? false : true,
                                data: options.data || "",
                                method: options.method || "GET",
                                onComplete: options.onComplete || function() {},
                                onError: options.onError || function() {},
                                onSuccess: options.onSuccess || function() {},
                                timeout: options.timeout || 0,
                                type: options.type || "text",
                                url: options.url || ""
                        }

                        if( !!options.data && options.data.constructor == Array || options.data.constructor == Object ) options.data = serializeData( options.data );
                        if( !options.cache ) options.data = "_=" + new Date().getTime() + ((options.data.length > 0) ?  "&" + options.data : '');

                        var requestDone = false;
                        var requestUrl = ( options.method === "GET" && options.data ) ? options.url + "?" + options.data : options.url;
                        var sendData = ( options.method == "POST" ) ? options.data : null;
                        var xmlHttp = new XMLHttpRequest();

                        xmlHttp.open( options.method, requestUrl, options.async );

                        if( options.method === "POST" ) xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

                        xmlHttp.onreadystatechange = function() {
                                if( xmlHttp.readyState === 4 && !requestDone ) {
                                        if( httpSuccess( xmlHttp ) ) {
                                                options.onSuccess( httpData( xmlHttp, options.type ) );
                                        } else {
                                                options.onError();
                                        }
                                        options.onComplete();
                                        xmlHttp = null;
                                }
                        }

                        xmlHttp.send(sendData);
                        return xmlHttp;

                }

        }

})();

(function() {

	var Get = window.Get = {
                byId : function() {
                        var aEls = [], aIds = arguments[0].replace(/\s/g,'').split(',');
                        var i = 0, j = aIds.length;
                        if(j > 1) {
                                while(i<j) { aEls[aEls.length] = document.getElementById(aIds[i]); i++; }
                        } else var oEl = document.getElementById(arguments[i]);

                        return !!aEls.length ? aEls : oEl;
                },
                byTag : function() {
                        var aEls = [], aTagSet = [], aTags = arguments[0].replace(/\s/g,'').split(',');
                        var oContext = (!!arguments[1]) ? arguments[1] : document;
                        var i = 0, j = aTags.length;

                        if(j > 1) {
                                while(i < j) {
                                        aTagSet[i] = oContext.getElementsByTagName(aTags[i]);
                                        var k = 0, l = aTagSet[i].length;
                                        while(k < l) { aEls[aEls.length] = aTagSet[i][k]; k++; }
                                        i++;
                                }
                        } else {
                                aTagSet = oContext.getElementsByTagName(aTags[i]);
                                j = aTagSet.length;
                                while(i < j) { aEls[aEls.length] = aTagSet[i]; i++; }
                        }

                        return aEls;
                },
                byClass : function() {
                        var aEls = [], aTagSet = [];
                        var oContext = (!!arguments[2]) ? arguments[2] : document;
                        var sClass = arguments[0].replace(/\s/g,'').replace(/,/g,'|'), sTags = arguments[1] || "*";

                        aTagSet = (sTags ==  "*" && oContext.all) ? oContext.all : Get.byTag(sTags, oContext);

                        var i = 0, j = aTagSet.length;
                        while(i < j) {
                                if(aTagSet[i].className.search(sClass) >= 0) {
                                        aEls[aEls.length] = aTagSet[i];
                                }
                                i++;
                        }

                        return aEls;
                }
        }

})();

(function() {

        var _uid = 1;

        function fixEvent(e) {
                e.preventDefault = fixEvent.preventDefault;
                e.stopPropagation = fixEvent.stopPropagation;
                return e;
        };

        fixEvent.preventDefault = function() {
                this.returnValue = false;
        };

        fixEvent.stopPropagation = function() {
                this.stopPropagation = true;
        };

        function handleEvent(e) {
                var returnVal;
                e = e || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);

                var aFns = this.events[e.type];
                for(var i in aFns) {
                        this._handleEvent = aFns[i];
                        returnValue = this._handleEvent(e);
                        if(returnValue === false) break;
                }

                return returnValue;
        };

	var Events = window.Events = {
		add : function(el, type, fn) {
			if(el.addEventListener) {
				el.addEventListener(type, fn, false);
			} else {
				if(!fn.uid) fn.uid = _uid++;
				if(!el.events) el.events = {};

				var aFns = el.events[type];
				if(!aFns) {
					aFns = el.events[type] = {};
					if(el['on'+type]) alert('true');
				}

				aFns[fn.uid] = fn;
				el['on'+type] = handleEvent;
			}
		},
		del : function(el, type, fn) {
			if(el.removeEventListener) {
				el.removeEventListener(type, fn, false);
			} else {
				if(el.events && el.events[type]) delete el.events[type][fn.uid];
			}
		}
	}

})();

(function() {

	var Load = window.Load = {
		script : function( options ) {
                        var _sId = options.id || '';
			var _sUrl = options.url || '';
			var _fn = options.onload || function() {};

			var _oEl = _sId.length > 1 ? Get.byId(_sId) : Get.byTag('head')[0];
		        var _oScript = document.createElement('script');
			_oScript.setAttribute('type','text/javascript');
			_oScript.setAttribute('src', _sUrl);

			_oEl.appendChild(_oScript);

			if(/MSIE/.test(navigator.userAgent)) {
				_oScript.onreadystatechange = function() {
					if(_oScript.readyState == 'loaded' || _oScript.readyState == 'complete') _fn();
				}
			} else {
				_oScript.onload = function() {
					_fn();
				}
			}
		}
	}

})();

