if (!(typeof(core) != 'undefined')) var core = new Object();

var FILESYS_DIRECTORY = 1;
var FILESYS_FILE = 2;


core.doc = document;
if (typeof(core.doc.all) != 'undefined')
{
	var ver = navigator.appVersion.match(/MSIE ([^;])/);
	core.browser = 'ie';
	core.browserVersion = ver[1];
}
else
{
	core.browser = 'mozilla';
	core.browserVersion = navigator.appVersion.match(/[0-9.]*/);
}

core.mouseButtons = { left: 1, middle: 2, right: 3 };

core.initialize = function ()
{
	core.initializeOnPageLoaded(
		window,
		function ()
		{
			core.page.invokeAllEvents('onPageLoaded');		
		}
	);
	core.page.size = core.page.getSize();
  
	setInterval(
		function ()
		{
			var oldPageSize = core.page.size;
			core.page.size = core.page.getSize();
			if (core.page.size.width != oldPageSize.width || core.page.size.height != oldPageSize.height)
			{
				core.page.invokeAllEvents('onPageResized');
			}
		}, 100
	);
	

	if ((typeof(core.doc.addEventListener) != 'undefined'))
	{
		core.doc.addEventListener('mousemove', core.page.onMouseMove, false);
		core.doc.addEventListener('mousedown', core.page.onMouseDown, false);
		core.doc.addEventListener('mouseup', core.page.onMouseUp, false);
		core.doc.addEventListener('click', core.page.onClick, false);
		core.doc.addEventListener('dblclick', core.page.onDoubleClick, false);
		core.doc.addEventListener('keypress', core.page.onKeyPress, false);
		core.doc.addEventListener('keydown', core.page.onKeyDown, false);
		core.doc.addEventListener('keyup', core.page.onKeyUp, false);
	}
	else
	{ 
		core.doc.onmousemove = core.page.onMouseMove;
		core.doc.onmousedown = core.page.onMouseDown;
		core.doc.onmouseup = core.page.onMouseUp;
		core.doc.onclick = core.page.onClick;
		core.doc.ondblclick = core.page.onDoubleClick;
		core.doc.onkeypress = core.page.onKeyPress;
		core.doc.onkeydown = core.page.onKeyDown; 
		core.doc.onkeyup = core.page.onKeyUp; 
	}
	   
	if ((typeof(onCoreInstalled) != 'undefined'))
	{
		onCoreInstalled();
	}
}

core.initializeOnPageLoaded = function (win, event)
{
	var doc = win.document;
	if ((typeof(win.core.onPageLoadedInitialized) != 'undefined')) return;
	
	/*@cc_on @*/
/*@if (@_win32)

	  doc.write('<script defer id="ie_onPageLoaded" src="javascript:void(0)"></' + 'script>');
	  var ie_onPageLoaded = doc.getElementById("ie_onPageLoaded");
	  ie_onPageLoaded.onreadystatechange = function ()
	  {
	  	if (this.readyState == "complete") 
		{
			core.page.loaded = true; 
			event();
		} 
	  }
	
/*@end @*/

	
	if ((typeof(doc.addEventListener) != 'undefined'))
	{
		doc.addEventListener("DOMContentLoaded", function () { core.page.loaded = true; event() }, false);
	}

	win.core.onPageLoadedInitalized = true;
}

core.page = {
	loaded: false,
	size: null, 
	events: new Array(),
	mousePos: {
		x: 0, y: 0,
		offset: function (x, y)
		{
			if (typeof(x) == 'object')
			{
				y = x.y;
				x = x.x;
			}
			
			x = parseInt_wd(x, 0);
			y = parseInt_wd(y, 0);
			
			return { x: this.x + x, y: this.y + y };
		},
		
		clone: function ()
		{
			return { x: 0 + this.x, y: 0 + this.y };
		}		
	},
	
	getMousePos: function ()
	{
		var mpos = this.mousePos.clone();
		mpos.y -= core.page.getScrollV();
		return mpos;
	},
	
	getWidth: function ()
	{
		var x = 0;
		
		if ((typeof(self.innerWidth) != 'undefined'))
		{
			x = self.innerWidth;
		}
		else if ((typeof(core.doc.documentElement) != 'undefined') && (typeof(core.doc.documentElement.clientWidth) != 'undefined'))
		{
			x = core.doc.documentElement.clientWidth;
		}
		else if ((typeof(core.doc.body) != 'undefined'))
		{
			x = core.doc.body.clientWidth;
		}
		
		return parseInt_wd(x, 0);
	},
	
	getHeight: function ()
	{
		var x = 0;
		
		if ((typeof(self.innerHeight) != 'undefined'))
		{
			x = self.innerHeight;
		}
		else if ((typeof(core.doc.documentElement) != 'undefined') && (typeof(core.doc.documentElement.clientHeight) != 'undefined'))
		{
			x = core.doc.documentElement.clientHeight;
		}
		else if ((typeof(core.doc.body) != 'undefined'))
		{
			x = core.doc.body.clientHeight;
		}
		
		return parseInt_wd(x, 0);
	},
	
	getSize: function ()
	{
		return {
			width: core.page.getWidth(),
			height: core.page.getHeight(),
			transform: function (w, h)
			{
			 	return { width: this.width + w, height: this.height + h };
			}
		};
	},
	
	getScrollH: function ()
	{
		if (window.pageXOffset)
			return window.pageXOffset;
		else
			return core.doc.documentElement.scrollLeft;	
	},

	getScrollV: function ()
	{
		if (window.pageYOffset)
			return window.pageYOffset;
		else
			return core.doc.documentElement.scrollTop;	
	},
	
	getScrollBarWidth: function ()
	{
		var bodyOverflow = core.doc.body.style.overflow;
		var width, widthWithSb;
		
		if (core.browser == 'ie' && core.browserVersion == '7.0')
		{
			return core.doc.body.offsetWidth - core.doc.body.clientWidth;
		}
		else
		{
			core.doc.body.style.overflow = 'hidden';
			width = core.doc.body.clientWidth;
			
			core.doc.body.style.overflow = 'scroll';
			widthWithSb = core.doc.body.clientWidth;
			
			core.doc.body.style.overflow = bodyOverflow;
			width -= widthWithSb;
		}
		
		return width;
	},	
		
	invokeAllEvents: function (eventName, obj)
	{
		var ret = true;
		if (!(typeof(obj) != 'undefined')) obj = window.event;
		 
		if ((typeof(core.page.events[eventName]) != 'undefined'))
		{
			var events = core.page.events[eventName];
			for (var i in events)
			{
				if (events[i] != null)
				{
					var eventReturn = events[i](this, obj);
					if (eventReturn == false) ret = false;
				}
			}
		}
		
		return ret;
	},
	
	createEvent: function (eventName, id, func)
	{
		if (typeof(id) == 'function')
		{
			func = id;
			id = 'event_' + eventName + '_' + Math.round(Math.random() * 1000);
		}
		
		if (eventName == 'onmousewheel')
		{
			if (core.browser == 'ie')
			{
				if (!((typeof(window.onmousewheel) != 'undefined') && (typeof(document.onmousewheel) != 'undefined')))
				{
					window.onmousewheel = document.onmousewheel = function (e) { core.page.onMouseWheel(e); }
				}
			}
			else
			{
				core.doc.addEventListener('DOMMouseScroll', core.page.onMouseWheel, false);
			}
		}
		
		if (typeof(core.page.events[eventName]) == 'undefined')
		{
			core.page.events[eventName] = new Array();
		}
		
		core.page.events[eventName][id] = func;
	},
	
	removeEvent: function (eventName, id)
	{
		if (typeof(core.page.events[eventName]) != 'undefined' && typeof(core.page.events[eventName][id]) != 'undefined')
		{
			core.page.events[eventName][id] = null;
		}
	},
	
	// Events
	
	onMouseMove: function (e)
	{
		var x, y;
		if (core.browser == 'ie') 
		{
			x = event.clientX;
			y = event.clientY;
		}
		else
		{
			x = e.pageX;
			y = e.pageY;
		}
		
		core.page.mousePos.x = x;
		core.page.mousePos.y = y;
		return core.page.invokeAllEvents('onmousemove', e);
	},

	onMouseDown: function (e)
	{
		var mb = null;
		if ((typeof(e) != 'undefined') && (typeof(e.which) != 'undefined'))
		{
			mb = e.which;
		}
		else if ((typeof(event.button) != 'undefined'))
		{
			mb = event.button;
			if (mb == 4) mb = core.mouseButtons.middle;
		}

		core.page.mouseButton = mb;
		return core.page.invokeAllEvents('onmousedown', e);
	},
	
	onMouseUp: function (e)
	{
		return core.page.invokeAllEvents('onmouseup', e);
	},
	
	onClick: function (e)
	{
		core.page.invokeAllEvents('onclick', e);
	},
	
	onDoubleClick: function (e)
	{
		return core.page.invokeAllEvents('ondblclick', e);
	},
	
	onKeyPress: function (e)
	{
		return core.page.invokeAllEvents('onkeypress', e);
	},

   	onKeyDown: function (e)
	{
		return core.page.invokeAllEvents('onkeydown', e);
	},

   	onKeyUp: function (e)
	{
		return core.page.invokeAllEvents('onkeyup', e);
	},
	
	onMouseWheel: function (e)
	{
		return core.page.invokeAllEvents('onmousewheel', e);
	}
};

core.page.createEvent('onPageLoaded',
	function ()
	{
	    core.page.scrollBarWidth = core.page.getScrollBarWidth();						
	}
);

core.events = {
	createEvent: function (eventName, id, func)
	{
		var __this = this;
	
		if (typeof(id) == 'function')
		{
			func = id;
			id = eventName;
		}
			
		if (!(typeof(this.__events) != 'undefined')) this.__events = new Object();	
		if (!(typeof(this.__events[eventName]) != 'undefined') || this.__events[eventName] == null)
		{
			this.__events[eventName] = new Object();
			if (typeof(this[eventName]) == 'function')
			{
				this.__oldEvent = this[eventName];
				this.__events[eventName]['oldEvent'] = {
					func: function (e) { return __this.__oldEvent(e); },
					enabled: true
				};
				
				this[eventName] = null;			
			}
		}
		
		this.__events[eventName][id] = { func: func, enabled: true };
		
		if (typeof(this[eventName]) != 'function')
		{
			this[eventName] = function (e)
			{
				if (!(typeof(e) != 'undefined') && (typeof(event) != 'undefined')) e = event;
				return __this.invokeAllEvents(eventName, e);
			}
		}
	},
	
	removeEvent: function (eventName, id)
	{
		if (!(typeof(this.__events) != 'undefined')) return false;
		
		if (!(typeof(id) != 'undefined')) id = eventName;
		if ((typeof(this.__events[eventName]) != 'undefined') && (typeof(this.__events[eventName][id]) != 'undefined'))
		{
			this.__events[eventName][id] = null;
			return true;
		}
		
		return false;
	},
	
	invokeEvent: function (eventName, id, obj)
	{
		var e = this.__events[eventName][i];
		if (e.enabled) return e.func(this, obj);
	},
	
	invokeAllEvents: function (eventName, obj)
	{
		if (typeof(this.__events) == 'undefined') return true;
		
		var eventReturn = true;
		var ret = true;
		for (var i in this.__events[eventName])
		{
			var e = this.__events[eventName][i];
			if (e.enabled) eventReturn = e.func(this, obj);
			if (eventReturn === false) ret = false;
		}
		
		return ret;
	}
};

core.timing = {
	setTimeout: function (id, func, timeout)
	{
		if (!(typeof(this.__timeouts) != 'undefined')) this.__timeouts = new Array();
		if ((typeof(this.__timeouts[id]) != 'undefined') && this.__timeouts[id] != null) this.clearTimeout(id);
		this.__timeouts[id] = setTimeout(func, timeout);
	},
	
	clearTimeout: function (id)
	{
		if (!(typeof(this.__timeouts) != 'undefined') || !(typeof(this.__timeouts[id]) != 'undefined') || this.__timeouts[id] == null)
			return;
			
		clearTimeout(this.__timeouts[id]);
		this.__timeouts[id] = null;
	},
	
	setInterval: function (id, func, interval)
	{
		if (!(typeof(this.__intervals) != 'undefined')) this.__intervals = new Array();
		if ((typeof(this.__intervals[id]) != 'undefined') && this.__intervals[id] != null) this.clearInterval(id);
		this.__intervals[id] = setInterval(func, interval);
	},
	
	clearInterval: function (id)
	{
		if (!(typeof(this.__intervals) != 'undefined') || !(typeof(this.__intervals[id]) != 'undefined') || this.__intervals[id] == null)
			return;

		clearInterval(this.__intervals[id]);
		this.__intervals[id] = null;
	}
};

core.redirect = function (url, target)
{
	if (!(typeof(target) != 'undefined')) target = '_self';
	
	if (target == '_blank')
	{
		core.openWin(url, { name: 'newWin' + $string.randomId(), toolbar: 'yes' });
	}
	else
	{
		top.location.href = url;
	}
}

core.openWin = function (url, params)
{
	if (!(typeof(params) != 'undefined')) params = new Object();
	if (!(typeof(params.name) != 'undefined')) params.name = 'win';
	//if (!(typeof(params.width) != 'undefined')) params.width = 400;
	//if (!(typeof(params.height) != 'undefined')) params.height = 400;
	if (!(typeof(params.toolbar) != 'undefined')) params.toolbar = 'no';
	if (!(typeof(params.resizable) != 'undefined')) params.resizable = 'yes';
	if (!(typeof(params.scrollbars) != 'undefined')) params.scrollbars = 'yes';
	
	var paramsStr = new Array();
	for (var i in params)
	{
		paramsStr.push(i + '=' + params[i]);
	}
	paramsStr = paramsStr.join(',');
	
	return window.open(url, name, paramsStr);
}

core.createClassPath = function (path)
{
	var segs = path.split('.');
	var node = core;
	for (var i=0; i<segs.length; i++)
	{
		var seg = segs[i];
		if (i == 0 && seg == 'core') continue;
		
		if (typeof(node[seg]) == 'undefined') node[seg] = new Object();
	}
}

core.classTemplates = new Object();

core.createClass = function (a, b)
{
	var template, params, c
	if (typeof(a) == 'string')
	{
	 	template = core.classTemplates[a];
	 	params = b;
	 	
		c = function (cId, cParams)
		{
		 	this.init(cId, cParams);
		 	if ((typeof(this.customInit) != 'undefined')) this.customInit(cId, cParams);
		}
		
		$object.extend(c, template);
		if ((typeof(params.init) != 'undefined'))
		{
			params.customInit = params.init
			delete params.init;
		}		
	}
	else
	{
	 	template = null;
	 	params = a;
	 	c = params.init;
	}

	core.extendClass(c, params);
	core.extendClass(c, core.timing);
	core.extendClass(c, core.events);
	return c;
}

core.createClassTemplateExtension = function (newClassName, extClassName, classParams)
{
	var ec = core.classTemplates[extClassName];
	
	ncInit = ((typeof(classParams.init) != 'undefined') ? classParams.init : null);
	ecInit = ec.init;
	
	$object.extend(classParams, ec);
	delete classParams.init;
	
	classParams.ecInit = ecInit;
	classParams.ncInit = ncInit;
	classParams.init = function (id, params)
	{
		this.ecInit(id, params);
	 	this.ncInit(id, params);	 	
	}
	
	core.classTemplates[newClassName] = classParams;	
}

core.isElement = function (obj)
{
	return ((typeof(obj) != 'undefined') && (typeof(obj.isCoreElement) != 'undefined'));
}

core.element = {
	defaults: new Object(),
	isCoreElement: function () { return true; },
	//__usingSetSize: false,

	appendTo: function (el)
	{
		if (el == 'BODY')
		{
			core.doc.body.appendChild(this);
		}
		else
		{
			$(el).appendElement(this);
		}
	},
	
	getCurrentStyle: function ()
	{
		var s;
		
		if (core.doc.defaultView && core.doc.defaultView.getComputedStyle)
		{
			s = core.doc.defaultView.getComputedStyle(this, "");
		}
		else if (this.currentStyle)
		{
			s = this.currentStyle;
		}
	
		return s;
	},
	
	getOuterHtml: function ()
	{
		if ((typeof(this.outerHTML) != 'undefined'))
		{
			return this.outerHTML;
		}
		else
		{
			/*var rndId = '__OUTER_HTML__' + $string.randomId();
			
			var before = $(null, 'div');
			before.id = rndId + '_before';

			var after = $(null, 'div');
			after.id = rndId + '_after';

			this.insertElementBefore(before);
			this.insertElementAfter(after);
			
			var html = this.parentElement.innerHTML;
			var lcHtml = html.toLowerCase();
			
			var posA = lcHtml.indexOf('<div id="' + before.id + '">');
			posA = lcHtml.indexOf('</div>', posA) + 6; 

			var posB = lcHtml.indexOf('<div id="' + before.id + '">');
			posB = lcHtml.indexOf('</div>', posA) + 6;*/

			var tester = $(null, 'div');
			var hasParent = (this.parentNode != null);
			
			if (hasParent)
			{
				this.insertElementBefore(tester);			
			}
						
			tester.appendElement(this);
			var html = tester.innerHTML;
			
			if (hasParent) tester.insertElementBefore(this);
			else this.remove();
			
			tester.remove();
			
			return html;			 
		}	
	},

	show: function ()
	{
		this.style.display = (typeof(this.defaults.display) != 'undefined' ? this.defaults.display : '');
	},
	
	hide: function ()
	{
		if (this.style.display == 'none') return false;
		this.defaults.display = this.style.display;
		this.style.display = 'none';
		
		return true;
	},
	

	
	/**
	 *	Dimension functions
	 */	
	
    getWidth: function ()
	{
		var oldDisplay = ((typeof(this.style) != 'undefined') ? this.style.display : '');
		this.style.display = 'block';
		var s = this.getCurrentStyle();
		var w = (this.offsetWidth != 0 ? this.offsetWidth : this.clientWidth);
		if ((typeof(s) != 'undefined'))
		{
			//if ((typeof(s.borderLeftWidth) != 'undefined')) w += parseInt_wd(s.borderLeftWidth);
			//if ((typeof(s.borderRightWidth) != 'undefined')) w += parseInt_wd(s.borderRightWidth);
		}
		this.style.display = oldDisplay;				
		return w;
	},

	getHeight: function ()
	{
		var oldDisplay = this.style.display;
		this.style.display = 'block';
		var s = this.getCurrentStyle();
		var h = (this.offsetHeight != 0 ? this.offsetHeight : this.clientHeight);
		if ((typeof(s) != 'undefined'))
		{
		//	if ((typeof(s.borderTopWidth) != 'undefined')) h += parseInt_wd(s.borderTopWidth);
		//	if ((typeof(s.borderBottomWidth) != 'undefined')) h += parseInt_wd(s.borderBottomWidth);
		}
		this.style.display = oldDisplay;
		return h;
	},
	
	getSize: function ()
	{
		var w = this.getWidth();
		var h = this.getHeight();		
		
		return {
			width: w, 
			height: h,
			transform: function (w, h)
			{
				if (typeof(w) == 'object')
				{
					h = w.height;
					w = w.width;
				}
				
			 	return { width: this.width + w, height: this.height + h };
			}
		};
	},
	
	getInnerWidth: function ()
	{
		return this.clientWidth - this.getPaddingTotalH();
	},
	
	getInnerHeight: function ()
	{
		return this.clientHeight - this.getPaddingTotalV();
	},

	getInnerSize: function ()
	{
		return {
			width: this.getInnerWidth(),
			height: this.getInnerHeight()
		};	
	},
	
	getOuterWidth: function (s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		return this.getWidth() + this.getMarginTotalH();
	},
	
	getOuterHeight: function (s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		return this.getHeight() + this.getMarginTotalV();
	},

	getOuterSize: function ()
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		return { width: this.getOuterWidth(s), height: this.getOuterHeight(s) };
	},
	
	calcInnerWidth: function (width, style)
	{
		var s = (!(typeof(style) != 'undefined') ? this.getCurrentStyle() : style);
		return width - this.getPaddingTotalH(s) - this.getBorderTotalH(s);
	},

	calcInnerHeight: function (height, style)
	{
		var s = (!(typeof(style) != 'undefined') ? this.getCurrentStyle() : style);
		return height - this.getPaddingTotalV(s) - this.getBorderTotalV(s);
	},
	
	calcInnerSize: function (width, height, style)
	{
		if (typeof(width) == 'object')
		{
		 	style = height;
		 	height = width.height;
		 	width = width.width;
		}
		
		if (!(typeof(style) != 'undefined')) style = this.getCurrentStyle();
		return { 
			width: this.calcInnerWidth(width, style),
			height: this.calcInnerHeight(height, style)
		};
	},		
	
	calcOuterWidth: function (width, style)
	{
		var s = (!(typeof(style) != 'undefined') ? this.getCurrentStyle() : style);
		return width +     
			parseInt_wd(s.marginLeft) + parseInt_wd(s.marginRight);
	},

	calcOuterHeight: function (height, style)
	{
		var s = (!(typeof(style) != 'undefined') ? this.getCurrentStyle() : style);

		return height +  
			parseInt_wd(s.marginTop) + parseInt_wd(s.marginBottom);
	},
	
	calcOuterSize: function (width, height, style)
	{
		if (typeof(width) == 'object')
		{
		 	style = height;
		 	height = width.height;
		 	width = width.width;
		}
		
		if (!(typeof(style) != 'undefined')) style = this.getCurrentStyle();
		return { 
			width: this.calcOuterWidth(width, style),
			height: this.calcOuterHeight(height, style)
		};
	},
	
	calcWidthFromInner: function (width, style)
	{
		var s = (!(typeof(style) != 'undefined') ? this.getCurrentStyle() : style);
		return width + this.getPaddingTotalH(s);
	},

	calcHeightFromInner: function (height, style)
	{
		var s = (!(typeof(style) != 'undefined') ? this.getCurrentStyle() : style);
		return height + this.getPaddingTotalV(s);
	},
	
	calcSizeFromInner: function (width, height, style)
	{
		if (typeof(width) == 'object')
		{
		 	style = height;
		 	height = width.height;
		 	width = width.width;
		}
		
		if (!(typeof(style) != 'undefined')) style = this.getCurrentStyle();
		return { 
			width: this.calcWidthFromInner(width, style),
			height: this.calcHeightFromInner(height, style)
		};
	},
	
	calcWidthFromOuter: function (width, style)
	{
		var s = (!(typeof(style) != 'undefined') ? this.getCurrentStyle() : style);
		return width + this.getPaddingTotalH(s) + this.getMarginTotalH(s);
	},

	calcHeightFromOuter: function (height, style)
	{
		var s = (!(typeof(style) != 'undefined') ? this.getCurrentStyle() : style);
		return height + this.getPaddingTotalV(s) + this.getMarginTotalV(s);
	},
	
	calcSizeFromOuter: function (width, height, style)
	{
		if (typeof(width) == 'object')
		{
		 	style = height;
		 	height = width.height;
		 	width = width.width;
		}
		
		if (!(typeof(style) != 'undefined')) style = this.getCurrentStyle();
		return { 
			width: this.calcWidthFromOuter(width, style),
			height: this.calcHeightFromOuter(height, style)
		};
	},
	
	
	getPaddingTotal: function (s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		return { hor: this.getPaddingTotalH(s), ver: this.getPaddingTotalV(s) };
	},
	
	getPaddingTotalV: function (s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		if (s == null) return 0;
		
		var t = $string.toValueUnit(s.paddingTop);						
		var b = $string.toValueUnit(s.paddingBottom);
		var pix = 0, per = 0;
		
		if (t.unit == 'px') pix += t.value;
		else per += t.value

		if (b.unit == 'px') pix += b.value;
		else per += b.value			

		if (per > 0) pix += Math.round(per * 7.12);

		return pix;		
	},

   	getPaddingTotalH: function (s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		if (s == null) return 0;
		
		var r = $string.toValueUnit(s.paddingRight);						
		var l = $string.toValueUnit(s.paddingLeft);
		var pix = 0, per = 0;
		
		if (r.unit == 'px') pix += r.value;
		else per += r.value

		if (l.unit == 'px') pix += l.value;
		else per += l.value			

		if (per > 0) pix += Math.round(per * 7.12);
		
		return pix;		
	},
	
	getBorderTotal: function (s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		return { hor: this.getBorderTotalH(s), ver: this.getBorderTotalV(s) };
	},
	
	getBorderTotalV: function (s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		if (s == null) return 0;
		
		var r = $string.toValueUnit(s.borderTopWidth);						
		var l = $string.toValueUnit(s.borderBottomWidth);
		var pix = 0, per = 0;
		
		if (r.unit == 'px') pix += r.value;
		else per += r.value

		if (l.unit == 'px') pix += l.value;
		else per += l.value			

		if (per > 0) pix += Math.round(per * 7.12);
		
		return pix;	
	},
	
	getBorderTotalH: function (s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		if (s == null) return 0;

		var r = $string.toValueUnit(s.borderRightWidth);						
		var l = $string.toValueUnit(s.borderLeftWidth);
		var pix = 0, per = 0;
		
		if (r.unit == 'px') pix += r.value;
		else per += r.value

		if (l.unit == 'px') pix += l.value;
		else per += l.value			

		if (per > 0) pix += Math.round(per * 7.12);
		
		return pix;			
	},
	
	getBorderWidth: function (which, s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		if (s == null) return 0;

        var b;
        
		switch (which.toUpperCase())
		{
		 	case 'LEFT':
		 		b = s.borderLeftWidth;
		 		break;
		 	
		 	case 'RIGHT':
		 		b = s.borderRightWidth;
		 		break;
		 		
		 	case 'TOP':
		 		b = s.borderTopWidth;
		 		break;
		 	
		 	case 'BOTTOM':
		 		b = s.borderBottomWidth;
		 		break;
		 		
		 	default:
		 		return 0;
		}
		
		var w = $string.toValueUnit(b);
		var pix = 0, per = 0;
		
		if (w.unit == 'px') pix = w.value;
		else per = w.value

		return pix;	
	},
	
	getMarginTotal: function (s)
	{
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		return { hor: this.getMarginTotalH(s), ver: this.getMarginTotalV(s) };
	},

	getMarginTotalH: function (s)
	{
		var r, l;

		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		if ((typeof(s) != 'undefined'))
		{
			r = $string.toValueUnit((!(typeof(s.marginRight) != 'undefined') ? '0px' : s.marginRight));						
			l = $string.toValueUnit((!(typeof(s.marginLeft) != 'undefined') ? '0px' : s.marginLeft));
		}
		else
		{
		 	r = { unit: 'px', value: 0 };
		 	l = { unit: 'px', value: 0 };
		}
		
		var pix = 0, per = 0;
		
		if (r.unit == 'px') pix += r.value;
		else per += r.value

		if (l.unit == 'px') pix += l.value;
		else per += l.value			

		if (per > 0) pix += Math.round(per * 7.12);
		
		return pix;		
	},
	
	getMarginTotalV: function (s)
	{
		var t, b;
		
		if (!(typeof(s) != 'undefined')) s = this.getCurrentStyle();
		if ((typeof(s) != 'undefined'))
		{
			t = $string.toValueUnit((!(typeof(s.marginTop) != 'undefined') ? '0px' : s.marginTop));						
			b = $string.toValueUnit((!(typeof(s.marginBottom) != 'undefined') ? '0px' : s.marginBottom));
		}
		else
		{
		 	t = { unit: 'px', value: 0 };
		 	b = { unit: 'px', value: 0 };
		}
		
		var pix = 0, per = 0;
		
		if (t.unit == 'px') pix += t.value;
		else per += t.value

		if (b.unit == 'px') pix += b.value;
		else per += b.value			

		if (per > 0) pix += Math.round(per * 7.12);

		return pix;		
	},
	
	setRawWidth: function (width)
	{
		width = parseInt_wd(width);
		if (width < 0) width = 0;
		this.style.width = width + 'px';
	},

	setRawHeight: function (height)
	{
		height = parseInt_wd(height);
		if (height < 0) height = 0;
		this.style.height = height + 'px';
	},
	
	setWidth: function (width)
	{
		this.setRawWidth(this.calcInnerWidth(width));
	},

	setHeight: function (height)
	{
		this.setRawHeight(this.calcInnerHeight(height));
	},
	
	setSize: function (width, height)
	{
		if (typeof(width) == 'object')
		{
		 	height = width.height;
		 	width = width.width;
		}
		
		var size = this.calcInnerSize(width, height);
		this.setRawWidth(size.width);
		this.setRawHeight(size.height);
	},
	
	setInnerWidth: function (width)
	{
		//width += this.getMarginTotalH();		
		this.setRawWidth(width);
	},
	
	setInnerHeight: function (height)
	{
		//height += this.getMarginTotalH();		
		this.setRawHeight(height);
	},

    setInnerSize: function (width, height)
    {
    	this.setInnerWidth(width);
    	this.setInnerHeight(height);
    },
	    
	setOuterWidth: function (width)
	{
		this.setRawWidth(width - this.getBorderTotalH() - this.getPaddingTotalH());
	},
	
	setOuterHeight: function (height)
	{
		this.setRawHeight(height - this.getBorderTotalV() - this.getPaddingTotalV());
	},

    setOuterSize: function (width, height)
    {
		if (typeof(width) == 'object')
		{
		 	height = width.height;
		 	width = width.width;
		}
		
		this.setOuterWidth(width);
		this.setOuterHeight(height);
    },

	/**
	 *	Position functions
	 */	 	

	getPos: function (absolute)
	{
        if (!(typeof(absolute) != 'undefined')) absolute = false;
		
		var left = 0;
		var top = 0;
	
		var curElement = this;
		while (curElement != null)
		{
			left += curElement.offsetLeft;
			top += curElement.offsetTop;
			curElement = curElement.offsetParent;
		}
	
	    if (absolute)
	    {
			curElement = this;
			while (curElement != null)
			{
			 	if (curElement.scrollLeft > 0) left -= curElement.scrollLeft;
			 	if (curElement.scrollTop > 0) top -= curElement.scrollTop;
			 	curElement = curElement.parentNode;
			}
		}

		
		left += core.page.getScrollH();
		top += core.page.getScrollV();
		
		return { left: left, top: top };
	},
	
	getInnerPos: function (absolute)
	{
        if (!(typeof(absolute) != 'undefined')) absolute = false;
        
		
		var pos = this.getPos(relative);
		var s = this.getCurrentStyle();
		pos.left += parseInt_wd(s.paddingLeft, 0);
		pos.top += parseInt_wd(s.paddingTop, 0);
		pos.left += parseInt_wd(s.borderLeftWidth, 0);
		pos.top += parseInt_wd(s.borderTopWidth, 0);
		
		return pos;
	},
		
	getTop: function (absolute)
	{
        if (!(typeof(absolute) != 'undefined')) absolute = false;
		
		var top = 0;
		var curElement = this;
		
		while (curElement != null)
		{
			top += curElement.offsetTop + $(curElement).getBorderWidth('TOP');
			curElement = curElement.offsetParent;
		}
		
	    if (absolute)
	    {
			curElement = this;
			while (curElement != null)
			{
			 	if (curElement.scrollTop > 0) top -= curElement.scrollTop;
			 	curElement = curElement.parentNode;
			}
		}
		
		return top;
	},
	
	getLeft: function (absolute)
	{
		if (!(typeof(absolute) != 'undefined')) absolute = false;
		var left = 0;
		var curElement = this;
		
		while (curElement != null)
		{
			left += curElement.offsetLeft + $(curElement).getBorderWidth('LEFT');
			curElement = curElement.offsetParent;
		}
		
	    if (absolute)
	    {
			curElement = this;
			while (curElement != null)
			{
			 	if (curElement.scrollTop > 0) top -= curElement.scrollTop;
			 	curElement = curElement.parentNode;
			}
		}
				
		return left;
	},

	setTop: function (top)
	{
		var s = this.getCurrentStyle();
		if ((typeof(s.marginTop) != 'undefined')) top -= parseInt_wd(s.marginTop);
		this.style.top = parseInt_wd(top) + 'px';	
	},

	setLeft: function (left)
	{
		var s = this.getCurrentStyle();
		if ((typeof(s.marginLeft) != 'undefined')) left -= parseInt_wd(s.marginLeft);
		this.style.left = parseInt_wd(left) + 'px';
	},
	
	setPos: function (left, top)
	{
		if (typeof(left) == 'object')
		{
			if ((typeof(left.x) != 'undefined'))
			{
				top = left.y;
				left = left.x;
			}
			else
			{
				top = left.top;
				left = left.left;
			}
		}
		
		var s = this.getCurrentStyle();
		if ((typeof(s.marginLeft) != 'undefined')) left -= parseInt_wd(s.marginLeft);
		if ((typeof(s.marginTop) != 'undefined')) top -= parseInt_wd(s.marginTop);
		
		this.style.left = parseInt_wd(left) + 'px';
		this.style.top = parseInt_wd(top) + 'px';	
	},    

	getOuterRect: function ()
	{
		var size = this.getOuterSize();
		var pos = this.getPos(); 
		return new core.Rect(pos.left, pos.top, size.width, size.height);
	},

	
	setScrollH: function (h)
	{
		this.scrollLeft = h;
	},

	setScrollV: function (v)
	{
		this.scrollTop = v;
	},
	
	getScrollH: function ()
	{
		return this.scrollLeft;	
	},

	getScrollV: function ()
	{
		return this.scrollTop;	
	},
	
	getRect: function (type)
	{
		switch (type)
		{
		 	case 'inner': getPosFunc = 'getInnerPos'; getSizeFunc = 'getInnerSize'; break;
		 	case 'outer': getPosFunc = 'getPos'; getSizeFunc = 'getOuterSize'; break;		 		
			default: getPosFunc = 'getPos'; getSizeFunc = 'getSize'; break;
		}
		 
		var pos = this[getPosFunc](true);
		var size = this[getSizeFunc]();
	  	return new core.Rect(pos.left, pos.top, size.width, size.height)
	},
	
	getInnerRect: function ()
	{
	  	return this.getRect('inner');
	},

	getOuterRect: function ()
	{
	  	return this.getRect('outer');
	},
	
	setContent: function (content, append)
	{
		if (!(typeof(append) != 'undefined')) append = false;
		
		var type = typeof(content);
		if (type == 'string' || type == 'number')
		{
			this.innerHTML = (append == true ? this.innerHTML : '') + content;
		}
		else
		{
		    if (!append)
		    {
				if (core.browser == 'ie') this.removeChildren();
		     	this.setContent('');
		    }

	     	this.appendElement(content);
		}	
	},
	
	removeChildren: function ()
	{
	  	for (var i in this.childNodes)
	  	{	
	  		var n = this.childNodes[i];
	  		if (n.parentNode != null)
	  		{
	  			n.parentNode.removeChild(n);
	  		}
	  	}
	},

    getMousePos: function ()
    {
      	var pos = this.getPos();
      	var mpos = core.page.mousePos.offset(core.page.getScrollH(), core.page.getScrollV());      	
      	return { x: mpos.x - pos.left, y: mpos.y - pos.top };
    },
	
	disableSelection: function (cursor)
	{
		if (!(typeof(cursor) != 'undefined')) cursor = 'default';
		
		var e = this;
        if (core.browser == 'ie')
		{
			e.createEvent('onselectstart', function () { return false; });
		}
		else
		{
			e.createEvent('onmousedown', 'disableSelection', function () { return false; });
		}
	
		e.style.cursor = cursor;
	},
	
	zIndex: function (z)
	{
		if (z != undefined)
		{
			this.style.zIndex = z;
		}
		else
		{
			var s = this.getCurrentStyle();
			z = s.zIndex;
		}
		
		return z;
	},
	
	fitTo: function (e)
	{
		e = $(e);	
		this.style.position = 'absolute';
		this.setSize(this.calcSize(e.getSize(true)));
		this.setPos(e.getPos());
	},   	

	autoCenter: function (enabled, params)
	{
		var __this = this;
		if (!(typeof(enabled) != 'undefined')) enabled = true;
		
		if (enabled)
		{
			this.autoCentering = true;
			
			this.center();
			core.page.createEvent(
				'onPageResized', 'autoCenter_' + this.id,
				function () { __this.center(); }
			);	
		}
		else
		{
			this.autoCentering = false;
			core.page.removeEvent('onPageResized', 'autoCenter_' + this.id);
		}
	},
	
	center: function ()
	{
		var pcx = core.page.getScrollH() + (core.page.size.width / 2);
		var pcy = core.page.getScrollV() + (core.page.size.height / 2);
		var x = pcx - (this.getWidth() / 2);
		var y = pcy - (this.getHeight() / 2);
		this.setPos(x, y);
	},
	
	alignTo: function (anchor, vPos, hPos, offsetX, offsetY)
	{
		if (anchor == null) anchor = this.parentNode;
		anchor = $(anchor);
		if (anchor == null) return false;

		var y = null;
		var x = null;

		var size = this.getSize();
		var halfSize = { width: size.width / 2, height: size.height / 2 };

		var anchorSize = anchor.getInnerSize();
		var halfAnchorSize = { width: anchorSize.width / 2, height: anchorSize.height / 2 }; 
		
		this.style.position = 'absolute';
		
		if (typeof(offsetX) == 'object' && offsetX != null)
		{
		 	offsetY = offsetX.y;
		 	offsetX = offsetX.x;
		}

		if (!(typeof(offsetX) != 'undefined') || offsetX == null) offsetX = 0;
		if (!(typeof(offsetY) != 'undefined') || offsetY == null) offsetY = 0;
		
		var parent = $(this.parentNode);
		offsetX += anchor.getLeft() - parent.getLeft();
		offsetY += anchor.getTop() - parent.getTop();		
				
		switch (vPos.toUpperCase())
		{
			case 'TOP':
				y = 0;
				break;
			
			case 'TOP-INSIDE':
				y = 0;
				break;
				
			case 'CENTER':
				y = halfAnchorSize.height - halfSize.height;
				break;

			case 'BOTTOM':				
			case 'BOTTOM-INSIDE':
				y = anchorSize.height - size.height;
				break;
				
			case 'TOP-OUTSIDE':
				y = -(size.height + anchor.getBorderWidth('TOP'));
				break;
				
			case 'BOTTOM-OUTSIDE':
				y = anchorSize.height + anchor.getBorderWidth('BOTTOM');
				break;
			
		}
		
		switch (hPos.toUpperCase())
		{
			case 'LEFT':
			case 'LEFT-INSIDE':
				x = 0;
				break;
				
			case 'CENTER':
				x = halfAnchorSize.width - halfSize.width;
				break;
				
			case 'RIGHT':
				x = anchor.getWidth() - size.width;
			    //x = anchorSize.width + anchor.getPaddingTotalH() - size.width;
				break;
				
			case 'RIGHT-INSIDE':
				x = anchorSize.width - size.width;
				break;
				
			case 'LEFT-OUTSIDE':
				x = -(size.width + anchor.getBorderWidth('LEFT'));
				break;
				
			case 'RIGHT-OUTSIDE':
				x = anchorSize.width + anchor.getBorderWidth('RIGHT');
				break;
		}

		
		x += offsetX;
		y += offsetY;
		
		if (x != null && y != null)
			this.setPos(x, y);
		else if (x != null)
			this.setLeft(x);
		else if (y != null)
			this.setTop(y);
			
		return true;				
	},
	
	isMouseOver: function ()
	{
		var pos = this.getPos();
		var size = this.getSize();
		
		var mpos = core.page.mousePos.offset(core.page.getScrollH(), core.page.getScrollV());
		if (mpos.x >= pos.left && mpos.x <= pos.left + size.width && mpos.y >= pos.top && mpos.y <= pos.top + size.height)
		{
			return true;
		}
		
		return false;
	},
	
	appendElement: function (element)
	{
		var e = $(element);

		try
		{
			this.appendChild(e);
		}
		catch (e)
		{
		}

	},

	insertElementBefore: function (el)
	{
		this.parentNode.insertBefore(el, this);
	},

	insertElementAfter: function (el)
	{
		var nextSibling = this.nextSibling;
		if (nextSibling == null)
		{			
			var nextSibling = $(null, 'div', this.parentNode);	
			this.parentNode.insertBefore(el, nextSibling);
			nextSibling.remove();
		}
		else
		{		
			this.parentNode.insertBefore(el, nextSibling);
		}
	},
		
	remove: function ()
	{
		if (this.parentNode == null) return false;
		this.parentNode.removeChild(this);
	},
	
	findAncestor: function (nodeName)
	{
		var cn = this.parentNode;
		nodeName = nodeName.toLowerCase();
		
	 	while (cn != null)
	 	{
			if (cn.nodeName.toLowerCase() == nodeName) return $(cn);
			cn = cn.parentNode;	 	
	 	}
	 	
	 	return null;
	},
	
	findSibling: function (nodeName, which)
	{
		if (!(typeof(which) != 'undefined')) which = 'next';
		
		var cn = this.parentNode;
		nodeName = nodeName.toLowerCase();
		var sibling = which + 'Sibling';
		
	 	while (cn != null)
	 	{
			if (cn.nodeName.toLowerCase() == nodeName) return $(cn);
			cn = cn[sibling];	 	
	 	}
	 	
	 	return null;
	}
};

core.Rect = function (left, top, width, height)
{
 	this.left = left;
 	this.top = top;
 	this.width = width;
 	this.height = height;
 	
 	this.testPoint = function (x, y)
 	{
 		return (x >= this.left && x <= this.left + this.width && y >= this.top && y <=this.top + this.height);
 	}
 	
 	this.expand = function (w, h)
 	{
 	 	if (w > 0)
		{
			this.left -= w;
 	 		this.width += w * 2;
 	 	}
 	 	
 	 	if (h > 0)
 	 	{
	 	 	this.top -= h;
	 	 	this.height += h * 2;
	 	}
 	}
}


function $(id, createElement, parentElement, params)
{
	var e = null;
	var type = typeof(id);
	
	if ((typeof(createElement) != 'undefined') && createElement != null)
	{
		if (createElement == 'clearer')
		{
			e = core.doc.createElement('p');
			e.style.clear = 'both';
			e.style.lineHeight = '0px';
			e.style.height = '0px';
			e.style.margin = '0px';
			e.style.border = '0px';
		}
		else
		{
			e = core.doc.createElement(createElement);
		}
		
		if (id !== null) e.id = id;
	}
	else
	{
		if (type == 'string')
		{
			e = core.doc.getElementById(id);
		}
		else if (type == 'object')
		{
			e = id;
		}
	}
	
	if (e == null) return null;
	
	if (!(typeof(e.isCoreElement) != 'undefined'))
	{
		if ((typeof(params) != 'undefined') && (typeof(params.extendWith) != 'undefined'))
		{
			if (typeof(params.extendWith) == 'object')
			{
				for (var i=0; i<params.extendWith; i++)
				{
					core.extend(e, params.extendWith[i]);
				}
			}
			else
			{
			 	core.extend(e, params.extendWith);
			}
		}
		else
		{
			core.extend(e, core.element);
			core.extend(e, core.events);
			core.extend(e, core.timing);
		}
	}
	
	if ((typeof(parentElement) != 'undefined'))
	{
		if (parentElement == 'BODY')
		{
			core.doc.body.appendChild(e);
		}
		else
		{
			$(parentElement).appendElement(e);
		}
	}
	
	return e;
}

function parseInt_wd(obj, defaultVal)
{
	if (!(typeof(defaultVal) != 'undefined'))
		defaultVal = 0;
		
	var val = parseInt(obj);
	if (isNaN(val) || val === null || typeof(val) === 'undefined' || val === '')
		val = defaultVal;
		
	return val;
}

core.install = function (win)
{
	var doc = win.document;
	win.core = new Object();
	core.initializeOnPageLoaded(
		win, 
		function ()
		{
			var scripts = core.doc.getElementsByTagName('script');
			var docHead = core.doc.getElementsByTagName('head');
				
			for (var i in scripts)
			{
			 	var s = scripts[i];
			 	if ((typeof(s.src) != 'undefined') && s.src != '')
			 	{
			 		var newScript = doc.createElement('script');
			 		newScript.src = s.src;
			 		newScript.type = s.type;
			 		doc.body.appendChild(newScript);
			 	}
			}
			
		}
	);
}

core.setDoc = function (doc)
{
	core.previousDoc = core.doc;
	core.doc = doc;
}

core.resetDoc = function ()
{
	core.doc = core.previousDoc;
}

/*
function addCss(cssCode) {
var styleElement = document.createElement("style");
  styleElement.type = "text/css";
  if (styleElement.styleSheet) {
    styleElement.styleSheet.cssText = cssCode;
  } else {
    styleElement.appendChild(document.createTextNode(cssCode));
  }
  document.getElementsByTagName("head")[0].appendChild(styleElement);
}
*/

core.insertScript = function (type, code, params)
{
	var doc = ((typeof(params.document) != 'undefined') ? params.document : core.doc);
	var head = doc.getElementsByTagName('head')[0];

    var e = $(null, 'style');
    e.type = 'text/css';
    if ((typeof(e.styleSheet) != 'undefined'))
    {
     	e.styleSheet.cssText = code;
    }
    else
    {
     	e.appendChild(document.createTextNode(code));
    }
	
	head.appendChild(e);
	/*var scriptEl = $(null, 'style');
	scriptEl.type = 'text/stylesheet';
	scriptEl.innerHTML = code;
	head.appendChild(scriptEl);*/
}


function onPageLoaded(func)
{
	core.__onPageLoaded.push(func);
}


core.extend = function (dst, src)
{
	$object.extend(dst, src);
}

core.extendClass = function (dst, src)
{
	$object.extend(dst, src);
}

var $object = {
	count: function (obj)
	{
		var c = 0;
		for (var i in obj);
			c++;
		
		return c;
	},
	
	firstKey: function (obj)
	{
		for (var i in obj)
			return i;
	},
	
	getFirst: function (obj)
	{
		for (var i in obj)
			return obj[i];		
	},
	
	getLast: function (obj)
	{
		for (var i in obj)
			continue;
		
		return obj[i];
	},
	
	getKeys: function (obj)
	{
		var keys = new Array();
		for (var i in obj)
		{
			keys.push(i);		
		}
		return keys;
	},
	
	iterate: function (obj, func, ignoreFuncs)
	{
		if (typeof(ignoreFuncs) == 'undefined') ignoreFuncs = true;
		 
		for (var i in obj)
		{
			if (ignoreFuncs == true && typeof(obj[i]) == 'function')
				continue;
				
			func(obj, obj[i], i);
		}
	},
	
	extend: function (dst, src)
	{
		var hasPrototype = (typeof(dst.prototype) != 'undefined');
		
		try {
		for (var i in src)
		{
			if (hasPrototype && typeof(src[i]) == 'function')
			{
				dst.prototype[i] = src[i];
			}
			else
			{
				dst[i] = src[i];
			}
		}
		} catch (ex) {  }
	},
	
	clone: function (obj)
	{		
		function _getValue(v)
		{
			var t = typeof(v);
			switch (t)
			{
				case 'string': return '' + v; 
				case 'object': return $object.clone(v);
				case 'number': return 0 + v;
				case 'boolean': return (v ? true : false);
			}
			
			return null;
		}
		
		if (typeof(obj) == 'object')
		{
			var newObj = ((typeof(obj.length) != 'undefined') ? [] : {});
		 	for (var i in obj)
		 	{
		 	 	newObj[i] = _getValue(obj[i]);
		 	}
		 	
		 	return newObj;
		}
		
		return _getValue(obj);
	},
	
	toQueryString: function (obj, forPHP, parentObject)
	{
	   if( typeof obj != 'object' ) return '';
	
	   if (arguments.length == 1)
	      forPHP = /\.php$/.test(core.doc.location.href);
	   
	   var rv = '';
	   for(var prop in obj) if (obj.hasOwnProperty(prop) ) {
	
	      var qname = parentObject
	         ? parentObject + '.' + prop
	         : prop;
	
	      // Expand Arrays
	      if (obj[prop] instanceof Array)
	         for( var i = 0; i < obj[prop].length; i++ )
	            if( typeof obj[prop][i] == 'object' )
	               rv += '&' + core.toQueryString( obj[prop][i], forPHP, qname );
	            else
	               rv += '&' + encodeURIComponent(qname) + (forPHP ? '[]' : '')
						+ '=' + encodeURIComponent( obj[prop][i] );
	
	      // Expand Dates
	      else if (obj[prop] instanceof Date)
	         rv += '&' + encodeURIComponent(qname) + '=' + obj[prop].getTime();
	
	      // Expand Objects
	      else if (obj[prop] instanceof Object)
	         // If they're String() or Number() etc
	         if (obj.toString && obj.toString !== Object.prototype.toString)
	            rv += '&' + encodeURIComponent(qname) + '=' + encodeURIComponent( obj[prop].toString() );
	         // Otherwise, we want the raw properties
	         else
	            rv += '&' + $object.toQueryString(obj[prop], forPHP, qname);
	
	      // Output non-object
	      else
	         rv += '&' + encodeURIComponent(qname) + '=' + encodeURIComponent( obj[prop] );
	
	   }
	   return rv.replace(/^&/,'');
	
	}
}

var $string = {
	truncate: function (str, maxLen, suffix)
	{
		if (!(typeof(str) != 'undefined') || str == null) return null;
		if (!(typeof(suffix) != 'undefined')) suffix = '...';
		return (str.length > maxLen ? str.substr(0, maxLen) + suffix : str);
	},
	
	trim: function (str)
	{
	    return str.replace(/^\s*/, "").replace(/\s*$/, "");
	},
	
	translate: function (str, translations, re)
	{
		if (!(typeof(re) != 'undefined'))
		{
			re = /\${([^}]*)}/g;
		}
		
		var key;
		var ret = str;
		
		while ((key = re.exec(str)) != null)
		{
			if ((typeof(translations[key[1]]) != 'undefined'))
				ret = ret.replace(key[0], translations[key[1]]);
		}
		
		return ret;
	},
	
	isEmpty: function (str)
	{
		if (str.length == 0) return true;
	},
	
	endsWith: function (str, cmpStr, caseSensitive)
	{
		if (!(typeof(str) != 'undefined')) return false;
		var strLen = str.length;
		var cmpStrLen = cmpStr.length;
		if (strLen == 0 || strLen < cmpStrLen) return false;
		
		if (!(typeof(caseSensitive) != 'undefined')) caseSensitive = true;

		var _str, _cmpStr;
		if (!caseSensitive)
		{
			_str = str.toLowerCase();
			_cmpStr = cmpStr.toLowerCase();
		}
		else
		{
			_str = str;
			_cmpStr = cmpStr;
		}
		
		if (strLen >= cmpStrLen && _str.substr(strLen - cmpStrLen, cmpStrLen) == _cmpStr)
			return true;
			
		return false;
	}, 

	beginsWith: function (str, cmpStr, caseSensitive)
	{
		if (!(typeof(str) != 'undefined')) return false;
		var strLen = str.length;
		var cmpStrLen = cmpStr.length;
		if (strLen == 0 || strLen < cmpStrLen) return false;

		var _str, _cmpStr;
		if (!caseSensitive)
		{
			_str = str.toLowerCase();
			_cmpStr = cmpStr.toLowerCase();
		}
		else
		{
			_str = str;
			_cmpStr = cmpStr;
		}
		
		if (strLen >= cmpStrLen && _str.substr(0, cmpStrLen) == _cmpStr)
			return true;
			
		return false;
	},
	
	toAlias: function (str)
	{
		var alias = '';
		alias = $string.removeAccents(str);
		alias = $string.trim(alias);
		alias = alias.toLowerCase();
		alias = alias.replace(/&/, '-and-');
		//alias = alias.replace(/&/g, 'and', alias);
		alias = alias.replace(/\W/g, '-', alias);
		alias = alias.replace(/-{2,}/g, '-');
		alias = alias.replace(/-$|^-/g, '');
		
		return alias;	
	},
	
	modifyUrl: function (url, params)
	{
		append = '';
		
		if (url == null)
		{
			url = String(window.location);
			if ($string.beginsWith(url.toLowerCase(), 'http://'))
			{
			 	url = url.substr(url.indexOf('/', 7));
			}
		} 
		
		if ((typeof(params.namedParams) != 'undefined'))
		{
			var appendList = new Array();
			for (var name in params.namedParams)
			{
				var value = params.namedParams[name];
				var re = new RegExp('(([\/;]+)' + name + ':[^\/;]*)');
			
				var match = re.exec(url);
				if (match != null)
				{
					url = url.replace(match[0], match[2] + name + ':' + value);
				}
				else
				{
					appendList.push(name + ':' + value);  
				}
			}
			
			url += (!$string.endsWith(url, '/') ? '/' : '') + appendList.join(';');
		}
		
		return url;
	},
	
	randomId: function ()
	{
	 	return String(Math.round(Math.random() * 1000));
	},
	
	toBool: function (str)
	{
		var type = typeof(str);
		if (type == 'boolean' || type == 'number')
		 	return (str === true || str === 1);
		
		var lcstr = String(str).toLowerCase();
		return (lcstr == 'true' || lcstr == 'yes' || lcstr == 1);
	},
	
	toValueUnit: function (value)
	{
		var m, unit;
		m = /([0-9.]*)(.*)/.exec(value);
		value = m[1];
		unit = m[2];
		return { value: parseInt_wd(value), unit: unit };		
	},

	utf8: function (str)
	{
		str = str.replace(/\r\n/g,"\n");
		var ret = '';
 
		for (var i=0; i<str.length; i++) {
 
			var c = str.charCodeAt(i);
 
			if (c < 128)
			{
				ret += String.fromCharCode(c);
			}
			else if ((c > 127) && (c < 2048))
			{
				ret += String.fromCharCode((c >> 6) | 192);
				ret += String.fromCharCode((c & 63) | 128);
			}
			else
			{
				ret += String.fromCharCode((c >> 12) | 224);
				ret += String.fromCharCode(((c >> 6) & 63) | 128);
				ret += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return ret;
	},
			
	crc32: function crc32 (str)
	{
		str = $string.utf8(str);

		var table = [
			0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419,
			0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4,
			0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07,
			0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
			0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856,
			0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
			0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
			0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
			0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,
			0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A,
			0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599,
			0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
			0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190,
			0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
			0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E,
			0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
			0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED,
			0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
			0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3,
			0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
			0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
			0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
			0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010,
			0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
			0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17,
			0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6,
			0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,
			0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
			0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344,
			0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
			0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A,
			0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
			0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1,
			0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C,
			0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
			0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
			0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE,
			0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
			0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C,
			0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
			0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B,
			0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
			0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1,
			0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
			0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278,
			0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
			0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66,
			0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
			0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
			0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8,
			0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B,
			0x2D02EF8D
		];
	 
		var crc = 0;
		var x = 0;
		var y = 0;
		var strLen = str.length;
		crc = crc ^ (-1);
		
		for(var i=0; i<strLen; i++)
		{
			y = (crc ^ str.charCodeAt( i )) & 0xFF;
			x = table[y];
			crc = (crc >>> 8) ^ x;
		}
	 
		return crc ^ (-1);
	},

	remAccentsRegExs: {
		'a': '[\xE0\xE1\xE2\xE3\xE4\xE5]',
		'A': '[\xC0\xC1\xC2\xC3\xC4\xC5]',
		'E': '[\xC8\xC9\xCA\xCB]',
		'e': '[\xE8\xE9\xEA\xEB]',
		'i': '[\xEC\xED\xEE\xEF]',
		'I': '[\xCC\xCD\xCE\xCF]',
		'u': '[\xF9\xFA\xFB\xFC]',
		'U': '[\xD9\xDA\xDB\xDC]',
		'O': '[\xD2\xD3\xD4\xD5\xD6\xD8]',
		'o': '[\xF2\xF3\xF4\xF5\xF6\xF8]',
		'c': '\xE7',
		'C': '\xC7',
		'ae': '\u00E6',
		'AE': '\u00C6',
		'N': '\xD1',
		'n': '\xF1',
		'y': '[\xFD\xFF]',
		'Y': '[\xDD\x9F]',
		'oe': '\u0153',
		'OE': '\u0152',
		'S': '\u0160',
		's': '\u0161',
		'Z': '\u017D',
		'z': '\u017E'		
	},
	
	removeAccents: function (str)
	{
		var re;
	 	for (var repl in this.remAccentsRegExs)
	 	{
	 		re = this.remAccentsRegExs[repl];
	 	 	str = str.replace(new RegExp(re, 'g'), repl);
	 	}
	 	
	 	return str;
	},
	
	convertNewLines: function (str, toText)
	{
		if (!(typeof(toText) != 'undefined')) toText = true;
		str = str.replace(new RegExp('\\r', 'g'), '');
		
		if (toText)
		{
			str = str.replace(new RegExp('\\n', 'g'), '\\n');
		}
		else
		{
			str = str.replace(new RegExp('\\\\n', 'g'), '\n');
		}
		
		return str;
	},
	
	toHtml: function (str, inline)
	{
		if (typeof(str) != 'string') return str;
		if (!(typeof(inline) != 'undefined')) inline = false;
		
		str = str.replace(new RegExp('&(?![a-z]*;)', 'g'), '&amp;');
		str = str.replace(new RegExp('<', 'g'), '&lt;');
		str = str.replace(new RegExp('>', 'g'), '&gt;');
		str = str.replace(new RegExp('"', 'g'), '&quot;');
		
		if (inline)
		{
			str = str.replace(new RegExp('\\r', 'g'), '');
			str = str.replace(new RegExp('\\n', 'g'), '\\n');
		}
		
		return str;
	},
	
	fromHtml: function (str)
	{
		if (typeof(str) != 'string') return str;
		
		str = str.replace(new RegExp('&lt;', 'ig'), '<');
		str = str.replace(new RegExp('&gt;', 'ig'), '>');
		str = str.replace(new RegExp('&quot;', 'ig'), '"');
		str = str.replace(new RegExp('&amp;', 'ig'), '&');
		str = str.replace(new RegExp('\\\\n', 'ig'), '\n');
		
		return str;
	},
	
	decodeHtmlEntities: function (str) 
	{
		var e, ret;
		
	    e = document.createElement('div');
	    e.innerHTML = str;
	    ret = e.innerHTML;

	    return ret;
	},

	escapeChars: [
		'$', '%', '+', '<', '>', '#', '{', '}', '|', '\\', '^', '~', '[', ']', 
		'`', ';', '/', '?', ':', '@', '=', '&', "\n", "\r", "\t", '"', '\''
	],
	
	escapeCodes: [
		'$24', '$25', '$2B', '$3C', '$3E', '$23', '$7B', '$7D', '$7C', 
		'$5C', '$5E', '$7E', '$5B', '$5D', '$60', '$3B', '$2F', '$3F',
		'$3A', '$40', '$3D', '$26', '$0A', '$0D', '$09', '$22', '$27'
	],

 	htmlAttrEscapeChars: [
		'$', '<', '>', '\\', '/', "\n", "\r", "\t", '"', '\''
	],                                 
	
	htmlAttrEscapeCodes: [
		'$24', '$3C', '$3E', '$5C', '$2F', '$0A', '$0D', '$09', '$22', '$27'
	], 
			
	escape: function (str, htmlAttrib)
	{
		if (!(typeof(htmlAttrib) != 'undefined')) htmlAttrib = false;
		
		if (!htmlAttrib)
		{		
			var escChars = $string.escapeChars;
			var escCodes = $string.escapeCodes;
		}
		else
		{
			var escChars = $string.htmlAttrEscapeChars;
			var escCodes = $string.htmlAttrEscapeCodes;
		}

	 	for (var i=0; i<escChars.length; i++)
	 	{
	 	 	var ec = escChars[i];
			str = str.replace(new RegExp($string.regexEscape(ec), 'mg'), escCodes[i]); 
	 	}
	 	
	 	if (!htmlAttrib) str = str.replace(/\s/mg, '+');

	 	return str;
	},
	
	unescape: function (str, htmlAttrib)
	{
		if (!(typeof(htmlAttrib) != 'undefined')) htmlAttrib = false;

		if (!htmlAttrib)
		{
			str = str.replace(/\+/mg, ' ');		
			var escChars = $string.escapeChars;
			var escCodes = $string.escapeCodes;
		}
		else
		{
			var escChars = $string.htmlAttrEscapeChars;
			var escCodes = $string.htmlAttrEscapeCodes;
		}
		
	 	for (var i=0; i<escCodes.length; i++)
	 	{
	 	 	var ec = escCodes[i];
			str = str.replace(new RegExp($string.regexEscape(ec), 'mg'), escChars[i]); 
	 	}
	 	
	 	return str;
	},
	
	regexEscape: function (str)
	{
		return str.replace(/([[\]\^$.|?*+(){}\\])/img, '\\$1')
			.replace(/\r/mg, '\\r')
			.replace(/\n/mg, '\\n')
			.replace(/\t/mg, '\\t'); 
	} 

};

var $array = {
  	remove: function (arr, index, count)
  	{
  		if (!(typeof(count) != 'undefined')) count = 1;
  		return arr.splice(index, count);
  	},
  	
  	insert: function (arr, index, obj)
  	{
  	 	arr.splice(index, 0, obj);
  	},
  	
  	getPath: function (arr, path)
  	{
		var varStr = "arr['" + path.replace('/', '\'][\'') + "']";
		try
		{
  	 		eval("var node = " + varStr + ";");
  	 		return node;
  	 	}
  	 	catch (ex)
  	 	{
  	 		return null;
  	 	}
  	},
  
  	firstNode: function (arr, remove)
	{  		
  		if (!(typeof(remove) != 'undefined')) remove = false;
  	 	var n = arr[0];
  	 	if ((typeof(remove) != 'undefined') && remove == true) $array.remove(arr, 0, 1);
		return n;	
	},
		
  	lastNode: function (arr, remove)
  	{
  		var i, n;
  		i = arr.length - 1;
  	 	n = arr[i];
  	 	if ((typeof(remove) != 'undefined') && remove == true) $array.remove(arr, i, 1);
		return n; 
  	},
  	
  	indexOf: function (arr, search)
  	{
		for (var i=0; i<arr.length; i++)
		{
		 	if (arr[i] == search) return i;
		}
		
		return -1;  	
  	}
};

var $number = {
	isNumeric: function (str)
	{
		for (var i=0; i<str.length; i++)
		{
		 	var c = str.charAt(i);
		 	if (!((c >= '0' && c <= '9') || c == '.'))
		 		return false;
		}
		
		return true;
	},

	format: function (n, decimals, decimalChar, thousandSep)
	{
		if (!(typeof(decimals) != 'undefined')) decimals = 0;
		if (!(typeof(decimalChar) != 'undefined')) decimalChar = '.';
		if (!(typeof(thousandSep) != 'undefined')) thousandSep = ',';
		if (decimals == 0) n = Math.round(n);
		
		var nStr = '' + n;
		var segs = nStr.split('.');
		var num = segs[0];
		var dec = (segs.length > 1 ? decimalChar + (decimals > 0 ? segs[1].substr(0, decimals) : segs[1]) : '');
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(num))
		{
			num = num.replace(rgx, '$1' + thousandSep + '$2');
		}
		
		return num + dec;
	},
	
	humanize: function (n, type)
	{
		if (!(typeof(type) != 'undefined')) type = 'filesize';
		var ret = '';
		
		switch (type)
		{
			case 'filesize':
				if (n >= 1073741824)
				{
					ret = $number.format(n / 1073741824, 2, '.', '') + ' GB';
				}
				else
				{
					if (n >= 1048576)
					{
						ret = $number.format(n / 1048576, 2, '.', '') + ' MB';
					}
					else
					{
						if (n >= 1024)
						{
							ret = $number.format(n / 1024, 0) + ' KB';
						}
						else
						{
							ret = $number.format(n, 0) + ' bytes';
						}
					}
				}
				break;
				
			default:
				ret = n;
		}
		
		return ret;
	}	
};

var $filesys = {
	getExtension: function (path)
	{
		var lastDotPos = path.lastIndexOf('.');
		return (lastDotPos > -1 ? path.substr(lastDotPos) : null);
	}
};

var $serialize = {
 	encode: function (obj)
 	{ 	
 		switch (typeof(obj))
 		{
 			case 'string':
	 			return 's:' + obj.length + ':' + obj;
	 			
			case 'object':
				if (obj == null) return '0';
				
				var nodes = [];
				for (var id in obj)
				{
					var value = obj[id];
					var n = $serialize.encode(value);
					if (n == null) continue;
				 	nodes.push(id.length + ':' + id + ':' + n.length + ':' + n);
				}
				
				var arrStr = nodes.join(';');
				return 'a:' + nodes.length + ':' + arrStr.length + ':' + arrStr;
			case 'number':
				var typeId = 'i';
				var objStr = String(obj);
				if (objStr.indexOf('.') > -1)
				{
				 	typeId = 'f';
				}
				
				return typeId + ':' + objStr.length + ':' + objStr;
			
			case 'boolean':
				return 'b:' + (obj == true ? '1' : '0');			 
		}
		
		return null;
		/*else if (is_int($obj)) return 'i:' . $obj; 
		else if (is_double($obj)) return 'd:' . $obj;
		else if (is_float($obj)) return 'f:' . $obj;*/
 	}
 	
 	/*
 	
 	public static function decode($str)
 	{
 		switch ($str[0])
 		{
 			case 's':
 				$sp = strpos($str, ':', 2);
 				$len = substr($str, 2, $sp - 2);
 				return substr($str, $sp + 1, $len);

            case 'a':
 				$sp = strpos($str, ':', 2);
 				$cnt = substr($str, 2, $sp - 2);
 				
 				$offset = $sp + 1;
				$sp = strpos($str, ':', $offset);
				$len = substr($str, $offset, $sp - $offset);

                $offset = $sp + 1;
                $arrStr = substr($str, $offset, $len + 2);
                
                $offset = 0;
                $nodes = array();
				
				for ($i=0; $i<$cnt; $i++)
				{
				 	$sp = strpos($arrStr, ':', $offset);
				 	$idLen = substr($arrStr, $offset, $sp - $offset);
				 	$id = substr($arrStr, $sp + 1, $idLen);
				 	
				 	$offset = $sp + 2 + $idLen;
				 	
				 	$sp = strpos($arrStr, ':', $offset);
				 	$strLen = substr($arrStr, $offset, $sp - $offset);
				 	$offset = $sp + 1;

					$nodes[$id] = SERIALIZE::decode(substr($arrStr, $offset));
					
					$offset = $sp + $strLen + 2;
				}
				
				return $nodes;
				
			case 'i':
 				$sp = strpos($str, ':', 2);
 				return (int)substr($str, 2);
 		}
 	} */
};
/*core.createClassPath('core.elements');

core.elements.DatePicker = core.createClass(
{
	init: function (id, params)
	{
		this.id = id;
		core.extend(this, params);
		
		this.els = new Object();
		this.els.container = $(null, 'div', 'BODY');
		
		this.els.container.applyStyle({ position: 'absolute' });
		
		
	}
});
*/


// Temporary date picker below... new one to come!

/**
This is a JavaScript library that will allow you to easily add some basic DHTML
drop-down datepicker functionality to your Notes forms. This script is not as
full-featured as others you may find on the Internet, but it's free, it's easy to
understand, and it's easy to change.

You'll also want to include a stylesheet that makes the datepicker elements
look nice. An example one can be found in the database that this script was
originally released with, at:

http://www.nsftools.com/tips/NotesTips.htm#datepicker

I've tested this lightly with Internet Explorer 6 and Mozilla Firefox. I have no idea
how compatible it is with other browsers.

version 1.5
December 4, 2005
Julian Robichaux -- http://www.nsftools.com

HISTORY
--  version 1.0 (Sept. 4, 2004):
Initial release.

--  version 1.1 (Sept. 5, 2004):
Added capability to define the date format to be used, either globally (using the
defaultDateSeparator and defaultDateFormat variables) or when the displayDatePicker
function is called.

--  version 1.2 (Sept. 7, 2004):
Fixed problem where datepicker x-y coordinates weren't right inside of a table.
Fixed problem where datepicker wouldn't display over selection lists on a page.
Added a call to the datePickerClosed function (if one exists) after the datepicker
is closed, to allow the developer to add their own custom validation after a date
has been chosen. For this to work, you must have a function called datePickerClosed
somewhere on the page, that accepts a field object as a parameter. See the
example in the comments of the updateDateField function for more details.

--  version 1.3 (Sept. 9, 2004)
Fixed problem where adding the <div> and <iFrame> used for displaying the datepicker
was causing problems on IE 6 with global variables that had handles to objects on
the page (I fixed the problem by adding the elements using document.createElement()
and document.body.appendChild() instead of document.body.innerHTML += ...).

--  version 1.4 (Dec. 20, 2004)
Added "targetDateField.focus();" to the updateDateField function (as suggested
by Alan Lepofsky) to avoid a situation where the cursor focus is at the top of the
form after a date has been picked. Added "padding: 0px;" to the dpButton CSS
style, to keep the table from being so wide when displayed in Firefox.

-- version 1.5 (Dec 4, 2005)
Added display=none when datepicker is hidden, to fix problem where cursor is
not visible on input fields that are beneath the date picker. Added additional null
date handling for date errors in Safari when the date is empty. Added additional
error handling for iFrame creation, to avoid reported errors in Opera. Added
onMouseOver event for day cells, to allow color changes when the mouse hovers
over a cell (to make it easier to determine what cell you're over). Added comments
in the style sheet, to make it more clear what the different style elements are for.
*/

var datePickerDivID = "datepicker";
var iFrameDivID = "datepickeriframe";

var dayArrayShort = new Array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa');
var dayArrayMed = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
var dayArrayLong = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var monthArrayShort = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var monthArrayMed = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
var monthArrayLong = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
 
// these variables define the date formatting we're expecting and outputting.
// If you want to use a different format by default, change the defaultDateSeparator
// and defaultDateFormat variables either here or on your HTML page.
var defaultDateSeparator = "/";        // common values would be "/" or "."
var defaultDateFormat = "dmy"    // valid values are "mdy", "dmy", and "ymd"
var dateSeparator = defaultDateSeparator;
var dateFormat = defaultDateFormat;

/**
This is the main function you'll call from the onClick event of a button.
Normally, you'll have something like this on your HTML page:

Start Date: <input name="StartDate">
<input type=button value="select" onclick="displayDatePicker('StartDate');">

That will cause the datepicker to be displayed beneath the StartDate field and
any date that is chosen will update the value of that field. If you'd rather have the
datepicker display beneath the button that was clicked, you can code the button
like this:

<input type=button value="select" onclick="displayDatePicker('StartDate', this);">

So, pretty much, the first argument (dateFieldName) is a string representing the
name of the field that will be modified if the user picks a date, and the second
argument (displayBelowThisObject) is optional and represents an actual node
on the HTML document that the datepicker should be displayed below.

In version 1.1 of this code, the dtFormat and dtSep variables were added, allowing
you to use a specific date format or date separator for a given call to this function.
Normally, you'll just want to set these defaults globally with the defaultDateSeparator
and defaultDateFormat variables, but it doesn't hurt anything to add them as optional
parameters here. An example of use is:

<input type=button value="select" onclick="displayDatePicker('StartDate', false, 'dmy', '.');">

This would display the datepicker beneath the StartDate field (because the
displayBelowThisObject parameter was false), and update the StartDate field with
the chosen value of the datepicker using a date format of dd.mm.yyyy
*/
function displayDatePicker(dateFieldName, displayBelowThisObject, dtFormat, dtSep)
{
  var targetDateField = document.getElementsByName (dateFieldName).item(0);
 
  // if we weren't told what node to display the datepicker beneath, just display it
  // beneath the date field we're updating
  if (!displayBelowThisObject)
    displayBelowThisObject = targetDateField;
 
  // if a date separator character was given, update the dateSeparator variable
  if (dtSep)
    dateSeparator = dtSep;
  else
    dateSeparator = defaultDateSeparator;
 
  // if a date format was given, update the dateFormat variable
  if (dtFormat)
    dateFormat = dtFormat;
  else
    dateFormat = defaultDateFormat;
 
  var x = displayBelowThisObject.offsetLeft;
  var y = displayBelowThisObject.offsetTop + displayBelowThisObject.offsetHeight ;
 
  // deal with elements inside tables and such
  var parent = displayBelowThisObject;
  while (parent.offsetParent) {
    parent = parent.offsetParent;
    x += parent.offsetLeft;
    y += parent.offsetTop ;
  }
 
  drawDatePicker(targetDateField, x, y);
}


/**
Draw the datepicker object (which is just a table with calendar elements) at the
specified x and y coordinates, using the targetDateField object as the input tag
that will ultimately be populated with a date.

This function will normally be called by the displayDatePicker function.
*/
function drawDatePicker(targetDateField, x, y)
{
  var dt = getFieldDate(targetDateField.value );
 
  // the datepicker table will be drawn inside of a <div> with an ID defined by the
  // global datePickerDivID variable. If such a div doesn't yet exist on the HTML
  // document we're working with, add one.
  if (!document.getElementById(datePickerDivID)) {
    // don't use innerHTML to update the body, because it can cause global variables
    // that are currently pointing to objects on the page to have bad references
    //document.body.innerHTML += "<div id='" + datePickerDivID + "' class='dpDiv'></div>";
    var newNode = document.createElement("div");
    newNode.setAttribute("id", datePickerDivID);
    newNode.setAttribute("class", "dpDiv");
    newNode.setAttribute("style", "visibility: hidden;");
    document.body.appendChild(newNode);
  }
 
  // move the datepicker div to the proper x,y coordinate and toggle the visiblity
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.position = "absolute";
  pickerDiv.style.left = x + "px";
  pickerDiv.style.top = y + "px";
  pickerDiv.style.visibility = (pickerDiv.style.visibility == "visible" ? "hidden" : "visible");
  pickerDiv.style.display = (pickerDiv.style.display == "block" ? "none" : "block");
  pickerDiv.style.zIndex = 10000;
 
  // draw the datepicker table
  refreshDatePicker(targetDateField.name, dt.getFullYear(), dt.getMonth(), dt.getDate());
}


/**
This is the function that actually draws the datepicker calendar.
*/
function refreshDatePicker(dateFieldName, year, month, day)
{
  // if no arguments are passed, use today's date; otherwise, month and year
  // are required (if a day is passed, it will be highlighted later)
  var thisDay = new Date();
 
  if ((month >= 0) && (year > 0)) {
    thisDay = new Date(year, month, 1);
  } else {
    day = thisDay.getDate();
    thisDay.setDate(1);
  }
 
  // the calendar will be drawn as a table
  // you can customize the table elements with a global CSS style sheet,
  // or by hardcoding style and formatting elements below
  var crlf = "\r\n";
  var TABLE = "<table cols=7 class='dpTable'>" + crlf;
  var xTABLE = "</table>" + crlf;
  var TR = "<tr class='dpTR'>";
  var TR_title = "<tr class='dpTitleTR'>";
  var TR_days = "<tr class='dpDayTR'>";
  var TR_todaybutton = "<tr class='dpTodayButtonTR'>";
  var xTR = "</tr>" + crlf;
  var TD = "<td class='dpTD' onMouseOut='this.className=\"dpTD\";' onMouseOver=' this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var TD_title = "<td colspan=5 class='dpTitleTD'>";
  var TD_buttons = "<td class='dpButtonTD'>";
  var TD_todaybutton = "<td colspan=7 class='dpTodayButtonTD'>";
  var TD_days = "<td class='dpDayTD'>";
  var TD_selected = "<td class='dpDayHighlightTD' onMouseOut='this.className=\"dpDayHighlightTD\";' onMouseOver='this.className=\"dpTDHover\";' ";    // leave this tag open, because we'll be adding an onClick event
  var xTD = "</td>" + crlf;
  var DIV_title = "<div class='dpTitleText'>";
  var DIV_selected = "<div class='dpDayHighlight'>";
  var xDIV = "</div>";
 
  // start generating the code for the calendar table
  var html = TABLE;
 
  // this is the title bar, which displays the month and the buttons to
  // go back to a previous month or forward to the next month
  html += TR_title;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, -1, "&lt;") + xTD;
  html += TD_title + DIV_title + monthArrayLong[ thisDay.getMonth()] + " " + thisDay.getFullYear() + xDIV + xTD;
  html += TD_buttons + getButtonCode(dateFieldName, thisDay, 1, "&gt;") + xTD;
  html += xTR;
 
  // this is the row that indicates which day of the week we're on
  html += TR_days;
  for(i = 0; i < dayArrayShort.length; i++)
    html += TD_days + dayArrayShort[i] + xTD;
  html += xTR;
 
  // now we'll start populating the table with days of the month
  html += TR;
 
  // first, the leading blanks
  for (i = 0; i < thisDay.getDay(); i++)
    html += TD + "&nbsp;" + xTD;
 
  // now, the days of the month
  do {
    dayNum = thisDay.getDate();
    TD_onclick = " onclick=\"updateDateField('" + dateFieldName + "', '" + getDateString(thisDay) + "');\">";
    
    if (dayNum == day)
      html += TD_selected + TD_onclick + DIV_selected + dayNum + xDIV + xTD;
    else
      html += TD + TD_onclick + dayNum + xTD;
    
    // if this is a Saturday, start a new row
    if (thisDay.getDay() == 6)
      html += xTR + TR;
    
    // increment the day
    thisDay.setDate(thisDay.getDate() + 1);
  } while (thisDay.getDate() > 1)
 
  // fill in any trailing blanks
  if (thisDay.getDay() > 0) {
    for (i = 6; i > thisDay.getDay(); i--)
      html += TD + "&nbsp;" + xTD;
  }
  html += xTR;
 
  // add a button to allow the user to easily return to today, or close the calendar
  var today = new Date();
  var todayString = "Today is " + dayArrayMed[today.getDay()] + ", " + monthArrayMed[ today.getMonth()] + " " + today.getDate();
  html += TR_todaybutton + TD_todaybutton;
  html += "<button class='dpTodayButton' onClick='refreshDatePicker(\"" + dateFieldName + "\");'>this month</button> ";
  html += "<button class='dpTodayButton' onClick='updateDateField(\"" + dateFieldName + "\");'>close</button>";
  html += xTD + xTR;
 
  // and finally, close the table
  html += xTABLE;
 
  document.getElementById(datePickerDivID).innerHTML = html;
  // add an "iFrame shim" to allow the datepicker to display above selection lists
  adjustiFrame();
}


/**
Convenience function for writing the code for the buttons that bring us back or forward
a month.
*/
function getButtonCode(dateFieldName, dateVal, adjust, label)
{
  var newMonth = (dateVal.getMonth () + adjust) % 12;
  var newYear = dateVal.getFullYear() + parseInt((dateVal.getMonth() + adjust) / 12);
  if (newMonth < 0) {
    newMonth += 12;
    newYear += -1;
  }
 
  return "<button class='dpButton' onClick='refreshDatePicker(\"" + dateFieldName + "\", " + newYear + ", " + newMonth + ");'>" + label + "</button>";
}


/**
Convert a JavaScript Date object to a string, based on the dateFormat and dateSeparator
variables at the beginning of this script library.
*/
function getDateString(dateVal)
{
  var dayString = "00" + dateVal.getDate();
  var monthString = "00" + (dateVal.getMonth()+1);
  dayString = dayString.substring(dayString.length - 2);
  monthString = monthString.substring(monthString.length - 2);
 
  switch (dateFormat) {
    case "dmy" :
      return dayString + dateSeparator + monthString + dateSeparator + dateVal.getFullYear();
    case "ymd" :
      return dateVal.getFullYear() + dateSeparator + monthString + dateSeparator + dayString;
    case "mdy" :
    default :
      return monthString + dateSeparator + dayString + dateSeparator + dateVal.getFullYear();
  }
}


/**
Convert a string to a JavaScript Date object.
*/
function getFieldDate(dateString)
{
  var dateVal;
  var dArray;
  var d, m, y;
 
  try {
    dArray = splitDateString(dateString);
    if (dArray) {
      switch (dateFormat) {
        case "dmy" :
          d = parseInt(dArray[0], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
        case "ymd" :
          d = parseInt(dArray[2], 10);
          m = parseInt(dArray[1], 10) - 1;
          y = parseInt(dArray[0], 10);
          break;
        case "mdy" :
        default :
          d = parseInt(dArray[1], 10);
          m = parseInt(dArray[0], 10) - 1;
          y = parseInt(dArray[2], 10);
          break;
      }
      dateVal = new Date(y, m, d);
    } else if (dateString) {
      dateVal = new Date(dateString);
    } else {
      dateVal = new Date();
    }
  } catch(e) {
    dateVal = new Date();
  }
 
  return dateVal;
}


/**
Try to split a date string into an array of elements, using common date separators.
If the date is split, an array is returned; otherwise, we just return false.
*/
function splitDateString(dateString)
{
  var dArray;
  if (dateString.indexOf("/") >= 0)
    dArray = dateString.split("/");
  else if (dateString.indexOf(".") >= 0)
    dArray = dateString.split(".");
  else if (dateString.indexOf("-") >= 0)
    dArray = dateString.split("-");
  else if (dateString.indexOf("\\") >= 0)
    dArray = dateString.split("\\");
  else
    dArray = false;
 
  return dArray;
}

/**
Update the field with the given dateFieldName with the dateString that has been passed,
and hide the datepicker. If no dateString is passed, just close the datepicker without
changing the field value.

Also, if the page developer has defined a function called datePickerClosed anywhere on
the page or in an imported library, we will attempt to run that function with the updated
field as a parameter. This can be used for such things as date validation, setting default
values for related fields, etc. For example, you might have a function like this to validate
a start date field:

function datePickerClosed(dateField)
{
  var dateObj = getFieldDate(dateField.value);
  var today = new Date();
  today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
 
  if (dateField.name == "StartDate") {
    if (dateObj < today) {
      // if the date is before today, alert the user and display the datepicker again
      alert("Please enter a date that is today or later");
      dateField.value = "";
      document.getElementById(datePickerDivID).style.visibility = "visible";
      adjustiFrame();
    } else {
      // if the date is okay, set the EndDate field to 7 days after the StartDate
      dateObj.setTime(dateObj.getTime() + (7 * 24 * 60 * 60 * 1000));
      var endDateField = document.getElementsByName ("EndDate").item(0);
      endDateField.value = getDateString(dateObj);
    }
  }
}

*/
function updateDateField(dateFieldName, dateString)
{
  var targetDateField = document.getElementsByName (dateFieldName).item(0);
  if (dateString)
    targetDateField.value = dateString;
 
  var pickerDiv = document.getElementById(datePickerDivID);
  pickerDiv.style.visibility = "hidden";
  pickerDiv.style.display = "none";
 
  adjustiFrame();
  targetDateField.focus();
 
  // after the datepicker has closed, optionally run a user-defined function called
  // datePickerClosed, passing the field that was just updated as a parameter
  // (note that this will only run if the user actually selected a date from the datepicker)
  if ((dateString) && (typeof(datePickerClosed) == "function"))
    datePickerClosed(targetDateField);
}


/**
Use an "iFrame shim" to deal with problems where the datepicker shows up behind
selection list elements, if they're below the datepicker. The problem and solution are
described at:

http://dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx
http://dotnetjunkies.com/WebLog/jking/archive/2003/10/30/2975.aspx
*/
function adjustiFrame(pickerDiv, iFrameDiv)
{
  // we know that Opera doesn't like something about this, so if we
  // think we're using Opera, don't even try
  var is_opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
  if (is_opera)
    return;
  
  // put a try/catch block around the whole thing, just in case
  try {
    if (!document.getElementById(iFrameDivID)) {
      // don't use innerHTML to update the body, because it can cause global variables
      // that are currently pointing to objects on the page to have bad references
      //document.body.innerHTML += "<iframe id='" + iFrameDivID + "' src='javascript:false;' scrolling='no' frameborder='0'>";
      var newNode = document.createElement("iFrame");
      newNode.setAttribute("id", iFrameDivID);
      newNode.setAttribute("src", "javascript:false;");
      newNode.setAttribute("scrolling", "no");
      newNode.setAttribute ("frameborder", "0");
      document.body.appendChild(newNode);
    }
    
    if (!pickerDiv)
      pickerDiv = document.getElementById(datePickerDivID);
    if (!iFrameDiv)
      iFrameDiv = document.getElementById(iFrameDivID);
    
    try {
      iFrameDiv.style.position = "absolute";
      iFrameDiv.style.width = pickerDiv.offsetWidth;
      iFrameDiv.style.height = pickerDiv.offsetHeight ;
      iFrameDiv.style.top = pickerDiv.style.top;
      iFrameDiv.style.left = pickerDiv.style.left;
      iFrameDiv.style.zIndex = pickerDiv.style.zIndex - 1;
      iFrameDiv.style.visibility = pickerDiv.style.visibility ;
      iFrameDiv.style.display = pickerDiv.style.display;
    } catch(e) {
    }
 
  } catch (ee) {
  }
 
}

core.element.fade = function (opacity, speed, params)
{
	var e = this;

	if (typeof(params) != 'undefined')
	{
		if (typeof(params.delay) != 'undefined')
		{
			var delay = params.delay;
			params.delay = undefined;
			setTimeout(
				function ()
				{
					e.fade(opacity, speed, params);
				}, delay
			);
		}
	}
	else
	{
		params = {};
	}

	var o = e.getOpacity();
	var step = (opacity < o ? -1 : 1) * speed; 

	this.setInterval(
		'EFFECT:fade',
		function ()
		{
			o += step;
				
			if ((step < 0 && o <= opacity) || (step > 0 && o >= opacity))
			{
				o = opacity;
				e.clearInterval('EFFECT:fade');

				if (typeof(params.onComplete) != 'undefined')
				{
					params.onComplete();
				}
			}
			
			e.setOpacity(o);

			if (typeof(params.onTick) != 'undefined')
				params.onTick({ opacity: o });

		}, 
		25
	);
}

core.element.ease = function (param, to, speed, params)
{
	var e = this;

	if (typeof(params) != 'undefined')
	{
		if (typeof(params.delay) != 'undefined')
		{
			var delay = params.delay;
			params.delay = undefined;
			setTimeout(
				function ()
				{
					e.ease(param, to, speed, params);
				}, delay
			);
		}
	}
	else
	{
		params = {};
	}

	var intId = 'EFFECT:ease:' + param;
	var curVal = 0;
	
	if (typeof(params.startVal) == 'undefined')
	{
		switch (param)
		{
			case 'width': curVal = this.getWidth(); break;
			case 'height': curVal = this.getHeight(); break;
			case 'top': curVal = this.getTop(); break;
			case 'left': curVal = this.getLeft(); break;
			default: curVal = this.style[param]; break;
		}
	}
	else
	{
		curVal = parseInt_wd(params.startVal, 0);
	}
	
	var step = (param < curVal ? -1 : 1) * speed; 
	
	this.setInterval(
		intId,
		function ()
		{
			var pos = to - curVal;
			var newPos = pos / speed;
			var newVal = to - newPos;
			var done = false; 
			
			if (Math.round(curVal) == Math.round(newVal))
			{
				newVal = to; 
				e.clearInterval(intId);
				done = true;				
			}

			curVal = newVal;

			if (param == 'width')
			{
				e.setWidth(newVal);
			}
			else if (param == 'height')
			{
				e.setHeight(newVal);
			} 
			else
			{
				if (param == 'top' || param == 'left')
					newVal += 'px';
				
				e.style[param] = newVal;
			}
			
			if (typeof(params.onTick) != 'undefined')
				params.onTick({ curVal: curVal });
				
			if (done == true && (typeof(params.onComplete) != 'undefined'))
			{
				params.onComplete();
			}

		},
		25
	);
}

core.element.clearFade = function ()
{
	this.clearInterval('EFFECT:fade');
}

core.element.clearEase = function (param)
{
	this.clearInterval('EFFECT:ease:' + param);
}

core.element.setOpacity = function (opacity)
{
	if (core.browser == 'ie')
	{
		if (opacity == 100)
		{
			this.style.filter = 'none';
		}
		else
		{ 
			this.style.filter = 'alpha(opacity=' + opacity + ')';
		}
	}
	else
	{
		this.style.opacity = opacity / 100;
	}
}

core.element.getOpacity = function ()
{
	var opacity;

	if (core.browser == 'ie')
	{
		if (!(typeof(this.filters[0]) != 'undefined'))
		{
			return 100;
		}
		
		opacity = parseInt_wd(this.filters[0].opacity, 100)
	}
	else
	{
		if (!(typeof(this.style.opacity) != 'undefined') || this.style.opacity == '')
			opacity = 1;
		else
			opacity = this.style.opacity;
			
		opacity *= 100;
	}
	
	return opacity;
}

core.shader = {
	element: null,
	zIndex: 1000,
	
	show: function (params)
	{
		var el;
		
		if (core.shader.element == null)
		{
			el = core.shader.element = $(null, 'div', 'BODY');
			el.applyStyle(
				{
					backgroundColor: '#000000',
					position: 'absolute'
				}
			);
			
			el.setOpacity(0);
		}
		else
		{
			el = core.shader.element;
		}

		core.shader.update();
		document.body.style.overflow = 'hidden';
		
		el.show();
		el.fade(
			70, 20,
			{
				onComplete: function ()
				{
					if (typeof(params.onComplete) != 'undefined')
						params.onComplete();
				}
			}
		);

		core.page.createEvent(
			'onPageResized', 'shader', core.shader.update
		);

	},
	
	update: function ()
	{
		var ss = core.page.size;
		var el = core.shader.element;
		el.setPos(core.page.getScrollH(), core.page.getScrollV());
		el.setSize(ss);
		el.zIndex(core.shader.zIndex);
	},
	
	setClassName: function (className)
	{
		core.shader.element.setClassName(className);
	},
	
	hide: function ()
	{
		core.shader.element.fade(
			0, 20, 
			{
				onComplete: function ()
				{
					core.shader.element.hide();
					document.body.style.overflow = 'auto';
				}
			}
		);
	}
};

core.css = {
	getClassName: function (name, state, prefix, suffix)
	{
		if (typeof(name) == 'object')
		{
			var names = new Array();
			for (var i=0; i<name.length; i++)
			{
				names.push(name[i].join('_'));
			}
	
			return names.join(' ');
		}
		
		if (typeof(state) == 'undefined') state = null;
		if (typeof(prefix) == 'undefined') prefix = null;
		if (typeof(suffix) == 'undefined') suffix = null;
	
		var segs = new Array();
		if (prefix != null) segs.push(prefix);
		segs.push(name);
		if (state != null) segs.push(state);
		if (suffix != null) segs.push(suffix);
		return segs.join('_');
	}
}

core.element.setClassName = function (name, state, prefix, suffix)
{
	this.className = core.css.getClassName(name, state, prefix, suffix);
}

core.element.hasClassName = function (name)
{
	return (new RegExp('(^|\\W+)' + name + '($|\\W+)', 'ig').test(this.className)); 
}

core.element.appendClassName = function (name, state, prefix, suffix)
{
	if (this.hasClassName(name)) return false;
	this.className += ' ' + core.css.getClassName(name, state, prefix, suffix);
}

core.element.removeClassName = function (name)
{
	this.className = this.className.replace(
		new RegExp('(^|\\W+)' + name + '($|\\W+)', 'ig'), 
		' '
	);		 
}

core.element.applyStyle = function (style)
{
	for (var i in style)
	{
		if (typeof(style[i]) != 'function')
		{
			var name = i;
			if (core.browser == 'ie' && name == 'cssFloat')
			{
				name = 'styleFloat';
			}
			 
			this.style[name] = style[i];
		}
	}
}

core.element.removeStyle = function (style)
{
	var s = this.style.cssText;
    
 	for (var i=0; i<style.length; i++)
 	{
 		var name = style[i];
		var re = new RegExp(name + '\: [^;]*;?', 'i');
		s = s.replace(re, '');
 	}

	this.style.cssText = s;
}

core.createClassPath('core.effects');

var sequenceInstances = new Object();

function SQ_VAR(id)
{
 	return '$SQVAR$' + id;
}

function SQ_RESUME(params)
{
	params.index++;
	params.playing = true;
 	SQ_PLAY(params.sequence, params.startElement, params.id, params);
}

function SQ_CALL(s, element, procName)
{
	var params;
	
	if ((typeof(s.sequence) != 'undefined'))
	{
	 	params = s;
	 	procName = element;
	}
	else
	{
	 	params = SQ_INIT(s, element);
	 	params.playing = false;
	}

    params.pauseAfterCall = true;
    params.callIndex = params.index;
	params.index = params.procs[procName].startIndex + 1;

 	SQ_PLAY(params.sequence, params.startElement, params.id, params);
}

function SQ_INIT(s, element)
{
	var params = {
		sequence: s,
	  	index: 0,
	  	onComplete: null,
	  	onTick: null,
	  	clearOnTick: true,
	  	element: element,
	  	startElement: element,
	  	vars: new Object(),
	  	procs: new Object(),
		playing: true,
		stop: false,
		pauseAfterCall: false 
	};

    // Get procedures    
 	var procName, startIndex, endIndex;
	
	for (var i=0; i<s.length; i++)
	{
	 	var n = s[i];
	 	if (n[0] == 'PROC')
	 	{
	 	 	procName = n[1];
	 	 	startIndex = i;
	 	 	endIndex = null;
	 	 	
	 	 	for (var j=i+1; j<s.length; j++)
	 	 	{
	 	 	 	if (s[j][0] == 'END_PROC')
	 	 	 	{
	 	 	 		endIndex = j;
	 	 	 	 	break;
	 	 	 	}
	 	 	}
	 	 	
	 	 	if (endIndex == null) return _error('`END_PROC` missing');
	 	 	
	 	 	params.procs[procName] = {
	 	 	  	startIndex: startIndex,
	 	 	  	endIndex: endIndex
	 	 	};
	 	}
	}
	
	return params;
}

function SQ_STOP(params)
{
 	if (typeof(params) == 'string')
 	{
 		if (!(typeof(sequenceInstances[params]) != 'undefined')) return;
 	 	params = sequenceInstances[params];
 	}
 	
 	params.stop = true;
 	params.element.clearFade();
 	params.element.clearEase('width');
 	params.element.clearEase('height');
} 

function SQ_PLAY(s, element, id, params)
{
	if (!(typeof(params) != 'undefined') || params == null)
	{
		params = SQ_INIT(s, element);
		
		if ((typeof(id) != 'undefined'))
		{
			params.id = id;
			sequenceInstances[id] = params;
		}
	}
	
	var __this = params.startElement;
	var n, e, skipOnComplete, skipTo;
	e = params.element;
	skipOnComplete = false;
	skipTo = null;
	
	while (true)
	{
		
		if (skipTo != null)
		{
			params.index++;
			if (!(typeof(s[params.index]) != 'undefined')) return;
			
			if (s[params.index][0] != skipTo)
			{
				continue;
			}
			else
			{
				skipTo = null;
			 	params.index++;
			}
		}

		n = s[params.index];
	 	if (!(typeof(s[params.index]) != 'undefined')) return;
	
		switch (n[0])
		{
		 	/*case SQ_ELEMENT:
		 		e = (n[1] == null ? this : n[1]);
		 		break;
		 		
		 	case SQ_CHILD_ELEMENT:
		 		
		 		break; */
		 	case 'SET_POS':
		 		e.setPos(_gp(1), _gp(2));
		 		break;
		 		
		 	case 'SET_LEFT':
		 		e.setLeft(_gp(1));
		 		break;

		 	case 'SET_TOP':
		 		e.setTop(_gp(1));
		 		break;
		 		
		 	case 'SET_SIZE':
		 		e.setSize(_gp(1), _gp(2));
		 		break;
		 		
		 	case 'SET_WIDTH':
		 		e.setWidth(_gp(1));
		 		break;
		 		
		 	case 'SET_HEIGHT':
		 		e.setHeight(_gp(1));
		 		break;
		 		
		 	case 'SHOW':
		 		var showEl = _gp(1); 
		 	    if (showEl == null) e.show();
		 	    else showEl.show();
		 		break;

		 	case 'HIDE':
		 	    var hideEl = _gp(1); 
		 	    if (hideEl == null) e.hide();
		 	    else hideEl.hide();
		 		break;
		 		
		 	case 'SET_OPACITY':
		 		e.setOpacity(_gp(1));
		 		break;
		 		
		 	case 'FADE':
		 		var eParams = { onComplete: function () { _clearOnTick(), _resume(); } };
		 		if (params.onTick != null) eParams.onTick = function (o) { params.onTick(params, o); };
		 		
		 		e.fade(_gp(1), _gp(2), eParams);
		 		return;
		 		
		 	case 'EASE_WIDTH':             
		 		var eParams = { onComplete: function () { _clearOnTick(); _resume(); } };
		 		if (params.onTick != null) eParams.onTick = function (o) { params.onTick(params, o); };
		 		e.ease('width', _gp(1), _gp(2), eParams);
		 		_pause();
		 		return;
	
		 	case 'EASE_HEIGHT':
		 		var eParams = { onComplete: function () { _clearOnTick(); _resume(); } };
		 		if (params.onTick != null) eParams.onTick = function (o) { params.onTick(params, o); };
		 		e.ease('height', _gp(1), _gp(2), eParams);
		 		_pause();
		 		return;

		 	case 'EASE_TOP':
		 		var eParams = { onComplete: function () { _clearOnTick(); _resume(); } };
		 		if (params.onTick != null) eParams.onTick = function (o) { params.onTick(params, o); };
		 		e.ease('top', _gp(1), _gp(2), eParams);
		 		_pause();
		 		return;
		 		
		 	case 'WAIT':
		 		setTimeout(function () { _resume(); }, _gp(1));
				_pause(); 
		 		return;
		 		
		 	case 'SET_VAR':
		 		params.vars[_gp(1)] = _gp(2);
		 		break;
	
			case 'ON_COMPLETE':
				params.onComplete = n[1];
				skipOnComplete = true;
				break;

			case 'ON_TICK':
				params.onTick = n[1];
				if ((params.clearOnTick = _gp(2)) == null)
					params.clearOnTick = true;
				break;
				
			case 'CLEAR_ON_TICK':
				params.onTick = null;
				params.clearOnTick = true;
				break;
				
			case 'PROC':
				var procName = n[1];
				var proc = params.procs[procName];
				params.index = proc.endIndex;
				break;
				
			case 'END_PROC':
				params.index = params.callIndex;
				if (params.pauseAfterCall === true) return _pause();
				break;
				
			case 'CALL':
				var proc = params.procs[n[1]];
				params.callIndex = params.index;
				params.index = proc.startIndex;
				break;
				
			case 'EXEC':
				if (n[1](params) === false)
				{
					_pause();
					return;
				}
				break;
				
			case 'ELEMENT':
				params.lastElement = params.element;
				params.element = _gp(1);
				e = params.element;
				break;
				
			case 'RESTORE_ELEMENT':
				params.element = params.lastElement;
				break;
				
			case 'IF_TRUE':
				if (_gp(1) !== true)
				{
					skipTo = 'END_IF';
					continue;
				}
				break;
		}
			
		if (!skipOnComplete && params.onComplete != null)
		{
			params.onComplete(params);
			params.onComplete = null;
		}
				
		params.index++;
		if (params.stop) return;
		if (!(typeof(s[params.index]) != 'undefined')) return;	
	}
	
	function _gp(pIndex)
	{
	 	var val = n[pIndex];
	 	var type = typeof(val);
	 	
	 	if (type == 'string' && $string.beginsWith(val, '$SQVAR$'))
	 	{
	 	 	val = params.vars[val.substr(7)];
	 	}
	 	else if (type == 'function')
	 	{
	 	 	return val(params);
	 	}
	 	
	 	return val;
	}
	
	function _resume()
	{	
		params.playing = true;
	 	SQ_RESUME(params);
	}
	
	function _pause()
	{
	 	params.playing = false;
	}
	
	function _clearOnTick()
	{
	 	if (params.clearOnTick == true)
	 		params.onTick = null;
	}
		
	function _error(msg)
	{
		alert('SEQUENCE ERROR: ' + msg);
		params.playing = false;
	}
}

 
var menuBar;
core.page.createEvent('onPageLoaded', initMenu);

function initMenu()
{
	menuBar = $('menuBar');

	var firstNode = $object.getFirst(map);	
	for (var i in map)
	{
		var n = map[i];
		if (n == firstNode) n.alias = '';		
		n.url = (n.type == 'link' ? n.url : '/' + n.alias);
        n.els = new Object();
        
		var e = n.els.container = $(null, 'div', menuBar);
		e.setClassName('menu-bar-item');		
		e.setContent(n.name);
		e.node = n;
		e.createEvent('onmouseover', function (o) { menuBarItemMouseOver(o.node); });
		e.createEvent('onmouseout', function (o) { menuBarItemMouseOut(o.node); });
		e.createEvent('onclick', function (o) { core.redirect(o.node.url); });
		
		if ((typeof(n.nodes) != 'undefined'))
		{
			n.openMenus = new Array();
		 	n.dropDown = new DropDownMenu(null, n, 0)
		}
	}	
}

function closeAllMenus(exceptNode)
{
	for (var i in map)
	{
		var n = map[i];
		if (n == exceptNode) continue;
		menuBarItemHighlight(n, false);
			
		if ((typeof(n.dropDown) != 'undefined'))
		{
		 	n.dropDown.closeAll(true);
		}
	}
}


function menuBarItemMouseOver(n)
{
	closeAllMenus(n)
	menuBarItemHighlight(n, true);
	if ((typeof(n.dropDown) != 'undefined')) n.dropDown.show();
}

function menuBarItemMouseOut(n)
{
	closeAllMenus(n);   
}

function menuBarItemHighlight(n, isHighlighted)
{
	if (!(typeof(isHighlighted) != 'undefined')) isHighlighted = true;
	n.els.container.setClassName('menu-bar-item' + (isHighlighted ? ' menu-bar-item-mouseover' : ''));
}

var DropDownMenu = core.createClass(
{
	init: function (parentDropDown, parent, level)
	{
		var __this = this;
		this.level = level;

		this.rootNode = (parentDropDown == null ? parent : parentDropDown.rootNode);
		this.parentDropDown = parentDropDown;		
		this.parent = parent;
		this.nodes = parent.nodes;
		this.els = new Object();
		this.dropDownOpen = false;

        var parentElement = 'BODY'; // (level == 0 ? parent.element : parent.els.container);
        
		this.els.container = $(null, 'div', parentElement);
		this.els.container.applyStyle({ position: 'absolute', width: '210px', height: '400px', overflow: 'hidden' });
		
		this.els.nodes = $(null, 'div', this.els.container);
		this.els.nodes.applyStyle({ position: 'absolute', width: '100%' });
		
		
		this.els.container.zIndex(100);
		this.els.container.hide();
				
		for (var i in this.nodes)
		{
		 	var n = this.nodes[i];
		 	n.url = (n.type == 'link' ? n.url : parent.url + '/' + n.alias);
		 	n.els = new Object();
		 	n.els.container = $(null, 'div', this.els.nodes);
		 	n.els.left = $(null, 'div', n.els.container);
		 	n.els.label = $(null, 'a', n.els.container);
		 	n.els.right = $(null, 'div', n.els.container);

            n.els.label.setContent(n.name);
			n.els.container.setClassName('Rotary-mnu-item Rotary-mnu-mid');		 	
		 	n.els.left.setClassName('Rotary-mnu-left');
		 	n.els.right.setClassName('Rotary-mnu-right');
		 	n.els.container.node = n;
		 	n.els.container.createEvent('onmouseover', function (o) { __this.onNodeMouseOver(o.node) });
		 	n.els.container.createEvent('onmouseout', function (o) { __this.onNodeMouseOut(o.node) });
		 	n.els.container.createEvent('onclick', function (o) { __this.onNodeClick(o.node) });
		 	
		 	if ((typeof(n.nodes) != 'undefined')) n.dropDown = new DropDownMenu(this, n, level + 1);
		 	
		}
		
		this.els.bottom = $(null, 'div', this.els.nodes);
		this.els.bottom.setClassName('Rotary-mnu-btm-mid');
		this.els.bottom.setContent(
			'<div class="Rotary-mnu-btm-left"></div>' + 
			'<div class="Rotary-mnu-btm-right"></div>'
		);
	},

	onNodeMouseOver: function (n)
	{
		this.clearCloseAll();
		
		if ((typeof(n.dropDown) != 'undefined'))
		{
			if (this.rootNode.openMenus[this.level + 1] != n.dropDown)
		 		n.dropDown.show();
				                               	
		 	n.dropDown.closeFromHere();
		}
		else
		{
			this.closeFromHere();
		}

		n.els.container.setClassName('Rotary-mnu-item Rotary-mnu-mid-active');		
		//n.els.label.setClassName('_MOUSEOVER');
	},
	

	onNodeMouseOut: function (n)
	{
		this.closeAll();
		
		n.els.container.setClassName('Rotary-mnu-item Rotary-mnu-mid');
		n.els.label.setClassName('');
	},
	
	onNodeClick: function (n)
	{
		if (n.type == 'link' && n.link_target == '_blank')
		{
			window.open(n.url, '');
		}
		else
		{
	  		core.redirect(n.url);
	  	}
	},
	
	clearCloseAll: function ()
	{
        core.timing.clearTimeout(
			'menuCloseAll'
		); 
	},
	
	closeAll: function (now)
	{
		var __this = this;
		if (!(typeof(now) != 'undefined')) now = false;
		
		if (now)
		{
			this.closeFrom(0);
		}
		else
		{
	        core.timing.setTimeout(
				'menuCloseAll', 
				function ()
				{
				  	__this.closeFrom(0);
				},
				200
			);
		}
	},
	
	closeFromHere: function ()
	{
		this.closeFrom(this.level + 1);
	},
	
	closeFrom: function (level)
	{
	  	for (var i=level, j=0; i<this.rootNode.openMenus.length; i++, j++)
	  	{
			if (!(typeof(this.rootNode.openMenus[i]) != 'undefined')) continue;
	  	 	this.rootNode.openMenus[i].hide();
	  	}

		if (j > 0)
		{	  	
	  		this.rootNode.openMenus.splice(level, j);
		}
		
		if (level == 0)
		{
		 	menuBarItemHighlight(this.rootNode, false);
		}
	},
		
	show: function ()
	{	
		var __this = this;	
		this.clearTimeout('hideMenu');
		this.els.container.show();

		var openMenus = this.rootNode.openMenus;		
		/*if ((typeof(openMenus[this.level]) != 'undefined'))
		{
			if (openMenus[this.level] == this) return;
		 	openMenus[this.level].hide();
		}*/
		
		this.closeFromHere();
		
		openMenus[this.level] = this;
		
		var pPos = this.parent.els.container.getPos();
		var pSize = this.parent.els.container.getSize();
		var x, y;

		if (this.level == 0)
		{		
			x = pPos.left - 5;
			y = pPos.top + pSize.height + 2;
		}
		else
		{
		 	x = pPos.left - 203;
		 	y = pPos.top;
		}
		
		this.els.container.setPos(x, y);
		var startHeight = 10;
		var endHeight = this.els.nodes.getHeight();
		this.els.nodes.setTop(-endHeight + startHeight);
		this.els.container.setHeight(startHeight);
		
		/*alert(endHeight);*/
		
		var s = [
			['ELEMENT',		this.els.container],
			['ON_TICK',		function (p, o)
							{
								var e = __this.els.nodes;
								e.setTop(p.element.getHeight() - endHeight);
							}],			
			['EASE_HEIGHT',	endHeight, 1.3]
		];
		
		SQ_PLAY(s);
		
	},
	
	hide: function ()
	{
		var __this = this;
		
		this.setTimeout(
			'hideMenu',
			function ()
			{
            	__this.els.container.hide();
	 		},
	 		200
	 	);
	}
});


/*

				<div class="menu-bar-item">Home</div>
				<div class="menu-bar-item">News</div>
				<div class="menu-bar-item">About Us</div>
				<div class="menu-bar-item">Photo Gallery</div>


<div style="position: absolute; top: 300px; left: 200px; width: 200px;">
	<div class="Rotary-mnu-item Rotary-mnu-mid">
		<div class="Rotary-mnu-left"></div>
		<a href="">Testing</a>
		<div class="Rotary-mnu-right"></div>
	</div>
	<div class="Rotary-mnu-btm-mid">
		<div class="Rotary-mnu-btm-left"></div>
		<div class="Rotary-mnu-btm-right"></div>
	</div>
</div>
*/
var PublisherTicker = core.createClass(
{
	init: function (params)
	{
		this.showItems = 3;
		this.interval = 1000;		
		this.index = 0;
		this.itemHeight = 60;
		$object.extend(this, params);	 	

	 	this.els = new Object();
	 	this.els.container = $('publisherTicker');
		this.els.container.applyStyle({ overflow: 'hidden' });
		
		this.els.list = $('publisherTickerList');
		this.els.list.applyStyle({ position: 'relative' });

	 	
	},
	
	render: function ()
	{
		var __this  = this;
		var liItems = this.els.container.getElementsByTagName('li');
		this.items = new Array();
		this.itemCount = liItems.length;
		for (var i=0; i<this.itemCount; i++)
		{
			this.items[i] = $(liItems[i]);
			var item = this.items[i];
			item.link = $(item.getElementsByTagName('a')[0]);
			item.image = $(item.link.getElementsByTagName('img')[0]);
			item.link.createEvent('onmouseover', function (el, e) { __this.onItemMouseOver(el); });
			item.link.createEvent('onmouseout', function (el, e) { __this.onItemMouseOut(el); });
			item.link.setHeight(this.itemHeight);
			if (item.image != null)
			{
				var itemInnerHeight = item.link.getInnerHeight();
			 	item.image.setOuterSize(itemInnerHeight, itemInnerHeight);
			}
			
		}
 
		this.itemWindowHeight = this.itemHeight * (this.itemCount < this.showItems ? this.itemCount : this.showItems);
		this.els.container.setInnerHeight(this.itemWindowHeight);		
	},
	
	start: function ()
	{
		if (this.itemCount <= this.showItems) return;
	
		var __this = this;
	 	this.setInterval(
	 		'scrolling',
	 		function () { __this.stop(); __this.next() },
	 		this.interval
	 	);
	},
	
	stop: function ()
	{
	 	this.clearInterval('scrolling');
	},
	
	next: function ()
	{
		var __this = this;



		if ((typeof(this.removeItem) != 'undefined'))
		{
			if (this.index == this.itemCount)
			{
				this.index = 0;
			}

			this.removeItem.remove();
			this.els.list.appendElement(this.removeItem);
			this.els.list.setTop(0);
		}

		var h = this.itemHeight;
		this.index++;
		
	 	this.els.list.ease(
		 	'top', 
			-h,
			1.3,
			{
				startVal: 0,
				onComplete: function ()
				{
					__this.removeItem = __this.items[__this.index - 1];
				 	__this.start();
				}
			}
		);
	},
	
	onItemMouseOver: function (e)
	{
		this.stop();	 	
	},
	
	onItemMouseOut: function (e)
	{
		this.start();
	}
});

var publisherTicker;

core.page.createEvent(
	'onPageLoaded',
	function ()
	{
		publisherTicker = new PublisherTicker();
		publisherTicker.render();
		publisherTicker.start();
	}
);


core.createClassPath('core.elements');

core.elements.Button = core.createClass(
{
	init: function (id, params)
	{
		this.id = id;
		this.state = 'normal';
		this.classPrefix = null;
		this.width = null;
		this.height = null;
		this.enabled = true;
		this.showLabel = true;
		this.iconSpacing = 5;
		this.mode = 'normal';
		$object.extend(this, params);
		
		if ((typeof(this.text) != 'undefined')) this.label = this.text;
		
		if (!(typeof(this.placeHolder) != 'undefined')) this.placeHolder = id;	
		
		this.els = new Object();
		this.els.placeHolder = $(this.placeHolder);
		if (this.els.placeHolder == null)
		{
			alert('Could not find place holder element!');
			return false;
		}
		
		core.extend(this, core.events);

		if (typeof(this.onClick) != 'undefined') this.createEvent('onclick', 'onclick', this.onClick);
		if (typeof(this.onMouseUp) != 'undefined') this.createEvent('onmouseup', 'onmouseup', this.onMouseUp);
		if (typeof(this.onMouseDown) != 'undefined') this.createEvent('onmousedown', 'onmousedown', this.onMouseDown);
		if (typeof(this.onMouseOver) != 'undefined') this.createEvent('onmouseover', 'onmouseover', this.onMouseOver);
		if (typeof(this.onMouseOut) != 'undefined') this.createEvent('onmouseout', 'onmouseout', this.onMouseOut);

		this.render();
	},
	
	render: function ()
	{
		var e;
		
		// container element
		e = this.els.container = $(null, 'div', this.els.placeHolder);
        this.applyEvents(e);
        
		this.els.icon = $(null, 'div', this.els.container);
		this.els.icon.applyStyle({ cssFloat: 'left' });
		
		this.els.label = $(null, 'a', this.els.container);
		this.els.label.setContent(this.label);
		this.els.label.disableSelection();

		this.update();
	},
	
	applyEvents: function (e)
	{
		var __this = this;
		e.createEvent('onmouseover', 'onmouseover', function () { __this.__onMouseOver() });
		e.createEvent('onmouseout', 'onmouseout', function () { __this.__onMouseOut() });
		e.createEvent('onmousedown', 'onmousedown', function () { __this.__onMouseDown() });
		e.createEvent('onmouseup', 'onmouseup', function () { __this.__onMouseUp() });
	},
	
	update: function (state)
	{
		if (typeof(state) != 'undefined')
		{
			this.previousState = this.state;
			this.state = state;
		}		

        if (this.enabled == false)
        {
        	this.els.container.setOpacity(50);
        }
        else
        {
        	this.els.container.setOpacity(100);
        }
        
        if (this.mode == 'toggle')
        {
         	this.state = (this.toggled ? 'mousedown' : 'normal');
        }
        
        if (this.showLabel == true) this.els.label.show();
        else this.els.label.hide();

		this.els.container.setClassName([[this.classPrefix], ['button', 'container', this.state]]);		
		//this.els.container.setClassName('container', this.state, 'button');	
		//if (this.classPrefix != null) e.appendClassName('container', this.state, this.classPrefix);
		
		if ((typeof(this.icon) != 'undefined')) this.els.icon.setClassName(this.icon);
		if (this.width != null) this.els.container.setWidth(this.width);
		if (this.height != null) this.els.container.setHeight(this.height);
		if (this.showIcon == false || !(typeof(this.icon) != 'undefined'))
		{
			this.els.icon.hide();
		}
		else
		{
			this.els.icon.show();
			this.els.icon.style.marginRight = (this.label == '' || this.showLabel == false ? 0 : this.iconSpacing);
		}
	},
	
	setLabel: function (label)
	{
		this.label = label;
		this.els.label.setContent(this.label);
	},
	
	disable: function ()
	{
		this.enabled = false;
		this.update();
	},
	
	enable: function ()
	{
		this.enabled = true;
		this.update();
	},
	
	hide: function ()
	{
	 	this.els.container.hide();
	},
	
	show: function ()
	{
		this.els.container.show();	
	},
	
	__onMouseOver: function (e)
	{
		if (!this.enabled) return;
		this.invokeAllEvents('onmouseover', this);
		this.update('mouseover');
	},
	
	__onMouseOut: function (e)
	{
		if (!this.enabled) return; 
		this.invokeAllEvents('onmouseout', this);
		this.update('normal');
		this.previousState = 'normal';
	},
	
	__onMouseDown: function (e)
	{
		if (!this.enabled) return;
		this.invokeAllEvents('onmousedown', this);
		this.update('mousedown');
	},
	
	__onMouseUp: function (e)
	{
		if (!this.enabled) return;
		
		if (this.mode == 'toggle')
		{
		 	if (!(typeof(this.toggled) != 'undefined'))
			{
				this.toggled = true;
			}
		 	else
		 	{
		 		this.toggled = (this.toggled ? false : true);
		 	}

		 	this.invokeAllEvents('ontoggle', this);
		}
		
		this.invokeAllEvents('onclick', this);
		this.invokeAllEvents('onmouseup', this);
		this.update(this.previousState);
	}
});


if (typeof(core) != 'undefined') core.initialize();

