var PbLib = {};
document.html	= document.getElementsByTagName('html').item(0);
document.head	= document.getElementsByTagName('head').item(0);
PbLib.get = function(e){(!pbDev || alert('PbLib.get() is no longer supported!'));return e;};
PbLib.getNewURI = (function ()
		{
			var scripts = document.getElementsByTagName('script');
			var match;

			PbLib.uriBase = '/';
			PbLib.langInfix = '';
			PbLib.self = {
					pathName: 'ui/uibase/script/pblib',
					fileName: 'pblib.js'
				};
			var re = new RegExp("^(.*)" + PbLib.self.pathName + "/" + PbLib.self.fileName + "(\\?.*)?$");
			for (var i = 0; i < scripts.length; i++) {
				match = scripts[i].src.match(re);
				if (match) {
					PbLib.uriBase = match[1] == '' ? '/' : match[1];
					var re = new RegExp('^' + PbLib.uriBase + '([a-z]/)?([a-z]{2})(/.*)?$');
					match = location.href.match(re);
					if (match) {
						PbLib.langInfix = match[2] + '/';
					}
					break;
				}
			}

			return function(path)
				{
					if (path) {
						path = path.replace(/^\/*/, '');
					} else {
						path = '';
					}

					var ret, match;
					ret = PbLib.uriBase;

					match = path.match(/^lt?\/(.*)$/);
					if (match) {
						ret += 'l/';
						path = match[1];
					}

					if (!path.match(/^(files|ui)\//)) {
						ret += PbLib.langInfix;
					}
					return ret + path;
				};
		})();
PbLib.topWindow = (function () {
	if (window.top) {
		return window.top;
	} else if (parent) {
		var win = parent;
		while (true) {
			if (!win.parent) break;
			win = win.parent;
		}
		return win;
	} else {
		return window;
	}
})();
PbLib.def = function(e)
	{(!pbDev || alert('PbLib.def() is no longer supported!'));
		return !((typeof e) == 'undefined');
	};
PbLib.log = function (e)
	{
		if (window.console) {
			if (window.console.log) {
				PbLib.log = window.console.log;
				return PbLib.log(e);
			}
		}

		PbLib.log = function (e)
			{
				if (true || !document.body) return alert(e.toString());
				document.body.appendChild(document.createElement('pre'))
					.appendChild(document.createTextNode(e.toString()))
			};
		return PbLib.log(e);
	};
PbLib.debug = function (e)
	{(!pbDev || alert('PbLib.debug() is no longer supported!'));
		if (window.console) {
			PbLib.debug = window.console.debug;
		} else {
			PbLib.debug = PbLib.log;
		}
		PbLib.debug(e);
	};
// single page notice bar
// noticeType: 'failure', 'success', 'neutral'
PbLib.notice = function (noticeClass, noticeText)
	{
		var contentElement = window.top.document.getElementById('content');
		if (!contentElement || !contentElement.parentNode) {
			return false;
		}

		// Check for existing spiNotices element and remove it
		var spiNotices = window.top.document.getElementById('spiNotices');
		if (spiNotices) {
			spiNotices.parentNode.removeChild(spiNotices);
			delete spiNotices;
		}

		var notice = window.top.document.createElement('ul');
		notice.setAttribute('id', 'spiNotices');
		var item = window.top.document.createElement('li');
		var text = window.top.document.createTextNode(noticeText)
		var closeButton = window.top.document.createElement('span');

		contentElement.parentNode.insertBefore(notice, contentElement.parentNode.firstChild);
		notice.appendChild(item);
		item.appendChild(text);
		item.appendChild(closeButton);
		closeButton.onclick = function() { notice.parentNode.removeChild(notice); }

		notice.className = 'notice singlepage ' + noticeClass;
		closeButton.className = 'closebutton';

		PbLib.fadeIn(notice, 0.05, 50);
		setTimeout(function() { PbLib.fadeOut(notice, 0.05, 50); }, 10000);
		setTimeout(function() {
			if (notice.parentNode) notice.parentNode.removeChild(notice);
		}, 12000);
	}
PbLib.types = ['Number', 'String', 'Function', 'Array', 'Object', 'Date', 'Boolean'];
for (var i = 0; i < PbLib.types.length; i++) {
	eval("PbLib.is" + PbLib.types[i] + " = function(a) { (!pbDev || alert('PbLib.is" + PbLib.types[i] + "() is no longer supported!'));return !(a.constructor.toString().indexOf('" + PbLib.types[i] + "') == -1); };");
}
PbLib.objectMerge = function(obj1, obj2, createNew)
	{(!pbDev || alert('PbLib.objectMerge() is no longer supported!'));
		var createNew = !!(createNew);
		var targetObj = createNew ? {} : obj1;

		if (typeof obj1 != 'object' || typeof obj2 != 'object') return targetObj;
		for (var p in obj2) {
			if (typeof obj1[p] == 'object' && typeof obj2[p] == 'object') {
				targetObj[p] = PbLib.objectMerge(obj1[p], obj2[p], createNew);
			} else {
				targetObj[p] = (typeof(obj2[p]) == 'object') ? PbLib.objectClone(obj2[p]) : obj2[p];
			}
		}
		for (var p in obj1) {
			if (typeof targetObj[p] == 'undefined') {
				targetObj[p] = (typeof(obj1[p]) == 'object') ? PbLib.objectClone(obj1[p]) : obj1[p];
			}
		}
		return targetObj;
	};
PbLib.objectClone = function(obj)
	{
		if (obj == null || typeof(obj) != 'object') return obj;

		var tObj = {};
		for (var k in obj) {
			tObj[k] = PbLib.objectClone(obj[k]);
		}
		return tObj;
	};
PbLib.ajaxCallQueue = [];
PbLib.ajaxRunning = false;
// Makes a (A)synchronous Javascript And XML HTTP request.
// @var url: a fully formed URL
// @options: an object containing any of these values:
// - async: the call should be asynchronous (the function waits for the http request to finish);
//   if this parameter is not defined, the function checks for callback functions; if these are found, async is true, otherwise false
// - method: 'GET' or 'POST' or such; default: 'GET'
// - funcSuccess: a function to be called when the async. request returns with OK; default: false
// - funcFailed: a function to be called when the async. request was aborted or did not return OK; default: false
// - returnType: the response will be returned as 'text' or 'xml'; default: 'text'
// - cache: allow the browser to cache the results: default: false
// - message: the contents of a POST request; may contain the requests variables in this form: number=133&category=16
// - parameters: parameters to be passed to the callback function
// If the function is called sync. the HTTP response will be returned, or false if something went wrong;
// If the function is called async. funcSuccess is called with the response as parameter, or funcFailed is case something went wrong
PbLib.ajax = function()
	{
	   var xmlhttp;
		try {
			xmlhttp = new XMLHttpRequest();
		}
		catch(e) {
			var msxml = [
				'MSXML2.XMLHTTP.3.0',
				'MSXML2.XMLHTTP',
				'Microsoft.XMLHTTP'
			];
			for ( var i=0, len = msxml.length; i < len; ++i ) {
				try {
					xmlhttp = new ActiveXObject(msxml[i]);
					break;
				}
				catch(e) {}
			}
		}
		var funcSuccess = function (response, parameters, func) {
				PbLib.ajaxRunning = false;
				PbLib.ajaxQueueProcess();
				if (func) return func(response, parameters);
			};
		var funcFailed = function (parameters, func) {
				PbLib.ajaxRunning = false;
				PbLib.ajaxQueueProcess();
				if (func) return func(parameters);
			};
		return function(url, options) {
			(!pbDev || alert('PbLib.ajax() is no longer supported!'));
			if (Object.isUndefined(options)) options = {};

			var returnValue = false;

			var method = !Object.isUndefined(options['method']) ? options['method'].toLowerCase() : 'get';
			var returnType = !Object.isUndefined(options['returnType']) ? options['returnType'].toLowerCase() : (method == 'head' ? 'headers' : 'text');
			var cache = !Object.isUndefined(options['cache']) ? options['cache'] : false;
			var message = !Object.isUndefined(options['message']) ? options['message'] : null;
			var parameters = !Object.isUndefined(options['parameters']) ? options['parameters'] : {};

			if (Object.isUndefined(options['funcSuccess'])) options['funcSuccess'] = false;
			else options['async'] = true;
			if (Object.isUndefined(options['funcFailed'])) options['funcFailed'] = false;
			else options['async'] = true;
			var async = !Object.isUndefined(options['async']) ? options['async'] : true;

			// While working with multiple windows (threads) it is possible to do an ajax call while another ajax call is running, set ajaxRunning to be able to prevent that
			if (PbLib.ajaxRunning) {
				if (async) {
					// throw on the ajax call queue
					if (PbLib.ajaxCallQueue.push([url, options]) > 5) {
						// Never keep more than 5 requests in the queue
						PbLib.ajaxCallQueue.shift();
					}
				}
				return false;
			}

			PbLib.ajaxRunning = true;

			xmlhttp.open(method, url, async);
			if (!cache) xmlhttp.setRequestHeader("If-Modified-Since", "Wed, 15 Nov 1995 04:58:08 GMT");
			if (method == 'post') xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			if (async) {
				xmlhttp.onreadystatechange = function() {
					if (xmlhttp.readyState == 4) {
						if (xmlhttp.status == 200 && xmlhttp.statusText == "OK" && funcSuccess) {
							if (returnType == 'text') funcSuccess(xmlhttp.responseText, parameters, options['funcSuccess']);
							else if (returnType == 'xml') funcSuccess(xmlhttp.responseXML, parameters, options['funcSuccess']);
							else if (returnType == 'headers') funcSuccess(PbLib.ajaxParseHeaders(xmlhttp.getAllResponseHeaders()), parameters, options['funcSuccess']);
						} else if (funcFailed) {
							funcFailed(parameters, options['funcFailed']);
						}
					}
				}
				xmlhttp.send(message);
			} else {
				xmlhttp.send(message);
				if (xmlhttp.status == 200 && xmlhttp.statusText == "OK") {
					if (returnType == 'text') returnValue = xmlhttp.responseText;
					else if (returnType == 'xml') returnValue = xmlhttp.responseXML;
					else if (returnType == 'headers') returnValue = PbLib.ajaxParseHeaders(xmlhttp.getAllResponseHeaders());
				}
				PbLib.ajaxRunning = false;
			}
			return returnValue;
		};
	}();
PbLib.ajaxQueueProcess = function ()
	{
		var ajaxArgs = PbLib.ajaxCallQueue.shift();
		if (ajaxArgs) {
			PbLib.ajax(ajaxArgs[0], ajaxArgs[1]);
		}
	};
PbLib.ajaxParseHeaders = function (headerString)
	{
		var lines = headerString.split('\n');
		var headers = new Array();
		for (var i=0; i<lines.length; i++) {
			var line = lines[i];
			var index = line.indexOf(':');
			headers[line.substring(0, index).toLowerCase()] = line.substr(index+1);
		}
		return headers;
	};
PbLib.guid = 1;
PbLib.getUniqId = function()
	{
		var idBase = 'pblibguid';
		var idBaseNum = 0;
		while (true) {
			var testElem = document.getElementById(idBase + (idBaseNum == 0 ? '' : idBaseNum) + '_1');
			if (!testElem) break;
			idBaseNum++;
		}
		idBase = idBase + (idBaseNum == 0 ? '' : idBaseNum) + '_';
		return function() { return idBase + (this.guid++); };
	}();
PbLib.escapeFrame = function ()
	{
		if(window != window.top) window.top.document.location.replace(document.location.href);
	};
PbLib.module = {};
PbLib.modules = {};
PbLib.curDate = new Date();
PbLib.cacheString = "" + (PbLib.curDate.getFullYear()) + (PbLib.curDate.getMonth() + 1) + (PbLib.curDate.getDate()) + (PbLib.curDate.getHours());
PbLib.module.load = function(modName)
	{
		if (Object.isArray(modName)) {
			var returnval = true;
			for (var i = 0; i < modName.length; i++) {
				returnval = returnval && PbLib.module.load(modName[i]);
			}
			return returnval;
		} else if (!Object.isString(modName)) {
			return false;
		}

		modName = modName.toLowerCase();
		if (Object.isUndefined(PbLib.modules[modName])) {
			PbLib.modules[modName] = {
					loaded: false,
					loading: true,
					dependencies: [],
					dependencyOf: []
				};
		} else if (PbLib.modules[modName].loaded) {
			// Module is loaded
			return true;
		} else if (PbLib.modules[modName].loading) {
			// Module is being loaded
			return true;
		}

		// Load module content
		new Ajax.Request(PbLib.getNewURI(PbLib.self.pathName + "/" + modName + '.js?' + PbLib.cacheString), {
			'evalJS'		: false,
			'method'		: 'get',
			'asynchronous'	: false,
			'onSuccess'		: function (transport)
				{
					if (transport.responseText) {
						eval(transport.responseText);
					}
				}
		});

		return PbLib.modules[modName].loaded;
	};

PbLib.module.loadDependencies = function(modName, dependencyString)
	{
		var modName = modName.toLowerCase();
		if (Object.isUndefined(PbLib.modules[modName])|| Object.isUndefined(PbLib.modules[modName].loaded) || (!PbLib.modules[modName].loading && !PbLib.modules[modName].loaded)) return false;

		var dependencies = dependencyString.toLowerCase().split(',');

		for (var i = 0; i < dependencies.length; i++) {
			PbLib.modules[modName].dependencies.push(dependencies[i]);
			if (PbLib.module.load(dependencies[i])) {
				PbLib.modules[dependencies[i]].dependencyOf.push(modName);
			} else {
				return false;
			}
		}

		return true;
	};
PbLib.module.setLoaded = function(modName)
	{
		modName = modName.toLowerCase();
		if (Object.isUndefined(PbLib.modules[modName])) {
			PbLib.modules[modName] = {
					loaded: true,
					loading: false,
					dependencies: [],
					dependencyOf: []
				};
		} else {
			PbLib.modules[modName].loading = false;
			PbLib.modules[modName].loaded = true;
		}
	};

// Event functions
PbLib.getTarget = function(event)
	{(!pbDev || alert('PbLib.getTarget() is no longer supported!'));
		if (typeof event.srcElement != 'undefined') return event.srcElement;
		if (typeof event.target) return event.target;
		else return null;
	};
// a counter used to create unique IDs
PbLib.attachEventGuid = 1;
PbLib.attachEventCache = {};
PbLib.attachEvent = function(element, type, handler, prepend)
	{(!pbDev || alert('PbLib.attachEvent() is no longer supported!'));
		var prepend = !!(prepend);
		type = type.replace(/^on/, '');

		if (!element || !type || !handler) return false;

		// assign each event handler a unique ID
		if (!handler.$$guid) handler.$$guid = PbLib.attachEventGuid++;
		// assign each object a unique ID
		if (!element.$$guid) element.$$guid = PbLib.attachEventGuid++;
		// create a hash table of event types for the element
		if (!PbLib.attachEventCache[element.$$guid]) PbLib.attachEventCache[element.$$guid] = {};
		// create a hash table of event handlers for each element/event pair
		if (!PbLib.attachEventCache[element.$$guid][type]) PbLib.attachEventCache[element.$$guid][type] = {};

		var handlers = PbLib.attachEventCache[element.$$guid][type];
		if (!element.PbLibHandlers) element.PbLibHandlers = {};
		if (!element.PbLibHandlers[type]) {
			if (element["on" + type]) {
				handlers[0] = element["on" + type];
				handlers[0].$$guid = 0;
			}
			// assign a global event handler to do all the work
			element["on" + type] = function(event){
				if (typeof PbLib == 'undefined') return true;
				else return PbLib.handleEvent(event, this);
			};
			element.PbLibHandlers[type] = true;
		}
		// store the event handler in the hash table
		if (prepend) {
			var oldHandlers = handlers;
			handlers = {};
			handlers[handler.$$guid] = handler;
			for (var h in oldHandlers) {
				handlers[h.$$guid] = h;
			}
			delete h;
			delete oldHandlers;
		} else {
			handlers[handler.$$guid] = handler;
		}
	};

PbLib.detachEvent = function(element, type, handler)
	{(!pbDev || alert('PbLib.detachEvent() is no longer supported!'));
		if (!element || !type || !handler) return false;

		type = type.replace(/^on/, '');

		if (!element.$$guid || !handler.$$guid) {
			return true;
		}

		// delete the event handler from the hash table
		if (PbLib.attachEventCache[element.$$guid] && PbLib.attachEventCache[element.$$guid][type]) {
			delete PbLib.attachEventCache[element.$$guid][type][handler.$$guid];
		}
	};

PbLib.handleEvent = function(event, elem)
	{(!pbDev || alert('PbLib.handleEvent() is no longer supported!'));
		var returnValue = true;

		// grab the event object (IE uses a global event object)
		event = event || window.event;
		// Only handle events for elements for which events have been set using attachEvent
		if (!elem.$$guid) return true;
		if (typeof PbLib == 'undefined') return true;
		if (!PbLib.attachEventCache) return true;
		if (!PbLib.attachEventCache[elem.$$guid]) return true;
		if (!PbLib.attachEventCache[elem.$$guid][event.type]) return true;

		// get a reference to the hash table of event handlers
		var handlers = PbLib.attachEventCache[elem.$$guid][event.type];
		// execute each event handler
		for (var i in handlers) {
			if (PbLib.def(event.pbCancelledEvent)) return false;
			elem.$$handle = handlers[i];
			if (elem.$$handle(event) === false) {
				returnValue = false;
			}
		}
		return returnValue;
	};

PbLib.cancelEvent = function(e)
	{(!pbDev || alert('PbLib.cancelEvent() is no longer supported!'));
		e.cancelBubble = true;
		if (document.all) {
			e.returnValue = false;
		} else {
			e.preventDefault();
		}
		e.pbCancelledEvent = true;
	};
if (!pbDev) {
PbLib.browser = {
		isW3C: PbLib.def(document.getElementById),
		isOpera: navigator.userAgent.indexOf("Opera") != -1,
		isSafari: navigator.userAgent.indexOf("Safari") != -1,
		isNN4: PbLib.def(document.layers)
	};
}

PbLib.windowIsLoaded = false;

// Dialog code
PbLib.dialog = {};
PbLib.dialog.eventElem;
PbLib.dialog.scrollElem	= null;
PbLib.dialog.scrollElemIsArray = false;
PbLib.dialog.container = null;
PbLib.dialog.reqSize = null;
PbLib.dialog.origReqSize = null;
PbLib.dialog.chromeSize = null;
PbLib.dialog.dragPosDiff = null;
PbLib.dialog.dragShield = null;
PbLib.dialog.dragStartTimeout = null;
PbLib.dialog.doDragInterval = null;
PbLib.dialog.defaultOptions = {
		enableMaximize: true,
		enableDragging: true,
		enableResize: true,
		enableScrollBars: true,
		shadeWindow: true,
		blockerIsTransparent: true,
		showCloseButton: true,
		showMaximizeButton: true,
		waitForPageReady: false,
		title: '',
		icon: ''
	};
PbLib.dialog.resizing = null;
PbLib.dialog.topWindow = (function(){
	var myHost = window.location.host;
	var pWin = window;
	var pHost;
	while (true) {
		if (!pWin.parent || pWin.parent == pWin) break;
		try {
			pHost = pWin.parent.location.host;
			if (pHost != myHost) break;
		} catch (e) {
			break;
		}
		pWin = pWin.parent;
	}
	return pWin;
})();
PbLib.dialog.windowStack = [];
PbLib.dialog.mousePos = {x:0,y:0};
PbLib.createDialog = function (url, reqWidth, reqHeight, options)
{
	if (typeof options != 'object') options = {};

	var myOptions = Object.extend(PbLib.objectClone(PbLib.dialog.defaultOptions), options);

	if (PbLib.dialog.container) {
		PbLib.destroyDialog();
	}

	PbLib.dialog.addToStack(window);

	if (myOptions.shadeWindow) {
		PbLib.dialog.createBlocker(!!(myOptions.blockerIsTransparent));
	}
	return PbLib.dialog.createElement(url, reqWidth, reqHeight, myOptions);
};
PbLib.dialog.getOpener = function ()
{
	if (window != PbLib.dialog.topWindow) {
		return PbLib.dialog.topWindow.PbLib.dialog.getOpener();
	} else if (PbLib.dialog.windowStack.length == 0) {
		return PbLib.dialog.topWindow;
	} else {
		return PbLib.dialog.windowStack[PbLib.dialog.windowStack.length - 1];
	}
};
PbLib.dialog.addToStack = function (subWindow)
{
	if (window != PbLib.dialog.topWindow) {
		PbLib.dialog.topWindow.PbLib.dialog.addToStack(subWindow);
	} else {
		PbLib.dialog.windowStack.push(subWindow);
	}
};
PbLib.dialog.getScrollElem = function ()
{
	if (!PbLib.dialog.scrollElem) {
		var htmlElem = PbLib.dialog.topWindow.document.getElementsByTagName('html')[0];
		PbLib.dialog.scrollElem = [htmlElem, PbLib.dialog.topWindow.document.body];
		PbLib.dialog.scrollElemIsArray = true;
	}

	if (PbLib.dialog.scrollElemIsArray) {
		for (var i = 0; i < PbLib.dialog.scrollElem.size; i++) {
			if (PbLib.dialog.scrollElem[i].scrollLeft > 0 || PbLib.dialog.scrollElem[i].scrollTop > 0) {
				PbLib.dialog.scrollElem = PbLib.dialog.scrollElem[i];
				PbLib.dialog.scrollElemIsArray = false;
				return PbLib.dialog.scrollElem;
			}
		}
		return PbLib.dialog.scrollElem[0];
	}
	return PbLib.dialog.scrollElem;
}
PbLib.destroyDialog = function (force)
{
	var force = !!(force);

	if (!force) {
		if (window == PbLib.dialog.topWindow) {
			var subWindow = PbLib.dialog.windowStack.pop();
			return subWindow.PbLib.destroyDialog(true);
		} else {
			return PbLib.dialog.topWindow.PbLib.destroyDialog();
		}
	}

	$(PbLib.dialog.eventElem).fire('dialog:close');

	if (Prototype.Browser.IE) {
		if (PbLib.dialog.container.dialogOptions.shadeWindow)
			PbLib.dialog.topWindow.Event.stopObserving(PbLib.dialog.topWindow, 'resize', PbLib.dialog.resizeBlocker);

		PbLib.dialog.topWindow.Event.stopObserving(PbLib.dialog.topWindow, 'scroll', PbLib.dialog.repositionNoAni);
	}
	PbLib.dialog.dragPosDiff = null;

	PbLib.dialog.topWindow.Event.stopObserving(PbLib.dialog.topWindow, 'resize', PbLib.dialog.repositionNoAni);
	PbLib.dialog.topWindow.Event.stopObserving(PbLib.dialog.topWindow.document, 'keypress', PbLib.dialog.handleKeys);

	PbLib.dialog.destroyBlocker();
	PbLib.dialog.destroyElement();
};
PbLib.dialog.createElement = function (url, reqWidth, reqHeight, myOptions)
{
	// Create dialog: 4 divs to create rounded corners and a content div
	PbLib.dialog.container = PbLib.dialog.topWindow.document.body.appendChild(PbLib.dialog.topWindow.document.createElement('div'));
	PbLib.dialog.container = $(PbLib.dialog.container);
	PbLib.dialog.container.className = 'pbdialogcontainer';
	Object.extend(PbLib.dialog.container.style, {
			position: 'fixed',
			zIndex: '999',
			padding: 0,
			margin: 0,
			visibility: 'hidden'
		});
	PbLib.dialog.container.dialogOptions = myOptions;

	if (myOptions.enableResize) {
		Event.observe(PbLib.dialog.container, 'mousemove', function(event){
			if (PbLib.dialog.frame.maximized) return true;

			var dialogSize		= this.getDimensions();
			var dialogOffset	= {left: this.offsetLeft, top: this.offsetTop};
			var scroll = document.viewport.getScrollOffsets();
			if (PbLib.dialog.container.getStyle('position') != 'fixed') {
				dialogOffset.left -= scroll.left;
				dialogOffset.top -= scroll.top;
			}
			var pointer = {
				x: Event.pointerX(event) - scroll.left,
				y: Event.pointerY(event) - scroll.top
			};
			var relativePos = {
				left: pointer.x - dialogOffset.left,
				top: pointer.y - dialogOffset.top
			};

			var hoverWidth = 9;
			var cursor = '';
			if (relativePos.top < hoverWidth) {
				cursor += 'n';
			} else if (relativePos.top > (dialogSize.height - hoverWidth)) {
				cursor += 's';
			}
			if (relativePos.left < hoverWidth) {
				cursor += 'w';
			} else if (relativePos.left > (dialogSize.width - hoverWidth)) {
				cursor += 'e';
			}

			this.style.cursor = cursor ? cursor + '-resize' : '';
		});
	}

	var tempElem, button, topBar;
	tempElem = topBar = PbLib.dialog.container.appendChild(PbLib.dialog.topWindow.document.createElement('div'));
	tempElem.className = 'top';
	if (myOptions.title || myOptions.icon) {
		var topBarTitle = topBar.appendChild(PbLib.dialog.topWindow.document.createElement('span'));
		topBarTitle.className = 'title';

		if (myOptions.icon) {
			var topBarIcon = topBarTitle.appendChild(PbLib.dialog.topWindow.document.createElement('img'));
			topBarIcon.src = myOptions.icon;
		}
		if (myOptions.title) {
			topBarTitle.appendChild(PbLib.dialog.topWindow.document.createTextNode(myOptions.title));
		}
		topBarTitle.onselectstart = function(){
			return false;
		};
		topBarTitle.onmousedown = function(){
			return false;
		};
	}

	var buttons = tempElem.appendChild(PbLib.dialog.topWindow.document.createElement('span'));
	buttons.className = 'buttons';
	if (myOptions.showMaximizeButton && myOptions.enableMaximize) {
		button = buttons.appendChild(PbLib.dialog.topWindow.document.createElement('a'));
		button.className = 'maximize';
		button.setAttribute('href', 'javascript:void(0);');
		button.onclick = function () {PbLib.dialog.toggleMaximize();};
	}
	if (myOptions.showCloseButton) {
		button = buttons.appendChild(PbLib.dialog.topWindow.document.createElement('a'));
		button.className = 'close';
		button.setAttribute('href', 'javascript:void(0);');
		button.onclick = function () {PbLib.destroyDialog();};
	}

	tempElem.appendChild(PbLib.dialog.topWindow.document.createElement('div'));

	tempElem = PbLib.dialog.container.appendChild(PbLib.dialog.topWindow.document.createElement('div'));
	tempElem.className = 'middle1';
	tempElem.onselectstart = function(){
			return false;
		};
	tempElem = tempElem.appendChild(PbLib.dialog.topWindow.document.createElement('div'));
	tempElem.className = 'middle2';
	PbLib.dialog.frame = tempElem.appendChild(PbLib.dialog.topWindow.document.createElement('div'));
	PbLib.dialog.frame.className = 'middle3';
	tempElem.onselectstart = function(){
			return false;
		};
	PbLib.dialog.frame.style.position = 'relative';

	tempElem = PbLib.dialog.container.appendChild(PbLib.dialog.topWindow.document.createElement('div'));
	tempElem.className = 'bottom';
	tempElem.onselectstart = function(){
			return false;
		};
	tempElem.appendChild(PbLib.dialog.topWindow.document.createElement('div'));

	if (myOptions.enableResize) {
		var resizeRidge = $(tempElem.appendChild(PbLib.dialog.topWindow.document.createElement('span')));
		resizeRidge.className = 'resize-ridge';
		Event.observe(resizeRidge, 'mousedown', function (e) {
			PbLib.dialog.startResize(e, {v: 'd', h: 'r'});
			Event.stop(e);
			return false;
		});
	}

	var setOnloadEvent = false;
	if (url) {
		var iframeElem = PbLib.dialog.topWindow.document.createElement('iframe');
		iframeElem.frameBorder = 0;
		iframeElem.border = 0;
		iframeElem.scrolling = (myOptions.enableScrollBars) ? 'auto' : 'no';
		PbLib.dialog.frame.appendChild(iframeElem);
		Object.extend(iframeElem.style, {
				border: '0px',
				width: '100%',
				height: '100%',
				padding: 0,
				margin: 0
			});


		if (!Object.isUndefined(iframeElem.contentWindow)) {
			if (myOptions.waitForPageReady) {
				iframeElem.contentWindow.onload = function(){PbLib.dialog.reposition(false);};
				PbLib.dialog.topWindow.setTimeout(function(){PbLib.dialog.reposition(false);}, 2000);
				setOnloadEvent = true;
			}
			iframeElem.contentWindow.onkeypress = PbLib.dialog.handleKeys;
		}
		iframeElem.src = url;

		PbLib.dialog.eventElem = iframeElem;
	} else {
		// Add space for Internet Explorer
		PbLib.dialog.frame.appendChild(PbLib.dialog.topWindow.document.createTextNode(' '));
		PbLib.dialog.eventElem = PbLib.dialog.frame;
		if (PbLib.dialog.blocker) {
			PbLib.dialog.blocker.className = PbLib.dialog.blocker.className.replace(/(^|\s)dialogblockerwait(\s|$)/, ' ');
		}
	}

	PbLib.dialog.chromeSize = {};
	PbLib.dialog.chromeSize.w = PbLib.dialog.container.offsetWidth - PbLib.dialog.frame.offsetWidth;
	PbLib.dialog.chromeSize.h = PbLib.dialog.container.offsetHeight - PbLib.dialog.frame.offsetHeight;

	if (!url) {
		while (PbLib.dialog.frame.firstChild) {
			PbLib.dialog.frame.removeChild(PbLib.dialog.frame.firstChild);
		}
	}

	PbLib.dialog.origReqSize = {w: reqWidth, h: reqHeight};
	PbLib.dialog.reqSize = {w: PbLib.dialog.origReqSize.w, h: PbLib.dialog.origReqSize.h};

	if (!setOnloadEvent) {
		PbLib.dialog.reposition(false);
	}
	PbLib.dialog.topWindow.Event.observe(PbLib.dialog.topWindow, 'resize', PbLib.dialog.repositionNoAni);
	PbLib.dialog.topWindow.Event.observe(PbLib.dialog.topWindow, 'keypress', PbLib.dialog.handleKeys);

	if (myOptions.enableDragging || myOptions.enableResize) {
		Event.observe(PbLib.dialog.container, 'mousedown', function(e) {
			if (myOptions.enableResize) {
				var dialogSize		= this.getDimensions();
				var dialogOffset	= {left: this.offsetLeft, top: this.offsetTop};
				var scroll = document.viewport.getScrollOffsets();
				if (PbLib.dialog.container.getStyle('position') != 'fixed') {
					dialogOffset.left -= scroll.left;
					dialogOffset.top -= scroll.top;
				}
				var pointer = {
					x: Event.pointerX(e) - scroll.left,
					y: Event.pointerY(e) - scroll.top
				};
				var relativePos = {
					left: pointer.x - dialogOffset.left,
					top: pointer.y - dialogOffset.top
				};

				var hoverWidth = 9;
				var resizeDir = {v: false, h: false};
				if (relativePos.top < hoverWidth) {
					resizeDir.v = 'u';
				} else if (relativePos.top > (dialogSize.height - hoverWidth)) {
					resizeDir.v = 'd';
				}
				if (relativePos.left < hoverWidth) {
					resizeDir.h = 'l';
				} else if (relativePos.left > (dialogSize.width - hoverWidth)) {
					resizeDir.h = 'r';
				}

				if (resizeDir.h || resizeDir.v) {
					PbLib.dialog.startResize(e, resizeDir);
					Event.stop(e);
					return false;
				}
			}
			if (myOptions.enableDragging) {
				var tmp = e.element();
				while (tmp != topBar) {
					if (!tmp.parentNode) return true;
					tmp = tmp.parentNode;
				}
				PbLib.dialog.startDrag(e, true);
				Event.stop(e);
				return false;
			}
		});
	}

	if (myOptions.enableMaximize)
		PbLib.dialog.topWindow.Event.observe(topBar, 'dblclick', function(){PbLib.dialog.toggleMaximize();});

	if (Prototype.Browser.IE) {
		PbLib.dialog.container.style.position = 'absolute';
		PbLib.dialog.topWindow.Event.observe(PbLib.dialog.topWindow, 'scroll', PbLib.dialog.repositionNoAni);
	}

	return PbLib.dialog.eventElem;
};
PbLib.dialog.startDrag = function (e, firstCall)
{
	var dragOpts = {};
	var firstCall = !!(firstCall);

	if (PbLib.dialog.doDragInterval) return true;

	if (firstCall) {
		dragOpts.setStartPos = true;
		PbLib.dialog.topWindow.Event.observe(PbLib.dialog.topWindow.document, 'mouseup', PbLib.dialog.stopDrag);
	}

	if (!firstCall || !PbLib.dialog.frame.maximized) {
		PbLib.dialog.dragStartTimeout = null;
		if (PbLib.dialog.frame.maximized) {
			dragOpts.unMaximize = true;
			dragOpts.resetSize = true;
		}

		dragOpts.followMouse = true;

		PbLib.dialog.startDragResize(e, dragOpts);
		PbLib.dialog.doDragInterval = PbLib.dialog.topWindow.setInterval(function () {
			PbLib.dialog.doDrag();
			Object.extend(PbLib.dialog.oldMouseKeys, PbLib.dialog.mouseKeys);
		}, 1);
	} else {
		PbLib.dialog.startDragResize(e, dragOpts);
		PbLib.dialog.dragStartTimeout = PbLib.dialog.topWindow.setTimeout(function(){PbLib.dialog.startDrag(null, false);}, 200);
	}
};
PbLib.dialog.oldResizeDir;
PbLib.dialog.startResize = function (e, directions)
{
	var dragOpts = {};
	if (PbLib.dialog.doResizeInterval) return true;
	if (PbLib.dialog.frame.maximized) return true;

	dragOpts.setStartPos	= true;
	PbLib.dialog.topWindow.Event.observe(PbLib.dialog.topWindow.document, 'mouseup', PbLib.dialog.stopResize);
	dragOpts.unMaximize		= true;
	dragOpts.followMouse	= true;
	PbLib.dialog.startDragResize(e, dragOpts);
	PbLib.dialog.dragPosDiff.resizeDir = directions;
	PbLib.dialog.doResizeInterval = PbLib.dialog.topWindow.setInterval(function() {
		PbLib.dialog.doResize();
		Object.extend(PbLib.dialog.oldMouseKeys, PbLib.dialog.mouseKeys);
	}, 1);
};
PbLib.dialog.startDragResize = function (e, opts)
{
	var opts = Object.extend({
		unMaximize: false,
		resetSize: false,
		setStartPos: false,
		followMouse: false
	}, opts);

	if (opts.setStartPos) {
		var e = e || event;
		PbLib.dialog.followMouse(e);
		PbLib.dialog.dragPosDiff = {
				x: PbLib.dialog.mousePos.x - PbLib.dialog.currentPos.x,
				y: PbLib.dialog.mousePos.y - PbLib.dialog.currentPos.y,
				start: PbLib.objectClone(PbLib.dialog.mousePos)
			};
	}

	if (opts.unMaximize && PbLib.dialog.frame.maximized) {
		if (opts.resetSize) {
			var curTop = parseInt(PbLib.dialog.container.style.top);
			var startPos = PbLib.dialog.dragPosDiff;

			PbLib.dialog.toggleMaximize(true, true);

			// Adjust left position so the mouse ends up in the middle
			PbLib.dialog.dragPosDiff = {
					x: ((PbLib.dialog.frame.offsetWidth + PbLib.dialog.chromeSize.w) / 2),
					y: startPos.y,
					start: startPos.start
				};
			var curLeft = PbLib.dialog.dragPosDiff.start.x - PbLib.dialog.dragPosDiff.x;

			PbLib.dialog.currentPos.x = curLeft;
			PbLib.dialog.currentPos.y = curTop;
			PbLib.dialog.container.style.left = curLeft + 'px';
			PbLib.dialog.container.style.top = curTop + 'px';
		} else {
			PbLib.dialog.reqSize = PbLib.dialog.origReqSize;
			PbLib.dialog.toggleMaximize(true, true);
		}
	}

	if (opts.followMouse) {
		// Create shield to catch mousemove above iframes
		PbLib.dialog.dragShield = PbLib.dialog.frame.appendChild(PbLib.dialog.topWindow.document.createElement('div'));
		Object.extend(PbLib.dialog.dragShield.style, {
				position: 'absolute',
				top: 0,
				left: 0,
				width: PbLib.dialog.frame.style.width,
				height: PbLib.dialog.frame.style.height
			})

		PbLib.dialog.topWindow.document.observe('mousemove', PbLib.dialog.followMouse);
	}
};
PbLib.dialog.mouseKeys = {
		ctrl: false,
		alt: false,
		shift: false
	};
PbLib.dialog.oldMouseKeys = {
		ctrl: false,
		alt: false,
		shift: false
	};
PbLib.dialog.lastMouseEvent;
PbLib.dialog.followMouse = function (e)
{
	var e = e || event;
	PbLib.dialog.lastMouseEvent = {
			clientX: + e.clientX,
			clientY: + e.clientY,
			ctrlKey: !!(e.ctrlKey),
			altKey: !!(e.altKey),
			shiftKey: !!(e.shiftKey)
		};
	PbLib.dialog.mousePos = {x:Event.pointerX(e), y:Event.pointerY(e)};
	PbLib.dialog.mouseKeys.ctrl = e.ctrlKey;
	PbLib.dialog.mouseKeys.alt = e.altKey;
	PbLib.dialog.mouseKeys.shift = e.shiftKey;
}
PbLib.dialog.doDrag = function (e)
{
	if (PbLib.dialog.oldMouseKeys.alt != PbLib.dialog.mouseKeys.alt) {
		if (PbLib.dialog.oldMouseKeys.alt && PbLib.dialog.oldResizeDir) {
			Object.extend(PbLib.dialog.oldMouseKeys, PbLib.dialog.mouseKeys);
			PbLib.dialog.stopDrag(PbLib.dialog.lastMouseEvent);
			PbLib.dialog.startResize(PbLib.dialog.lastMouseEvent, PbLib.dialog.oldResizeDir);
			return true;
		} else {
			PbLib.dialog.oldResizeDir = null;
		}
	}

	if (!PbLib.dialog.dragPosDiff) return true;

	PbLib.dialog.currentPos.x = PbLib.dialog.mousePos.x - PbLib.dialog.dragPosDiff.x;
	PbLib.dialog.currentPos.y = PbLib.dialog.mousePos.y - PbLib.dialog.dragPosDiff.y;

	PbLib.dialog.container.style.left = PbLib.dialog.currentPos.x + 'px';
	PbLib.dialog.container.style.top = PbLib.dialog.currentPos.y + 'px';
};
PbLib.dialog.doResize = function (e)
{
	// Alt moves
	if (!PbLib.dialog.oldMouseKeys.alt && PbLib.dialog.mouseKeys.alt) {
		PbLib.dialog.oldResizeDir = PbLib.objectClone(PbLib.dialog.dragPosDiff.resizeDir);
		Object.extend(PbLib.dialog.oldMouseKeys, PbLib.dialog.mouseKeys);
		PbLib.dialog.stopResize(PbLib.dialog.lastMouseEvent);
		PbLib.dialog.startDrag(PbLib.dialog.lastMouseEvent, true);
		return true;
	}

	if (!PbLib.dialog.dragPosDiff) return true;
	if (!PbLib.dialog.dragPosDiff.startSize) {
		PbLib.dialog.dragPosDiff.startSize = {
				w: PbLib.dialog.reqSize.w * 1,
				h: PbLib.dialog.reqSize.h * 1
			};

		var windowSize = PbLib.dialog.topWindow.document.viewport.getDimensions();
		var match = Object.isString(PbLib.dialog.reqSize.w) && PbLib.dialog.reqSize.w.match(/^(\d+)%$/);
		if (match) PbLib.dialog.dragPosDiff.startSize.w = (windowSize.width * match[1]) / 100;
		match = Object.isString(PbLib.dialog.reqSize.h) && PbLib.dialog.reqSize.h.match(/^(\d+)%$/);
		if (match) PbLib.dialog.dragPosDiff.startSize.h = (windowSize.height * match[1]) / 100;
	}

	var opts = PbLib.dialog.dragPosDiff;
	var mouseX = + PbLib.dialog.mousePos.x;
	var mouseY = + PbLib.dialog.mousePos.y;
	if (opts.resizeDir.v == 'u') {
		PbLib.dialog.currentPos.y	= mouseY - opts.y;
		if (PbLib.dialog.mouseKeys.ctrl) {
			PbLib.dialog.reqSize.h		= opts.startSize.h + (2 * (opts.start.y - mouseY));
		} else {
			PbLib.dialog.reqSize.h		= opts.startSize.h + (opts.start.y - mouseY);
		}

		if (PbLib.dialog.reqSize.h < 50) {
			if (PbLib.dialog.mouseKeys.ctrl) {
				PbLib.dialog.currentPos.y -= ((50 - PbLib.dialog.reqSize.h) / 2);
			} else {
				PbLib.dialog.currentPos.y -= (50 - PbLib.dialog.reqSize.h);
			}
			PbLib.dialog.reqSize.h = 50;
		}
	} else if (opts.resizeDir.v == 'd') {
		if (PbLib.dialog.mouseKeys.ctrl) {
			PbLib.dialog.currentPos.y	= opts.start.y - opts.y - (mouseY - opts.start.y);
			PbLib.dialog.reqSize.h		= opts.startSize.h + (2 * (mouseY - opts.start.y));
		} else {
			PbLib.dialog.reqSize.h		= opts.startSize.h + (mouseY - opts.start.y);
		}
		if (PbLib.dialog.reqSize.h < 50) {
			if (PbLib.dialog.mouseKeys.ctrl) {
				PbLib.dialog.currentPos.y	-= ((50 - PbLib.dialog.reqSize.h) / 2);
			}
			PbLib.dialog.reqSize.h = 50;
		}
	} else {
		PbLib.dialog.reqSize.h = opts.startSize.h;
	}

	if (opts.resizeDir.h == 'l') {
		PbLib.dialog.currentPos.x	= mouseX - opts.x;
		if (PbLib.dialog.mouseKeys.ctrl) {
			PbLib.dialog.reqSize.w		= opts.startSize.w + (2 * (opts.start.x - mouseX));
		} else {
			PbLib.dialog.reqSize.w		= opts.startSize.w + (opts.start.x - mouseX);
		}

		if (PbLib.dialog.reqSize.w < 100) {
			if (PbLib.dialog.mouseKeys.ctrl) {
				PbLib.dialog.currentPos.x -= ((100 - PbLib.dialog.reqSize.w) / 2);
			} else {
				PbLib.dialog.currentPos.x -= (100 - PbLib.dialog.reqSize.w);
			}
			PbLib.dialog.reqSize.w = 100;
		}
	} else if (opts.resizeDir.h == 'r') {
		if (PbLib.dialog.mouseKeys.ctrl) {
			PbLib.dialog.currentPos.x	= opts.start.x - opts.x - (mouseX - opts.start.x);
			PbLib.dialog.reqSize.w		= opts.startSize.w + (2 * (mouseX - opts.start.x));
		} else {
			PbLib.dialog.reqSize.w		= opts.startSize.w + (mouseX - opts.start.x);
		}
		if (PbLib.dialog.reqSize.w < 100) {
			if (PbLib.dialog.mouseKeys.ctrl) {
				PbLib.dialog.currentPos.x	-= ((100 - PbLib.dialog.reqSize.w) / 2);
			}
			PbLib.dialog.reqSize.w = 100;
		}
	} else {
		PbLib.dialog.reqSize.w = opts.startSize.w;
	}

	PbLib.dialog.container.style.left = PbLib.dialog.currentPos.x + 'px';
	PbLib.dialog.container.style.top = PbLib.dialog.currentPos.y + 'px';
	PbLib.dialog.reposition(false, true);
};
PbLib.dialog.stopDrag = function (e)
{
	if (PbLib.dialog.dragStartTimeout) {
		PbLib.dialog.topWindow.clearTimeout(PbLib.dialog.dragStartTimeout);
		PbLib.dialog.dragStartTimeout = null;
		PbLib.dialog.topWindow.Event.stopObserving(PbLib.dialog.topWindow.document, 'mouseup', PbLib.dialog.stopDrag);
		return true;
	}

	if (!PbLib.dialog.dragShield) return;

	if (PbLib.dialog.doDragInterval) {
		PbLib.dialog.topWindow.clearInterval(PbLib.dialog.doDragInterval);
		PbLib.dialog.doDragInterval = false;
	}
	PbLib.dialog.topWindow.Event.stopObserving(PbLib.dialog.topWindow.document, 'mouseup', PbLib.dialog.stopDrag);
	PbLib.dialog.topWindow.document.stopObserving('mousemove', PbLib.dialog.followMouse);

	var e = e || event;
	PbLib.dialog.doDrag(e);

	PbLib.dialog.frame.removeChild(PbLib.dialog.dragShield);
	PbLib.dialog.dragShield = null;
};
PbLib.dialog.stopResize = function (e)
{
	if (!PbLib.dialog.dragShield) return;
	if (PbLib.dialog.doResizeInterval) {
		PbLib.dialog.topWindow.clearInterval(PbLib.dialog.doResizeInterval);
		PbLib.dialog.doResizeInterval = false;
	}
	PbLib.dialog.topWindow.Event.stopObserving(PbLib.dialog.topWindow.document, 'mouseup', PbLib.dialog.stopResize);
	PbLib.dialog.topWindow.document.stopObserving('mousemove', PbLib.dialog.followMouse);

	var e = e || event;
	PbLib.dialog.doResize(e);

	PbLib.dialog.origReqSize = Object.extend({}, PbLib.dialog.reqSize);

	PbLib.dialog.frame.removeChild(PbLib.dialog.dragShield);
	PbLib.dialog.dragShield = null;
};
PbLib.dialog.handleKeys = function (e)
{
	var e = e || event;

	if (e.keyCode == 27 && PbLib.dialog.container.dialogOptions.showCloseButton) PbLib.destroyDialog();
};
PbLib.dialog.destroyElement = function ()
{
	if (typeof PbLib.dialog.eventElem == 'object') {
		if (PbLib.dialog.eventElem.tagName) {
			if (PbLib.dialog.eventElem.tagName.toLowerCase() == 'iframe') {
				if (PbLib.dialog.eventElem.src != 'about:blank') {
					PbLib.dialog.eventElem.src = 'about:blank';
				}

				// Use try catch to prevent crosssite scripting error
				try {
					if (PbLib.dialog.eventElem.contentWindow) {
						if (PbLib.dialog.eventElem.contentWindow.document.body) {
							if (PbLib.dialog.eventElem.contentWindow.document.body.childNodes.length != 0) {
								window.setTimeout(function(){PbLib.dialog.destroyElement();}, 50);
								return false;
							}
						}
					}
				} catch (e) {
				}
			}
		}
	}

	PbLib.dialog.container.parentNode.removeChild(PbLib.dialog.container);
	PbLib.dialog.container = null;
	PbLib.dialog.frame = null;
	PbLib.dialog.chromeSize = null;
};
PbLib.dialog.toggleMaximize = function (noAnimation, scaleOnly)
{
	var noAnimation = !!(noAnimation);
	var scaleOnly = !!(scaleOnly);

	PbLib.dialog.dragPosDiff = null;
	if (PbLib.dialog.frame.maximized) {
		PbLib.dialog.reqSize = Object.extend({}, PbLib.dialog.origReqSize);
		PbLib.dialog.frame.maximized = false;
	} else {
		PbLib.dialog.reqSize = {w: '100%', h: '100%'};
		PbLib.dialog.frame.maximized = true;
	}
	PbLib.dialog.reposition(!noAnimation, scaleOnly);
};
PbLib.dialog.createBlocker = function (transparent)
{
	var transparent = (Object.isUndefined(transparent)) || !!(transparent);
	if (PbLib.dialog.topWindow.PbLib.dialog.windowStack.length > 1) {
		PbLib.dialog.topWindow.PbLib.dialog.windowStack[PbLib.dialog.topWindow.PbLib.dialog.windowStack.length - 2].PbLib.dialog.container.style.zIndex = 997;
		return true;
	}

	if (Prototype.Browser.IE) {
		// Hide all selectboxes
		var boxes = document.getElementsByTagName('select');
		for (var i = 0; i < boxes.length; i++) {
			boxes[i].preDialogVis = "" + boxes[i].style.visibility;
			boxes[i].style.visibility = 'hidden';
		}
	}

	PbLib.dialog.blocker = PbLib.dialog.topWindow.document.body.appendChild(PbLib.dialog.topWindow.document.createElement('div'));
	PbLib.dialog.blocker.className = 'dialogblocker dialogblockerwait';
	Element.setStyle(PbLib.dialog.blocker, {
			position: 'fixed',
			top: '0px',
			left: '0px',
			width: '100%',
			height: '100%',
			zIndex: '998',
			opacity: 0});
	if (transparent) {
		Element.setOpacity(PbLib.dialog.blocker, 0.5);
		PbLib.dialog.blocker.className += ' transparent';
	} else {
		PbLib.dialog.blocker.style.visibility = 'visible';
	}

	if (Prototype.Browser.IE) {
		PbLib.dialog.blocker.style.position = 'absolute';
		PbLib.dialog.resizeBlocker();
		PbLib.dialog.topWindow.Event.observe(PbLib.dialog.topWindow, 'resize', PbLib.dialog.resizeBlocker);
	}
};
PbLib.dialog.destroyBlocker = function ()
{
	if (PbLib.dialog.topWindow.PbLib.dialog.windowStack.length > 0) {
		PbLib.dialog.topWindow.PbLib.dialog.windowStack[PbLib.dialog.topWindow.PbLib.dialog.windowStack.length - 1].PbLib.dialog.container.style.zIndex = 999;
		return true;
	}

	if (PbLib.dialog.container.dialogOptions.shadeWindow) {
		if (Prototype.Browser.IE) {
			// Show all selectboxes
			var boxes = document.getElementsByTagName('select');
			for (var i = 0; i < boxes.length; i++) {
				boxes[i].style.visibility = boxes[i].preDialogVis ? boxes[i].preDialogVis : '';
			}
		}

		PbLib.dialog.blocker.parentNode.removeChild(PbLib.dialog.blocker);
	}

	PbLib.dialog.blocker = null;
};
PbLib.dialog.resizeBlocker = function ()
{
	PbLib.dialog.blocker.style.width = PbLib.dialog.getScrollElem().scrollWidth + 'px';
	PbLib.dialog.blocker.style.height = PbLib.dialog.getScrollElem().scrollHeight + 'px';
};
PbLib.dialog.repositionNoAni = function () {PbLib.dialog.reposition();};
PbLib.dialog.repositionAni = function () {PbLib.dialog.reposition(true);};
PbLib.dialog.reposition = function (animate, scaleOnly)
{
	var animate = false; // crappy on many pc's !!(animate);
	var scaleOnly = !!(scaleOnly);
	var windowSize = PbLib.dialog.topWindow.document.viewport.getDimensions();

	// Calculate size, reposition and scale
	var size = {};
	var match = Object.isString(PbLib.dialog.reqSize.w) && PbLib.dialog.reqSize.w.match(/^(\d+)%$/);
	size.w = (match ? (windowSize.width * match[1]) / 100 : PbLib.dialog.reqSize.w)
	match = Object.isString(PbLib.dialog.reqSize.h) && PbLib.dialog.reqSize.h.match(/^(\d+)%$/);
	size.h = match ? (windowSize.height * match[1]) / 100 : PbLib.dialog.reqSize.h;

	var width = size.w * 1;
	var height = size.h * 1;

	size.w += PbLib.dialog.chromeSize.w;
	size.h += PbLib.dialog.chromeSize.h;

	if (size.w > windowSize.width) {
		size.w = windowSize.width;
		width = size.w - PbLib.dialog.chromeSize.w;
	}
	if (size.h > windowSize.height) {
		size.h = windowSize.height;
		height = size.h - PbLib.dialog.chromeSize.h;
	}

	var doPosition = !scaleOnly && PbLib.dialog.dragPosDiff == null;
	if (doPosition) {
		var left = Math.round((windowSize.width - size.w) / 2);
		var top = Math.round((windowSize.height - size.h) / 2);
		if (Prototype.Browser.IE) {
			left += PbLib.dialog.getScrollElem().scrollLeft;
			top += PbLib.dialog.getScrollElem().scrollTop;
		}
		PbLib.dialog.currentPos = {x: left, y: top};
	}

	if (animate) {
		if (!doPosition) {
			var left	=  parseInt(PbLib.dialog.container.style.left);
			var top		= parseInt(PbLib.dialog.container.style.top);
		}
		PbLib.dialog.container.style.visibility = 'visible';
		PbLib.dialog.animate(left, top, width, height, 4, 5);
	} else {
		if (doPosition) {
			PbLib.dialog.container.style.left = left + 'px';
			PbLib.dialog.container.style.top = top + 'px';
		}
		PbLib.dialog.frame.style.width = width + 'px';
		PbLib.dialog.frame.style.height = height + 'px';
		PbLib.dialog.container.style.width = width + PbLib.dialog.chromeSize.w + 'px';
		PbLib.dialog.container.style.height = height + PbLib.dialog.chromeSize.h + 'px';
		PbLib.dialog.container.style.visibility = 'visible';
	}

	if (PbLib.dialog.blocker) {
		PbLib.dialog.blocker.className = PbLib.dialog.blocker.className.replace(/(^|\s)dialogblockerwait(\s|$)/, ' ');
	}
};

PbLib.dialog.resize = function (toWidth, toHeight)
{
	PbLib.dialog.reqSize.w = toWidth;
	PbLib.dialog.reqSize.h = toHeight;
	PbLib.dialog.reposition(false);
};

PbLib.dialog.animate = function (toLeft, toTop, toWidth, toHeight, steps, timePerStep)
{
	if (Object.isUndefined(PbLib.dialog.frame.style)) return false;
	if (Object.isUndefined(PbLib.dialog.container.style)) return false;

	if (toLeft != null) {
		var curLeft = parseInt(PbLib.dialog.container.style.left);
		var diffLeft = Math.round((toLeft - curLeft) / steps);
		PbLib.dialog.container.style.left = (curLeft + diffLeft) + 'px';

		if ((curLeft + diffLeft) == toLeft) toLeft = null;
	}
	if (toTop != null) {
		var curTop = parseInt(PbLib.dialog.container.style.top);
		var diffTop = Math.round((toTop - curTop) / steps);
		PbLib.dialog.container.style.top = (curTop + diffTop) + 'px';

		if ((curTop + diffTop) == toTop) toTop = null;
	}
	if (toWidth != null) {
		var curWidth = parseInt(PbLib.dialog.frame.style.width);
		var diffWidth = (toWidth - curWidth) / steps;
		PbLib.dialog.frame.style.width = (curWidth + diffWidth) + 'px';
		PbLib.dialog.container.style.width = (curWidth + diffWidth + PbLib.dialog.chromeSize.w) + 'px';

		if ((curWidth + diffWidth) == toWidth) toWidth = null;
	}
	if (toHeight != null) {
		var curHeight = parseInt(PbLib.dialog.frame.style.height);
		var diffHeight = (toHeight - curHeight) / steps;
		PbLib.dialog.frame.style.height = (curHeight + diffHeight) + 'px';
		PbLib.dialog.container.style.height = (curHeight + diffHeight + PbLib.dialog.chromeSize.h) + 'px';

		if ((curHeight + diffHeight) == toHeight) toHeight = null;
	}

	if (steps > 1) {
		steps--;
		PbLib.dialog.topWindow.setTimeout(function(){PbLib.dialog.animate(toLeft, toTop, toWidth, toHeight, steps, timePerStep);}, timePerStep);
	}
};

PbLib.dialog.findDialogCSS = function (win)
{
	var headElem = win.document.getElementsByTagName('head')[0];
	var childElem;
	for (var i = 0; i < headElem.childNodes.length; i++) {
		childElem = headElem.childNodes[i];
		if (childElem.tagName && childElem.tagName == 'link') {
			if (childElem.href.match(/dialog\.css$/)) {
				return childElem;
			}
		}
	}
	return false;
};

PbLib.dialog.findTopWindowInterval = null;

if (window != PbLib.dialog.topWindow) {
	PbLib.dialog.findTopWindowInterval = window.setInterval(function () {
		var allFound = true;
		if (!PbLib.dialog.findDialogCSS(PbLib.dialog.topWindow)) {
			allFound = false;
			// Add styles to the top window
			var styleElem = PbLib.dialog.findDialogCSS(window);
			if (styleElem) {
				PbLib.dialog.topWindow.document.getElementsByTagName('head')[0].appendChild(styleElem.cloneNode(true));
			}
		}
		if (allFound || PbLib.windowIsLoaded) {
			window.clearInterval(PbLib.dialog.findTopWindowInterval);
		}
	}, 10);
}

// Effects module
PbLib.moveTo = function (elem, posLeft, posTop, stepLeft, stepTop, time, accelerateLeft, accelerateTop)
	{
		if (!stepLeft) {
			PbLib.setPos(elem, posLeft, posTop);
			return true;
		}

		if (!elem) {
			return false;
		} else if (!elem.parentNode) {
			return false;
		}

		curPos = Element.cumulativeOffset(elem);
		posLeft	= parseInt(posLeft);
		posTop	= parseInt(posTop);
		time	= Math.max(1, parseInt(time));

		var newPosLeft = posLeft;
		var newPosTop = posTop;

		if (accelerateLeft) {
			var diff = ((curPos.left - posLeft) / stepLeft);
			if (diff < 0 && diff > -1) diff = -1;
			else if (diff > 0 && diff < 1) diff = 1;

			newPosLeft = curPos.left - diff;
			if (Math.abs(newPosLeft - posLeft) < 1) {
				newPosLeft = posLeft;
			}
		} else {
			if (Math.abs(posLeft - curPos.left) <= stepLeft) {
				newPosLeft = posLeft;
			} else if (curPos.left > posLeft) {
				newPosLeft = curPos.left - stepLeft;
			} else {
				newPosLeft = curPos.left + stepLeft;
			}
		}
		if (accelerateTop) {
			var diff = ((curPos.top - posTop) / stepTop);
			if (diff < 0 && diff > -1) diff = -1;
			else if (diff > 0 && diff < 1) diff = 1;

			newPosTop = curPos.top - diff;
			if (Math.abs(newPosTop - posTop) < 1) {
				newPosTop = posTop;
			}
		} else {
			if (Math.abs(posTop - curPos.top) <= stepTop) {
				newPosTop = posTop;
			} else if (curPos.top > posTop) {
				newPosTop = curPos.top - stepTop;
			} else {
				newPosTop = curPos.top + stepTop;
			}
		}

		PbLib.setPos(elem, newPosLeft, newPosTop);
		if (Math.abs(newPosLeft - posLeft) > 1 || Math.abs(newPosTop - posTop) > 1) {
			setTimeout(function(){PbLib.moveTo(elem, posLeft, posTop, stepLeft, stepTop, time, accelerateLeft, accelerateTop)}, time);
		}
	};
PbLib.scaleTo = function (elem, width, height, stepLeft, stepTop, time, accelerateLeft, accelerateTop, actionOnZero)
	{
		if (Object.isUndefined(actionOnZero)) actionOnZero = 1;

		if (elem.scaleToTimeout) {
			window.clearTimeout(elem.scaleToTimeout);
			elem.scaleToTimeout = null;
		}

		var changeWidth		= width != null;
		var changeHeight	= height != null;

		if (!changeWidth && !changeHeight) {
			return true;
		}
		if (changeWidth && !stepLeft) {
			if (changeWidth) elem.style.width = width + 'px';
		}
		if (changeHeight && !stepTop) {
			if (changeHeight) elem.style.height = height + 'px';
		}
		if ((!changeWidth || !stepLeft) && (!changeHeight || !stepTop)) {
			return true;
		}

		if (!elem) {
			return false;
		} else if (!elem.parentNode) {
			return false;
		}

		if (!elem.sizeOffset) {
			elem.sizeOffset = {x:0, y:0};
			if (changeWidth) {
				var w = elem.offsetWidth;
				elem.style.width	= w + 'px';
				elem.sizeOffset.x	= elem.offsetWidth - w;
				elem.style.width	= w + elem.sizeOffset.x + 'px';
			}
			if (changeHeight) {
				var h = elem.offsetHeight;
				elem.style.height	= h + 'px';
				elem.sizeOffset.y	= elem.offsetHeight - h;
				elem.style.height	= h + elem.sizeOffset.y + 'px';
			}
		}

		if (changeWidth) {
			var curWidth = elem.offsetWidth - elem.sizeOffset.x;
			width	= Math.max(0, parseInt(width));
		}
		if (changeHeight) {
			var curHeight = elem.offsetHeight - elem.sizeOffset.y;
			height	= Math.max(0, parseInt(height));
		}
		time	= Math.max(1, parseInt(time));

		if (changeWidth) {
			var newWidth = width;
			if (accelerateLeft) {
				var widthDiff = ((curWidth - width) / stepLeft);
				if (widthDiff <= 1) {
					widthDiff = 1;
				}
				newWidth = curWidth - widthDiff;
				if (Math.abs(newWidth - width) < 1) {
					newWidth = width;
				}
			} else {
				if (Math.abs(width - curWidth) <= stepLeft) {
					newWidth = width;
				} else if (curWidth > width) {
					newWidth = curWidth - stepLeft;
				} else {
					newWidth = curWidth + stepLeft;
				}
			}
		}
		if (changeHeight) {
			var newHeight = height;
			if (accelerateTop) {
				var heightDiff = ((curHeight - height) / stepTop);
				if (Math.abs(heightDiff) <= 1) {
					heightDiff = heightDiff < 0 ? -1 : 1;
				}
				newHeight = curHeight - heightDiff;
				if (Math.abs(newHeight - height) < 1) {
					newHeight = height;
				}
			} else {
				if (Math.abs(height - curHeight) <= stepTop) {
					newHeight = height;
				} else if (curHeight > height) {
					newHeight = curHeight - stepTop;
				} else {
					newHeight = curHeight + stepTop;
				}
			}
		}

		if (changeWidth) elem.style.width	= newWidth + 'px';
		if (changeHeight) elem.style.height	= newHeight + 'px';
		if ((changeWidth && Math.abs(newWidth - width) >= 1) || (changeHeight && Math.abs(newHeight - height) >= 1)) {
			elem.scaleToTimeout = setTimeout(function(){PbLib.scaleTo(elem, width, height, stepLeft, stepTop, time, accelerateLeft, accelerateTop, actionOnZero)}, time);
		} else if ((changeWidth && newWidth == 0) || (changeHeight && newHeight  == 0)) {
			switch (actionOnZero) {
				case 1: // Remove node
					elem.parentNode.removeChild(elem);
					break;
				case 2: // Display none
					elem.style.display = 'none';
					break;
				case 3: // Visibility hidden
					elem.style.visibility = 'hidden';
					break;
				default: // Do nothing
					break;
			}
		}
	};

/**
 * Fade an element in or out
 * @param string elem 		The html element to fade
 * @param string from		The opacity percentage to start with (0-1)
 * @param string to 		The opacity  percentage to end with (0-1)
 * @param string fadeTime 	The total time of the fade
 * @param string onFinished The function call to execute when fading is done
 * @param string frameRate 	The amount of steps per second to take
 */
PbLib.fade = function (elem, from, to, fadeTime, onFinished, frameRate)
	{
		if (!elem) {
			return false;
		} else if (!elem.parentNode) {
			return false;
		}

		if (isIE) {
		  //IE element needs to have layout for alpha filter to work
		  elem.style.zoom = '1';
		}

		if (!frameRate) { frameRate = 12; }
		fadeTime = Math.max(1, parseInt(fadeTime));
		from	 = Math.min(1, parseInt(from));
		to		 = Math.max(0, parseInt(to));

		time = 1000 / frameRate;
		step = (to-from) / ((fadeTime/1000)*frameRate) ;

		stop = false;
		if (typeof(elem.curOpacity) == 'undefined') {
			elem.curOpacity = from;
		} else {
			elem.curOpacity += step;
			if (to > from) {
				if (elem.curOpacity >= to) {
					elem.curOpacity = to;
					stop = true;
				}
			} else {
				if (elem.curOpacity <= to) {
					elem.curOpacity = to;
					stop = true;
				}
			}
		}

		if (elem.curOpacity > 0) {
			if (elem.style.display == 'none') {
				elem.style.display = '';
			}
			if (elem.style.visibility == 'hidden') {
				elem.style.visibility = 'visible';
			}
		}

		Element.setOpacity(elem, elem.curOpacity);

		if (stop) {
			if (onFinished) {
				onFinished(elem);
			}
			return;
		}
		setTimeout(function(){PbLib.fade(elem, from, to, fadeTime, onFinished, frameRate);}, time);
	};

/**
 * Set the opacity on an element in a browser compatible way
 * @param string elem	 	HTML element
 * @param string opacity 	Opacity to set (0-100)
 */
PbLib.setOpacity = function (elem, opacity)
	{(!pbDev || alert('PbLib.setOpacity() is no longer supported!'));
		elem.curOpacity = opacity;
		opacity = (opacity == 100)?99.999:opacity; // IE/Win
		elem.style.filter = "alpha(opacity:"+opacity+")"; // Safari<1.2, Konqueror
		elem.style.KHTMLOpacity = opacity/100; // Older Mozilla and Firefox
		elem.style.MozOpacity = opacity/100; // Safari 1.2, newer Firefox and Mozilla, CSS3
		elem.style.opacity = opacity/100;

		if (opacity > 0) {
			if (elem.style.display == 'none') {
				elem.style.display = '';
			}
			if (elem.style.visibility == 'hidden') {
				elem.style.visibility = 'visible';
			}
		}
	};

/**
 * DEPRICATED FUNCTION - exists only for backwards compatibility
 *
 * Fade an element in
 * @param string elem	 	HTML element to fade in
 * @param string step		Opacity to increase per step (0-1)
 * @param string time 		Time in milliseconds per step
 */
PbLib.fadeIn = function (elem, step, time)
	{
		PbLib.fade(elem, 0, 1, step*time, false, 1000/time );
	};
/**
 * DEPRICATED FUNCTION - exists only for backwards compatibility
 *
 * Fade an element out
 * @param string elem	 	HTML element to fade out
 * @param string step		Opacity to decrease per step (0-1)
 * @param string time 		Time in milliseconds per step
 */
PbLib.fadeOut = function (elem, step, time, removeAfter)
	{
		var onFinished = false;
		if (removeAfter) {
			onFinished = function (elem) {if (elem.parentNode) elem.parentNode.removeChild(elem);};
		}
		PbLib.fade(elem, 1, 0, step*time, onFinished, 1000/time );
	};

PbLib.getScrollPos = function()
{(!pbDev || alert('PbLib.getScrollPos() is no longer supported!'));
	return {x:Math.max(document.body.scrollLeft, document.html.scrollLeft),y:Math.max(document.body.scrollTop, document.html.scrollTop)};
}
PbLib.getPos	= function(elem)
{(!pbDev || alert('PbLib.getPos() is no longer supported!'));
	var parent	= elem;
	var xPos, yPos;
	xPos = yPos = 0;
	do {
		xPos += parent.offsetLeft;
		yPos += parent.offsetTop;
		parent = parent.offsetParent;
	} while (parent);

	return {x:xPos, y:yPos};
}
PbLib.setPos = function(elem, posLeft, posTop)
{
	if (!posTop && typeof posLeft == 'object') {
		// Result of getPos given
		var posTop	= posLeft.top;
		var posLeft	= posLeft.left;
	}

	if (Object.isUndefined(elem.posDiff)) {
		elem = $(elem);
		var startPos = elem.cumulativeOffset();

		elem.absolutize();

		var curPos = elem.cumulativeOffset();
		elem.posDiff = {left:curPos.left - startPos.left,top:curPos.top - startPos.top};
	}

	elem.setStyle({
		'left':	parseInt(posLeft) + elem.posDiff.left + 'px',
		'top':	parseInt(posTop) + elem.posDiff.top + 'px'});
}

// Window module
PbLib.getDocumentSize = function (doc)
{(!pbDev || alert('PbLib.getDocumentSize() is no longer supported!'));
	if (!doc) doc = document;

	var size = {x:0,y:0};
	if (doc.body.scrollHeight > doc.body.offsetHeight) // all but Explorer Mac
	{
		size.x = doc.body.scrollWidth;
		size.y = doc.body.scrollHeight;
	}
	else // Explorer Mac;
		 //would also work in Explorer 6 Strict, Mozilla and Safari
	{
		size.x = doc.body.offsetWidth;
		size.y = doc.body.offsetHeight;
	}
	return size;
}

PbLib.getWindowSize = function (win)
{
	if (!win) var win = window;

	if (Object.isUndefined(win.chromeSize)) {
		PbLib.setChromeSize(win);
	}


	var size = {x:win.chromeSize.x,y:win.chromeSize.y};
	if (!Object.isUndefined(win.innerWidth)) {
		size.x += win.innerWidth;
		size.y += win.innerHeight;
	} else if (!Object.isUndefined(win.document.clientWidth)) {
		size.x += win.document.clientWidth;
		size.y += win.document.clientHeight;
	} else if (!Object.isUndefined(win.documentElement)) {
		if (!Object.isUndefined(win.documentElement.clientWidth)) {
			size.x += win.documentElement.clientWidth;
			size.y += win.documentElement.clientHeight;
		}
	} else if (!Object.isUndefined(win.document.html.clientWidth)) {
		size.x += win.document.html.clientWidth;
		size.y += win.document.html.clientHeight;
	}

	return size;
}
PbLib.getWindowInnerSize = function (win)
{(!pbDev || alert('PbLib.getWindowInnerSize() is no longer supported!'));
	if (!win) var win = window;

	var size = {x:0,y:0};
	if (win.innerHeight) {
		size.x = win.innerWidth;
		if (win.scrollMaxY) size.x -= 16;
		size.y = win.innerHeight;
		if (win.scrollMaxX) size.y -= 16;
	} else if (win.document.documentElement && win.document.documentElement.clientHeight) {
		size.x = win.document.documentElement.clientWidth;
		size.y = win.document.documentElement.clientHeight;
	} else if (win.document.body) {
		size.x = win.document.body.clientWidth;
		size.y = win.document.body.clientHeight;
	}

	return size;
}
PbLib.getWindowPos = function (win)
{
	if (!win) var win = window;

	return {x:win.screenX, y:win.screenY}
}
PbLib.setWindowSize = function (width, height, win)
{
	if (!win) var win = window;

	win.resizeTo(parseInt(width), parseInt(height));
}
PbLib.setChromeSize = function (win)
{
	if (!win) var win = window;
	win.chromeSize = {x:0,y:0};

	var startSize = PbLib.getWindowSize(win);
	PbLib.setWindowSize(startSize.x, startSize.y, win);
	var curSize = PbLib.getWindowSize(win);

	win.chromeSize = {x:startSize.x - curSize.x, y:startSize.y - curSize.y};

	PbLib.setWindowSize(startSize.x + win.chromeSize.x, startSize.y + win.chromeSize.y, win);
}
PbLib.availScreenWidth	= screen.availWidth ? screen.availWidth : 1024;
PbLib.availScreenHeight	= screen.availHeight ? screen.availHeight : 768;
PbLib.centerWindow = function (win)
{
	if (!win) var win = window;

	var winS = PbLib.getWindowSize(win);
	win.moveTo((PbLib.availScreenWidth - winS.x) / 2, (PbLib.availScreenHeight - winS.y) / 2);
}
PbLib.scaleWindowToContent = function (scaleWidth, scaleHeight, win)
{
	if (!win) var win = window;
	if (Object.isUndefined(scaleHeight)) var scaleHeight	= true;
	if (Object.isUndefined(scaleWidth)) var scaleWidth		= false;

	var doc = win.document;
	if (!doc.body) return false;

	if (!scaleWidth && !scaleHeight) return true;

	var curSize = PbLib.getWindowSize(win);
	var targetWidth = curSize.x;
	var targetHeight = curSize.y;

	if (scaleWidth) {
		var curScroll = 0;
		if (doc.all) {
			do {
				curScroll += 200;
				win.scrollTo(curScroll, 0);
			} while (Math.max(doc.body.scrollLeft, doc.body.parentNode.scrollLeft) >= curScroll);
			targetWidth += Math.max(doc.body.scrollLeft, doc.body.parentNode.scrollLeft);
		} else {
			do {
				curScroll += 200;
				win.scrollTo(curScroll, 0);
			} while (win.scrollX >= curScroll);
			targetWidth += win.scrollX;
		}
		win.scrollTo(0,0);
		targetWidth = Math.min(PbLib.availScreenWidth, targetWidth + 1);
		win.moveTo((PbLib.availScreenWidth - targetWidth) / 2, (PbLib.availScreenHeight - targetHeight) / 2);
		win.resizeTo(targetWidth, targetHeight);
	}
	if (scaleHeight) {
		var curScroll = 0;
		if (doc.all) {
			do {
				curScroll += 200;
				win.scrollTo(0, curScroll);
			} while (Math.max(doc.body.scrollTop, doc.body.parentNode.scrollTop) >= curScroll);
			targetHeight += Math.max(doc.body.scrollTop, doc.body.parentNode.scrollTop);
		} else {
			do {
				curScroll += 200;
				win.scrollTo(0, curScroll);
			} while (win.scrollY >= curScroll);
			targetHeight += win.scrollY;
		}
		win.scrollTo(0,0);
		targetHeight = Math.min(PbLib.availScreenHeight, targetHeight + 1);
	}

	win.moveTo((PbLib.availScreenWidth - targetWidth) / 2, (PbLib.availScreenHeight - targetHeight) / 2);
	win.resizeTo(targetWidth, targetHeight);
}
PbLib.getWindowScrollWidth = function(win)
{
	if (!win) var win = window;
	return PbLib.getWindowScrollSize(win, 'x');
}
PbLib.getWindowScrollHeight = function(win)
{
	if (!win) var win = window;
	return PbLib.getWindowScrollSize(win, 'y');
}
PbLib.getWindowScrollSize = function(win, axle)
{
	if (!win) var win = window;
	var doc = win.document;
	var scrollSize, startScroll, startScrollX, startScrollY = 0;
	var curScroll;
	var prop;

	if (doc.all) {
		prop = axle == 'x' ? 'scrollLeft' : 'scrollTop';
		startScrollX	= Math.max(doc.body.scrollLeft, doc.body.parentNode.scrollLeft);
		startScrollY	= Math.max(doc.body.scrollTop, doc.body.parentNode.scrollTop);
		startScroll		= axle == 'x' ? startScrollX : startScrollY;

		// Measure scroll size
		curScroll = 0;
		do {
			curScroll += 200;
			if (axle == 'x') {
				win.scrollTo(curScroll, startScrollY);
			} else {
				win.scrollTo(startScrollX, curScroll);
			}
		} while (Math.max(doc.body[prop], doc.body.parentNode[prop]) >= curScroll);
		scrollSize = Math.max(doc.body[prop], doc.body.parentNode[prop]);
	} else {
		prop = axle == 'x' ? 'scrollX' : 'scrollY';
		startScrollX	= win.scrollX;
		startScrollY	= win.scrollY;
		startScroll		= axle == 'x' ? startScrollX : startScrollY;

		// Measure scroll size
		curScroll = 0;
		do {
			curScroll += 200;
			if (axle == 'x') {
				win.scrollTo(curScroll, startScrollY);
			} else {
				win.scrollTo(startScrollX, curScroll);
			}
		} while (win[prop] >= curScroll);
		scrollSize = win[prop];
	}
	win.scrollTo(startScrollX, startScrollY);
	return scrollSize;
}

// Mousepos module
PbLib.mousePos = function(e)
{(!pbDev || alert('PbLib.mousePos() is no longer supported!'));
	var scrollPos = PbLib.getScrollPos();
	return {x:e.clientX + scrollPos.x, y:e.clientY + scrollPos.y};
};

// Trackmovement module
PbLib.trackMovement = [];
PbLib.move = function(e)
{
	if (typeof event != 'undefined') var e = event;
	if (PbLib.trackMovement.length > 0) {
		for (var i = 0; i < PbLib.trackMovement.length; i++) {
			PbLib.trackMovement[i](e);
		}
	}
}
PbLib.movementTrackerRunning = false;
PbLib.addMovementTracker = function (func)
{(!pbDev || alert('PbLib.addMovementTracker() is no longer supported!'));
	if (!PbLib.movementTrackerRunning) {
		PbLib.attachEvent(document, 'onmousemove', PbLib.move);
		PbLib.movementTrackerRunning = true;
	}
	if (typeof func == 'function') {
		PbLib.trackMovement.push(func);
	}
	return true;
}
PbLib.removeMovementTracker = function (func)
{(!pbDev || alert('PbLib.removeMovementTracker() is no longer supported!'));
	if (typeof func == 'function') {
		var oldArr = PbLib.trackMovement;
		PbLib.trackMovement = [];
		for (var i = 0; i < oldArr.length; i++) {
			if (oldArr[i] != func) {
				PbLib.trackMovement.push(oldArr[i]);
			}
		}
		if (PbLib.movementTrackerRunning && PbLib.trackMovement.length == 0) {
			PbLib.detachEvent(document, 'onmousemove', PbLib.move);
			PbLib.movementTrackerRunning = false;
		}
	}
}
PbLib.gCache = {};
PbLib.g = function(string)
	{
		if (PbLib.gCache[string]) {
			return PbLib.gCache[string];
		}
		return string;
	};

Event.observe(window, 'load', function(){PbLib.windowIsLoaded = true;});
