//general purpose
function exists (o) {
	return (((typeof(o) != 'undefined') && (o != null)) ? true : false);
}

function isFunction(f) {
	return ((typeof(f) == 'function') ? true : false);
}		

//string extensions
String.prototype.trim = function () {
	return this.replace(/^\s+|\s+$/g,'');
}

String.prototype.ltrim = function () {
	return this.replace(/^\s+/,'');
}

String.prototype.rtrim = function () {
	return this.replace(/\s+$/,'');
}

String.prototype.normalizeEOL = function () {
	return this.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
}

//encode/decode functions
String.prototype.utf8_encode = function () {
	var str=this.normalizeEOL();
	var utftext="";

	for (var n=0; n < str.length; n++) {
	   var c = str.charCodeAt(n);
	   if (c < 128) {
		   utftext += String.fromCharCode(c);
	   } else if((c > 127) && (c < 2048)) {
		   utftext += String.fromCharCode((c >> 6) | 192);
		   utftext += String.fromCharCode((c & 63) | 128);
	   } else {
		   utftext += String.fromCharCode((c >> 12) | 224);
		   utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
	   }
	}

	return utftext;
}

String.prototype.utf8_decode = function () {
	var str = "";
	var i = 0;
	var c = c1 = c2 = 0;

	while (i < this.length) {
		c = this.charCodeAt(i);

		if (c < 128) {
			str += String.fromCharCode(c);
			i++;
		} else if((c > 191) && (c < 224)) {
			c2 = this.charCodeAt(i+1);
			str += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		} else {
			c2 = this.charCodeAt(i+1);
			c3 = this.charCodeAt(i+2);
			str += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
	   }
	}

	return str;
}

//string extensions specific to framework
String.prototype.fxClassName = function () {
	return ((this.substring(0,1) == '.') ? true : false);
}

String.prototype.fxId = function() {
	return ((this.substring(0,1) == '#') ? true : false);
}

String.prototype.fxNamed = function() {
	return ((this.substring(0,1) == '@') ? true : false);
}

String.prototype.isEmailAddress = function() {
	var valid = /^[a-zA-Z0-9_\.\-]+@([a-zA-Z0-9][a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}$/;
	if (this.search(valid) != -1) 
		return true;	
   return false;
}

String.prototype.isNumberOnly = function(length) {
	 var valid = /^[0-9]+$/;
	 if (this.search(valid) != -1) {
		if (exists(length)) {
			if (this.length <= length)
				return true;
		} else {
			return true;
		}
	 }
	 return false;
}

String.prototype.empty = function () {
	var valid = /^\s*$/
	if (valid.test(this))
		return true;
	return false;
}

String.prototype.basename = function () {
	var toks=this.split('.');
	var ext='';
	var base='';
	if (toks > 1) {	
		ext=toks[toks.length-1];
		base=toks.slice(0, toks.length-2).implode('.');
	} else {
		return { name: this, extension: '' };
	}
	
	return { name: base, extension: ext };
}

String.prototype.dirname = function () {
	var toks=this.split(/[\/\\]+/);
	if (toks.count < 2)
		return '';
	toks.pop();
	return toks.implode('/');	
}

//array extensions
Array.prototype.inArray = function (needle, caseSensitive) {
	if (!exists(needle))
		return false;
	if (!exists(caseSensitive))
		caseSensitive=false;

	if (caseSensitive) {
		var n=needle.toLower();
		for (var i=0; i < this.length; i++) {
			var check=this[i].toLower();
			if (check == n);
				return i;
		}		
	} else {
		for (var i=0; i < this.length; i++) {
			if (this[i] == needle)
				return i;
		}
	}
	return false;
};

Array.prototype.getKeys = function() {
	var keys=[];
	var index=0;
	for (var i in this) {
		if (typeof this[i] == 'function')
			continue;
		keys[index++]=i;
	}
	return keys;
};

Array.prototype.reverse = function() {
	var elements=[];
	var index=0;
	for (var i=this.length-1; i >= 0; i--) {
		elements[index++]=this[i];
	}
	return elements;
};

Array.prototype.keyExists = function (key) {
	if (!exists(key))
		return false;
	if (!exists(this[key]))
		return false;
	return this[key];
};

Array.prototype.implode = function (glue) {
	var str='';
	for (var i=0; i < this.length; i++) {
		str = str + ((i > 0) ? glue : '') + this[i];
	}
	return str;
}

Array.prototype.find = function (value) {
	var found=new Array();
	for (var i=0; i < this.length; i++) {
		if (this[i] === value)
			found.push(i);
	}
	return found;
}

//fix so parent isn't needed
function insertAfter (parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}	

function getElementsByClassName (classname, node, tag) {	
	var elements=[];
	if (node == null)
		node=document;
	if (tag == null)
		tag='*';			
	var els=node.getElementsByTagName(tag);
	var elsLen=els.length;
	for (i=0; i < elsLen; i++) {		
		if (!els[i].className.empty()) {
			var classes=els[i].className.split(' ');	
			if (classes.inArray(classname) !== false) {
				elements.push(els[i]);
			}
		}
	}
	return elements;
};

if (!exists(document.getElementsByClassName)) {
	//add the functionality if it's not in there just to emulate it and make simpler code
	document.getElementsByClassName=getElementsByClassName;	
}

(function(window){
	var _fxPreload = { imagesCompleted: [], count: 0, imageFiles: [], extension: 'jpg', completedCallBack: '', onloadCallBack: '' };
	var _fxPlugins={ plugins: [], completed: [] };
	var _fxPluginsLoaded=[];
	var _fxReadyEvent=[];
	var _fxAfterLoadEvent=[];
	var _fxSelectorCache=[];
	
	function fx (selector, data) {	
		var Effects = {
			fadeIn: function (element, options, callback) {
				/*options are:
					interval - in ms, how long it takes to fade
					opacity - 0 - 100, opacity to fade to					
				*/
				var level=0;
				var timer=options.interval / 100;
				if (exists(element.style.filter)) {
					//ie 7 setInterval doesn't like fractional timings, so we have to fix this to be a minimum of 1 ms
					if (timer < 1)
						timer=1;
				}				
				var interval = setInterval(function() {					
					Effects.opacity(element, ++level);
					if (level == options.opacity) {
						clearInterval(interval);
						if (isFunction(callback))
							callback(element);
					}
				}, timer);
			},
			
			fadeOut: function (element, options, callback) {
				/*options are:
					interval - in ms, how long it takes to fade
					opacity - 0 - 100, opacity to fade to					
				*/
				
				var level=100;
				var timer=options.interval / 100;
				if (exists(element.style.filter)) {
					//ie 7 setInterval doesn't like fractional timings, so we have to fix this to be a minimum of 1 ms
					if (timer < 1)
						timer=1;
				}
				var interval = setInterval(function() {					
					Effects.opacity(element, --level);					
					if (level == options.opacity) {
						clearInterval(interval);
						if (isFunction(callback))
							callback(element);						
					}
				}, timer);
			},
			
			opacity: function (element, alpha) {
				if (element.filters) {
					//ie			
					element.style.filter='alpha(opacity=' + alpha + ')';
				 } else { 					
					element.style.opacity=(alpha / 100);
				 }
			}
		};
		
		var _fx  = {
			_isFX: true,
			_version: '0.0.1',		
			document: window.document,
			domReady: null,
			plugins: _fxPlugins,
			pluginsInit: _fxPluginsLoaded,
			pluginsAreReady: null,
			onReadyChain: _fxReadyEvent,	
			onAfterLoadChain: _fxAfterLoadEvent,			
			selCache: _fxSelectorCache,
			elements: [],
			preloaded: _fxPreload,
			lastHoverObject: '',
			lastHoverTimer: false,
			effects: Effects,
			httpFactories : [
				function () { return new XMLHttpRequest(); },
				function () { return new ActiveXObject("Msxml2.XMLHTTP"); },
				function () { return new ActiveXObject("Msxml3.XMLHTTP"); },
				function () { return new ActiveXObject("Microsoft.XMLHTTP"); }
			],
				
			//dom ready event functions
			isDOMReady: function () {
				var done = false;
				var _fx=this;
				
				var checkLoaded = setInterval (function(){ 
					if (done === true)
						return;
					
					if (window.attachEvent) {						
						if (!document.body.readyState == 'complete')
							return;
					}
					
					if (document && document.body && document.getElementById && document.getElementsByTagName) {
						clearInterval(checkLoaded); 
						done = true;
						_fx.domReady=true;		
						
						if (!exists(_fx.onReadyChain)) 
							return;						
												
						for (var i=0; i < _fx.onReadyChain.length; i++) {
							_fx.onReadyChain.shift()();
						}						
					}
				}, 10);
			},
			
			ready: function (callback) {
				if (!exists(callback))
					return;
				this.onReadyChain.push(callback);
				
				if (this.domReady == null) {
					this.domReady=false;						
					this.isDOMReady();		
				}
			},
			
			//fx plugin ready event functions, usable by $().pluginsReady
			arePluginsReady: function() {
				var done = false;
				var _fx=this;
								
				var checkLoaded = setInterval (function() {
					if (done === true) {
						clearInterval(checkLoaded);
						return;
					}
					
					var completed=new Array();
					for (var i=0; i < _fx.pluginsInit.length; i++) {
						if (_fx.plugins.completed[_fx.pluginsInit[i]] === true)
							completed.push(_fx.pluginsInit[i]);
					}
						
					if (_fx.pluginsInit.length == completed.length) {						
						done=true;
						_fx.pluginsAreReady=true;
						
						if (!exists(_fx.onAfterLoadChain)) 
							return;	

						for (var i=0; i < _fx.onAfterLoadChain.length; i++) {
							_fx.onAfterLoadChain.shift()();
						}
					}		
				}, 10);				
			},
			
			pluginsReady: function(callback) {
				if (!exists(callback))
					return;
				
				this.onAfterLoadChain.push(callback);
				if (this.pluginsAreReady == null) {
					this.pluginsAreReady=false;
					this.arePluginsReady();
				}
			},
						
			//get element function
			get: function() {
				var found=[];
				for (var i=0; i < arguments.length; i++) {		
					var sel=arguments[i];					
					var element=false;
					var type=typeof sel;
					//if (exists(this.selCache[sel])) {
						//element=this.selCache[sel];
					//} else 
					if (typeof sel == 'string') {
						var selector=sel.substring(1);
						if (sel.fxId()) {							
							var o=document.getElementById(selector);
							if (o == null) {
								element=null;
							} else {
								this.selCache[sel]=o;
							}
						} else if (sel.fxNamed()) {
							this.selCache[sel]=document.getElementsByName(selector);
						} else if (sel.fxClassName()) {
							if (document.getElementsByClassName) {								
								this.selCache[sel]=document.getElementsByClassName(selector);
								var o=this.selCache[sel];								
							} else {								
								this.selCache[sel]=getElementsByClassName(selector);								
							}
						} else {
							//default to tagname since it's not an id, name or class specifier
							this.selCache[sel]=document.getElementsByTagName(sel);
						}
						element=this.selCache[sel];
					} else {
						element=sel;
					}								
					if (exists(element) === false) {
						this.elements=found;
						return this;
					}
					//if (typeof element == 'array') {
					if (exists(element['length']) && (element.tagName != 'SELECT')) {						
						//check for form object, or any other object that does this
						if (element != element[0]) {
							//HTMLCollections cause issues here... dont add the collection itself to the found list, just the indexes							
							if (typeof element != 'object') {
								found.push(element);
							}

							/*
							alert('collection');
							alert(element);
							found.push(element);
							*/
						}
						for (var j=0; j < element.length; j++) {
							found.push(element[j]);
						}
					} else {
						//alert(element);
						found.push(element);
					}
					//alert('found len: ' + found.length);
				}				
				this.elements=found;
				//alert(this.elements.length);
				return this;			
			},		
			
			hasElements: function() {
				if (!exists(this.elements))
					return false;
				if (this.elements.length < 1)
					return false;
				return true;
			}, 
			
			stash: function(obj) {
				if (!exists(obj))
					return this;					
				var o=obj;
				if (exists(obj['_isFX'])) {
					o=obj.elements;	
				}				
				this.elements=this.elements.concat(o);				
				return this;
			},
			
			each: function(callback) {								
				if (!this.hasElements())
					return;
				
				if (!isFunction(callback)) 
					return;
					
				for (var i=0; i < this.elements.length; i++) {
					callback (this.elements[i], i);
				}
			},
			
			getClass: function(index) {
				if (!this.hasElements())
					return false;
				if (!exists(index))
					index=0;
				if (index > this.elements.length)
					return false;
				return this.elements[index].className;
			},
			
			addClass: function(className) {
				if (!this.hasElements())
					return this;
				//TODO: make sure this doesn't add classes infinitely.
				//meaning, if the class already exists, don't add it				
				for (var i=0; i < this.elements.length; i++) {
					if (fx(this.elements[i]).hasClass(className))
						continue;
					
					var className=(this.elements[i].className + ' ' + className).trim(); //Here is where we add the new class
					this.elements[i].className=className;
					//alert(this.elements[i].className);
				}
				return this;
			},
			
			removeClass: function(className) {
				if (!this.hasElements())
					return this;
				for (var i=0; i < this.elements.length; i++) {
					if (fx(this.elements[i]).hasClass(className) === false) 
						continue;
					
					this.elements[i].className=this.elements[i].className.replace(className,'').replace('  ',' ').trim();					
				}
				return this;			
			},
			
			hasClass: function(theseClasses) {
				//TODO: Make this work on mutliple element objects, for now it just works on the first element found from the selector
				if (!this.hasElements())
					return false;
				if (!exists(theseClasses))
					return false;
				if (!exists(this.elements[0].className))
					return;
				if (this.elements[0].className.length < 1)
					return false;
				
				if (theseClasses.indexOf(',') != -1) {
					theseClasses=theseClasses.split(',');
				} else {
					theseClasses=[theseClasses];
				}
				
				var oClasses=this.elements[0].className.split(' ');				
				var has=true;
				for (var i=0; i < theseClasses.length; i++) {
					has=oClasses.inArray(theseClasses[i]);
					if (has === false) {
						break;
					}
				}
				return (has === false) ? false : true;
			},			
			
			bind: function(eventName, callback) {		
				if (!exists(eventName))
					return this;
				if (!isFunction(callback))
					return this;
				if (eventName == 'hover') {
					alert("FX Error::Unsupported event type '" + eventName + "'");
					return;
				}
				if (!this.hasElements())
					return this;									

				//var callbackHandler='';					
				//if ((eventName == 'mouseover') || (eventName == 'mouseout')) {
				var _fxInstance=this;					
				var callbackHandler=function(e) {
					var event = e || window.event;
					
					callback.apply(this,[event]);
					
					if (event.stopPropagation) {
						event.stopPropagation();
					} else {
						event.cancelBubble = true;
					} 								
					return false; 
				};					
				//}
				for (var i=0; i < this.elements.length; i++) {				
					var obj=this.elements[i];
					if (obj.addEventListener) {
						obj.addEventListener(eventName, function(e) { callbackHandler.apply(this,[e]); }, false);
					} else {						
						obj['on' + eventName] = function(e) { callbackHandler.apply(this,[e]); };
						/*
						if (obj.attachEvent) {		
							//var f=function(e) { alert(this.id); return; callbackHandler.apply(this,[e]); };
							//obj.attachEvent(fevent, function() { alert(this.id); return; callbackHandler.apply(this,[window.event]); });
							//obj[fevent] = function(e) { callbackHandler.apply(this,[e]); };
						} else {
							alert('what?');
							obj[fevent] = function(e) { callbackHandler.apply(this,[e]); };
						}
						*/
					}
				}
				return this;
			},
			
			unbind: function (eventName, callback) {
				if (!isFunction(callback))
					return this;			
				if (!this.hasElements())
					return this;										
				for (var i=0; i < this.elements.length; i++) {
					var obj=this.elements[i];
					if (this.elements[i].removeEventListener) {
						this.elements[i].removeEventListener(eventName, callback, false);
					} else {
						if (obj.detachEvent) {
							this.elements[i].detachEvent('on' + eventName, callback);
						} else {
							this.elements[i][eventName]=null;
						}
					}
				}			
				return this;				
			},
			
			click: function (callback) {
				if (!this.hasElements())
					return this;
				if (!isFunction(callback)) {
					var o=this.obj();
					o.click();
					return false;
				}
				
				this.bind('click', callback);
				
				return this;
			},
			
			hover: function (hoverCallBack, unHoverCallBack) {				
				if (!this.hasElements())
					return this;				
				if (!exists(hoverCallBack))
					return this;							
				if (!isFunction(hoverCallBack))
					return this;
								
				this.bind('mouseover', hoverCallBack);
				
				if (unHoverCallBack == 'toggle') {
					unHoverCallBack=hoverCallBack;
				} else {
					if (!isFunction(unHoverCallBack))
						return this;
				}				
				this.bind('mouseout', unHoverCallBack);
								
				return this;
			},
			
			filterField: function (fieldName, value, callback) {
				if (!this.hasElements())
					return this;
				if (!exists(value) || !exists(callback))
					return this;
				
				for (var i=0; i < this.elements.length; i++) {
				}
			},
			
			focus: function () {
				if (!this.hasElements())
					return this;
				if (this.elements[0].nodeName.toLowerCase()==='input' && (t == 'text' || 'password')) {
					this.elements[0].focus();
				}
				return this;
			},
			
			toggle: function () {
				if (!this.hasElements())
					return this;
				for (var i=0; i < this.elements.length; i++) {
					if (!exists(this.elements[i].style['_fxDisplay']))
						this.elements[i].style['_fxDisplay']=(exists(this.elements[i].style['display']) ? this.elements[i].style['display'] : '');					
					this.elements[i].style['display']=(this.elements[i].style['display'] == 'none') ? this.elements[i].style['_fxDisplay'] : 'none';
				}
				return this;
			},
			
			hide: function () {
				if (!this.hasElements())
					return this;	
				for (var i=0; i < this.elements.length; i++) {
					if (!exists(this.elements[i].style['_fxDisplay']))
						this.elements[i].style['_fxDisplay']=(!exists(this.elements[i].style['display']) ? '' : this.elements[i].style['display']);
					this.elements[i].style['display']='none';
				}				
				return this;				
			},
			
			show: function() {
				if (!this.hasElements())
					return this;					
				for (var i=0; i < this.elements.length; i++) {
					this.elements[i].style['display']=(!exists(this.elements[i].style['_fxDisplay']) ? '' : this.elements[i].style['_fxDisplay']);
					//alert(this.elements[i].style['display']);
				}				
				return this;								
			},			
			
			checked: function (bool) {
				if (!this.hasElements())
					return this;			
				for (var i=0; i < this.elements.length; i++) {
					var t=this.elements[i].getAttribute('type');
					if (this.elements[i].nodeName.toLowerCase()==='input' && (t == 'checkbox' || t == 'radio')) {
						this.elements[i].checked = bool;
					}
				}
				return this;
			},
			
			even: function () {
				if (!this.hasElements())
					return this;					
				var e=[];
				for (var i=0; i < this.elements.length; i += 2) {
					e.push(this.elements[i]);
				}
				this.elements=e;
				return this;
			},
			
			odd: function () {
				if (!this.hasElements())
					return this;					
				var e=[];
				for (var i=1; i < this.elements.length; i += 2) {
					e.push(this.elements[i]);
				}
				this.elements=e;
				return this;
			},
						
			css: function (decl) {				
				if (!this.hasElements())
					return this;				
				for (var i=0; i < this.elements.length; i++) {					
					for (var sel in decl) {
						if (sel == 'float') {
							this.elements[i].style['cssFloat']=decl[sel];
							//ie only
							this.elements[i].style['styleFloat']=decl[sel];
						} else {							
							this.elements[i].style[sel] = decl[sel];
						}
					}
				}				
				return this;
			},
			
			val: function (newValue) {
				if (!this.hasElements())
					return this;		
								
				if (exists(newValue)) {
					for (var i=0; i < this.elements.length; i++) {
						var t=this.elements[i].getAttribute('type');							
						if ((this.elements[i].nodeName.toLowerCase() === 'input' && (t == 'text' || 'password' || 'hidden')) ||
						    (this.elements[i].nodeName.toLowerCase() === 'textarea')) {							
							this.elements[i].value=newValue;					
						}
					}
					return this;
				}
				
				var e=[];				
				for (var i=0; i < this.elements.length; i++) {
					var t=this.elements[i].getAttribute('type');
					if (t == 'checkbox' || t == 'radio') {
						if (this.elements[i].checked === true) 
							e.push(this.elements[i].value);
					} else {
						e.push(this.elements[i].value);
					}
				}
				if (e.length == 1)
					return e[0];										
				return e;
			},
			
			attr: function (attr, val) {
				if (!this.hasElements())
					return this;				
				var e=[];
				var attrs=attr.split(',');
				for (var i=0; i < this.elements.length; i++) {				
					var a=[];
					for (var j=0; j < attrs.length; j++) {
						if (val) 
							this.elements[i].setAttribute(attrs[j], val);
						a.push(this.elements[i].getAttribute(attrs[j]));
					}
					e.push(a);
				}
				
				if (val)
					return this;
					
				if (e.length == 1)
					return e[0];					
				return e;
			},
			
			obj: function (index) {
				if (!this.hasElements())
					return this;
				if (!index)
					index=0;
				
				if ((this.elements.length < index) || (index < 0))
					return this;
				
				return this.elements[index];				
			},
			
			create: function(type) {
				this.elements=[document.createElement(type)];
				return this;
			},
			
			children: function (index) {
				if (!this.hasElements())
					return this;
				
				var children=[];
				if (!exists(index)) {
					for (var i=0; i < this.elements.length; i++) {					
						for (var j=0; j < this.elements[i].children.length; j++) {
							children.push(this.elements[i].children[j]);
						}
					}
				} else {
					if (this.elements.length >= 1) {
						if (this.elements[0].children.length >= 1) {
							children.push(this.elements[0].children[0]);
						} 
					}				
				}
				this.elements=children;
				
				return this;
			},
						
			left: function (obj) {
				if (exists(obj)) {
					//if (obj == 'window')
						//return window.innerHeight;
					if (obj == 'document')
						return document.style.offsetLeft;
					
					this.elements[0].style['left']=obj;
					return this;
				}
				
				return this.elements[0].clientLeft;
			},
			
			top: function (obj) {
				if (exists(obj)) {
					//if (obj == 'window')
						//return window.innerHeight;
					if (obj == 'document')
						return document.style.offsetTop;
					
					this.elements[0].style['top']=obj;
					return this;
				}
				
				return this.elements[0].clientTop;
			},
			
			height: function (obj) {	
				if (exists(obj)) {
					if (obj == 'window')
						return window.innerHeight;
					if (obj == 'document')
						return document.style.offsetTop;
					
					this.elements[0].style['height']=obj;
					return this;
				}
				
				return this.elements[0].clientHeight;
			},

			width: function (obj) {
				if (exists(obj)) {							
					if (obj == 'window')
						return window.innerWidth;
					if (obj == 'document')
						return document.offsetWidth;
					
					this.elements[0].style.width=obj;
					return this;
				} 
				
				return this.elements[0].clientWidth;
			},			
			
			html: function (data) {				
				if (!this.hasElements())
					return this;
				if (exists(data)) {
				//alert('data: ' + data);
					for (var i=0; i < this.elements.length; i++) {
						this.elements[i].innerHTML=data;
					}
					return this;
				} 
				
				var str='';
				//alert('hi: ' + this.elements.length);
				for (var i=0; i < this.elements.length; i++) {
					str += this.elements[i].innerHTML;
				}
				return str;
			},
			
			selected: function(index) {
				if (!this.hasElements())
					return this;					
				
				if (!exists(index))
					index=false;				
								
				var tag=this.elements[0].nodeName.toLowerCase();	
				if (tag != 'select')
					return this;
					
				var t=this.elements[0].type;				
				var selected=[];		
					
				switch (t) {
					case 'select-one': {
						selected.push(this.elements[0].options[this.elements[0].selectedIndex]);
					} break;
					case 'select-multiple': {
						for (var i=0; i < this.elements[0].length; i++) {
							if (this.elements[0].options[i].selected) 
								selected.push(this.elements[0].options[i]);
						}
					} break;
				}
				
				this.elements=selected;
				return this;
			},
			
			select: function () {
				if (!this.hasElements())
					return this;			
					
				var tag=this.elements[0].nodeName.toLowerCase();	
				if (tag != 'select')
					return this;	

				var el=[];
				for (var i=0; i < this.elements[0].length; i++) {
					this.elements[0].options[i].selected=true;
					el.push(this.elements[0].options[i]);
				}
				this.elements=el;
				
				return this;			
			},
			
			selected: function() {
				if (!this.hasElements())
					return this;			
					
				var tag=this.elements[0].nodeName.toLowerCase();	
				if (tag != 'select')
					return this;	

				if (this.elements[0].selectedIndex == -1)
					return false;
					
				var el=[];
				for (var i=0; i < this.elements[0].length; i++) {
					if (this.elements[0].options[i].selected)
						el.push(this.elements[0].options[i]);
				}
				this.elements=el;
				
				return this;						
			},
				
			append: function (obj) {
				if (!this.hasElements())
					return this;

				if (obj._isFX) {				
					for (var j=0; j < this.elements.length; j++) {
						for (var i=0; i < obj.elements.length; i++) {
							this.elements[j].appendChild(obj.elements[i]);
						}					
					}
					return this;
				}
				
				if (this.elements.length) {
					for (var i=0; i < this.elements.length; i++) {
						this.elements[i].appendChild(obj);
					}
				} else {
					this.elements.appendChild(obj);
				}
				
				return this;
			},
			
			addOptions: function(options, unique) {
				if (!this.hasElements())
					return this;			
				if (!unique)
					unique=false;
				
				if  (!options._isFX)
					return this;
				options=options.elements;
					
				var tag=this.elements[0].nodeName.toLowerCase();	
				if (tag != 'select')
					return this;				
					
				for (var i=0; i < options.length; i++) {
					if (unique === true) {
						var found=false;
						for (var j=0; j < this.elements[0].length; j++) {
							if (this.elements[0].options[j].value == options[i].value) {
								found=true;
								break;
							}
						}
						if (found === true)
							continue;
					}
					var option = document.createElement('option');
					option.setAttribute('value', options[i].value);
					option.appendChild(document.createTextNode(options[i].text));
					this.elements[0].appendChild(option);
				}
				
				return this;
			},
			
			appendOption: function (value, text) {
				if (!this.hasElements())
					return this;			
			
				var option = document.createElement('option');
				option.setAttribute('value', value);
				option.appendChild(document.createTextNode(text));
				this.elements[0].appendChild(option);			
				
				return this;
			},
			
			clearOptions: function() {
				if (!this.hasElements())
					return this;			
					
				var tag=this.elements[0].nodeName.toLowerCase();	
				if (tag != 'select')
					return this;	
					
				this.elements[0].options.length=0;
				this.elements=[this.elements[0]];
				
				return this;									
			},
			
			removeOptions: function(options) {
				if (!this.hasElements())
					return this;			
				
				if  (!options._isFX)
					return this;
				options=options.elements;
					
				var tag=this.elements[0].nodeName.toLowerCase();	
				if (tag != 'select')
					return this;				
					
				for (var i=0; i < this.elements[0].length; i++) {
					for (var j=0; j < options.length; j++) {
						if (this.elements[0].options[i].value == options[j].value)
							this.elements[0].removeChild(this.elements[0].options[i]);
					}
				}
				
				return this;			
			},
			
			remove: function() {
				if (!this.hasElements())
					return this;			

				for (var i=0; i < this.elements.length; i++) {
					if (this.elements[i].parentNode && this.elements[i].parentNode.removeChild) {
						this.elements[i].parentNode.removeChild(this.elements[i]);				
					}
				}
					
				return this;
			},
			
			getFormData: function () {
				if (!this.hasElements())
					return this;					

				var data='';
				for (var i=0; i < this.elements.length; i++) {					
					if (this.elements[i].name.length < 1)
						continue;
					var t=this.elements[i].type;
					var tag=this.elements[i].nodeName.toLowerCase();
					
					switch (tag) {
						case 'input': {
							switch (t) {
								case 'text':
								case 'hidden':
								case 'password': {
									data += ((data.length > 1) ? '&' : '') + this.elements[i].name + '=' + encodeURI(this.elements[i].value);
								} break;
								case 'checkbox': {
									if (this.elements[i].checked)
										data += ((data.length > 1) ? '&' : '') + this.elements[i].name + '=' + encodeURI(this.elements[i].value);
								} break;
								case 'radio': {
								}
							}							
						} break;
						case 'textarea': {
							data += ((data != '') ? '&' : '') + this.elements[i].name + '=' + encodeURI(this.elements[i].value);
						} break;
						case 'select': {
							switch (t) {
								case 'select-one': {
									data += ((data.length > 1) ? '&' : '') + this.elements[i].name + '=' + encodeURI(this.elements[i].options[this.elements[i].selectedIndex].value);
								} break;
								case 'select-multiple': {
									var subdata='';
									for (var j=0; j < this.elements[i].options.length; j++) {
										if (this.elements[i].options[j].selected) 
											subdata += ((subdata != '') ? ',' : '') + encodeURI(this.elements[i].options[j].value);
									}
									data += ((data.length > 1) ? '&' : '') + this.elements[i].name + '=' + subdata;
								} break;
							}
						}
					}
				}
				
				return data;
			},
			
			preloadHoverImages: function (imageList, ext, completedCallBack, onloadCallBack) {
				this.preloaded.completed=false;
				
				if (exists(ext))
					this.preloaded.extension=ext;
				
				if (exists(completedCallBack) && isFunction(completedCallBack))
					this.preloaded.completedCallBack=completedCallBack;

				if (exists(onloadCallBack) && isFunction(onloadCallBack))
					this.preloaded.onloadCallBack=onloadCallBack;
				
				var self=this;
				for (var i=0; i < imageList.length; i++) {		
					if (exists(this.preloaded.imageFiles[imageList[i]])) 
						continue;
					if (typeof(imageList[i]) != 'string')
						continue;
					
										
					var base=imageList[i].basename();					
					base.extension=base.extension.empty() ? this.preloaded.extension : base.extension;
					
					this.preloaded.count++;
					this.preloaded.imageFiles[imageList[i]]={
							image: {},
							hoverImage: {},
							imageType: 'hover',
							imageLoaded: false,
							hoverLoaded: false,
							complete: false,
							index: this.preloaded.count-1
					};			
					
					this.preloaded.imageFiles[imageList[i]].image=new Image();
					this.preloaded.imageFiles[imageList[i]].image.id=imageList[i];
					this.preloaded.imageFiles[imageList[i]].image.src="/images/" + base.name + (base.extension.empty() ? '' : ('.' + base.extension));
					$(this.preloaded.imageFiles[imageList[i]].image).bind('load', function(e) {
						self.preloadImageCompleted(this.id, 'normal'); 
					});				

					
					this.preloaded.imageFiles[imageList[i]].hoverImage=new Image();
					this.preloaded.imageFiles[imageList[i]].hoverImage.id=imageList[i];
					this.preloaded.imageFiles[imageList[i]].hoverImage.src="/images/" + base.name + 'Over' + (base.extension.empty() ? '' : ('.' + base.extension));
					
					$(this.preloaded.imageFiles[imageList[i]].hoverImage).bind('load', function(e) {
						self.preloadImageCompleted(this.id, 'hover'); 
					});					
				}
			},
			
			preloadImageCompleted: function (imageKey, type) {
				//alert('Image loaded(' + imageKey + ') as "' + type +'"');
				if (!exists(imageKey) || !exists(type))
					return;				
				if (!exists(this.preloaded.imageFiles[imageKey]))
					return;
				switch (type) {
					case 'normal':
						this.preloaded.imageFiles[imageKey].imageLoaded=true;
					break;
					case 'hover':
						this.preloaded.imageFiles[imageKey].hoverLoaded=true;
					break;
				}
				if (this.preloaded.imageFiles[imageKey].complete == false) {
					if (this.preloaded.imageFiles[imageKey].imageLoaded && this.preloaded.imageFiles[imageKey].hoverLoaded) {
						this.preloaded.imageFiles[imageKey].complete=true;
						if (isFunction(this.preloaded.onloadCallBack)) {
							this.preloaded.onloadCallBack(imageKey);
						}
						this.checkPreloadComplete();
					}
				}
			},
			
			checkPreloadComplete: function() {				
				var newfiles=[];
				for (var i in this.preloaded.imageFiles) {											
					if (typeof(this.preloaded.imageFiles[i]) != 'object')
						continue;					
					if (this.preloaded.imagesCompleted[this.preloaded.imageFiles[i].index] == true)
						continue;
					
					if (this.preloaded.imageFiles[i].imageType == 'hover') {						
						if (this.preloaded.imageFiles[i].imageLoaded && this.preloaded.imageFiles[i].hoverLoaded) {							
							this.preloaded.imagesCompleted[this.preloaded.imageFiles[i].index]=true;
							continue;
						}
					}
					//newfiles[i]=this.preloaded.imageFiles[i];					
				}
				//this.preloaded.imageFiles=newfiles;
				if (this.preloaded.imagesCompleted.length < this.preloaded.count) {
					//alert('preloading(' + this.preloaded.count +') images at (' + this.preloaded.images.length + ')');
					return false;
				}
				
				if (isFunction(this.preloaded.completedCallBack) && (this.preloaded.completed == false)) {
					this.preloaded.completed=true;
					this.preloaded.completedCallBack(this.preloaded.imagesCompleted.length);
				}
				return true;
			},
			
			getPreloadedImage: function(key, type) {
				if (!exists(key))
					return false;
				if (!exists(type))
					type='normal';
				
				if (!exists(this.preloaded.imageFiles[key]))
					return false;
				
				switch (type) {
					case 'hover':
						return this.preloaded.imageFiles[key].hoverImage.src;
					break;
					default:
						return this.preloaded.imageFiles[key].image.src;
				}				
			},			
			
			opacity: function (alpha) {
				if (!this.hasElements())
					return this;					
				for (var i=0; i < this.elements.length; i++) {
					this.effects.opacity(this.elements[i], alpha);
				}
				return this;
			},
			
			fadeIn: function (time, callback) {
				if (!this.hasElements())
					return this;			
				for (var i=0; i < this.elements.length; i++) {
					this.effects.fadeIn(this.elements[i], { opacity: 100, interval: time }, callback);
				}
				return this;
			},
			
			fadeOut: function (time, callback) {
				if (!this.hasElements())
					return this;
				for (var i=0; i < this.elements.length; i++) {
					this.effects.fadeOut(this.elements[i], { opacity: 0, interval: time}, callback);
				}
				return this;
			},
			
			toJSON: function (obj) {
				return JSON.stringify(obj);
			},
			
			xmlHTTPObj: function () {
				var request=false;
				for (var i=0; i < this.httpFactories.length; i++) {
					try {
						request = this.httpFactories[i]();
					} catch (e) {
						continue;
					}
					break;
				}
				return request;
			},
			
			http: function (url, callback, postData, requestType) {
				var request = this.xmlHTTPObj();
				if (!request)
					return;
					
				var method = (postData) ? "POST" : "GET";
				requestType = (requestType) ? ((requestType == 'raw' || 'json') ? requestType : 'raw') : 'raw';
				request.open(method,url,true);
				request.setRequestHeader('User-Agent','XMLHTTP/1.0');
				if (postData)
					request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
					
				request.onreadystatechange = function () {
					if (request.readyState != 4) 
						return;
					if (request.status != 200 && request.status != 304) {
						//alert('HTTP error ' + request.status);
						return;
					}
					if (requestType == 'json') {
						var o='invalid';
						try {
							o=JSON.parse(request.responseText);	
						} catch(e) {
							callback({ error: 'Invalid', data: {} });
							return;
						}
						callback({ error: '', data: o });
					} else {
						callback({ error: '', data: request.responseText });
					}
				};
				
				if (request.readyState == 4)
					return;
				request.send(postData);
			},
			
			registerPlugin: function (pluginName, obj) {				
				if (!exists(pluginName))
					return false;
				if (!exists(obj))
					return false;
								
				_fx.plugins.plugins[pluginName]=obj;
				_fx.plugins.plugins[pluginName]['fx']=fx;	
				_fx.plugins.plugins[pluginName]['getPluginName']=function() {
					return pluginName;
				};
				_fx.plugins.completed[pluginName]=false;
				if (_fx.pluginsInit.inArray(pluginName) === false) {
					_fx.pluginsInit.push(pluginName);
				}				
				
				if (exists(obj['onRegister'])) {
					_fx.plugins.plugins[pluginName].onRegister.apply(_fx.plugins.plugins[pluginName], []);
				}
				
				return this.plugins.plugins[pluginName];
			},
			
			isPluginRegistered: function (pluginName) {
				if (!exists(_fx.plugins.plugins[pluginName]))
					return false;
				return true;
			},
			
			pluginLoaded: function(plugin) {
				if (!exists(plugin))
					return;
				
				var name=plugin.getPluginName();
				_fx.plugins.completed[name]=true;
			},
			
			loadPlugin: function(plugin, forcedPath) {
				//TODO: this is a cluster f right now, fix it later
				if (!exists(forcedPath))
					forcedPath=true;
				
				var path=plugin.dirname();
				if (path.empty()) {
					if  (forcedPath !== false) {
						path='/js/fxPlugins';
					}					
				}
				
				var plugin=path + '/' + plugin + (plugin.basename().extension.empty() ? '.js' : '');
				var head=_fx.get('head').obj(0);

//				alert(document.getElementsByTagName('head').item(0));
				var s=_fx.create('script').attr('type', 'text/javascript').attr('src', plugin).obj();
				document.getElementsByTagName('head').item(0).appendChild(s);
				
				this.pluginsAreReady=false;
				this.arePluginsReady();
				
				//var head=_fx.get('head').append(_fx.create('script').attr('type', 'text/javascript').attr('src', path));				
			}
		};
		
		
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		//startup code, triggered by fx(), or $()
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		if (exists(selector)) {
			//alert(selector);			
			var dexist=exists(data);
			var t=typeof data;		
			var selectorType=typeof selector;
			if (!dexist) {
				if (_fx.isPluginRegistered(selector) === true) {
					return _fx.plugins.plugins[selector];
				}
				if ((typeof(selector) == 'array' || 'object') && (exists(selector['length']) && (selectorType != 'string'))) {
					return _fx.get.apply(_fx, selector);
				} else {					
					return _fx.get(selector);
				}
			} else if ((dexist) && (t == 'object') && (selectorType == 'string')) {
				return _fx.registerPlugin(selector, data);
			}
			return _fx;
		} 
		return _fx;	
	}
	
	var _$='';
	if (typeof $ != 'undefined')
		_$=$;	
	window.$=fx;
	window.fx=fx;
})(window);


//$.bind('load', fxReady);
/*
$().ready(function() {
	//$('.container').toggle();
	//$('.container').toggle();
	//$('.container').opacity(20);
	//$('.inside_block').stash($('.comment')).css({backgroundColor: 'red'});
	//$('.inside_block').stash($('.comment')).toggle();
	//$('.container').fadeIn(5000);
	//$('.container').fadeOut(1000);
	//$('.container').opacity(20);
});
*/




/*
    http://www.JSON.org/json2.js
    2011-02-23

    Public Domain.

    NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.

    See http://www.JSON.org/js.html


    This code should be minified before deployment.
    See http://javascript.crockford.com/jsmin.html

    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
    NOT CONTROL.


    This file creates a global JSON object containing two methods: stringify
    and parse.

        JSON.stringify(value, replacer, space)
            value       any JavaScript value, usually an object or array.

            replacer    an optional parameter that determines how object
                        values are stringified for objects. It can be a
                        function or an array of strings.

            space       an optional parameter that specifies the indentation
                        of nested structures. If it is omitted, the text will
                        be packed without extra whitespace. If it is a number,
                        it will specify the number of spaces to indent at each
                        level. If it is a string (such as '\t' or '&nbsp;'),
                        it contains the characters used to indent at each level.

            This method produces a JSON text from a JavaScript value.

            When an object value is found, if the object contains a toJSON
            method, its toJSON method will be called and the result will be
            stringified. A toJSON method does not serialize: it returns the
            value represented by the name/value pair that should be serialized,
            or undefined if nothing should be serialized. The toJSON method
            will be passed the key associated with the value, and this will be
            bound to the value

            For example, this would serialize Dates as ISO strings.

                Date.prototype.toJSON = function (key) {
                    function f(n) {
                        // Format integers to have at least two digits.
                        return n < 10 ? '0' + n : n;
                    }

                    return this.getUTCFullYear()   + '-' +
                         f(this.getUTCMonth() + 1) + '-' +
                         f(this.getUTCDate())      + 'T' +
                         f(this.getUTCHours())     + ':' +
                         f(this.getUTCMinutes())   + ':' +
                         f(this.getUTCSeconds())   + 'Z';
                };

            You can provide an optional replacer method. It will be passed the
            key and value of each member, with this bound to the containing
            object. The value that is returned from your method will be
            serialized. If your method returns undefined, then the member will
            be excluded from the serialization.

            If the replacer parameter is an array of strings, then it will be
            used to select the members to be serialized. It filters the results
            such that only members with keys listed in the replacer array are
            stringified.

            Values that do not have JSON representations, such as undefined or
            functions, will not be serialized. Such values in objects will be
            dropped; in arrays they will be replaced with null. You can use
            a replacer function to replace those with JSON values.
            JSON.stringify(undefined) returns undefined.

            The optional space parameter produces a stringification of the
            value that is filled with line breaks and indentation to make it
            easier to read.

            If the space parameter is a non-empty string, then that string will
            be used for indentation. If the space parameter is a number, then
            the indentation will be that many spaces.

            Example:

            text = JSON.stringify(['e', {pluribus: 'unum'}]);
            // text is '["e",{"pluribus":"unum"}]'


            text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
            // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'

            text = JSON.stringify([new Date()], function (key, value) {
                return this[key] instanceof Date ?
                    'Date(' + this[key] + ')' : value;
            });
            // text is '["Date(---current time---)"]'


        JSON.parse(text, reviver)
            This method parses a JSON text to produce an object or array.
            It can throw a SyntaxError exception.

            The optional reviver parameter is a function that can filter and
            transform the results. It receives each of the keys and values,
            and its return value is used instead of the original value.
            If it returns what it received, then the structure is not modified.
            If it returns undefined then the member is deleted.

            Example:

            // Parse the text. Values that look like ISO date strings will
            // be converted to Date objects.

            myData = JSON.parse(text, function (key, value) {
                var a;
                if (typeof value === 'string') {
                    a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
                    if (a) {
                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
                    }
                }
                return value;
            });

            myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
                var d;
                if (typeof value === 'string' &&
                        value.slice(0, 5) === 'Date(' &&
                        value.slice(-1) === ')') {
                    d = new Date(value.slice(5, -1));
                    if (d) {
                        return d;
                    }
                }
                return value;
            });


    This is a reference implementation. You are free to copy, modify, or
    redistribute.
*/

/*jslint evil: true, strict: false, regexp: false */

/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
    call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
    getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
    lastIndex, length, parse, prototype, push, replace, slice, stringify,
    test, toJSON, toString, valueOf
*/


// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.

var JSON;
if (!JSON) {
    JSON = {};
}

(function () {
    "use strict";

    function f(n) {
        // Format integers to have at least two digits.
        return n < 10 ? '0' + n : n;
    }

    if (typeof Date.prototype.toJSON !== 'function') {

        Date.prototype.toJSON = function (key) {

            return isFinite(this.valueOf()) ?
                this.getUTCFullYear()     + '-' +
                f(this.getUTCMonth() + 1) + '-' +
                f(this.getUTCDate())      + 'T' +
                f(this.getUTCHours())     + ':' +
                f(this.getUTCMinutes())   + ':' +
                f(this.getUTCSeconds())   + 'Z' : null;
        };

        String.prototype.toJSON      =
            Number.prototype.toJSON  =
            Boolean.prototype.toJSON = function (key) {
                return this.valueOf();
            };
    }

    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        indent,
        meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        rep;


    function quote(string) {

// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.

        escapable.lastIndex = 0;
        return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
            var c = meta[a];
            return typeof c === 'string' ? c :
                '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
        }) + '"' : '"' + string + '"';
    }


    function str(key, holder) {

// Produce a string from holder[key].

        var i,          // The loop counter.
            k,          // The member key.
            v,          // The member value.
            length,
            mind = gap,
            partial,
            value = holder[key];

// If the value has a toJSON method, call it to obtain a replacement value.

        if (value && typeof value === 'object' &&
                typeof value.toJSON === 'function') {
            value = value.toJSON(key);
        }

// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.

        if (typeof rep === 'function') {
            value = rep.call(holder, key, value);
        }

// What happens next depends on the value's type.

        switch (typeof value) {
        case 'string':
            return quote(value);

        case 'number':

// JSON numbers must be finite. Encode non-finite numbers as null.

            return isFinite(value) ? String(value) : 'null';

        case 'boolean':
        case 'null':

// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.

            return String(value);

// If the type is 'object', we might be dealing with an object or an array or
// null.

        case 'object':

// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.

            if (!value) {
                return 'null';
            }

// Make an array to hold the partial results of stringifying this object value.

            gap += indent;
            partial = [];

// Is the value an array?

            if (Object.prototype.toString.apply(value) === '[object Array]') {

// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.

                length = value.length;
                for (i = 0; i < length; i += 1) {
                    partial[i] = str(i, value) || 'null';
                }

// Join all of the elements together, separated with commas, and wrap them in
// brackets.

                v = partial.length === 0 ? '[]' : gap ?
                    '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
                    '[' + partial.join(',') + ']';
                gap = mind;
                return v;
            }

// If the replacer is an array, use it to select the members to be stringified.

            if (rep && typeof rep === 'object') {
                length = rep.length;
                for (i = 0; i < length; i += 1) {
                    if (typeof rep[i] === 'string') {
                        k = rep[i];
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            } else {

// Otherwise, iterate through all of the keys in the object.

                for (k in value) {
                    if (Object.prototype.hasOwnProperty.call(value, k)) {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            }

// Join all of the member texts together, separated with commas,
// and wrap them in braces.

            v = partial.length === 0 ? '{}' : gap ?
                '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
                '{' + partial.join(',') + '}';
            gap = mind;
            return v;
        }
    }

// If the JSON object does not yet have a stringify method, give it one.

    if (typeof JSON.stringify !== 'function') {
        JSON.stringify = function (value, replacer, space) {

// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.

            var i;
            gap = '';
            indent = '';

// If the space parameter is a number, make an indent string containing that
// many spaces.

            if (typeof space === 'number') {
                for (i = 0; i < space; i += 1) {
                    indent += ' ';
                }

// If the space parameter is a string, it will be used as the indent string.

            } else if (typeof space === 'string') {
                indent = space;
            }

// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.

            rep = replacer;
            if (replacer && typeof replacer !== 'function' &&
                    (typeof replacer !== 'object' ||
                    typeof replacer.length !== 'number')) {
                throw new Error('JSON.stringify');
            }

// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.

            return str('', {'': value});
        };
    }


// If the JSON object does not yet have a parse method, give it one.

    if (typeof JSON.parse !== 'function') {
        JSON.parse = function (text, reviver) {

// The parse method takes a text and an optional reviver function, and returns
// a JavaScript value if the text is a valid JSON text.

            var j;

            function walk(holder, key) {

// The walk method is used to recursively walk the resulting structure so
// that modifications can be made.

                var k, v, value = holder[key];
                if (value && typeof value === 'object') {
                    for (k in value) {
                        if (Object.prototype.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v;
                            } else {
                                delete value[k];
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value);
            }


// Parsing happens in four stages. In the first stage, we replace certain
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.

            text = String(text);
            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx, function (a) {
                    return '\\u' +
                        ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
                });
            }

// In the second stage, we run the text against regular expressions that look
// for non-JSON patterns. We are especially concerned with '()' and 'new'
// because they can cause invocation, and '=' because it can cause mutation.
// But just to be safe, we want to reject all unexpected forms.

// We split the second stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

            if (/^[\],:{}\s]*$/
                    .test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
                        .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
                        .replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.

                j = eval('(' + text + ')');

// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.

                return typeof reviver === 'function' ?
                    walk({'': j}, '') : j;
            }

// If the text is not JSON parseable, then a SyntaxError is thrown.

            throw new SyntaxError('JSON.parse');
        };
    }
}());


//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//fx plugins
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////


function fxWindow (options) {
	fxWindowClose();
	
	if (!options)
		return;
	if (!options['url'])
		return;
	
	var height = $().height('window');
	var width = $().width('window');	
	var dw=(options['width']) ? options['width'] : 1000; 
	var dh=(options['height']) ? options['height'] : 400;
	
	var div=$().create('div').addClass('fWindow shadow').attr('id', 'oWindow').css({ width:dw + 'px', height:dh+'px', position:"absolute", display:"block", "left": width/2 - (dw / 2) + "px", "top": height/2 - (dh / 2) + "px",border:"1px solid black",'backgroundColor':'white',zIndex: 100});
	var wTitle=$().create('div').attr('id', 'oTitle').css({position: "relative",display: "block",width:(dw-10)+"px",height:"22px",top:"-1px",left:"0px",color:"black",border:"0px",margin: "0px",padding: "0px",'padding': "5px",'fontSize':'12pt'});
	var titleText=$().create('div').html((options['title']) ? options['title'] : '').attr('id', 'oCaption').css({"float":"left",'width':'90%',border:"0px",'textAlign': 'center'});
	var titleIcon=$().create('div').addClass('ico').addClass('close').attr('id', 'oCloseButton').css({'float':'right'});
	var content=$().create('div').attr('id','oContent').css({position:'relative',display:'block',width:(dw)+"px",height:(dh-30)+"px",left:"0px",top:"-1px",color:"white",border:"0px",margin: "0px",padding: "0px"});
	content.append(
		$().create('iframe').attr('src', options['url']).attr('width', ((dw-4) + 'px')).attr('height',((dh-35)+'px')).css({border:'0px'})
	);

	titleIcon.bind('click', function(e) {
		fxWindowClose();
		if (options['closeCallback'])
			if (isFunction(options['closeCallback']))
				options['closeCallback']();		
	});
	
	wTitle.append(titleText).append(titleIcon);
	div.append(wTitle).append(content);
	var _body = document.getElementsByTagName('body')[0];
	_body.appendChild(div.obj());	
}

function fxWindowClose () {
	var win=$('#oWindow');
	if (win.obj()) 
		win.remove();		
}

