document.timeBeforeLoadad = (new Date()).getTime();
var myLib = function (name) {
	return myLib_o.get(name);
}
myLib_o = function (name) {
	this._name = name;
	this.init();
};
myLib.Time = {
	Delta: null,
	snap: function (tos) {
		var oDelta = myLib.Time.Delta;
		if (tos == undefined) {
			var _delta = ((new Date()).getTime() - document.timeBeforeLoadad)/1000;
			var currentServerTime = document.timeOnServer + _delta;
		} else {
			var currentServerTime = tos;
		}
		myLib.Time.Delta = Math.round(parseFloat(jQuery.now()/1000 - currentServerTime)*1000)/1000;
		if (oDelta != null) myLib.Time.Delta = (myLib.Time.Delta+oDelta)/2;
	},
	now: function () {
		if (myLib.Time.Delta == null) return jQuery.now()/1000;
		return Math.ceil(jQuery.now()/1000 - myLib.Time.Delta);
	},
	nowFloat: function () {
		if (myLib.Time.Delta == null) return jQuery.now()/1000;
		return (jQuery.now()/1000 - myLib.Time.Delta);
	},
	milis: function() {
		if (myLib.Time.Delta == null) return jQuery.now();
		return (jQuery.now() - myLib.Time.Delta*1000);
	}
};
myLib.base = 'js/';
myLib.TemplateBase = 'skin/jpocker/styleImages/';
myLib.ready = false;
myLib.init = function () {
	jQuery(document).ready(function () {
		myLib.Time.snap();
		jQuery('script').each(function () {
			if (typeof(this.src) == 'string' && this.src.indexOf(myLib.base) != -1) {
				var name = this.src.substring(this.src.indexOf(myLib.base) + myLib.base.length);
				name = name.substring(0, name.length-3);
				myLib(name).isLoaded = true;
			}
		});
		myLib.ready = true;
	});
};
myLib_o.get = function (name) {
	if (typeof(this._register) != 'object') this._register = {};
	if (typeof(this._register[name]) == 'object') return this._register[name];
	else {
		this._register[name] = new myLib_o(name);
		this._register[name].init();
		return this._register[name];
	}
};
myLib_o.prototype = {
	init: function () {
		this.isLoaded = false;
		this.isLoading = false;
		this._timeout = null;
		this._queue = null;
		if (this._name != 'lib')
			this.path = myLib.base + this._name + '.js';
	},
	register: function () {
		this.isLoaded = true;
		this.isLoading = false;
	},
	load: function () {
		if (this._name == 'lib') {
			this.register();
			return true;
		}
		if (this.isLoading) return true;
		if (this.isLoaded) return true;
		try {
			this.isLoading = true;
			var self = this;
			var el = document.createElement('script');
			el.type = 'text/javascript';
			el.className = 'mylib-script';
			//el.onload = function () { self.isLoaded = true; self.isLoading = false; }
			document['body'].appendChild(el);
			el.src = this.path;
			return true;
		} catch (e) {
			this.isLoading = false;
			return false;
		}
	},
	require: function () {
		if (!this.isLoaded) {
			if (!myLib.ready) {
				var $this = this;
				jQuery(document).ready(function () { $this.load(); });
			} else if (myLib.ready) this.load();
		}
		return this;
	},
	exec: function (_callback, _context) {
		if (typeof(this._queue) != 'object' || this._queue == null) {
			this._queue = new Queue();
		}
		this.require();
		var $this = this;
		if (this.isLoaded == true && this._queue.isEmpty()) {
			if (this._name == 'swfobject') alert('loaded and running');
			_callback.apply(_context);
		} else {
			this._queue.enqueue({fn: _callback, context: _context});
			if (typeof(this._timeout) == 'number') {
				//alert(myLib('swfobject')._name + ':' + this._timeout + "\n\n" + this._name + ':' + this._timeout);
				clearInterval(this._timeout);
			}
			this._timeout = setInterval(function () {
				if ($this.isLoaded) {
					clearInterval($this._timeout);
					$this._timeout = 'none';
					var c = {};
					while (!$this._queue.isEmpty()) {
						try {
							c = $this._queue.dequeue();
							c.fn.apply(c.context);
						} catch (e) { }
					}
				}
			}, 100);
		}
		return this;
	}
}

myLib.init();
var SysMessages = {};
SysMessages.alert = function (msg) {alert(msg);};

var Queue = function () {
	this.queue = [];
	this.queueSpace = 0;
}
Queue.prototype = {
	getSize: function() { return this.queue.length - this.queueSpace; },
	isEmpty: function() { return (this.queue.length == 0); },
	enqueue: function(element) { this.queue.push(element); },
	dequeue: function() {
		var element = undefined;
		if (this.queue.length){
			element = this.queue[this.queueSpace];
			if (++this.queueSpace * 2 >= this.queue.length){
				this.queue = this.queue.slice(this.queueSpace);
				this.queueSpace=0;
			}
		}
		return element;
	},
	peek: function() {
		var element = undefined;
		if (this.queue.length) element = this.queue[this.queueSpace];
		return element;
	}
}
