(function($) {

$.require = function(script) {
	var rootpath = '';
	var csspath = '';
	var jspath = '';
	var meta = document.all ? document.all.tags('META') :
		document.getElementsByTagName ?
		document.getElementsByTagName ('META') : new Array();

	if( meta.length ) {
		var len = meta.length;
		var i = 0;
		for ( ; i<len; i++) {
			if( meta[i].name == 'Document-Path' ) {
				var s = meta[i].content.replace(/\s*=\s*([a-z- _.\/]+|)(?=;|$)/gi, "='$1'"); // wrap quote
				eval(s);
			}
		}
	}

	document.write('<script type="text/javascript" src="'+rootpath+script+'"></script>');
};

$.Util = {

	ce: function(el) {
		return document.createElement(el);
	},

	gid: function(id) {
		return document.getElementById(id);
	},


	JSON2String: function(obj, options) {
		if( !obj ) return;
		var s = [];
		var settings = {};
		settings.html = options ? (options.html ? options.html : false) : false;
		var ln = function() {
			return settings.html ? '<br />' : "\n\t";
		}();
		switch( obj.constructor ) {
			case Object:
				s.push('{');
				s.push(ln);
				var t = [];
				for( var i in obj ) {
					t.push(i+': '+$.Util.JSON2String(obj[i], settings));
				}
				s.push(t.join(", "+ln), ln, '}');
				return s.join('');
			case Array:
				s.push('[');
				var t = [];
				for( var i in obj ) {
					t.push($.Util.JSON2String(obj[i], settings));
				}
				s.push(t.join(', '), ']');
				return s.join('');
			case String:
				return '"' + obj + '"';
			case Number:
				return obj;
			default:
				return;
		}
	},

	/**
	* extract paramters in element's attribute
	* <img lang="datefield='date1: Y-n-j'">
	*/
	getParam: function(el, attr, param) {
		var o, re, p;
		re = '(?:^|\\s)' + param + '=(?:\\\'|\\\")([^\\\"]+)(?:\\\'|\\\"|\\\'$)';
		//~ console.log('re: '+re);
		//~ console.log('el.getAttribute(attr): '+el.getAttribute(attr));
		p = el.getAttribute(attr).match(RegExp(re))[1];
		//~ console.log('p: '+p);
		o = p.match(/(?=[^:]\s*)([0-9a-z]+:)\s*([0-9a-zA-Z-+=._ ]+)(?=\s*,|\s*$)/gi); // match unwrap segment
		//~ console.log('o: '+o);
		if ( o ) {
			var i=0;
			var len = o.length;
			for( ; i<len; i++ ){
				//~ console.log('o['+i+']: '+o[i]);
				var s = o[i].replace(/:+\s*([0-9a-zA-Z-., _$@%\/]*)/gi, ":'$1'"); // wrap quote
				p = p.split(o[i]).join(s);
			}
		}
		eval('o = {' + p + '}');
		return o;
	},


	getMouseOffset: function(target, ev){
		ev = ev || window.event;

		var p0 = getPosition(target);
		var p1 = mouseCoords(ev);
		return {x:p1.x - p0.x, y:p1.y - p0.y};
	},



	getxy: function(n) {
		var _top, _left;
		_top = _left = 0;
		if( n.offsetParent )
		{
			_top = n.offsetTop;
			_left = n.offsetLeft;

			while( n.offsetParent ) {
				n = n.offsetParent;
				_top += n.offsetTop;
				_left += n.offsetLeft;
			}
		}
		return {top: _top, left: _left};
	}

}; // End of jQuery.Util declaration


$.Event = {

	/** Firefox uses event.target here, MSIE uses event.srcElement */
	getElement: function(ev) {
		return (ev.target || ev.srcElement);
	},

	mouseCoords: function(ev)
	{
		//~ console.log("document.body.clientTop:"+document.body.scrollLeft);
		if(ev.pageX || ev.pageY){ // Firefox
			return {x:ev.pageX, y:ev.pageY};
		}
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop - document.body.clientTop
		};
	}

}; // End of jQuery.Event declaration


$.UIObject = {


	getAbsoluteLeft: function( ob ) {

		if(!ob){return null;}
		var el = ob;
		var t = el.offsetLeft;
		while( el != null && el.offsetParent != null
			&& el.offsetParent.tagName != 'BODY' )
		{
			t += el.offsetParent.offsetLeft;
			el = el.offsetParent;
		}
		return t;

	},

	getAbsoluteTop: function( ob ) {

		if(!ob){return null;}
		var el = ob;
		var t = el.offsetTop;
		while( el != null && el.offsetParent != null
			&& el.offsetParent.tagName != 'BODY' )
		{
			t += el.offsetParent.offsetTop;
			el = el.offsetParent;
		}
		return t;

	},

	getAbsoluteSize: function (ob) {
		return {width:ob.offsetWidth, height:ob.offsetHeight};
	},

	setHeight: function (String) {
	}

}; // End of jQuery.UIObject declaration


/**
* MODULE - Class Extend
* Extend Class Further in scriptaculous wiki:
* http://wiki.script.aculo.us/scriptaculous/show/ExtendClassFurther
*/
$.Class = {
    // Creators
    create: function (proto)
    {
        /* Accepting prototype definition of the class.  Idea presented by Greg
         * Wiley: http://wiki.script.aculo.us/scriptaculous/show/ExtendClass
         */
        var klass = function ()
        {
            if (this.initialize && arguments.callee.caller != Class.extend)
            {
                this.__class__ = arguments.callee.prototype;
                Object.extend(this, Class.Methods);
                this.initialize.apply(this, arguments);
            }
        };
        klass.prototype = proto || {};
        klass.extend = Class.extend;
        return klass;
    },
    singleton: function (proto)
    {
        var klass =
        {
            instance: function ()
            {
                if (!this.__instance__)
                {
                    var klass = Class.create(proto);
                    this.__instance__ = eval('new klass');
                    proto = null;
                }
                return this.__instance__;
            }
        };
        return klass;
    },

    // Care-takers
    append_features: function (object, module)
    {
        for (var prop in module)
            if (Class.kind_of(module[prop], Function))
                (function (method)
                {
                    object[method] = function ()
                    {
                        return module[method].apply(object, arguments);
                    };
                })(prop);
            else
                object[prop] = module[prop];
    },
    extend: function (subobj)   // implementation of inheritance
    {
        /* Create an instance of the superclass.  This is necessary to maintain
         * a prototype chain correctly.
         */
        var subproto = new this;
        // Update it with the subclass definitions
        Object.extend(subproto, subobj);
        subproto.__super__ = this.prototype;
        return Class.create(subproto);
    },
    get_method: function (klass, args)  // obtain method name being called
    {
        var c = args.callee.caller;
        for (var method in klass)
            if (klass[method] == c)
                return method;
        return null;
    },
    call_super: function (superclass, self, method, args)
    {
        // NOTE: `self' should always refer to the object being instantiated
        if (superclass && superclass[method])
        {
            /* Make the next call of `this.SUPER()' in the superclass refer
             * farther up the class hierarchy */
            var __class__  = self.__class__;
            self.__class__ = superclass;
            self.__super__ = superclass.__super__;

            try
            {
                superclass[method].apply(self, args);
            }
            finally
            {
                // Restore values
                self.__class__ = __class__;
                self.__super__ = superclass;
            }
        }
    },
    kind_of: function (object, klass)
    {
        return eval('klass.prototype.isPrototypeOf(object)');
    }
}; // End of jQuery.Class namespace


/**
* Array extending
*/

var a = Array.prototype;
if (!a.push) {
	a.push = function() {
		for( var i = 0; arguments[i] !== undefined; i++ )
		{
			this[this.length] = arguments[i];
		}
		return this.length;
	};
}
delete a;


})(jQuery);
