/*
Script: Core.js
	MooTools - My Object Oriented JavaScript Tools.

License:
	MIT-style license.

Copyright:
	Copyright (c) 2006-2008 [Valerio Proietti](http://mad4milk.net/).

Code & Documentation:
	[The MooTools production team](http://mootools.net/developers/).

Inspiration:
	- Class implementation inspired by [Base.js](http://dean.edwards.name/weblog/2006/03/base/) Copyright (c) 2006 Dean Edwards, [GNU Lesser General Public License](http://opensource.org/licenses/lgpl-license.php)
	- Some functionality inspired by [Prototype.js](http://prototypejs.org) Copyright (c) 2005-2007 Sam Stephenson, [MIT License](http://opensource.org/licenses/mit-license.php)
*/

var MooTools = {
	'version': '1.2.1',
	'build': '0d4845aab3d9a4fdee2f0d4a6dd59210e4b697cf'
};

var Native = function(options){
	options = options || {};
	var name = options.name;
	var legacy = options.legacy;
	var protect = options.protect;
	var methods = options.implement;
	var generics = options.generics;
	var initialize = options.initialize;
	var afterImplement = options.afterImplement || function(){};
	var object = initialize || legacy;
	generics = generics !== false;

	object.constructor = Native;
	object.$family = {name: 'native'};
	if (legacy && initialize) object.prototype = legacy.prototype;
	object.prototype.constructor = object;

	if (name){
		var family = name.toLowerCase();
		object.prototype.$family = {name: family};
		Native.typize(object, family);
	}

	var add = function(obj, name, method, force){
		if (!protect || force || !obj.prototype[name]) obj.prototype[name] = method;
		if (generics) Native.genericize(obj, name, protect);
		afterImplement.call(obj, name, method);
		return obj;
	};

	object.alias = function(a1, a2, a3){
		if (typeof a1 == 'string'){
			if ((a1 = this.prototype[a1])) return add(this, a2, a1, a3);
		}
		for (var a in a1) this.alias(a, a1[a], a2);
		return this;
	};

	object.implement = function(a1, a2, a3){
		if (typeof a1 == 'string') return add(this, a1, a2, a3);
		for (var p in a1) add(this, p, a1[p], a2);
		return this;
	};

	if (methods) object.implement(methods);

	return object;
};

Native.genericize = function(object, property, check){
	if ((!check || !object[property]) && typeof object.prototype[property] == 'function') object[property] = function(){
		var args = Array.prototype.slice.call(arguments);
		return object.prototype[property].apply(args.shift(), args);
	};
};

Native.implement = function(objects, properties){
	for (var i = 0, l = objects.length; i < l; i++) objects[i].implement(properties);
};

Native.typize = function(object, family){
	if (!object.type) object.type = function(item){
		return ($type(item) === family);
	};
};

(function(){
	var natives = {'Array': Array, 'Date': Date, 'Function': Function, 'Number': Number, 'RegExp': RegExp, 'String': String};
	for (var n in natives) new Native({name: n, initialize: natives[n], protect: true});

	var types = {'boolean': Boolean, 'native': Native, 'object': Object};
	for (var t in types) Native.typize(types[t], t);

	var generics = {
		'Array': ["concat", "indexOf", "join", "lastIndexOf", "pop", "push", "reverse", "shift", "slice", "sort", "splice", "toString", "unshift", "valueOf"],
		'String': ["charAt", "charCodeAt", "concat", "indexOf", "lastIndexOf", "match", "replace", "search", "slice", "split", "substr", "substring", "toLowerCase", "toUpperCase", "valueOf"]
	};
	for (var g in generics){
		for (var i = generics[g].length; i--;) Native.genericize(window[g], generics[g][i], true);
	};
})();

var Hash = new Native({

	name: 'Hash',

	initialize: function(object){
		if ($type(object) == 'hash') object = $unlink(object.getClean());
		for (var key in object) this[key] = object[key];
		return this;
	}

});

Hash.implement({

	forEach: function(fn, bind){
		for (var key in this){
			if (this.hasOwnProperty(key)) fn.call(bind, this[key], key, this);
		}
	},

	getClean: function(){
		var clean = {};
		for (var key in this){
			if (this.hasOwnProperty(key)) clean[key] = this[key];
		}
		return clean;
	},

	getLength: function(){
		var length = 0;
		for (var key in this){
			if (this.hasOwnProperty(key)) length++;
		}
		return length;
	}

});

Hash.alias('forEach', 'each');

Array.implement({

	forEach: function(fn, bind){
		for (var i = 0, l = this.length; i < l; i++) fn.call(bind, this[i], i, this);
	}

});

Array.alias('forEach', 'each');

function $A(iterable){
	if (iterable.item){
		var array = [];
		for (var i = 0, l = iterable.length; i < l; i++) array[i] = iterable[i];
		return array;
	}
	return Array.prototype.slice.call(iterable);
};

function $arguments(i){
	return function(){
		return arguments[i];
	};
};

function $chk(obj){
	return !!(obj || obj === 0);
};

function $clear(timer){
	clearTimeout(timer);
	clearInterval(timer);
	return null;
};

function $defined(obj){
	return (obj != undefined);
};

function $each(iterable, fn, bind){
	var type = $type(iterable);
	((type == 'arguments' || type == 'collection' || type == 'array') ? Array : Hash).each(iterable, fn, bind);
};

function $empty(){};

function $extend(original, extended){
	for (var key in (extended || {})) original[key] = extended[key];
	return original;
};

function $H(object){
	return new Hash(object);
};

function $lambda(value){
	return (typeof value == 'function') ? value : function(){
		return value;
	};
};

function $merge(){
	var mix = {};
	for (var i = 0, l = arguments.length; i < l; i++){
		var object = arguments[i];
		if ($type(object) != 'object') continue;
		for (var key in object){
			var op = object[key], mp = mix[key];
			mix[key] = (mp && $type(op) == 'object' && $type(mp) == 'object') ? $merge(mp, op) : $unlink(op);
		}
	}
	return mix;
};

function $pick(){
	for (var i = 0, l = arguments.length; i < l; i++){
		if (arguments[i] != undefined) return arguments[i];
	}
	return null;
};

function $random(min, max){
	return Math.floor(Math.random() * (max - min + 1) + min);
};

function $splat(obj){
	var type = $type(obj);
	return (type) ? ((type != 'array' && type != 'arguments') ? [obj] : obj) : [];
};

var $time = Date.now || function(){
	return +new Date;
};

function $try(){
	for (var i = 0, l = arguments.length; i < l; i++){
		try {
			return arguments[i]();
		} catch(e){}
	}
	return null;
};

function $type(obj){
	if (obj == undefined) return false;
	if (obj.$family) return (obj.$family.name == 'number' && !isFinite(obj)) ? false : obj.$family.name;
	if (obj.nodeName){
		switch (obj.nodeType){
			case 1: return 'element';
			case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
		}
	} else if (typeof obj.length == 'number'){
		if (obj.callee) return 'arguments';
		else if (obj.item) return 'collection';
	}
	return typeof obj;
};

function $unlink(object){
	var unlinked;
	switch ($type(object)){
		case 'object':
			unlinked = {};
			for (var p in object) unlinked[p] = $unlink(object[p]);
		break;
		case 'hash':
			unlinked = new Hash(object);
		break;
		case 'array':
			unlinked = [];
			for (var i = 0, l = object.length; i < l; i++) unlinked[i] = $unlink(object[i]);
		break;
		default: return object;
	}
	return unlinked;
};


/*
Script: Browser.js
	The Browser Core. Contains Browser initialization, Window and Document, and the Browser Hash.

License:
	MIT-style license.
*/

var Browser = $merge({

	Engine: {name: 'unknown', version: 0},

	Platform: {name: (window.orientation != undefined) ? 'ipod' : (navigator.platform.match(/mac|win|linux/i) || ['other'])[0].toLowerCase()},

	Features: {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)},

	Plugins: {},

	Engines: {

		presto: function(){
			return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925));
		},

		trident: function(){
			return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? 5 : 4);
		},

		webkit: function(){
			return (navigator.taintEnabled) ? false : ((Browser.Features.xpath) ? ((Browser.Features.query) ? 525 : 420) : 419);
		},

		gecko: function(){
			return (document.getBoxObjectFor == undefined) ? false : ((document.getElementsByClassName) ? 19 : 18);
		}

	}

}, Browser || {});

Browser.Platform[Browser.Platform.name] = true;

Browser.detect = function(){

	for (var engine in this.Engines){
		var version = this.Engines[engine]();
		if (version){
			this.Engine = {name: engine, version: version};
			this.Engine[engine] = this.Engine[engine + version] = true;
			break;
		}
	}

	return {name: engine, version: version};

};

Browser.detect();

Browser.Request = function(){
	return $try(function(){
		return new XMLHttpRequest();
	}, function(){
		return new ActiveXObject('MSXML2.XMLHTTP');
	});
};

Browser.Features.xhr = !!(Browser.Request());

Browser.Plugins.Flash = (function(){
	var version = ($try(function(){
		return navigator.plugins['Shockwave Flash'].description;
	}, function(){
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
	}) || '0 r0').match(/\d+/g);
	return {version: parseInt(version[0] || 0 + '.' + version[1] || 0), build: parseInt(version[2] || 0)};
})();

function $exec(text){
	if (!text) return text;
	if (window.execScript){
		try{window.execScript(text);} catch (ex){}
	} else {
		var script = document.createElement('script');
		script.setAttribute('type', 'text/javascript');
		script[(Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerText' : 'text'] = text;
		document.head.appendChild(script);
		document.head.removeChild(script);
	}
	return text;
};

Native.UID = 1;

var $uid = (Browser.Engine.trident) ? function(item){
	return (item.uid || (item.uid = [Native.UID++]))[0];
} : function(item){
	return item.uid || (item.uid = Native.UID++);
};

var Window = new Native({

	name: 'Window',

	legacy: (Browser.Engine.trident) ? null: window.Window,

	initialize: function(win){
		$uid(win);
		if (!win.Element){
			win.Element = $empty;
			if (Browser.Engine.webkit) win.document.createElement("iframe"); //fixes safari 2
			win.Element.prototype = (Browser.Engine.webkit) ? window["[[DOMElement.prototype]]"] : {};
		}
		win.document.window = win;
		return $extend(win, Window.Prototype);
	},

	afterImplement: function(property, value){
		window[property] = Window.Prototype[property] = value;
	}

});

Window.Prototype = {$family: {name: 'window'}};

new Window(window);

var Document = new Native({

	name: 'Document',

	legacy: (Browser.Engine.trident) ? null: window.Document,

	initialize: function(doc){
		$uid(doc);
		doc.head = doc.getElementsByTagName('head')[0];
		doc.html = doc.getElementsByTagName('html')[0];
		if (Browser.Engine.trident && Browser.Engine.version <= 4) $try(function(){
			doc.execCommand("BackgroundImageCache", false, true);
		});
		if (Browser.Engine.trident) doc.window.attachEvent('onunload', function() {
			doc.window.detachEvent('onunload', arguments.callee);
			doc.head = doc.html = doc.window = null;
		});
		return $extend(doc, Document.Prototype);
	},

	afterImplement: function(property, value){
		document[property] = Document.Prototype[property] = value;
	}

});

Document.Prototype = {$family: {name: 'document'}};

new Document(document);


/*
Script: Array.js
	Contains Array Prototypes like each, contains, and erase.

License:
	MIT-style license.
*/

Array.implement({

	every: function(fn, bind){
		for (var i = 0, l = this.length; i < l; i++){
			if (!fn.call(bind, this[i], i, this)) return false;
		}
		return true;
	},

	filter: function(fn, bind){
		var results = [];
		for (var i = 0, l = this.length; i < l; i++){
			if (fn.call(bind, this[i], i, this)) results.push(this[i]);
		}
		return results;
	},

	clean: function() {
		return this.filter($defined);
	},

	indexOf: function(item, from){
		var len = this.length;
		for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
			if (this[i] === item) return i;
		}
		return -1;
	},

	map: function(fn, bind){
		var results = [];
		for (var i = 0, l = this.length; i < l; i++) results[i] = fn.call(bind, this[i], i, this);
		return results;
	},

	some: function(fn, bind){
		for (var i = 0, l = this.length; i < l; i++){
			if (fn.call(bind, this[i], i, this)) return true;
		}
		return false;
	},

	associate: function(keys){
		var obj = {}, length = Math.min(this.length, keys.length);
		for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
		return obj;
	},

	link: function(object){
		var result = {};
		for (var i = 0, l = this.length; i < l; i++){
			for (var key in object){
				if (object[key](this[i])){
					result[key] = this[i];
					delete object[key];
					break;
				}
			}
		}
		return result;
	},

	contains: function(item, from){
		return this.indexOf(item, from) != -1;
	},

	extend: function(array){
		for (var i = 0, j = array.length; i < j; i++) this.push(array[i]);
		return this;
	},

	getLast: function(){
		return (this.length) ? this[this.length - 1] : null;
	},

	getRandom: function(){
		return (this.length) ? this[$random(0, this.length - 1)] : null;
	},

	include: function(item){
		if (!this.contains(item)) this.push(item);
		return this;
	},

	combine: function(array){
		for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
		return this;
	},

	erase: function(item){
		for (var i = this.length; i--; i){
			if (this[i] === item) this.splice(i, 1);
		}
		return this;
	},

	empty: function(){
		this.length = 0;
		return this;
	},

	flatten: function(){
		var array = [];
		for (var i = 0, l = this.length; i < l; i++){
			var type = $type(this[i]);
			if (!type) continue;
			array = array.concat((type == 'array' || type == 'collection' || type == 'arguments') ? Array.flatten(this[i]) : this[i]);
		}
		return array;
	},

	hexToRgb: function(array){
		if (this.length != 3) return null;
		var rgb = this.map(function(value){
			if (value.length == 1) value += value;
			return value.toInt(16);
		});
		return (array) ? rgb : 'rgb(' + rgb + ')';
	},

	rgbToHex: function(array){
		if (this.length < 3) return null;
		if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
		var hex = [];
		for (var i = 0; i < 3; i++){
			var bit = (this[i] - 0).toString(16);
			hex.push((bit.length == 1) ? '0' + bit : bit);
		}
		return (array) ? hex : '#' + hex.join('');
	}

});


/*
Script: Function.js
	Contains Function Prototypes like create, bind, pass, and delay.

License:
	MIT-style license.
*/

Function.implement({

	extend: function(properties){
		for (var property in properties) this[property] = properties[property];
		return this;
	},

	create: function(options){
		var self = this;
		options = options || {};
		return function(event){
			var args = options.arguments;
			args = (args != undefined) ? $splat(args) : Array.slice(arguments, (options.event) ? 1 : 0);
			if (options.event) args = [event || window.event].extend(args);
			var returns = function(){
				return self.apply(options.bind || null, args);
			};
			if (options.delay) return setTimeout(returns, options.delay);
			if (options.periodical) return setInterval(returns, options.periodical);
			if (options.attempt) return $try(returns);
			return returns();
		};
	},

	run: function(args, bind){
		return this.apply(bind, $splat(args));
	},

	pass: function(args, bind){
		return this.create({bind: bind, arguments: args});
	},

	bind: function(bind, args){
		return this.create({bind: bind, arguments: args});
	},

	bindWithEvent: function(bind, args){
		return this.create({bind: bind, arguments: args, event: true});
	},

	attempt: function(args, bind){
		return this.create({bind: bind, arguments: args, attempt: true})();
	},

	delay: function(delay, bind, args){
		return this.create({bind: bind, arguments: args, delay: delay})();
	},

	periodical: function(periodical, bind, args){
		return this.create({bind: bind, arguments: args, periodical: periodical})();
	}

});


/*
Script: Number.js
	Contains Number Prototypes like limit, round, times, and ceil.

License:
	MIT-style license.
*/

Number.implement({

	limit: function(min, max){
		return Math.min(max, Math.max(min, this));
	},

	round: function(precision){
		precision = Math.pow(10, precision || 0);
		return Math.round(this * precision) / precision;
	},

	times: function(fn, bind){
		for (var i = 0; i < this; i++) fn.call(bind, i, this);
	},

	toFloat: function(){
		return parseFloat(this);
	},

	toInt: function(base){
		return parseInt(this, base || 10);
	}

});

Number.alias('times', 'each');

(function(math){
	var methods = {};
	math.each(function(name){
		if (!Number[name]) methods[name] = function(){
			return Math[name].apply(null, [this].concat($A(arguments)));
		};
	});
	Number.implement(methods);
})(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']);


/*
Script: String.js
	Contains String Prototypes like camelCase, capitalize, test, and toInt.

License:
	MIT-style license.
*/

String.implement({

	test: function(regex, params){
		return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this);
	},

	contains: function(string, separator){
		return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1;
	},

	trim: function(){
		return this.replace(/^\s+|\s+$/g, '');
	},

	clean: function(){
		return this.replace(/\s+/g, ' ').trim();
	},

	camelCase: function(){
		return this.replace(/-\D/g, function(match){
			return match.charAt(1).toUpperCase();
		});
	},

	hyphenate: function(){
		return this.replace(/[A-Z]/g, function(match){
			return ('-' + match.charAt(0).toLowerCase());
		});
	},

	capitalize: function(){
		return this.replace(/\b[a-z]/g, function(match){
			return match.toUpperCase();
		});
	},

	escapeRegExp: function(){
		return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
	},

	toInt: function(base){
		return parseInt(this, base || 10);
	},

	toFloat: function(){
		return parseFloat(this);
	},

	hexToRgb: function(array){
		var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
		return (hex) ? hex.slice(1).hexToRgb(array) : null;
	},

	rgbToHex: function(array){
		var rgb = this.match(/\d{1,3}/g);
		return (rgb) ? rgb.rgbToHex(array) : null;
	},

	stripScripts: function(option){
		var scripts = '';
		var text = this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
			scripts += arguments[1] + '\n';
			return '';
		});
		if (option === true) $exec(scripts);
		else if ($type(option) == 'function') option(scripts, text);
		return text;
	},

	substitute: function(object, regexp){
		return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
			if (match.charAt(0) == '\\') return match.slice(1);
			return (object[name] != undefined) ? object[name] : '';
		});
	}

});


/*
Script: Hash.js
	Contains Hash Prototypes. Provides a means for overcoming the JavaScript practical impossibility of extending native Objects.

License:
	MIT-style license.
*/

Hash.implement({

	has: Object.prototype.hasOwnProperty,

	keyOf: function(value){
		for (var key in this){
			if (this.hasOwnProperty(key) && this[key] === value) return key;
		}
		return null;
	},

	hasValue: function(value){
		return (Hash.keyOf(this, value) !== null);
	},

	extend: function(properties){
		Hash.each(properties, function(value, key){
			Hash.set(this, key, value);
		}, this);
		return this;
	},

	combine: function(properties){
		Hash.each(properties, function(value, key){
			Hash.include(this, key, value);
		}, this);
		return this;
	},

	erase: function(key){
		if (this.hasOwnProperty(key)) delete this[key];
		return this;
	},

	get: function(key){
		return (this.hasOwnProperty(key)) ? this[key] : null;
	},

	set: function(key, value){
		if (!this[key] || this.hasOwnProperty(key)) this[key] = value;
		return this;
	},

	empty: function(){
		Hash.each(this, function(value, key){
			delete this[key];
		}, this);
		return this;
	},

	include: function(key, value){
		var k = this[key];
		if (k == undefined) this[key] = value;
		return this;
	},

	map: function(fn, bind){
		var results = new Hash;
		Hash.each(this, function(value, key){
			results.set(key, fn.call(bind, value, key, this));
		}, this);
		return results;
	},

	filter: function(fn, bind){
		var results = new Hash;
		Hash.each(this, function(value, key){
			if (fn.call(bind, value, key, this)) results.set(key, value);
		}, this);
		return results;
	},

	every: function(fn, bind){
		for (var key in this){
			if (this.hasOwnProperty(key) && !fn.call(bind, this[key], key)) return false;
		}
		return true;
	},

	some: function(fn, bind){
		for (var key in this){
			if (this.hasOwnProperty(key) && fn.call(bind, this[key], key)) return true;
		}
		return false;
	},

	getKeys: function(){
		var keys = [];
		Hash.each(this, function(value, key){
			keys.push(key);
		});
		return keys;
	},

	getValues: function(){
		var values = [];
		Hash.each(this, function(value){
			values.push(value);
		});
		return values;
	},

	toQueryString: function(base){
		var queryString = [];
		Hash.each(this, function(value, key){
			if (base) key = base + '[' + key + ']';
			var result;
			switch ($type(value)){
				case 'object': result = Hash.toQueryString(value, key); break;
				case 'array':
					var qs = {};
					value.each(function(val, i){
						qs[i] = val;
					});
					result = Hash.toQueryString(qs, key);
				break;
				default: result = key + '=' + encodeURIComponent(value);
			}
			if (value != undefined) queryString.push(result);
		});

		return queryString.join('&');
	}

});

Hash.alias({keyOf: 'indexOf', hasValue: 'contains'});


/*
Script: Event.js
	Contains the Event Native, to make the event object completely crossbrowser.

License:
	MIT-style license.
*/

var Event = new Native({

	name: 'Event',

	initialize: function(event, win){
		win = win || window;
		var doc = win.document;
		event = event || win.event;
		if (event.$extended) return event;
		this.$extended = true;
		var type = event.type;
		var target = event.target || event.srcElement;
		while (target && target.nodeType == 3) target = target.parentNode;

		if (type.test(/key/)){
			var code = event.which || event.keyCode;
			var key = Event.Keys.keyOf(code);
			if (type == 'keydown'){
				var fKey = code - 111;
				if (fKey > 0 && fKey < 13) key = 'f' + fKey;
			}
			key = key || String.fromCharCode(code).toLowerCase();
		} else if (type.match(/(click|mouse|menu)/i)){
			doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
			var page = {
				x: event.pageX || event.clientX + doc.scrollLeft,
				y: event.pageY || event.clientY + doc.scrollTop
			};
			var client = {
				x: (event.pageX) ? event.pageX - win.pageXOffset : event.clientX,
				y: (event.pageY) ? event.pageY - win.pageYOffset : event.clientY
			};
			if (type.match(/DOMMouseScroll|mousewheel/)){
				var wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
			}
			var rightClick = (event.which == 3) || (event.button == 2);
			var related = null;
			if (type.match(/over|out/)){
				switch (type){
					case 'mouseover': related = event.relatedTarget || event.fromElement; break;
					case 'mouseout': related = event.relatedTarget || event.toElement;
				}
				if (!(function(){
					while (related && related.nodeType == 3) related = related.parentNode;
					return true;
				}).create({attempt: Browser.Engine.gecko})()) related = false;
			}
		}

		return $extend(this, {
			event: event,
			type: type,

			page: page,
			client: client,
			rightClick: rightClick,

			wheel: wheel,

			relatedTarget: related,
			target: target,

			code: code,
			key: key,

			shift: event.shiftKey,
			control: event.ctrlKey,
			alt: event.altKey,
			meta: event.metaKey
		});
	}

});

Event.Keys = new Hash({
	'enter': 13,
	'up': 38,
	'down': 40,
	'left': 37,
	'right': 39,
	'esc': 27,
	'space': 32,
	'backspace': 8,
	'tab': 9,
	'delete': 46
});

Event.implement({

	stop: function(){
		return this.stopPropagation().preventDefault();
	},

	stopPropagation: function(){
		if (this.event.stopPropagation) this.event.stopPropagation();
		else this.event.cancelBubble = true;
		return this;
	},

	preventDefault: function(){
		if (this.event.preventDefault) this.event.preventDefault();
		else this.event.returnValue = false;
		return this;
	}

});


/*
Script: Class.js
	Contains the Class Function for easily creating, extending, and implementing reusable Classes.

License:
	MIT-style license.
*/

var Class = new Native({

	name: 'Class',

	initialize: function(properties){
		properties = properties || {};
		var klass = function(){
			for (var key in this){
				if ($type(this[key]) != 'function') this[key] = $unlink(this[key]);
			}
			this.constructor = klass;
			if (Class.prototyping) return this;
			var instance = (this.initialize) ? this.initialize.apply(this, arguments) : this;
			if (this.options && this.options.initialize) this.options.initialize.call(this);
			return instance;
		};

		for (var mutator in Class.Mutators){
			if (!properties[mutator]) continue;
			properties = Class.Mutators[mutator](properties, properties[mutator]);
			delete properties[mutator];
		}

		$extend(klass, this);
		klass.constructor = Class;
		klass.prototype = properties;
		return klass;
	}

});

Class.Mutators = {

	Extends: function(self, klass){
		Class.prototyping = klass.prototype;
		var subclass = new klass;
		delete subclass.parent;
		subclass = Class.inherit(subclass, self);
		delete Class.prototyping;
		return subclass;
	},

	Implements: function(self, klasses){
		$splat(klasses).each(function(klass){
			Class.prototying = klass;
			$extend(self, ($type(klass) == 'class') ? new klass : klass);
			delete Class.prototyping;
		});
		return self;
	}

};

Class.extend({

	inherit: function(object, properties){
		var caller = arguments.callee.caller;
		for (var key in properties){
			var override = properties[key];
			var previous = object[key];
			var type = $type(override);
			if (previous && type == 'function'){
				if (override != previous){
					if (caller){
						override.__parent = previous;
						object[key] = override;
					} else {
						Class.override(object, key, override);
					}
				}
			} else if(type == 'object'){
				object[key] = $merge(previous, override);
			} else {
				object[key] = override;
			}
		}

		if (caller) object.parent = function(){
			return arguments.callee.caller.__parent.apply(this, arguments);
		};

		return object;
	},

	override: function(object, name, method){
		var parent = Class.prototyping;
		if (parent && object[name] != parent[name]) parent = null;
		var override = function(){
			var previous = this.parent;
			this.parent = parent ? parent[name] : object[name];
			var value = method.apply(this, arguments);
			this.parent = previous;
			return value;
		};
		object[name] = override;
	}

});

Class.implement({

	implement: function(){
		var proto = this.prototype;
		$each(arguments, function(properties){
			Class.inherit(proto, properties);
		});
		return this;
	}

});


/*
Script: Class.Extras.js
	Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks.

License:
	MIT-style license.
*/

var Chain = new Class({

	$chain: [],

	chain: function(){
		this.$chain.extend(Array.flatten(arguments));
		return this;
	},

	callChain: function(){
		return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false;
	},

	clearChain: function(){
		this.$chain.empty();
		return this;
	}

});

var Events = new Class({

	$events: {},

	addEvent: function(type, fn, internal){
		type = Events.removeOn(type);
		if (fn != $empty){
			this.$events[type] = this.$events[type] || [];
			this.$events[type].include(fn);
			if (internal) fn.internal = true;
		}
		return this;
	},

	addEvents: function(events){
		for (var type in events) this.addEvent(type, events[type]);
		return this;
	},

	fireEvent: function(type, args, delay){
		type = Events.removeOn(type);
		if (!this.$events || !this.$events[type]) return this;
		this.$events[type].each(function(fn){
			fn.create({'bind': this, 'delay': delay, 'arguments': args})();
		}, this);
		return this;
	},

	removeEvent: function(type, fn){
		type = Events.removeOn(type);
		if (!this.$events[type]) return this;
		if (!fn.internal) this.$events[type].erase(fn);
		return this;
	},

	removeEvents: function(events){
		if ($type(events) == 'object'){
			for (var type in events) this.removeEvent(type, events[type]);
			return this;
		}
		if (events) events = Events.removeOn(events);
		for (var type in this.$events){
			if (events && events != type) continue;
			var fns = this.$events[type];
			for (var i = fns.length; i--; i) this.removeEvent(type, fns[i]);
		}
		return this;
	}

});

Events.removeOn = function(string){
	return string.replace(/^on([A-Z])/, function(full, first) {
		return first.toLowerCase();
	});
};

var Options = new Class({

	setOptions: function(){
		this.options = $merge.run([this.options].extend(arguments));
		if (!this.addEvent) return this;
		for (var option in this.options){
			if ($type(this.options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue;
			this.addEvent(option, this.options[option]);
			delete this.options[option];
		}
		return this;
	}

});


/*
Script: Element.js
	One of the most important items in MooTools. Contains the dollar function, the dollars function, and an handful of cross-browser,
	time-saver methods to let you easily work with HTML Elements.

License:
	MIT-style license.
*/

var Element = new Native({

	name: 'Element',

	legacy: window.Element,

	initialize: function(tag, props){
		
		var konstructor = Element.Constructors.get(tag);
		
		if (konstructor) return konstructor(props);
		
		if (typeof tag == 'string') { return document.newElement(tag, props); }
		
		return $(tag).set(props);
	},

	afterImplement: function(key, value){
		Element.Prototype[key] = value;
		if (Array[key]) return;
		Elements.implement(key, function(){
			var items = [], elements = true;
			for (var i = 0, j = this.length; i < j; i++){
				var returns = this[i][key].apply(this[i], arguments);
				items.push(returns);
				if (elements) elements = ($type(returns) == 'element');
			}
			return (elements) ? new Elements(items) : items;
		});
	}

});

Element.Prototype = {$family: {name: 'element'}};

Element.Constructors = new Hash;

var IFrame = new Native({

	name: 'IFrame',

	generics: false,

	initialize: function(){
		var params = Array.link(arguments, {properties: Object.type, iframe: $defined});
		var props = params.properties || {};
		var iframe = $(params.iframe) || false;
		var onload = props.onload || $empty;
		delete props.onload;
		props.id = props.name = $pick(props.id, props.name, iframe.id, iframe.name, 'IFrame_' + $time());
		iframe = new Element(iframe || 'iframe', props);
		var onFrameLoad = function(){
			var host = $try(function(){
				return iframe.contentWindow.location.host;
			});
			if (host && host == window.location.host){
				var win = new Window(iframe.contentWindow);
				new Document(iframe.contentWindow.document);
				$extend(win.Element.prototype, Element.Prototype);
			}
			onload.call(iframe.contentWindow, iframe.contentWindow.document);
		};
		(window.frames[props.id]) ? onFrameLoad() : iframe.addListener('load', onFrameLoad);
		return iframe;
	}

});

var Elements = new Native({

	initialize: function(elements, options){
		options = $extend({ddup: true, cash: true}, options);
		elements = elements || [];
		if (options.ddup || options.cash){
			var uniques = {}, returned = [];
			for (var i = 0, l = elements.length; i < l; i++){
				var el = $.element(elements[i], !options.cash);
				if (options.ddup){
					if (uniques[el.uid]) continue;
					uniques[el.uid] = true;
				}
				returned.push(el);
			}
			elements = returned;
		}
		return (options.cash) ? $extend(elements, this) : elements;
	}

});

Elements.implement({

	filter: function(filter, bind){
		if (!filter) return this;
		return new Elements(Array.filter(this, (typeof filter == 'string') ? function(item){
			return item.match(filter);
		} : filter, bind));
	}

});

Document.implement({

	newElement: function(tag, props){
		return $.element(this.createElement(tag)).set(props);
	},

	newTextNode: function(text){
		return this.createTextNode(text);
	},

	getDocument: function(){
		return this;
	},

	getWindow: function(){
		return this.window;
	}

});

Window.implement({

	$: function(el, nocash){
		if (el && el.$family && el.uid) return el;
		var type = $type(el);
		return ($[type]) ? $[type](el, nocash, this.document) : null;
	},

	$$: function(selector){
		if (arguments.length == 1 && typeof selector == 'string') return this.document.getElements(selector);
		var elements = [];
		var args = Array.flatten(arguments);
		for (var i = 0, l = args.length; i < l; i++){
			var item = args[i];
			switch ($type(item)){
				case 'element': elements.push(item); break;
				case 'string': elements.extend(this.document.getElements(item, true));
			}
		}
		return new Elements(elements);
	},

	getDocument: function(){
		return this.document;
	},

	getWindow: function(){
		return this;
	}

});

$.string = function(id, nocash, doc){
	id = doc.getElementById(id);
	return (id) ? $.element(id, nocash) : null;
};

$.element = function(el, nocash){
	$uid(el);
	if (!nocash && !el.$family && !(/^object|embed$/i).test(el.tagName)){
		var proto = Element.Prototype;
		for (var p in proto) el[p] = proto[p];
	};
	return el;
};

$.object = function(obj, nocash, doc){
	if (obj.toElement) return $.element(obj.toElement(doc), nocash);
	return null;
};

$.textnode = $.whitespace = $.window = $.document = $arguments(0);

Native.implement([Element, Document], {

	getElement: function(selector, nocash){
		return $(this.getElements(selector, true)[0] || null, nocash);
	},

	getElements: function(tags, nocash){
		tags = tags.split(',');
		var elements = [];
		var ddup = (tags.length > 1);
		tags.each(function(tag){
			var partial = this.getElementsByTagName(tag.trim());
			(ddup) ? elements.extend(partial) : elements = partial;
		}, this);
		return new Elements(elements, {ddup: ddup, cash: !nocash});
	}

});

(function(){

var collected = {}, storage = {};
var props = {input: 'checked', option: 'selected', textarea: (Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerHTML' : 'value'};

var get = function(uid){
	return (storage[uid] || (storage[uid] = {}));
};

var clean = function(item, retain){
	if (!item) return;
	var uid = item.uid;
	if (Browser.Engine.trident){
		if (item.clearAttributes){
			var clone = retain && item.cloneNode(false);
			item.clearAttributes();
			if (clone) item.mergeAttributes(clone);
		} else if (item.removeEvents){
			item.removeEvents();
		}
		if ((/object/i).test(item.tagName)){
			for (var p in item){
				if (typeof item[p] == 'function') item[p] = $empty;
			}
			Element.dispose(item);
		}
	}	
	if (!uid) return;
	collected[uid] = storage[uid] = null;
};

var purge = function(){
	Hash.each(collected, clean);
	if (Browser.Engine.trident) $A(document.getElementsByTagName('object')).each(clean);
	if (window.CollectGarbage) CollectGarbage();
	collected = storage = null;
};

var walk = function(element, walk, start, match, all, nocash){
	var el = element[start || walk];
	var elements = [];
	while (el){
		if (el.nodeType == 1 && (!match || Element.match(el, match))){
			if (!all) return $(el, nocash);
			elements.push(el);
		}
		el = el[walk];
	}
	return (all) ? new Elements(elements, {ddup: false, cash: !nocash}) : null;
};

var attributes = {
	'html': 'innerHTML',
	'class': 'className',
	'for': 'htmlFor',
	'text': (Browser.Engine.trident || (Browser.Engine.webkit && Browser.Engine.version < 420)) ? 'innerText' : 'textContent'
};
var bools = ['compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', 'disabled', 'readonly', 'multiple', 'selected', 'noresize', 'defer'];
var camels = ['value', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly', 'rowSpan', 'tabIndex', 'useMap'];

Hash.extend(attributes, bools.associate(bools));
Hash.extend(attributes, camels.associate(camels.map(String.toLowerCase)));

var inserters = {

	before: function(context, element){
		if (element.parentNode) element.parentNode.insertBefore(context, element);
	},

	after: function(context, element){
		if (!element.parentNode) return;
		var next = element.nextSibling;
		(next) ? element.parentNode.insertBefore(context, next) : element.parentNode.appendChild(context);
	},

	bottom: function(context, element){
		
		if(element){ element.appendChild(context); }
	},

	top: function(context, element){
		var first = element.firstChild;
		(first) ? element.insertBefore(context, first) : element.appendChild(context);
	}

};

inserters.inside = inserters.bottom;

Hash.each(inserters, function(inserter, where){

	where = where.capitalize();

	Element.implement('inject' + where, function(el){
		inserter(this, $(el, true));
		return this;
	});

	Element.implement('grab' + where, function(el){
		inserter($(el, true), this);
		return this;
	});

});

Element.implement({

	set: function(prop, value){
		switch ($type(prop)){
			case 'object':
				for (var p in prop) this.set(p, prop[p]);
				break;
			case 'string':
				var property = Element.Properties.get(prop);
				(property && property.set) ? property.set.apply(this, Array.slice(arguments, 1)) : this.setProperty(prop, value);
		}
		return this;
	},

	get: function(prop){
		var property = Element.Properties.get(prop);
		return (property && property.get) ? property.get.apply(this, Array.slice(arguments, 1)) : this.getProperty(prop);
	},

	erase: function(prop){
		var property = Element.Properties.get(prop);
		(property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop);
		return this;
	},

	setProperty: function(attribute, value){
		var key = attributes[attribute];
		if (value == undefined) return this.removeProperty(attribute);
		if (key && bools[attribute]) value = !!value;
		(key) ? this[key] = value : this.setAttribute(attribute, '' + value);
		return this;
	},

	setProperties: function(attributes){
		for (var attribute in attributes) this.setProperty(attribute, attributes[attribute]);
		return this;
	},

	getProperty: function(attribute){
		var key = attributes[attribute];
		var value = (key) ? this[key] : this.getAttribute(attribute, 2);
		return (bools[attribute]) ? !!value : (key) ? value : value || null;
	},

	getProperties: function(){
		var args = $A(arguments);
		return args.map(this.getProperty, this).associate(args);
	},

	removeProperty: function(attribute){
		var key = attributes[attribute];
		(key) ? this[key] = (key && bools[attribute]) ? false : '' : this.removeAttribute(attribute);
		return this;
	},

	removeProperties: function(){
		Array.each(arguments, this.removeProperty, this);
		return this;
	},

	hasClass: function(className){
		return this.className.contains(className, ' ');
	},

	addClass: function(className){
		if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();
		return this;
	},

	removeClass: function(className){
		this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1');
		return this;
	},

	toggleClass: function(className){
		return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
	},

	adopt: function(){
		Array.flatten(arguments).each(function(element){
			element = $(element, true);
			if (element) this.appendChild(element);
		}, this);
		return this;
	},

	appendText: function(text, where){
		return this.grab(this.getDocument().newTextNode(text), where);
	},

	grab: function(el, where){
		inserters[where || 'bottom']($(el, true), this);
		return this;
	},

	inject: function(el, where){
		inserters[where || 'bottom'](this, $(el, true));
		return this;
	},

	replaces: function(el){
		el = $(el, true);
		el.parentNode.replaceChild(this, el);
		return this;
	},

	wraps: function(el, where){
		el = $(el, true);
		return this.replaces(el).grab(el, where);
	},

	getPrevious: function(match, nocash){
		return walk(this, 'previousSibling', null, match, false, nocash);
	},

	getAllPrevious: function(match, nocash){
		return walk(this, 'previousSibling', null, match, true, nocash);
	},

	getNext: function(match, nocash){
		return walk(this, 'nextSibling', null, match, false, nocash);
	},

	getAllNext: function(match, nocash){
		return walk(this, 'nextSibling', null, match, true, nocash);
	},

	getFirst: function(match, nocash){
		return walk(this, 'nextSibling', 'firstChild', match, false, nocash);
	},

	getLast: function(match, nocash){
		return walk(this, 'previousSibling', 'lastChild', match, false, nocash);
	},

	getParent: function(match, nocash){
		return walk(this, 'parentNode', null, match, false, nocash);
	},

	getParents: function(match, nocash){
		return walk(this, 'parentNode', null, match, true, nocash);
	},

	getChildren: function(match, nocash){
		return walk(this, 'nextSibling', 'firstChild', match, true, nocash);
	},

	getWindow: function(){
		return this.ownerDocument.window;
	},

	getDocument: function(){
		return this.ownerDocument;
	},

	getElementById: function(id, nocash){
		var el = this.ownerDocument.getElementById(id);
		if (!el) return null;
		for (var parent = el.parentNode; parent != this; parent = parent.parentNode){
			if (!parent) return null;
		}
		return $.element(el, nocash);
	},

	getSelected: function(){
		return new Elements($A(this.options).filter(function(option){
			return option.selected;
		}));
	},

	getComputedStyle: function(property){
		if (this.currentStyle) return this.currentStyle[property.camelCase()];
		var computed = this.getDocument().defaultView.getComputedStyle(this, null);
		return (computed) ? computed.getPropertyValue([property.hyphenate()]) : null;
	},

	toQueryString: function(){
		var queryString = [];
		this.getElements('input, select, textarea', true).each(function(el){
			if (!el.name || el.disabled) return;
			var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){
				return opt.value;
			}) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value;
			$splat(value).each(function(val){
				if (typeof val != 'undefined') queryString.push(el.name + '=' + encodeURIComponent(val));
			});
		});
		return queryString.join('&');
	},

	clone: function(contents, keepid){
		contents = contents !== false;
		var clone = this.cloneNode(contents);
		var clean = function(node, element){
			if (!keepid) node.removeAttribute('id');
			if (Browser.Engine.trident){
				node.clearAttributes();
				node.mergeAttributes(element);
				node.removeAttribute('uid');
				if (node.options){
					var no = node.options, eo = element.options;
					for (var j = no.length; j--;) no[j].selected = eo[j].selected;
				}
			}
			var prop = props[element.tagName.toLowerCase()];
			if (prop && element[prop]) node[prop] = element[prop];
		};

		if (contents){
			var ce = clone.getElementsByTagName('*'), te = this.getElementsByTagName('*');
			for (var i = ce.length; i--;) clean(ce[i], te[i]);
		}

		clean(clone, this);
		return $(clone);
	},

	destroy: function(){
		Element.empty(this);
		Element.dispose(this);
		clean(this, true);
		return null;
	},

	empty: function(){
		$A(this.childNodes).each(function(node){
			Element.destroy(node);
		});
		return this;
	},

	dispose: function(){
		return (this.parentNode) ? this.parentNode.removeChild(this) : this;
	},

	hasChild: function(el){
		el = $(el, true);
		if (!el) return false;
		if (Browser.Engine.webkit && Browser.Engine.version < 420) return $A(this.getElementsByTagName(el.tagName)).contains(el);
		return (this.contains) ? (this != el && this.contains(el)) : !!(this.compareDocumentPosition(el) & 16);
	},

	match: function(tag){
		return (!tag || (tag == this) || (Element.get(this, 'tag') == tag));
	}

});

Native.implement([Element, Window, Document], {

	addListener: function(type, fn){
		if (type == 'unload'){
			var old = fn, self = this;
			fn = function(){
				self.removeListener('unload', fn);
				old();
			};
		} else {
			collected[this.uid] = this;
		}
		if (this.addEventListener) this.addEventListener(type, fn, false);
		else this.attachEvent('on' + type, fn);
		return this;
	},

	removeListener: function(type, fn){
		if (this.removeEventListener) this.removeEventListener(type, fn, false);
		else this.detachEvent('on' + type, fn);
		return this;
	},

	retrieve: function(property, dflt){
		var storage = get(this.uid), prop = storage[property];
		if (dflt != undefined && prop == undefined) prop = storage[property] = dflt;
		return $pick(prop);
	},

	store: function(property, value){
		var storage = get(this.uid);
		storage[property] = value;
		return this;
	},

	eliminate: function(property){
		var storage = get(this.uid);
		delete storage[property];
		return this;
	}

});

window.addListener('unload', purge);

})();

Element.Properties = new Hash;

Element.Properties.style = {

	set: function(style){
		this.style.cssText = style;
	},

	get: function(){
		return this.style.cssText;
	},

	erase: function(){
		this.style.cssText = '';
	}

};

Element.Properties.tag = {

	get: function(){
		return this.tagName.toLowerCase();
	}

};

Element.Properties.html = (function(){
	var wrapper = document.createElement('div');

	var translations = {
		table: [1, '<table>', '</table>'],
		select: [1, '<select>', '</select>'],
		tbody: [2, '<table><tbody>', '</tbody></table>'],
		tr: [3, '<table><tbody><tr>', '</tr></tbody></table>']
	};
	translations.thead = translations.tfoot = translations.tbody;

	var html = {
		set: function(){
			var html = Array.flatten(arguments).join('');
			var wrap = Browser.Engine.trident && translations[this.get('tag')];
			if (wrap){
				var first = wrapper;
				first.innerHTML = wrap[1] + html + wrap[2];
				for (var i = wrap[0]; i--;) first = first.firstChild;
				this.empty().adopt(first.childNodes);
			} else {
				this.innerHTML = html;
			}
		}
	};

	html.erase = html.set;

	return html;
})();

if (Browser.Engine.webkit && Browser.Engine.version < 420) Element.Properties.text = {
	get: function(){
		if (this.innerText) return this.innerText;
		var temp = this.ownerDocument.newElement('div', {html: this.innerHTML}).inject(this.ownerDocument.body);
		var text = temp.innerText;
		temp.destroy();
		return text;
	}
};


/*
Script: Element.Event.js
	Contains Element methods for dealing with events, and custom Events.

License:
	MIT-style license.
*/

Element.Properties.events = {set: function(events){
	this.addEvents(events);
}};

Native.implement([Element, Window, Document], {

	addEvent: function(type, fn){
		var events = this.retrieve('events', {});
		events[type] = events[type] || {'keys': [], 'values': []};
		if (events[type].keys.contains(fn)) return this;
		events[type].keys.push(fn);
		var realType = type, custom = Element.Events.get(type), condition = fn, self = this;
		if (custom){
			if (custom.onAdd) custom.onAdd.call(this, fn);
			if (custom.condition){
				condition = function(event){
					if (custom.condition.call(this, event)) return fn.call(this, event);
					return true;
				};
			}
			realType = custom.base || realType;
		}
		var defn = function(){
			return fn.call(self);
		};
		var nativeEvent = Element.NativeEvents[realType];
		if (nativeEvent){
			if (nativeEvent == 2){
				defn = function(event){
					event = new Event(event, self.getWindow());
					if (condition.call(self, event) === false) event.stop();
				};
			}
			this.addListener(realType, defn);
		}
		events[type].values.push(defn);
		return this;
	},

	removeEvent: function(type, fn){
		var events = this.retrieve('events');
		if (!events || !events[type]) return this;
		var pos = events[type].keys.indexOf(fn);
		if (pos == -1) return this;
		events[type].keys.splice(pos, 1);
		var value = events[type].values.splice(pos, 1)[0];
		var custom = Element.Events.get(type);
		if (custom){
			if (custom.onRemove) custom.onRemove.call(this, fn);
			type = custom.base || type;
		}
		return (Element.NativeEvents[type]) ? this.removeListener(type, value) : this;
	},

	addEvents: function(events){
		for (var event in events) this.addEvent(event, events[event]);
		return this;
	},

	removeEvents: function(events){
		if ($type(events) == 'object'){
			for (var type in events) this.removeEvent(type, events[type]);
			return this;
		}
		var attached = this.retrieve('events');
		if (!attached) return this;
		if (!events){
			for (var type in attached) this.removeEvents(type);
			this.eliminate('events');
		} else if (attached[events]){
			while (attached[events].keys[0]) this.removeEvent(events, attached[events].keys[0]);
			attached[events] = null;
		}
		return this;
	},

	fireEvent: function(type, args, delay){
		var events = this.retrieve('events');
		if (!events || !events[type]) return this;
		events[type].keys.each(function(fn){
			fn.create({'bind': this, 'delay': delay, 'arguments': args})();
		}, this);		
		return this;
	},

	cloneEvents: function(from, type){
		from = $(from);
		var fevents = from.retrieve('events');
		if (!fevents) return this;
		if (!type){
			for (var evType in fevents) this.cloneEvents(from, evType);
		} else if (fevents[type]){
			fevents[type].keys.each(function(fn){
				this.addEvent(type, fn);
			}, this);
		}
		return this;
	}

});

Element.NativeEvents = {
	click: 2, dblclick: 2, mouseup: 2, mousedown: 2, contextmenu: 2, //mouse buttons
	mousewheel: 2, DOMMouseScroll: 2, //mouse wheel
	mouseover: 2, mouseout: 2, mousemove: 2, selectstart: 2, selectend: 2, //mouse movement
	keydown: 2, keypress: 2, keyup: 2, //keyboard
	focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, //form elements
	load: 1, unload: 1, beforeunload: 2, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window
	error: 1, abort: 1, scroll: 1 //misc
};

(function(){

var $check = function(event){
	var related = event.relatedTarget;
	if (related == undefined) return true;
	if (related === false) return false;
	return ($type(this) != 'document' && related != this && related.prefix != 'xul' && !this.hasChild(related));
};

Element.Events = new Hash({

	mouseenter: {
		base: 'mouseover',
		condition: $check
	},

	mouseleave: {
		base: 'mouseout',
		condition: $check
	},

	mousewheel: {
		base: (Browser.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel'
	}

});

})();


/*
Script: Element.Style.js
	Contains methods for interacting with the styles of Elements in a fashionable way.

License:
	MIT-style license.
*/

Element.Properties.styles = {set: function(styles){
	this.setStyles(styles);
}};

Element.Properties.opacity = {

	set: function(opacity, novisibility){
		if (!novisibility){
			if (opacity == 0){
				if (this.style.visibility != 'hidden') this.style.visibility = 'hidden';
			} else {
				if (this.style.visibility != 'visible') this.style.visibility = 'visible';
			}
		}
		if (!this.currentStyle || !this.currentStyle.hasLayout) this.style.zoom = 1;
		if (Browser.Engine.trident) this.style.filter = (opacity == 1) ? '' : 'alpha(opacity=' + opacity * 100 + ')';
		this.style.opacity = opacity;
		this.store('opacity', opacity);
	},

	get: function(){
		return this.retrieve('opacity', 1);
	}

};

Element.implement({

	setOpacity: function(value){
		return this.set('opacity', value, true);
	},

	getOpacity: function(){
		return this.get('opacity');
	},

	setStyle: function(property, value){
		switch (property){
			case 'opacity': return this.set('opacity', parseFloat(value));
			case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat';
		}
		property = property.camelCase();
		if ($type(value) != 'string'){
			var map = (Element.Styles.get(property) || '@').split(' ');
			value = $splat(value).map(function(val, i){
				if (!map[i]) return '';
				return ($type(val) == 'number') ? map[i].replace('@', Math.round(val)) : val;
			}).join(' ');
		} else if (value == String(Number(value))){
			value = Math.round(value);
		}
		this.style[property] = value;
		return this;
	},

	getStyle: function(property){
		switch (property){
			case 'opacity': return this.get('opacity');
			case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat';
		}
		property = property.camelCase();
		var result = this.style[property];
		if (!$chk(result)){
			result = [];
			for (var style in Element.ShortStyles){
				if (property != style) continue;
				for (var s in Element.ShortStyles[style]) result.push(this.getStyle(s));
				return result.join(' ');
			}
			result = this.getComputedStyle(property);
		}
		if (result){
			result = String(result);
			var color = result.match(/rgba?\([\d\s,]+\)/);
			if (color) result = result.replace(color[0], color[0].rgbToHex());
		}
		if (Browser.Engine.presto || (Browser.Engine.trident && !$chk(parseInt(result)))){
			if (property.test(/^(height|width)$/)){
				var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0;
				values.each(function(value){
					size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt();
				}, this);
				return this['offset' + property.capitalize()] - size + 'px';
			}
			if ((Browser.Engine.presto) && String(result).test('px')) return result;
			if (property.test(/(border(.+)Width|margin|padding)/)) return '0px';
		}
		return result;
	},

	setStyles: function(styles){
		for (var style in styles) this.setStyle(style, styles[style]);
		return this;
	},

	getStyles: function(){
		var result = {};
		Array.each(arguments, function(key){
			result[key] = this.getStyle(key);
		}, this);
		return result;
	}

});

Element.Styles = new Hash({
	left: '@px', top: '@px', bottom: '@px', right: '@px',
	width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px',
	backgroundColor: 'rgb(@, @, @)', backgroundPosition: '@px @px', color: 'rgb(@, @, @)',
	fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)',
	margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)',
	borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)',
	zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@'
});

Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}};

['Top', 'Right', 'Bottom', 'Left'].each(function(direction){
	var Short = Element.ShortStyles;
	var All = Element.Styles;
	['margin', 'padding'].each(function(style){
		var sd = style + direction;
		Short[style][sd] = All[sd] = '@px';
	});
	var bd = 'border' + direction;
	Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)';
	var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color';
	Short[bd] = {};
	Short.borderWidth[bdw] = Short[bd][bdw] = All[bdw] = '@px';
	Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@';
	Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)';
});


/*
Script: Element.Dimensions.js
	Contains methods to work with size, scroll, or positioning of Elements and the window object.

License:
	MIT-style license.

Credits:
	- Element positioning based on the [qooxdoo](http://qooxdoo.org/) code and smart browser fixes, [LGPL License](http://www.gnu.org/licenses/lgpl.html).
	- Viewport dimensions based on [YUI](http://developer.yahoo.com/yui/) code, [BSD License](http://developer.yahoo.com/yui/license.html).
*/

(function(){

Element.implement({

	scrollTo: function(x, y){
		if (isBody(this)){
			this.getWindow().scrollTo(x, y);
		} else {
			this.scrollLeft = x;
			this.scrollTop = y;
		}
		return this;
	},

	getSize: function(){
		if (isBody(this)) return this.getWindow().getSize();
		return {x: this.offsetWidth, y: this.offsetHeight};
	},

	getScrollSize: function(){
		if (isBody(this)) return this.getWindow().getScrollSize();
		return {x: this.scrollWidth, y: this.scrollHeight};
	},

	getScroll: function(){
		if (isBody(this)) return this.getWindow().getScroll();
		return {x: this.scrollLeft, y: this.scrollTop};
	},

	getScrolls: function(){
		var element = this, position = {x: 0, y: 0};
		while (element && !isBody(element)){
			position.x += element.scrollLeft;
			position.y += element.scrollTop;
			element = element.parentNode;
		}
		return position;
	},

	getOffsetParent: function(){
		var element = this;
		if (isBody(element)) return null;
		if (!Browser.Engine.trident) return element.offsetParent;
		while ((element = element.parentNode) && !isBody(element)){
			if (styleString(element, 'position') != 'static') return element;
		}
		return null;
	},

	getOffsets: function(){
		if (Browser.Engine.trident){
			try{var bound = this.getBoundingClientRect();}catch (ex){return [0,0];}
			html = this.getDocument().documentElement;
			return {
				x: bound.left + html.scrollLeft - html.clientLeft,
				y: bound.top + html.scrollTop - html.clientTop
			};
		}

		var element = this, position = {x: 0, y: 0};
		if (isBody(this)) return position;

		while (element && !isBody(element)){
			position.x += element.offsetLeft;
			position.y += element.offsetTop;

			if (Browser.Engine.gecko){
				if (!borderBox(element)){
					position.x += leftBorder(element);
					position.y += topBorder(element);
				}
				var parent = element.parentNode;
				if (parent && styleString(parent, 'overflow') != 'visible'){
					position.x += leftBorder(parent);
					position.y += topBorder(parent);
				}
			} else if (element != this && Browser.Engine.webkit){
				position.x += leftBorder(element);
				position.y += topBorder(element);
			}

			element = element.offsetParent;
		}
		if (Browser.Engine.gecko && !borderBox(this)){
			position.x -= leftBorder(this);
			position.y -= topBorder(this);
		}
		return position;
	},

	getPosition: function(relative){
		if (isBody(this)) return {x: 0, y: 0};
		var offset = this.getOffsets(), scroll = this.getScrolls();
		var position = {x: offset.x - scroll.x, y: offset.y - scroll.y};
		var relativePosition = (relative && (relative = $(relative))) ? relative.getPosition() : {x: 0, y: 0};
		return {x: position.x - relativePosition.x, y: position.y - relativePosition.y};
	},

	getCoordinates: function(element){
		if (isBody(this)) return this.getWindow().getCoordinates();
		var position = this.getPosition(element), size = this.getSize();
		var obj = {left: position.x, top: position.y, width: size.x, height: size.y};
		obj.right = obj.left + obj.width;
		obj.bottom = obj.top + obj.height;
		return obj;
	},

	computePosition: function(obj){
		return {left: obj.x - styleNumber(this, 'margin-left'), top: obj.y - styleNumber(this, 'margin-top')};
	},

	position: function(obj){
		return this.setStyles(this.computePosition(obj));
	}

});

Native.implement([Document, Window], {

	getSize: function(){
		var win = this.getWindow();
		if (Browser.Engine.presto || Browser.Engine.webkit) return {x: win.innerWidth, y: win.innerHeight};
		var doc = getCompatElement(this);
		return {x: doc.clientWidth, y: doc.clientHeight};
	},

	getScroll: function(){
		var win = this.getWindow();
		var doc = getCompatElement(this);
		return {x: win.pageXOffset || doc.scrollLeft, y: win.pageYOffset || doc.scrollTop};
	},

	getScrollSize: function(){
		var doc = getCompatElement(this);
		var min = this.getSize();
		return {x: Math.max(doc.scrollWidth, min.x), y: Math.max(doc.scrollHeight, min.y)};
	},

	getPosition: function(){
		return {x: 0, y: 0};
	},

	getCoordinates: function(){
		var size = this.getSize();
		return {top: 0, left: 0, bottom: size.y, right: size.x, height: size.y, width: size.x};
	}

});

// private methods

var styleString = Element.getComputedStyle;

function styleNumber(element, style){
	return styleString(element, style).toInt() || 0;
};

function borderBox(element){
	return styleString(element, '-moz-box-sizing') == 'border-box';
};

function topBorder(element){
	return styleNumber(element, 'border-top-width');
};

function leftBorder(element){
	return styleNumber(element, 'border-left-width');
};

function isBody(element){
	return (/^(?:body|html)$/i).test(element.tagName);
};

function getCompatElement(element){
	var doc = element.getDocument();
	return (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
};

})();

//aliases

Native.implement([Window, Document, Element], {

	getHeight: function(){
		return this.getSize().y;
	},

	getWidth: function(){
		return this.getSize().x;
	},

	getScrollTop: function(){
		return this.getScroll().y;
	},

	getScrollLeft: function(){
		return this.getScroll().x;
	},

	getScrollHeight: function(){
		return this.getScrollSize().y;
	},

	getScrollWidth: function(){
		return this.getScrollSize().x;
	},

	getTop: function(){
		return this.getPosition().y;
	},

	getLeft: function(){
		return this.getPosition().x;
	}

});


/*
Script: Selectors.js
	Adds advanced CSS Querying capabilities for targeting elements. Also includes pseudoselectors support.

License:
	MIT-style license.
*/

Native.implement([Document, Element], {

	getElements: function(expression, nocash){
		expression = expression.split(',');
		var items, local = {};
		for (var i = 0, l = expression.length; i < l; i++){
			var selector = expression[i], elements = Selectors.Utils.search(this, selector, local);
			if (i != 0 && elements.item) elements = $A(elements);
			items = (i == 0) ? elements : (items.item) ? $A(items).concat(elements) : items.concat(elements);
		}
		return new Elements(items, {ddup: (expression.length > 1), cash: !nocash});
	}

});

Element.implement({

	match: function(selector){
		if (!selector || (selector == this)) return true;
		var tagid = Selectors.Utils.parseTagAndID(selector);
		var tag = tagid[0], id = tagid[1];
		if (!Selectors.Filters.byID(this, id) || !Selectors.Filters.byTag(this, tag)) return false;
		var parsed = Selectors.Utils.parseSelector(selector);
		return (parsed) ? Selectors.Utils.filter(this, parsed, {}) : true;
	}

});

var Selectors = {Cache: {nth: {}, parsed: {}}};

Selectors.RegExps = {
	id: (/#([\w-]+)/),
	tag: (/^(\w+|\*)/),
	quick: (/^(\w+|\*)$/),
	splitter: (/\s*([+>~\s])\s*([a-zA-Z#.*:\[])/g),
	combined: (/\.([\w-]+)|\[(\w+)(?:([!*^$~|]?=)(["']?)([^\4]*?)\4)?\]|:([\w-]+)(?:\(["']?(.*?)?["']?\)|$)/g)
};

Selectors.Utils = {

	chk: function(item, uniques){
		if (!uniques) return true;
		var uid = $uid(item);
		if (!uniques[uid]) return uniques[uid] = true;
		return false;
	},

	parseNthArgument: function(argument){
		if (Selectors.Cache.nth[argument]) return Selectors.Cache.nth[argument];
		var parsed = argument.match(/^([+-]?\d*)?([a-z]+)?([+-]?\d*)?$/);
		if (!parsed) return false;
		var inta = parseInt(parsed[1]);
		var a = (inta || inta === 0) ? inta : 1;
		var special = parsed[2] || false;
		var b = parseInt(parsed[3]) || 0;
		if (a != 0){
			b--;
			while (b < 1) b += a;
			while (b >= a) b -= a;
		} else {
			a = b;
			special = 'index';
		}
		switch (special){
			case 'n': parsed = {a: a, b: b, special: 'n'}; break;
			case 'odd': parsed = {a: 2, b: 0, special: 'n'}; break;
			case 'even': parsed = {a: 2, b: 1, special: 'n'}; break;
			case 'first': parsed = {a: 0, special: 'index'}; break;
			case 'last': parsed = {special: 'last-child'}; break;
			case 'only': parsed = {special: 'only-child'}; break;
			default: parsed = {a: (a - 1), special: 'index'};
		}

		return Selectors.Cache.nth[argument] = parsed;
	},

	parseSelector: function(selector){
		if (Selectors.Cache.parsed[selector]) return Selectors.Cache.parsed[selector];
		var m, parsed = {classes: [], pseudos: [], attributes: []};
		while ((m = Selectors.RegExps.combined.exec(selector))){
			var cn = m[1], an = m[2], ao = m[3], av = m[5], pn = m[6], pa = m[7];
			if (cn){
				parsed.classes.push(cn);
			} else if (pn){
				var parser = Selectors.Pseudo.get(pn);
				if (parser) parsed.pseudos.push({parser: parser, argument: pa});
				else parsed.attributes.push({name: pn, operator: '=', value: pa});
			} else if (an){
				parsed.attributes.push({name: an, operator: ao, value: av});
			}
		}
		if (!parsed.classes.length) delete parsed.classes;
		if (!parsed.attributes.length) delete parsed.attributes;
		if (!parsed.pseudos.length) delete parsed.pseudos;
		if (!parsed.classes && !parsed.attributes && !parsed.pseudos) parsed = null;
		return Selectors.Cache.parsed[selector] = parsed;
	},

	parseTagAndID: function(selector){
		var tag = selector.match(Selectors.RegExps.tag);
		var id = selector.match(Selectors.RegExps.id);
		return [(tag) ? tag[1] : '*', (id) ? id[1] : false];
	},

	filter: function(item, parsed, local){
		var i;
		if (parsed.classes){
			for (i = parsed.classes.length; i--; i){
				var cn = parsed.classes[i];
				if (!Selectors.Filters.byClass(item, cn)) return false;
			}
		}
		if (parsed.attributes){
			for (i = parsed.attributes.length; i--; i){
				var att = parsed.attributes[i];
				if (!Selectors.Filters.byAttribute(item, att.name, att.operator, att.value)) return false;
			}
		}
		if (parsed.pseudos){
			for (i = parsed.pseudos.length; i--; i){
				var psd = parsed.pseudos[i];
				if (!Selectors.Filters.byPseudo(item, psd.parser, psd.argument, local)) return false;
			}
		}
		return true;
	},

	getByTagAndID: function(ctx, tag, id){
		if (id){
			var item = (ctx.getElementById) ? ctx.getElementById(id, true) : Element.getElementById(ctx, id, true);
			return (item && Selectors.Filters.byTag(item, tag)) ? [item] : [];
		} else {
			return ctx.getElementsByTagName(tag);
		}
	},

	search: function(self, expression, local){
		var splitters = [];

		var selectors = expression.trim().replace(Selectors.RegExps.splitter, function(m0, m1, m2){
			splitters.push(m1);
			return ':)' + m2;
		}).split(':)');

		var items, filtered, item;

		for (var i = 0, l = selectors.length; i < l; i++){

			var selector = selectors[i];

			if (i == 0 && Selectors.RegExps.quick.test(selector)){
				items = self.getElementsByTagName(selector);
				continue;
			}

			var splitter = splitters[i - 1];

			var tagid = Selectors.Utils.parseTagAndID(selector);
			var tag = tagid[0], id = tagid[1];

			if (i == 0){
				items = Selectors.Utils.getByTagAndID(self, tag, id);
			} else {
				var uniques = {}, found = [];
				for (var j = 0, k = items.length; j < k; j++) found = Selectors.Getters[splitter](found, items[j], tag, id, uniques);
				items = found;
			}

			var parsed = Selectors.Utils.parseSelector(selector);

			if (parsed){
				filtered = [];
				for (var m = 0, n = items.length; m < n; m++){
					item = items[m];
					if (Selectors.Utils.filter(item, parsed, local)) filtered.push(item);
				}
				items = filtered;
			}

		}

		return items;

	}

};

Selectors.Getters = {

	' ': function(found, self, tag, id, uniques){
		var items = Selectors.Utils.getByTagAndID(self, tag, id);
		for (var i = 0, l = items.length; i < l; i++){
			var item = items[i];
			if (Selectors.Utils.chk(item, uniques)) found.push(item);
		}
		return found;
	},

	'>': function(found, self, tag, id, uniques){
		var children = Selectors.Utils.getByTagAndID(self, tag, id);
		for (var i = 0, l = children.length; i < l; i++){
			var child = children[i];
			if (child.parentNode == self && Selectors.Utils.chk(child, uniques)) found.push(child);
		}
		return found;
	},

	'+': function(found, self, tag, id, uniques){
		while ((self = self.nextSibling)){
			if (self.nodeType == 1){
				if (Selectors.Utils.chk(self, uniques) && Selectors.Filters.byTag(self, tag) && Selectors.Filters.byID(self, id)) found.push(self);
				break;
			}
		}
		return found;
	},

	'~': function(found, self, tag, id, uniques){
		while ((self = self.nextSibling)){
			if (self.nodeType == 1){
				if (!Selectors.Utils.chk(self, uniques)) break;
				if (Selectors.Filters.byTag(self, tag) && Selectors.Filters.byID(self, id)) found.push(self);
			}
		}
		return found;
	}

};

Selectors.Filters = {

	byTag: function(self, tag){
		return (tag == '*' || (self.tagName && self.tagName.toLowerCase() == tag));
	},

	byID: function(self, id){
		return (!id || (self.id && self.id == id));
	},

	byClass: function(self, klass){
		return (self.className && self.className.contains(klass, ' '));
	},

	byPseudo: function(self, parser, argument, local){
		return parser.call(self, argument, local);
	},

	byAttribute: function(self, name, operator, value){
		var result = Element.prototype.getProperty.call(self, name);
		if (!result) return (operator == '!=');
		if (!operator || value == undefined) return true;
		switch (operator){
			case '=': return (result == value);
			case '*=': return (result.contains(value));
			case '^=': return (result.substr(0, value.length) == value);
			case '$=': return (result.substr(result.length - value.length) == value);
			case '!=': return (result != value);
			case '~=': return result.contains(value, ' ');
			case '|=': return result.contains(value, '-');
		}
		return false;
	}

};

Selectors.Pseudo = new Hash({

	// w3c pseudo selectors

	checked: function(){
		return this.checked;
	},

	empty: function(){
		return !(this.innerText || this.textContent || '').length;
	},

	not: function(selector){
		return !Element.match(this, selector);
	},

	contains: function(text){
		return (this.innerText || this.textContent || '').contains(text);
	},

	'first-child': function(){
		return Selectors.Pseudo.index.call(this, 0);
	},

	'last-child': function(){
		var element = this;
		while ((element = element.nextSibling)){
			if (element.nodeType == 1) return false;
		}
		return true;
	},

	'only-child': function(){
		var prev = this;
		while ((prev = prev.previousSibling)){
			if (prev.nodeType == 1) return false;
		}
		var next = this;
		while ((next = next.nextSibling)){
			if (next.nodeType == 1) return false;
		}
		return true;
	},

	'nth-child': function(argument, local){
		argument = (argument == undefined) ? 'n' : argument;
		var parsed = Selectors.Utils.parseNthArgument(argument);
		if (parsed.special != 'n') return Selectors.Pseudo[parsed.special].call(this, parsed.a, local);
		var count = 0;
		local.positions = local.positions || {};
		var uid = $uid(this);
		if (!local.positions[uid]){
			var self = this;
			while ((self = self.previousSibling)){
				if (self.nodeType != 1) continue;
				count ++;
				var position = local.positions[$uid(self)];
				if (position != undefined){
					count = position + count;
					break;
				}
			}
			local.positions[uid] = count;
		}
		return (local.positions[uid] % parsed.a == parsed.b);
	},

	// custom pseudo selectors

	index: function(index){
		var element = this, count = 0;
		while ((element = element.previousSibling)){
			if (element.nodeType == 1 && ++count > index) return false;
		}
		return (count == index);
	},

	even: function(argument, local){
		return Selectors.Pseudo['nth-child'].call(this, '2n+1', local);
	},

	odd: function(argument, local){
		return Selectors.Pseudo['nth-child'].call(this, '2n', local);
	}

});


/*
Script: Domready.js
	Contains the domready custom event.

License:
	MIT-style license.
*/

Element.Events.domready = {

	onAdd: function(fn){
		if (Browser.loaded) fn.call(this);
	}

};

(function(){

	var domready = function(){
		if (Browser.loaded) return;
		Browser.loaded = true;
		window.fireEvent('domready');
		document.fireEvent('domready');
	};

	if (Browser.Engine.trident){
		var temp = document.createElement('div');
		(function(){
			($try(function(){
				temp.doScroll('left');
				return $(temp).inject(document.body).set('html', 'temp').dispose();
			})) ? domready() : arguments.callee.delay(50);
		})();
	} else if (Browser.Engine.webkit && Browser.Engine.version < 525){
		(function(){
			(['loaded', 'complete'].contains(document.readyState)) ? domready() : arguments.callee.delay(50);
		})();
	} else {
		window.addEvent('load', domready);
		document.addEvent('DOMContentLoaded', domready);
	}

})();


/*
Script: JSON.js
	JSON encoder and decoder.

License:
	MIT-style license.

See Also:
	<http://www.json.org/>
*/

var JSON = new Hash({

	$specialChars: {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'},

	$replaceChars: function(chr){
		return JSON.$specialChars[chr] || '\\u00' + Math.floor(chr.charCodeAt() / 16).toString(16) + (chr.charCodeAt() % 16).toString(16);
	},

	encode: function(obj){
		switch ($type(obj)){
			case 'string':
				return '"' + obj.replace(/[\x00-\x1f\\"]/g, JSON.$replaceChars) + '"';
			case 'array':
				return '[' + String(obj.map(JSON.encode).filter($defined)) + ']';
			case 'object': case 'hash':
				var string = [];
				Hash.each(obj, function(value, key){
					var json = JSON.encode(value);
					if (json) string.push(JSON.encode(key) + ':' + json);
				});
				return '{' + string + '}';
			case 'number': case 'boolean': return String(obj);
			case false: return 'null';
		}
		return null;
	},

	decode: function(string, secure){
		if ($type(string) != 'string' || !string.length) return null;
		if (secure && !(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(string.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) return null;
		return eval('(' + string + ')');
	}

});

Native.implement([Hash, Array, String, Number], {

	toJSON: function(){
		return JSON.encode(this);
	}

});


/*
Script: Cookie.js
	Class for creating, loading, and saving browser Cookies.

License:
	MIT-style license.

Credits:
	Based on the functions by Peter-Paul Koch (http://quirksmode.org).
*/

var Cookie = new Class({

	Implements: Options,

	options: {
		path: false,
		domain: false,
		duration: false,
		secure: false,
		document: document
	},

	initialize: function(key, options){
		this.key = key;
		this.setOptions(options);
	},

	write: function(value){
		value = encodeURIComponent(value);
		if (this.options.domain) value += '; domain=' + this.options.domain;
		if (this.options.path) value += '; path=' + this.options.path;
		if (this.options.duration){
			var date = new Date();
			date.setTime(date.getTime() + this.options.duration * 24 * 60 * 60 * 1000);
			value += '; expires=' + date.toGMTString();
		}
		if (this.options.secure) value += '; secure';
		this.options.document.cookie = this.key + '=' + value;
		return this;
	},

	read: function(){
		var value = this.options.document.cookie.match('(?:^|;)\\s*' + this.key.escapeRegExp() + '=([^;]*)');
		return (value) ? decodeURIComponent(value[1]) : null;
	},

	dispose: function(){
		new Cookie(this.key, $merge(this.options, {duration: -1})).write('');
		return this;
	}

});

Cookie.write = function(key, value, options){
	return new Cookie(key, options).write(value);
};

Cookie.read = function(key){
	return new Cookie(key).read();
};

Cookie.dispose = function(key, options){
	return new Cookie(key, options).dispose();
};


/*
Script: Swiff.js
	Wrapper for embedding SWF movies. Supports (and fixes) External Interface Communication.

License:
	MIT-style license.

Credits:
	Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject.
*/

var Swiff = new Class({

	Implements: [Options],

	options: {
		id: null,
		height: 1,
		width: 1,
		container: null,
		properties: {},
		params: {
			quality: 'high',
			allowScriptAccess: 'always',
			wMode: 'transparent',
			swLiveConnect: true
		},
		callBacks: {},
		vars: {}
	},

	toElement: function(){
		return this.object;
	},

	initialize: function(path, options){
		this.instance = 'Swiff_' + $time();

		this.setOptions(options);
		options = this.options;
		var id = this.id = options.id || this.instance;
		var container = $(options.container);

		Swiff.CallBacks[this.instance] = {};

		var params = options.params, vars = options.vars, callBacks = options.callBacks;
		var properties = $extend({height: options.height, width: options.width}, options.properties);

		var self = this;

		for (var callBack in callBacks){
			Swiff.CallBacks[this.instance][callBack] = (function(option){
				return function(){
					return option.apply(self.object, arguments);
				};
			})(callBacks[callBack]);
			vars[callBack] = 'Swiff.CallBacks.' + this.instance + '.' + callBack;
		}

		params.flashVars = Hash.toQueryString(vars);
		if (Browser.Engine.trident){
			properties.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
			params.movie = path;
		} else {
			properties.type = 'application/x-shockwave-flash';
			properties.data = path;
		}
		var build = '<object id="' + id + '"';
		for (var property in properties) build += ' ' + property + '="' + properties[property] + '"';
		build += '>';
		for (var param in params){
			if (params[param]) build += '<param name="' + param + '" value="' + params[param] + '" />';
		}
		build += '</object>';
		this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild;
	},

	replaces: function(element){
		element = $(element, true);
		element.parentNode.replaceChild(this.toElement(), element);
		return this;
	},

	inject: function(element){
		$(element, true).appendChild(this.toElement());
		return this;
	},

	remote: function(){
		return Swiff.remote.apply(Swiff, [this.toElement()].extend(arguments));
	}

});

Swiff.CallBacks = {};

Swiff.remote = function(obj, fn){
	var rs = obj.CallFunction('<invoke name="' + fn + '" returntype="javascript">' + __flash__argumentsToXML(arguments, 2) + '</invoke>');
	return eval(rs);
};


/*
Script: Fx.js
	Contains the basic animation logic to be extended by all other Fx Classes.

License:
	MIT-style license.
*/

var Fx = new Class({

	Implements: [Chain, Events, Options],

	options: {
		/*
		onStart: $empty,
		onCancel: $empty,
		onComplete: $empty,
		*/
		fps: 50,
		unit: false,
		duration: 500,
		link: 'ignore'
	},

	initialize: function(options){
		this.subject = this.subject || this;
		this.setOptions(options);
		this.options.duration = Fx.Durations[this.options.duration] || this.options.duration.toInt();
		var wait = this.options.wait;
		if (wait === false) this.options.link = 'cancel';
	},

	getTransition: function(){
		return function(p){
			return -(Math.cos(Math.PI * p) - 1) / 2;
		};
	},

	step: function(){
		var time = $time();
		if (time < this.time + this.options.duration){
			var delta = this.transition((time - this.time) / this.options.duration);
			this.set(this.compute(this.from, this.to, delta));
		} else {
			this.set(this.compute(this.from, this.to, 1));
			this.complete();
		}
	},

	set: function(now){
		return now;
	},

	compute: function(from, to, delta){
		return Fx.compute(from, to, delta);
	},

	check: function(caller){
		if (!this.timer) return true;
		switch (this.options.link){
			case 'cancel': this.cancel(); return true;
			case 'chain': this.chain(caller.bind(this, Array.slice(arguments, 1))); return false;
		}
		return false;
	},

	start: function(from, to){
		if (!this.check(arguments.callee, from, to)) return this;
		this.from = from;
		this.to = to;
		this.time = 0;
		this.transition = this.getTransition();
		this.startTimer();
		this.onStart();
		return this;
	},

	complete: function(){
		if (this.stopTimer()) this.onComplete();
		return this;
	},

	cancel: function(){
		if (this.stopTimer()) this.onCancel();
		return this;
	},

	onStart: function(){
		this.fireEvent('start', this.subject);
	},

	onComplete: function(){
		this.fireEvent('complete', this.subject);
		if (!this.callChain()) this.fireEvent('chainComplete', this.subject);
	},

	onCancel: function(){
		this.fireEvent('cancel', this.subject).clearChain();
	},

	pause: function(){
		this.stopTimer();
		return this;
	},

	resume: function(){
		this.startTimer();
		return this;
	},

	stopTimer: function(){
		if (!this.timer) return false;
		this.time = $time() - this.time;
		this.timer = $clear(this.timer);
		return true;
	},

	startTimer: function(){
		if (this.timer) return false;
		this.time = $time() - this.time;
		this.timer = this.step.periodical(Math.round(1000 / this.options.fps), this);
		return true;
	}

});

Fx.compute = function(from, to, delta){
	return (to - from) * delta + from;
};

Fx.Durations = {'short': 250, 'normal': 500, 'long': 1000};


/*
Script: Fx.CSS.js
	Contains the CSS animation logic. Used by Fx.Tween, Fx.Morph, Fx.Elements.

License:
	MIT-style license.
*/

Fx.CSS = new Class({

	Extends: Fx,

	//prepares the base from/to object

	prepare: function(element, property, values){
		values = $splat(values);
		var values1 = values[1];
		if (!$chk(values1)){
			values[1] = values[0];
			values[0] = element.getStyle(property);
		}
		var parsed = values.map(this.parse);
		return {from: parsed[0], to: parsed[1]};
	},

	//parses a value into an array

	parse: function(value){
		value = $lambda(value)();
		value = (typeof value == 'string') ? value.split(' ') : $splat(value);
		return value.map(function(val){
			val = String(val);
			var found = false;
			Fx.CSS.Parsers.each(function(parser, key){
				if (found) return;
				var parsed = parser.parse(val);
				if ($chk(parsed)) found = {value: parsed, parser: parser};
			});
			found = found || {value: val, parser: Fx.CSS.Parsers.String};
			return found;
		});
	},

	//computes by a from and to prepared objects, using their parsers.

	compute: function(from, to, delta){
		var computed = [];
		(Math.min(from.length, to.length)).times(function(i){
			computed.push({value: from[i].parser.compute(from[i].value, to[i].value, delta), parser: from[i].parser});
		});
		computed.$family = {name: 'fx:css:value'};
		return computed;
	},

	//serves the value as settable

	serve: function(value, unit){
		if ($type(value) != 'fx:css:value') value = this.parse(value);
		var returned = [];
		value.each(function(bit){
			returned = returned.concat(bit.parser.serve(bit.value, unit));
		});
		return returned;
	},

	//renders the change to an element

	render: function(element, property, value, unit){
		element.setStyle(property, this.serve(value, unit));
	},

	//searches inside the page css to find the values for a selector

	search: function(selector){
		if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector];
		var to = {};
		Array.each(document.styleSheets, function(sheet, j){
			var href = sheet.href;
			if (href && href.contains('://') && !href.contains(document.domain)) return;
			var rules = sheet.rules || sheet.cssRules;
			Array.each(rules, function(rule, i){
				if (!rule.style) return;
				var selectorText = (rule.selectorText) ? rule.selectorText.replace(/^\w+/, function(m){
					return m.toLowerCase();
				}) : null;
				if (!selectorText || !selectorText.test('^' + selector + '$')) return;
				Element.Styles.each(function(value, style){
					if (!rule.style[style] || Element.ShortStyles[style]) return;
					value = String(rule.style[style]);
					to[style] = (value.test(/^rgb/)) ? value.rgbToHex() : value;
				});
			});
		});
		return Fx.CSS.Cache[selector] = to;
	}

});

Fx.CSS.Cache = {};

Fx.CSS.Parsers = new Hash({

	Color: {
		parse: function(value){
			if (value.match(/^#[0-9a-f]{3,6}$/i)) return value.hexToRgb(true);
			return ((value = value.match(/(\d+),\s*(\d+),\s*(\d+)/))) ? [value[1], value[2], value[3]] : false;
		},
		compute: function(from, to, delta){
			return from.map(function(value, i){
				return Math.round(Fx.compute(from[i], to[i], delta));
			});
		},
		serve: function(value){
			return value.map(Number);
		}
	},

	Number: {
		parse: parseFloat,
		compute: Fx.compute,
		serve: function(value, unit){
			return (unit) ? value + unit : value;
		}
	},

	String: {
		parse: $lambda(false),
		compute: $arguments(1),
		serve: $arguments(0)
	}

});


/*
Script: Fx.Tween.js
	Formerly Fx.Style, effect to transition any CSS property for an element.

License:
	MIT-style license.
*/

Fx.Tween = new Class({

	Extends: Fx.CSS,

	initialize: function(element, options){
		this.element = this.subject = $(element);
		this.parent(options);
	},

	set: function(property, now){
		if (arguments.length == 1){
			now = property;
			property = this.property || this.options.property;
		}
		this.render(this.element, property, now, this.options.unit);
		return this;
	},

	start: function(property, from, to){
		if (!this.check(arguments.callee, property, from, to)) return this;
		var args = Array.flatten(arguments);
		this.property = this.options.property || args.shift();
		var parsed = this.prepare(this.element, this.property, args);
		return this.parent(parsed.from, parsed.to);
	}

});

Element.Properties.tween = {

	set: function(options){
		var tween = this.retrieve('tween');
		if (tween) tween.cancel();
		return this.eliminate('tween').store('tween:options', $extend({link: 'cancel'}, options));
	},

	get: function(options){
		if (options || !this.retrieve('tween')){
			if (options || !this.retrieve('tween:options')) this.set('tween', options);
			this.store('tween', new Fx.Tween(this, this.retrieve('tween:options')));
		}
		return this.retrieve('tween');
	}

};

Element.implement({

	tween: function(property, from, to){
		this.get('tween').start(arguments);
		return this;
	},

	fade: function(how){
		var fade = this.get('tween'), o = 'opacity', toggle;
		how = $pick(how, 'toggle');
		switch (how){
			case 'in': fade.start(o, 1); break;
			case 'out': fade.start(o, 0); break;
			case 'show': fade.set(o, 1); break;
			case 'hide': fade.set(o, 0); break;
			case 'toggle':
				var flag = this.retrieve('fade:flag', this.get('opacity') == 1);
				fade.start(o, (flag) ? 0 : 1);
				this.store('fade:flag', !flag);
				toggle = true;
			break;
			default: fade.start(o, arguments);
		}
		if (!toggle) this.eliminate('fade:flag');
		return this;
	},

	highlight: function(start, end){
		if (!end){
			end = this.retrieve('highlight:original', this.getStyle('background-color'));
			end = (end == 'transparent') ? '#fff' : end;
		}
		var tween = this.get('tween');
		tween.start('background-color', start || '#ffff88', end).chain(function(){
			this.setStyle('background-color', this.retrieve('highlight:original'));
			tween.callChain();
		}.bind(this));
		return this;
	}

});


/*
Script: Fx.Morph.js
	Formerly Fx.Styles, effect to transition any number of CSS properties for an element using an object of rules, or CSS based selector rules.

License:
	MIT-style license.
*/

Fx.Morph = new Class({

	Extends: Fx.CSS,

	initialize: function(element, options){
		this.element = this.subject = $(element);
		this.parent(options);
	},

	set: function(now){
		if (typeof now == 'string') now = this.search(now);
		for (var p in now) this.render(this.element, p, now[p], this.options.unit);
		return this;
	},

	compute: function(from, to, delta){
		var now = {};
		for (var p in from) now[p] = this.parent(from[p], to[p], delta);
		return now;
	},

	start: function(properties){
		if (!this.check(arguments.callee, properties)) return this;
		if (typeof properties == 'string') properties = this.search(properties);
		var from = {}, to = {};
		for (var p in properties){
			var parsed = this.prepare(this.element, p, properties[p]);
			from[p] = parsed.from;
			to[p] = parsed.to;
		}
		return this.parent(from, to);
	}

});

Element.Properties.morph = {

	set: function(options){
		var morph = this.retrieve('morph');
		if (morph) morph.cancel();
		return this.eliminate('morph').store('morph:options', $extend({link: 'cancel'}, options));
	},

	get: function(options){
		if (options || !this.retrieve('morph')){
			if (options || !this.retrieve('morph:options')) this.set('morph', options);
			this.store('morph', new Fx.Morph(this, this.retrieve('morph:options')));
		}
		return this.retrieve('morph');
	}

};

Element.implement({

	morph: function(props){
		this.get('morph').start(props);
		return this;
	}

});


/*
Script: Fx.Transitions.js
	Contains a set of advanced transitions to be used with any of the Fx Classes.

License:
	MIT-style license.

Credits:
	Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>, modified and optimized to be used with MooTools.
*/

Fx.implement({

	getTransition: function(){
		var trans = this.options.transition || Fx.Transitions.Sine.easeInOut;
		if (typeof trans == 'string'){
			var data = trans.split(':');
			trans = Fx.Transitions;
			trans = trans[data[0]] || trans[data[0].capitalize()];
			if (data[1]) trans = trans['ease' + data[1].capitalize() + (data[2] ? data[2].capitalize() : '')];
		}
		return trans;
	}

});

Fx.Transition = function(transition, params){
	params = $splat(params);
	return $extend(transition, {
		easeIn: function(pos){
			return transition(pos, params);
		},
		easeOut: function(pos){
			return 1 - transition(1 - pos, params);
		},
		easeInOut: function(pos){
			return (pos <= 0.5) ? transition(2 * pos, params) / 2 : (2 - transition(2 * (1 - pos), params)) / 2;
		}
	});
};

Fx.Transitions = new Hash({

	linear: $arguments(0)

});

Fx.Transitions.extend = function(transitions){
	for (var transition in transitions) Fx.Transitions[transition] = new Fx.Transition(transitions[transition]);
};

Fx.Transitions.extend({

	Pow: function(p, x){
		return Math.pow(p, x[0] || 6);
	},

	Expo: function(p){
		return Math.pow(2, 8 * (p - 1));
	},

	Circ: function(p){
		return 1 - Math.sin(Math.acos(p));
	},

	Sine: function(p){
		return 1 - Math.sin((1 - p) * Math.PI / 2);
	},

	Back: function(p, x){
		x = x[0] || 1.618;
		return Math.pow(p, 2) * ((x + 1) * p - x);
	},

	Bounce: function(p){
		var value;
		for (var a = 0, b = 1; 1; a += b, b /= 2){
			if (p >= (7 - 4 * a) / 11){
				value = b * b - Math.pow((11 - 6 * a - 11 * p) / 4, 2);
				break;
			}
		}
		return value;
	},

	Elastic: function(p, x){
		return Math.pow(2, 10 * --p) * Math.cos(20 * p * Math.PI * (x[0] || 1) / 3);
	}

});

['Quad', 'Cubic', 'Quart', 'Quint'].each(function(transition, i){
	Fx.Transitions[transition] = new Fx.Transition(function(p){
		return Math.pow(p, [i + 2]);
	});
});


/*
Script: Request.js
	Powerful all purpose Request Class. Uses XMLHTTPRequest.

License:
	MIT-style license.
*/

var Request = new Class({

	Implements: [Chain, Events, Options],

	options: {/*
		onRequest: $empty,
		onComplete: $empty,
		onCancel: $empty,
		onSuccess: $empty,
		onFailure: $empty,
		onException: $empty,*/
		url: '',
		data: '',
		headers: {
			'X-Requested-With': 'XMLHttpRequest',
			'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
		},
		async: true,
		format: false,
		method: 'post',
		link: 'ignore',
		isSuccess: null,
		emulation: true,
		urlEncoded: true,
		encoding: 'utf-8',
		evalScripts: false,
		evalResponse: false
	},

	initialize: function(options){
		this.xhr = new Browser.Request();
		this.setOptions(options);
		this.options.isSuccess = this.options.isSuccess || this.isSuccess;
		this.headers = new Hash(this.options.headers);
	},

	onStateChange: function(){
		if (this.xhr.readyState != 4 || !this.running) return;
		this.running = false;
		this.status = 0;
		$try(function(){
			this.status = this.xhr.status;
		}.bind(this));
		if (this.options.isSuccess.call(this, this.status)){
			this.response = {text: this.xhr.responseText, xml: this.xhr.responseXML};
			this.success(this.response.text, this.response.xml);
		} else {
			this.response = {text: null, xml: null};
			this.failure();
		}
		this.xhr.onreadystatechange = $empty;
	},

	isSuccess: function(){
		return ((this.status >= 200) && (this.status < 300));
	},

	processScripts: function(text){
		if (this.options.evalResponse || (/(ecma|java)script/).test(this.getHeader('Content-type'))) return $exec(text);
		return text.stripScripts(this.options.evalScripts);
	},

	success: function(text, xml){
		this.onSuccess(this.processScripts(text), xml);
	},

	onSuccess: function(){
		this.fireEvent('complete', arguments).fireEvent('success', arguments).callChain();
	},

	failure: function(){
		this.onFailure();
	},

	onFailure: function(){
		this.fireEvent('complete').fireEvent('failure', this.xhr);
	},

	setHeader: function(name, value){
		this.headers.set(name, value);
		return this;
	},

	getHeader: function(name){
		return $try(function(){
			return this.xhr.getResponseHeader(name);
		}.bind(this));
	},

	check: function(caller){
		if (!this.running) return true;
		switch (this.options.link){
			case 'cancel': this.cancel(); return true;
			case 'chain': this.chain(caller.bind(this, Array.slice(arguments, 1))); return false;
		}
		return false;
	},

	send: function(options){
		if (!this.check(arguments.callee, options)) return this;
		this.running = true;

		var type = $type(options);
		if (type == 'string' || type == 'element') options = {data: options};

		var old = this.options;
		options = $extend({data: old.data, url: old.url, method: old.method}, options);
		var data = options.data, url = options.url, method = options.method;

		switch ($type(data)){
			case 'element': data = $(data).toQueryString(); break;
			case 'object': case 'hash': data = Hash.toQueryString(data);
		}

		if (this.options.format){
			var format = 'format=' + this.options.format;
			data = (data) ? format + '&' + data : format;
		}

		if (this.options.emulation && ['put', 'delete'].contains(method)){
			var _method = '_method=' + method;
			data = (data) ? _method + '&' + data : _method;
			method = 'post';
		}

		if (this.options.urlEncoded && method == 'post'){
			var encoding = (this.options.encoding) ? '; charset=' + this.options.encoding : '';
			this.headers.set('Content-type', 'application/x-www-form-urlencoded' + encoding);
		}

		if (data && method == 'get'){
			url = url + (url.contains('?') ? '&' : '?') + data;
			data = null;
		}

		this.xhr.open(method.toUpperCase(), url, this.options.async);

		this.xhr.onreadystatechange = this.onStateChange.bind(this);

		this.headers.each(function(value, key){
			try {
				this.xhr.setRequestHeader(key, value);
			} catch (e){
				this.fireEvent('exception', [key, value]);
			}
		}, this);

		this.fireEvent('request');
		this.xhr.send(data);
		if (!this.options.async) this.onStateChange();
		return this;
	},

	cancel: function(){
		if (!this.running) return this;
		this.running = false;
		this.xhr.abort();
		this.xhr.onreadystatechange = $empty;
		this.xhr = new Browser.Request();
		this.fireEvent('cancel');
		return this;
	}

});

(function(){

var methods = {};
['get', 'post', 'put', 'delete', 'GET', 'POST', 'PUT', 'DELETE'].each(function(method){
	methods[method] = function(){
		var params = Array.link(arguments, {url: String.type, data: $defined});
		return this.send($extend(params, {method: method.toLowerCase()}));
	};
});

Request.implement(methods);

})();

Element.Properties.send = {

	set: function(options){
		var send = this.retrieve('send');
		if (send) send.cancel();
		return this.eliminate('send').store('send:options', $extend({
			data: this, link: 'cancel', method: this.get('method') || 'post', url: this.get('action')
		}, options));
	},

	get: function(options){
		if (options || !this.retrieve('send')){
			if (options || !this.retrieve('send:options')) this.set('send', options);
			this.store('send', new Request(this.retrieve('send:options')));
		}
		return this.retrieve('send');
	}

};

Element.implement({

	send: function(url){
		var sender = this.get('send');
		sender.send({data: this, url: url || sender.options.url});
		return this;
	}

});


/*
Script: Request.HTML.js
	Extends the basic Request Class with additional methods for interacting with HTML responses.

License:
	MIT-style license.
*/

Request.HTML = new Class({

	Extends: Request,

	options: {
		update: false,
		evalScripts: true,
		filter: false
	},

	processHTML: function(text){
		var match = text.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
		text = (match) ? match[1] : text;

		var container = new Element('div');

		return $try(function(){
			var root = '<root>' + text + '</root>', doc;
			if (Browser.Engine.trident){
				doc = new ActiveXObject('Microsoft.XMLDOM');
				doc.async = false;
				doc.loadXML(root);
			} else {
				doc = new DOMParser().parseFromString(root, 'text/xml');
			}
			root = doc.getElementsByTagName('root')[0];
			for (var i = 0, k = root.childNodes.length; i < k; i++){
				var child = Element.clone(root.childNodes[i], true, true);
				if (child) container.grab(child);
			}
			return container;
		}) || container.set('html', text);
	},

	success: function(text){
		var options = this.options, response = this.response;

		response.html = text.stripScripts(function(script){
			response.javascript = script;
		});

		var temp = this.processHTML(response.html);

		response.tree = temp.childNodes;
		response.elements = temp.getElements('*');

		if (options.filter) response.tree = response.elements.filter(options.filter);
		if (options.update) $(options.update).empty().set('html', response.html);
		if (options.evalScripts) $exec(response.javascript);

		this.onSuccess(response.tree, response.elements, response.html, response.javascript);
	}

});

Element.Properties.load = {

	set: function(options){
		var load = this.retrieve('load');
		if (load) load.cancel();
		return this.eliminate('load').store('load:options', $extend({data: this, link: 'cancel', update: this, method: 'get'}, options));
	},

	get: function(options){
		if (options || ! this.retrieve('load')){
			if (options || !this.retrieve('load:options')) this.set('load', options);
			this.store('load', new Request.HTML(this.retrieve('load:options')));
		}
		return this.retrieve('load');
	}

};

Element.implement({

	load: function(){
		this.get('load').send(Array.link(arguments, {data: Object.type, url: String.type}));
		return this;
	}

});


/*
Script: Request.JSON.js
	Extends the basic Request Class with additional methods for sending and receiving JSON data.

License:
	MIT-style license.
*/

Request.JSON = new Class({

	Extends: Request,

	options: {
		secure: true
	},

	initialize: function(options){
		this.parent(options);
		this.headers.extend({'Accept': 'application/json', 'X-Request': 'JSON'});
	},

	success: function(text){
		this.response.json = JSON.decode(text, this.options.secure);
		this.onSuccess(this.response.json, text);
	}

});
//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2008 Valerio Proietti, <http://mad4milk.net>, MIT Style License.

/*
Script: Fx.Slide.js
	Effect to slide an element in and out of view.

License:
	MIT-style license.
*/

Fx.Slide = new Class({

	Extends: Fx,

	options: {
		mode: 'vertical'
	},

	initialize: function(element, options){
		this.addEvent('complete', function(){
			this.open = (this.wrapper['offset' + this.layout.capitalize()] != 0);
			if (this.open && Browser.Engine.webkit419) this.element.dispose().inject(this.wrapper);
		}, true);
		this.element = this.subject = $(element);
		this.parent(options);
		var wrapper = this.element.retrieve('wrapper');
		this.wrapper = wrapper || new Element('div', {
			styles: $extend(this.element.getStyles('margin', 'position'), {'overflow': 'hidden'})
		}).wraps(this.element);
		this.element.store('wrapper', this.wrapper).setStyle('margin', 0);
		this.now = [];
		this.open = true;
	},

	vertical: function(){
		this.margin = 'margin-top';
		this.layout = 'height';
		this.offset = this.element.offsetHeight;
	},

	horizontal: function(){
		this.margin = 'margin-left';
		this.layout = 'width';
		this.offset = this.element.offsetWidth;
	},

	set: function(now){
		this.element.setStyle(this.margin, now[0]);
		this.wrapper.setStyle(this.layout, now[1]);
		return this;
	},

	compute: function(from, to, delta){
		var now = [];
		var x = 2;
		x.times(function(i){
			now[i] = Fx.compute(from[i], to[i], delta);
		});
		return now;
	},

	start: function(how, mode){
		if (!this.check(arguments.callee, how, mode)) return this;
		this[mode || this.options.mode]();
		var margin = this.element.getStyle(this.margin).toInt();
		var layout = this.wrapper.getStyle(this.layout).toInt();
		var caseIn = [[margin, layout], [0, this.offset]];
		var caseOut = [[margin, layout], [-this.offset, 0]];
		var start;
		switch (how){
			case 'in': start = caseIn; break;
			case 'out': start = caseOut; break;
			case 'toggle': start = (this.wrapper['offset' + this.layout.capitalize()] == 0) ? caseIn : caseOut;
		}
		return this.parent(start[0], start[1]);
	},

	slideIn: function(mode){
		return this.start('in', mode);
	},

	slideOut: function(mode){
		return this.start('out', mode);
	},

	hide: function(mode){
		this[mode || this.options.mode]();
		this.open = false;
		return this.set([-this.offset, 0]);
	},

	show: function(mode){
		this[mode || this.options.mode]();
		this.open = true;
		return this.set([0, this.offset]);
	},

	toggle: function(mode){
		return this.start('toggle', mode);
	}

});

Element.Properties.slide = {

	set: function(options){
		var slide = this.retrieve('slide');
		if (slide) slide.cancel();
		return this.eliminate('slide').store('slide:options', $extend({link: 'cancel'}, options));
	},
	
	get: function(options){
		if (options || !this.retrieve('slide')){
			if (options || !this.retrieve('slide:options')) this.set('slide', options);
			this.store('slide', new Fx.Slide(this, this.retrieve('slide:options')));
		}
		return this.retrieve('slide');
	}

};

Element.implement({

	slide: function(how, mode){
		how = how || 'toggle';
		var slide = this.get('slide'), toggle;
		switch (how){
			case 'hide': slide.hide(mode); break;
			case 'show': slide.show(mode); break;
			case 'toggle':
				var flag = this.retrieve('slide:flag', slide.open);
				slide[(flag) ? 'slideOut' : 'slideIn'](mode);
				this.store('slide:flag', !flag);
				toggle = true;
			break;
			default: slide.start(how, mode);
		}
		if (!toggle) this.eliminate('slide:flag');
		return this;
	}

});


/*
Script: Fx.Scroll.js
	Effect to smoothly scroll any element, including the window.

License:
	MIT-style license.
*/

Fx.Scroll = new Class({

	Extends: Fx,

	options: {
		offset: {'x': 0, 'y': 0},
		wheelStops: true
	},

	initialize: function(element, options){
		this.element = this.subject = $(element);
		this.parent(options);
		var cancel = this.cancel.bind(this, false);

		if ($type(this.element) != 'element') this.element = $(this.element.getDocument().body);

		var stopper = this.element;

		if (this.options.wheelStops){
			this.addEvent('start', function(){
				stopper.addEvent('mousewheel', cancel);
			}, true);
			this.addEvent('complete', function(){
				stopper.removeEvent('mousewheel', cancel);
			}, true);
		}
	},

	set: function(){
		var now = Array.flatten(arguments);
		this.element.scrollTo(now[0], now[1]);
	},

	compute: function(from, to, delta){
		var now = [];
		var x = 2;
		x.times(function(i){
			now.push(Fx.compute(from[i], to[i], delta));
		});
		return now;
	},

	start: function(x, y){
		if (!this.check(arguments.callee, x, y)) return this;
		var offsetSize = this.element.getSize(), scrollSize = this.element.getScrollSize();
		var scroll = this.element.getScroll(), values = {x: x, y: y};
		for (var z in values){
			var max = scrollSize[z] - offsetSize[z];
			if ($chk(values[z])) values[z] = ($type(values[z]) == 'number') ? values[z].limit(0, max) : max;
			else values[z] = scroll[z];
			values[z] += this.options.offset[z];
		}
		return this.parent([scroll.x, scroll.y], [values.x, values.y]);
	},

	toTop: function(){
		return this.start(false, 0);
	},

	toLeft: function(){
		return this.start(0, false);
	},

	toRight: function(){
		return this.start('right', false);
	},

	toBottom: function(){
		return this.start(false, 'bottom');
	},

	toElement: function(el){
		var position = $(el).getPosition(this.element);
		return this.start(position.x, position.y);
	}

});


/*
Script: Fx.Elements.js
	Effect to change any number of CSS properties of any number of Elements.

License:
	MIT-style license.
*/

Fx.Elements = new Class({

	Extends: Fx.CSS,

	initialize: function(elements, options){
		this.elements = this.subject = $$(elements);
		this.parent(options);
	},

	compute: function(from, to, delta){
		var now = {};
		for (var i in from){
			var iFrom = from[i], iTo = to[i], iNow = now[i] = {};
			for (var p in iFrom) iNow[p] = this.parent(iFrom[p], iTo[p], delta);
		}
		return now;
	},

	set: function(now){
		for (var i in now){
			var iNow = now[i];
			for (var p in iNow) this.render(this.elements[i], p, iNow[p], this.options.unit);
		}
		return this;
	},

	start: function(obj){
		if (!this.check(arguments.callee, obj)) return this;
		var from = {}, to = {};
		for (var i in obj){
			var iProps = obj[i], iFrom = from[i] = {}, iTo = to[i] = {};
			for (var p in iProps){
				var parsed = this.prepare(this.elements[i], p, iProps[p]);
				iFrom[p] = parsed.from;
				iTo[p] = parsed.to;
			}
		}
		return this.parent(from, to);
	}

});

/*
Script: Drag.js
  The base Drag Class. Can be used to drag and resize Elements using mouse events.
 
License:
  MIT-style license.
*/
 
var Drag = new Class({
 
  Implements: [Events, Options],
 
  options: {/*
    onBeforeStart: $empty,
    onStart: $empty,
    onDrag: $empty,
    onCancel: $empty,
    onComplete: $empty,*/
    snap: 6,
    unit: 'px',
    grid: false,
    style: true,
    limit: false,
    handle: false,
    invert: false,
    preventDefault: false,
    modifiers: {x: 'left', y: 'top'}
  },
 
  initialize: function(){
    var params = Array.link(arguments, {'options': Object.type, 'element': $defined});
    this.element = $(params.element);
    this.document = this.element.getDocument();
    this.setOptions(params.options || {});
    var htype = $type(this.options.handle);
    this.handles = (htype == 'array' || htype == 'collection') ? $$(this.options.handle) : $(this.options.handle) || this.element;
    this.mouse = {'now': {}, 'pos': {}};
    this.value = {'start': {}, 'now': {}};
 
    this.selection = (Browser.Engine.trident) ? 'selectstart' : 'mousedown';
 
    this.bound = {
      start: this.start.bind(this),
      check: this.check.bind(this),
      drag: this.drag.bind(this),
      stop: this.stop.bind(this),
      cancel: this.cancel.bind(this),
      eventStop: $lambda(false)
    };
    this.attach();
  },
 
  attach: function(){
    this.handles.addEvent('mousedown', this.bound.start);
    return this;
  },
 
  detach: function(){
    this.handles.removeEvent('mousedown', this.bound.start);
    return this;
  },
 
  start: function(event){
    if (this.options.preventDefault) event.preventDefault();
    this.mouse.start = event.page;
    this.fireEvent('beforeStart', this.element);
    var limit = this.options.limit;
    this.limit = {'x': [], 'y': []};
    for (var z in this.options.modifiers){
      if (!this.options.modifiers[z]) continue;
      if (this.options.style) this.value.now[z] = this.element.getStyle(this.options.modifiers[z]).toInt();
      else this.value.now[z] = this.element[this.options.modifiers[z]];
      if (this.options.invert) this.value.now[z] *= -1;
      this.mouse.pos[z] = event.page[z] - this.value.now[z];
      if (limit && limit[z]){
        for (var i = 2; i--; i){
          if ($chk(limit[z][i])) this.limit[z][i] = $lambda(limit[z][i])();
        }
      }
    }
    if ($type(this.options.grid) == 'number') this.options.grid = {'x': this.options.grid, 'y': this.options.grid};
    this.document.addEvents({mousemove: this.bound.check, mouseup: this.bound.cancel});
    this.document.addEvent(this.selection, this.bound.eventStop);
  },
 
  check: function(event){
    if (this.options.preventDefault) event.preventDefault();
    var distance = Math.round(Math.sqrt(Math.pow(event.page.x - this.mouse.start.x, 2) + Math.pow(event.page.y - this.mouse.start.y, 2)));
    if (distance > this.options.snap){
      this.cancel();
      this.document.addEvents({
        mousemove: this.bound.drag,
        mouseup: this.bound.stop
      });
      this.fireEvent('start', this.element).fireEvent('snap', this.element);
    }
	event.preventDefault();
  },
 
  drag: function(event){
    if (this.options.preventDefault) event.preventDefault();
    this.mouse.now = event.page;
    for (var z in this.options.modifiers){
      if (!this.options.modifiers[z]) continue;
      this.value.now[z] = this.mouse.now[z] - this.mouse.pos[z];
      if (this.options.invert) this.value.now[z] *= -1;
      if (this.options.limit && this.limit[z]){
        if ($chk(this.limit[z][1]) && (this.value.now[z] > this.limit[z][1])){
          this.value.now[z] = this.limit[z][1];
        } else if ($chk(this.limit[z][0]) && (this.value.now[z] < this.limit[z][0])){
          this.value.now[z] = this.limit[z][0];
        }
      }
      if (this.options.grid[z]) this.value.now[z] -= (this.value.now[z] % this.options.grid[z]);
      if (this.options.style) this.element.setStyle(this.options.modifiers[z], this.value.now[z] + this.options.unit);
      else this.element[this.options.modifiers[z]] = this.value.now[z];
    }
    this.fireEvent('drag', this.element);
	event.preventDefault();
  },
 
  cancel: function(event){
    this.document.removeEvent('mousemove', this.bound.check);
    this.document.removeEvent('mouseup', this.bound.cancel);
    if (event){
      this.document.removeEvent(this.selection, this.bound.eventStop);
      this.fireEvent('cancel', this.element);
    }
  },
 
  stop: function(event){
    this.document.removeEvent(this.selection, this.bound.eventStop);
    this.document.removeEvent('mousemove', this.bound.drag);
    this.document.removeEvent('mouseup', this.bound.stop);
    if (event) this.fireEvent('complete', this.element);
  }
 
});
 
Element.implement({
 
  makeResizable: function(options){
    return new Drag(this, $merge({modifiers: {'x': 'width', 'y': 'height'}}, options));
  }
 
});

/*
Script: Drag.Move.js
  A Drag extension that provides support for the constraining of draggables to containers and droppables.
 
License:
  MIT-style license.
*/
 
Drag.Move = new Class({
 
  Extends: Drag,
 
  options: {/*
    onEnter: $empty,
    onLeave: $empty,
    onDrop: $empty,*/
    droppables: [],
    container: false
  },
 
  initialize: function(element, options){
    this.parent(element, options);
    this.droppables = $$(this.options.droppables);
    this.container = $(this.options.container);
    if (this.container && $type(this.container) != 'element') this.container = $(this.container.getDocument().body);
    element = this.element;
 
    var current = element.getStyle('position');
    var position = (current != 'static') ? current : 'absolute';
    if (element.getStyle('left') == 'auto' || element.getStyle('top') == 'auto') element.position(element.getPosition(element.offsetParent));
    element.setStyle('position', position);
 
    this.addEvent('start', this.checkDroppables, true);
 
    this.overed = null;
  },
 
  start: function(event){
    if (this.container){
      var el = this.element, cont = this.container, ccoo = cont.getCoordinates(el.offsetParent), cps = {}, ems = {};
 
      ['top', 'right', 'bottom', 'left'].each(function(pad){
        cps[pad] = cont.getStyle('padding-' + pad).toInt();
        ems[pad] = el.getStyle('margin-' + pad).toInt();
      }, this);
 
      var width = el.offsetWidth + ems.left + ems.right, height = el.offsetHeight + ems.top + ems.bottom;
      var x = [ccoo.left + cps.left, ccoo.right - cps.right - width];
      var y = [ccoo.top + cps.top, ccoo.bottom - cps.bottom - height];
 
      this.options.limit = {x: x, y: y};
    }
    this.parent(event);
  },
 
  checkAgainst: function(el){
    el = el.getCoordinates();
    var now = this.mouse.now;
    return (now.x > el.left && now.x < el.right && now.y < el.bottom && now.y > el.top);
  },
 
  checkDroppables: function(){
    var overed = this.droppables.filter(this.checkAgainst, this).getLast();
    if (this.overed != overed){
      if (this.overed) this.fireEvent('leave', [this.element, this.overed]);
      if (overed) this.fireEvent('enter', [this.element, overed]);
      this.overed = overed;
    }
  },
 
  drag: function(event){
    this.parent(event);
    if (this.droppables.length) this.checkDroppables();
  },
 
  stop: function(event){
    this.checkDroppables();
    this.fireEvent('drop', [this.element, this.overed]);
    this.overed = null;
    return this.parent(event);
  }
 
});
 
Element.implement({
 
  makeDraggable: function(options){
    return new Drag.Move(this, options);
  }
 
});


/*
Script: Hash.Cookie.js
	Class for creating, reading, and deleting Cookies in JSON format.

License:
	MIT-style license.
*/

Hash.Cookie = new Class({

	Extends: Cookie,

	options: {
		autoSave: true
	},

	initialize: function(name, options){
		this.parent(name, options);
		this.load();
	},

	save: function(){
		var value = JSON.encode(this.hash);
		if (!value || value.length > 4096) return false; //cookie would be truncated!
		if (value == '{}') this.dispose();
		else this.write(value);
		return true;
	},

	load: function(){
		this.hash = new Hash(JSON.decode(this.read(), true));
		return this;
	}

});

Hash.Cookie.implement((function(){
	
	var methods = {};
	
	Hash.each(Hash.prototype, function(method, name){
		methods[name] = function(){
			var value = method.apply(this.hash, arguments);
			if (this.options.autoSave) this.save();
			return value;
		};
	});
	
	return methods;
	
})());

/*
Script: Color.js
	Class for creating and manipulating colors in JavaScript. Supports HSB -> RGB Conversions and vice versa.

License:
	MIT-style license.
*/

var Color = new Native({
  
	initialize: function(color, type){
		if (arguments.length >= 3){
			type = "rgb"; color = Array.slice(arguments, 0, 3);
		} else if (typeof color == 'string'){
			if (color.match(/rgb/)) color = color.rgbToHex().hexToRgb(true);
			else if (color.match(/hsb/)) color = color.hsbToRgb();
			else color = color.hexToRgb(true);
		}
		type = type || 'rgb';
		switch (type){
			case 'hsb':
				var old = color;
				color = color.hsbToRgb();
				color.hsb = old;
			break;
			case 'hex': color = color.hexToRgb(true); break;
		}
		color.rgb = color.slice(0, 3);
		color.hsb = color.hsb || color.rgbToHsb();
		color.hex = color.rgbToHex();
		return $extend(color, this);
	}

});

Color.implement({

	mix: function(){
		var colors = Array.slice(arguments);
		var alpha = ($type(colors.getLast()) == 'number') ? colors.pop() : 50;
		var rgb = this.slice();
		colors.each(function(color){
			color = new Color(color);
			for (var i = 0; i < 3; i++) rgb[i] = Math.round((rgb[i] / 100 * (100 - alpha)) + (color[i] / 100 * alpha));
		});
		return new Color(rgb, 'rgb');
	},

	invert: function(){
		return new Color(this.map(function(value){
			return 255 - value;
		}));
	},

	setHue: function(value){
		return new Color([value, this.hsb[1], this.hsb[2]], 'hsb');
	},

	setSaturation: function(percent){
		return new Color([this.hsb[0], percent, this.hsb[2]], 'hsb');
	},

	setBrightness: function(percent){
		return new Color([this.hsb[0], this.hsb[1], percent], 'hsb');
	}

});

function $RGB(r, g, b){
	return new Color([r, g, b], 'rgb');
};

function $HSB(h, s, b){
	return new Color([h, s, b], 'hsb');
};

function $HEX(hex){
	return new Color(hex, 'hex');
};

Array.implement({

	rgbToHsb: function(){
		var red = this[0], green = this[1], blue = this[2];
		var hue, saturation, brightness;
		var max = Math.max(red, green, blue), min = Math.min(red, green, blue);
		var delta = max - min;
		brightness = max / 255;
		saturation = (max != 0) ? delta / max : 0;
		if (saturation == 0){
			hue = 0;
		} else {
			var rr = (max - red) / delta;
			var gr = (max - green) / delta;
			var br = (max - blue) / delta;
			if (red == max) hue = br - gr;
			else if (green == max) hue = 2 + rr - br;
			else hue = 4 + gr - rr;
			hue /= 6;
			if (hue < 0) hue++;
		}
		return [Math.round(hue * 360), Math.round(saturation * 100), Math.round(brightness * 100)];
	},

	hsbToRgb: function(){
		var br = Math.round(this[2] / 100 * 255);
		if (this[1] == 0){
			return [br, br, br];
		} else {
			var hue = this[0] % 360;
			var f = hue % 60;
			var p = Math.round((this[2] * (100 - this[1])) / 10000 * 255);
			var q = Math.round((this[2] * (6000 - this[1] * f)) / 600000 * 255);
			var t = Math.round((this[2] * (6000 - this[1] * (60 - f))) / 600000 * 255);
			switch (Math.floor(hue / 60)){
				case 0: return [br, t, p];
				case 1: return [q, br, p];
				case 2: return [p, br, t];
				case 3: return [p, q, br];
				case 4: return [t, p, br];
				case 5: return [br, p, q];
			}
		}
		return false;
	}

});

String.implement({

	rgbToHsb: function(){
		var rgb = this.match(/\d{1,3}/g);
		return (rgb) ? hsb.rgbToHsb() : null;
	},
	
	hsbToRgb: function(){
		var hsb = this.match(/\d{1,3}/g);
		return (hsb) ? hsb.hsbToRgb() : null;
	}

});


/*
Script: Group.js
	Class for monitoring collections of events

License:
	MIT-style license.
*/

var Group = new Class({

	initialize: function(){
		this.instances = Array.flatten(arguments);
		this.events = {};
		this.checker = {};
	},

	addEvent: function(type, fn){
		this.checker[type] = this.checker[type] || {};
		this.events[type] = this.events[type] || [];
		if (this.events[type].contains(fn)) return false;
		else this.events[type].push(fn);
		this.instances.each(function(instance, i){
			instance.addEvent(type, this.check.bind(this, [type, instance, i]));
		}, this);
		return this;
	},

	check: function(type, instance, i){
		this.checker[type][i] = true;
		var every = this.instances.every(function(current, j){
			return this.checker[type][j] || false;
		}, this);
		if (!every) return;
		this.checker[type] = {};
		this.events[type].each(function(event){
			event.call(this, this.instances, instance);
		}, this);
	}

});


//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.

/*
---

script: More.js

description: MooTools More

license: MIT-style license

authors:
- Guillermo Rauch
- Thomas Aylott
- Scott Kyle

requires:
- core:1.2.4/MooTools

provides: [MooTools.More]

...
*/

MooTools.More = {
	'version': '1.2.4.4',
	'build': '6f6057dc645fdb7547689183b2311063bd653ddf'
};

/*
---

script: Assets.js

description: Provides methods to dynamically load JavaScript, CSS, and Image files into the document.

license: MIT-style license

authors:
- Valerio Proietti

requires:
- core:1.2.4/Element.Event
- /MooTools.More

provides: [Assets]

...
*/

var Asset = {

	javascript: function(source, properties){
		properties = $extend({
			onload: $empty,
			document: document,
			check: $lambda(true)
		}, properties);
		
		if (properties.onLoad) properties.onload = properties.onLoad;
		
		var script = new Element('script', {src: source, type: 'text/javascript'});

		var load = properties.onload.bind(script), 
			check = properties.check, 
			doc = properties.document;
		delete properties.onload;
		delete properties.check;
		delete properties.document;

		script.addEvents({
			load: load,
			readystatechange: function(){
				if (['loaded', 'complete'].contains(this.readyState)) load();
			}
		}).set(properties);

		if (Browser.Engine.webkit419) var checker = (function(){
			if (!$try(check)) return;
			$clear(checker);
			load();
		}).periodical(50);

		return script.inject(doc.head);
	},

	css: function(source, properties){
		return new Element('link', $merge({
			rel: 'stylesheet',
			media: 'screen',
			type: 'text/css',
			href: source
		}, properties)).inject(document.head);
	},

	image: function(source, properties){
		properties = $merge({
			'onload': $empty,
			'onabort': $empty,
			'onerror': $empty
		}, properties);
		var image = new Image();
		var element = $(image) || new Element('img');
		['load', 'abort', 'error'].each(function(name){
			var type = 'on' + name;
			var event = properties[type];
			delete properties[type];
			image[type] = function(){
				if (!image) return;
				if (!element.parentNode){
					element.width = image.width;
					element.height = image.height;
				}
				image = image.onload = image.onabort = image.onerror = null;
				event.delay(1, element, element);
				element.fireEvent(name, element, 1);
			};
		});
		image.src = element.src = source;
		if (image && image.complete) image.onload.delay(1);
		return element.setProperties(properties);
	},

	images: function(sources, options){
		options = $merge({
			onComplete: $empty,
			onProgress: $empty,
			onError: $empty,
			properties: {}
		}, options);
		sources = $splat(sources);
		var images = [];
		var counter = 0;
		return new Elements(sources.map(function(source){
			return Asset.image(source, $extend(options.properties, {
				onload: function(){
					options.onProgress.call(this, counter, sources.indexOf(source));
					counter++;
					if (counter == sources.length) options.onComplete();
				},
				onerror: function(){
					options.onError.call(this, counter, sources.indexOf(source));
					counter++;
					if (counter == sources.length) options.onComplete();
				}
			}));
		}));
	}

};




/*
Script: Sortables.js
	Class for creating a drag and drop sorting interface for lists of items.

License:
	MIT-style license.
*/

var Sortables = new Class({

	Implements: [Events, Options],

	options: {/*
		onSort: $empty,
		onStart: $empty,
		onComplete: $empty,*/
		snap: 4,
		opacity: 1,
		clone: false,
		revert: false,
		handle: false,
		constrain: false
	},

	initialize: function(lists, options){
		this.setOptions(options);
		this.elements = [];
		this.lists = [];
		this.idle = true;
		
		this.addLists($$($(lists) || lists));
		if (!this.options.clone) this.options.revert = false;
		if (this.options.revert) this.effect = new Fx.Morph(null, $merge({duration: 250, link: 'cancel'}, this.options.revert));
	},

	attach: function(){
		this.addLists(this.lists);
		return this;
	},

	detach: function(){
		this.lists = this.removeLists(this.lists);
		return this;
	},

	addItems: function(){
		Array.flatten(arguments).each(function(element){
			this.elements.push(element);
			var start = element.retrieve('sortables:start', this.start.bindWithEvent(this, element));
			(this.options.handle ? element.getElement(this.options.handle) || element : element).addEvent('mousedown', start);
		}, this);
		return this;
	},

	addLists: function(){
		Array.flatten(arguments).each(function(list){
			this.lists.push(list);
			this.addItems(list.getChildren());
		}, this);
		return this;
	},

	removeItems: function(){
		var elements = [];
		Array.flatten(arguments).each(function(element){
			elements.push(element);
			this.elements.erase(element);
			var start = element.retrieve('sortables:start');
			(this.options.handle ? element.getElement(this.options.handle) || element : element).removeEvent('mousedown', start);
		}, this);
		return $$(elements);
	},

	removeLists: function(){
		var lists = [];
		Array.flatten(arguments).each(function(list){
			lists.push(list);
			this.lists.erase(list);
			this.removeItems(list.getChildren());
		}, this);
		return $$(lists);
	},

	getClone: function(event, element){
		if (!this.options.clone) return new Element('div').inject(document.body);
		if ($type(this.options.clone) == 'function') return this.options.clone.call(this, event, element, this.list);
		return element.clone(true).setStyles({
			'margin': '0px',
			'position': 'absolute',
			'visibility': 'hidden',
			'width': element.getStyle('width')
		}).inject(this.list).position(element.getPosition(element.getOffsetParent()));
	},

	getDroppables: function(){
		var droppables = this.list.getChildren();
		if (!this.options.constrain) droppables = this.lists.concat(droppables).erase(this.list);
		return droppables.erase(this.clone).erase(this.element);
	},

	insert: function(dragging, element){
		var where = 'inside';
		if (this.lists.contains(element)){
			this.list = element;
			this.drag.droppables = this.getDroppables();
		} else {
			where = this.element.getAllPrevious().contains(element) ? 'before' : 'after';
		}
		this.element.inject(element, where);
		this.fireEvent('sort', [this.element, this.clone]);
	},

	start: function(event, element){
		if (!this.idle) return;
		this.idle = false;
		this.element = element;
		this.opacity = element.get('opacity');
		this.list = element.getParent();
		this.clone = this.getClone(event, element);
		
		this.drag = new Drag.Move(this.clone, {
			snap: this.options.snap,
			container: this.options.constrain && this.element.getParent(),
			droppables: this.getDroppables(),
			onSnap: function(){
				event.stop();
				this.clone.setStyle('visibility', 'visible');
				this.element.set('opacity', this.options.opacity || 0);
				this.fireEvent('start', [this.element, this.clone]);
			}.bind(this),
			onEnter: this.insert.bind(this),
			onCancel: this.reset.bind(this),
			onComplete: this.end.bind(this)
		});
		
		this.clone.inject(this.element, 'before');
		this.drag.start(event);
	},

	end: function(){
		this.drag.detach();
		this.element.set('opacity', this.opacity);
		if (this.effect){
			var dim = this.element.getStyles('width', 'height');
			var pos = this.clone.computePosition(this.element.getPosition(this.clone.offsetParent));
			this.effect.element = this.clone;
			this.effect.start({
				top: pos.top,
				left: pos.left,
				width: dim.width,
				height: dim.height,
				opacity: 0.25
			}).chain(this.reset.bind(this));
		} else {
			this.reset();
		}
	},

	reset: function(){
		this.idle = true;
		this.clone.destroy();
		this.fireEvent('complete', this.element);
	},

	serialize: function(){
		var params = Array.link(arguments, {modifier: Function.type, index: $defined});
		var serial = this.lists.map(function(list){
			return list.getChildren().map(params.modifier || function(element){
				return element.get('id');
			}, this);
		}, this);
		
		var index = params.index;
		if (this.lists.length == 1) index = 0;
		return $chk(index) && index >= 0 && index < this.lists.length ? serial[index] : serial;
	}

});

/*
Script: Tips.js
	Class for creating nice tips that follow the mouse cursor when hovering an element.

License:
	MIT-style license.
*/

var Tips = new Class({

	Implements: [Events, Options],

	options: {
		onShow: function(tip){
			tip.setStyle('visibility', 'visible');
		},
		onHide: function(tip){
			tip.setStyle('visibility', 'hidden');
		},
		showDelay: 100,
		hideDelay: 100,
		className: null,
		offsets: {x: 16, y: 16},
		fixed: false
	},

	initialize: function(){
		var params = Array.link(arguments, {options: Object.type, elements: $defined});
		this.setOptions(params.options || null);
		
		this.tip = new Element('div').inject(document.body);
		
		if (this.options.className) this.tip.addClass(this.options.className);
		
		var top = new Element('div', {'class': 'tip-top'}).inject(this.tip);
		this.container = new Element('div', {'class': 'tip'}).inject(this.tip);
		var bottom = new Element('div', {'class': 'tip-bottom'}).inject(this.tip);

		this.tip.setStyles({position: 'absolute', top: 0, left: 0, visibility: 'hidden'});
		
		if (params.elements) this.attach(params.elements);
	},
	
	attach: function(elements){
		$$(elements).each(function(element){
			var title = element.retrieve('tip:title', element.get('title'));
			var text = element.retrieve('tip:text', element.get('rel') || element.get('href'));
			var enter = element.retrieve('tip:enter', this.elementEnter.bindWithEvent(this, element));
			var leave = element.retrieve('tip:leave', this.elementLeave.bindWithEvent(this, element));
			element.addEvents({mouseenter: enter, mouseleave: leave});
			if (!this.options.fixed){
				var move = element.retrieve('tip:move', this.elementMove.bindWithEvent(this, element));
				element.addEvent('mousemove', move);
			}
			element.store('tip:native', element.get('title'));
			element.erase('title');
		}, this);
		return this;
	},
	
	detach: function(elements){
		$$(elements).each(function(element){
			element.removeEvent('mouseenter', element.retrieve('tip:enter') || $empty);
			element.removeEvent('mouseleave', element.retrieve('tip:leave') || $empty);
			element.removeEvent('mousemove', element.retrieve('tip:move') || $empty);
			element.eliminate('tip:enter').eliminate('tip:leave').eliminate('tip:move');
			var original = element.retrieve('tip:native');
			if (original) element.set('title', original);
		});
		return this;
	},
	
	elementEnter: function(event, element){
		
		$A(this.container.childNodes).each(Element.dispose);
		
		var title = element.retrieve('tip:title');
		
		if (title){
			this.titleElement = new Element('div', {'class': 'tip-title'}).inject(this.container);
			this.fill(this.titleElement, title);
		}
		
		var text = element.retrieve('tip:text');
		if (text){
			this.textElement = new Element('div', {'class': 'tip-text'}).inject(this.container);
			this.fill(this.textElement, text);
		}
		
		this.timer = $clear(this.timer);
		this.timer = this.show.delay(this.options.showDelay, this);

		this.position((!this.options.fixed) ? event : {page: element.getPosition()});
	},
	
	elementLeave: function(event){
		$clear(this.timer);
		this.timer = this.hide.delay(this.options.hideDelay, this);
	},
	
	elementMove: function(event){
		this.position(event);
	},
	
	position: function(event){
		var size = window.getSize(), scroll = window.getScroll();
		var tip = {x: this.tip.offsetWidth, y: this.tip.offsetHeight};
		var props = {x: 'left', y: 'top'};
		for (var z in props){
			var pos = event.page[z] + this.options.offsets[z];
			if ((pos + tip[z] - scroll[z]) > size[z]) pos = event.page[z] - this.options.offsets[z] - tip[z];
			this.tip.setStyle(props[z], pos);
		}
	},
	
	fill: function(element, contents){
		(typeof contents == 'string') ? element.set('html', contents) : element.adopt(contents);
	},

	show: function(){
		this.fireEvent('show', this.tip);
	},

	hide: function(){
		this.fireEvent('hide', this.tip);
	}

});

/*
Script: SmoothScroll.js
	Class for creating a smooth scrolling effect to all internal links on the page.

License:
	MIT-style license.
*/

var SmoothScroll = new Class({

	Extends: Fx.Scroll,

	initialize: function(options, context){
		context = context || document;
		var doc = context.getDocument(), win = context.getWindow();
		this.parent(doc, options);
		this.links = (this.options.links) ? $$(this.options.links) : $$(doc.links);
		var location = win.location.href.match(/^[^#]*/)[0] + '#';
		this.links.each(function(link){
			if (link.href.indexOf(location) != 0) return;
			var anchor = link.href.substr(location.length);
			if (anchor && $(anchor)) this.useLink(link, anchor);
		}, this);
		if (!Browser.Engine.webkit419) this.addEvent('complete', function(){
			win.location.hash = this.anchor;
		}, true);
	},

	useLink: function(link, anchor){
		link.addEvent('click', function(event){
			this.anchor = anchor;
			this.toElement(anchor);
			event.stop();
		}.bind(this));
	}

});

/*
Script: Slider.js
	Class for creating horizontal and vertical slider controls.

License:
	MIT-style license.
*/

var Slider = new Class({

	Implements: [Events, Options],

	options: {/*
		onChange: $empty,
		onComplete: $empty,*/
		onTick: function(position){
			if(this.options.snap) position = this.toPosition(this.step);
			this.knob.setStyle(this.property, position);
		},
		snap: false,
		offset: 0,
		range: false,
		wheel: false,
		steps: 100,
		mode: 'horizontal'
	},

	initialize: function(element, knob, options){
		this.setOptions(options);
		this.element = $(element);
		this.knob = $(knob);
		this.previousChange = this.previousEnd = this.step = -1;
		this.element.addEvent('mousedown', this.clickedElement.bind(this));
		if (this.options.wheel) this.element.addEvent('mousewheel', this.scrolledElement.bindWithEvent(this));
		var offset, limit = {}, modifiers = {'x': false, 'y': false};
		switch (this.options.mode){
			case 'vertical':
				this.axis = 'y';
				this.property = 'top';
				offset = 'offsetHeight';
				break;
			case 'horizontal':
				this.axis = 'x';
				this.property = 'left';
				offset = 'offsetWidth';
		}
		this.half = this.knob[offset] / 2;
		this.full = this.element[offset] - this.knob[offset] + (this.options.offset * 2);
		this.min = $chk(this.options.range[0]) ? this.options.range[0] : 0;
		this.max = $chk(this.options.range[1]) ? this.options.range[1] : this.options.steps;
		this.range = this.max - this.min;
		this.steps = this.options.steps || this.full;
		this.stepSize = Math.abs(this.range) / this.steps;
		this.stepWidth = this.stepSize * this.full / Math.abs(this.range) ;
		
		this.knob.setStyle('position', 'relative').setStyle(this.property, - this.options.offset);
		modifiers[this.axis] = this.property;
		limit[this.axis] = [- this.options.offset, this.full - this.options.offset];
		this.drag = new Drag(this.knob, {
			snap: 0,
			limit: limit,
			modifiers: modifiers,
			onDrag: this.draggedKnob.bind(this),
			onStart: this.draggedKnob.bind(this),
			onComplete: function(){
				this.draggedKnob();
				this.end();
			}.bind(this)
		});
		if (this.options.snap) {
			this.drag.options.grid = Math.ceil(this.stepWidth);
			this.drag.options.limit[this.axis][1] = this.full;
		}
	},

	set: function(step){
		
		if (!((this.range > 0) ^ (step < this.min))) step = this.min;
		if (!((this.range > 0) ^ (step > this.max))) step = this.max;
		this.step = Math.round(step);
		this.checkStep();
		//this.end();
		this.fireEvent('tick', this.toPosition(this.step));
		return this;
	},
	
	setRange: function(newRange,maxWidth,minWidth){
		this.range = newRange;
		this.max = maxWidth;
		this.min = minWidth;
		this.stepSize = Math.abs(this.range) / this.steps;
		this.stepWidth = this.stepSize * this.full / Math.abs(this.range) ;
		
	},

	clickedElement: function(event){
		var dir = this.range < 0 ? -1 : 1;
		var position = event.page[this.axis] - this.element.getPosition()[this.axis] - this.half;
		position = position.limit(-this.options.offset, this.full -this.options.offset);
		this.step = Math.round(this.min + dir * this.toStep(position));
		
		this.checkStep();
		this.end();
		this.fireEvent('tick', position);
	},
	
	scrolledElement: function(event){
		var mode = (this.options.mode == 'horizontal') ? (event.wheel < 0) : (event.wheel > 0);
		this.set(mode ? this.step - this.stepSize : this.step + this.stepSize);
		event.stop();
	},

	draggedKnob: function(){
		var dir = this.range < 0 ? -1 : 1;
		var position = this.drag.value.now[this.axis];
		position = position.limit(-this.options.offset, this.full -this.options.offset);
		this.step = Math.round(this.min + dir * this.toStep(position));
		this.checkStep();
	},

	checkStep: function(){
		if (this.previousChange != this.step){
			this.previousChange = this.step;
			this.fireEvent('change', this.step);
		}
	},

	end: function(){
		if (this.previousEnd !== this.step){
			this.previousEnd = this.step;
			this.fireEvent('complete', this.step + '');
		}
	},

	toStep: function(position){
		var step = (position + this.options.offset) * this.stepSize / this.full * this.steps;
		return this.options.steps ? Math.round(step -= step % this.stepSize) : step;
	},

	toPosition: function(step){
		return (this.full * Math.abs(this.min - step)) / (this.steps * this.stepSize) - this.options.offset;
	}

});

/*
Script: Scroller.js
	Class which scrolls the contents of any Element (including the window) when the mouse reaches the Element's boundaries.

License:
	MIT-style license.
*/

var Scroller = new Class({

	Implements: [Events, Options],

	options: {
		area: 20,
		velocity: 1,
		onChange: function(x, y){
			this.element.scrollTo(x, y);
		}
	},

	initialize: function(element, options){
		this.setOptions(options);
		this.element = $(element);
		this.listener = ($type(this.element) != 'element') ? $(this.element.getDocument().body) : this.element;
		this.timer = null;
		this.coord = this.getCoords.bind(this);
	},

	start: function(){
		this.listener.addEvent('mousemove', this.coord);
	},

	stop: function(){
		this.listener.removeEvent('mousemove', this.coord);
		this.timer = $clear(this.timer);
	},

	getCoords: function(event){
		this.page = (this.listener.get('tag') == 'body') ? event.client : event.page;
		if (!this.timer) this.timer = this.scroll.periodical(50, this);
	},

	scroll: function(){
		var size = this.element.getSize(), scroll = this.element.getScroll(), pos = this.element.getPosition(), change = {'x': 0, 'y': 0};
		for (var z in this.page){
			if (this.page[z] < (this.options.area + pos[z]) && scroll[z] != 0)
				change[z] = (this.page[z] - this.options.area - pos[z]) * this.options.velocity;
			else if (this.page[z] + this.options.area > (size[z] + pos[z]) && size[z] + size[z] != scroll[z])
				change[z] = (this.page[z] - size[z] + this.options.area - pos[z]) * this.options.velocity;
		}
		if (change.y || change.x) this.fireEvent('change', [scroll.x + change.x, scroll.y + change.y]);
	}

});

/*
Script: Accordion.js
	An Fx.Elements extension which allows you to easily create accordion type controls.

License:
	MIT-style license.
*/

var Accordion = new Class({

	Extends: Fx.Elements,

	options: {/*
		onActive: $empty,
		onBackground: $empty,*/
		display: 0,
		show: false,
		height: true,
		width: false,
		opacity: true,
		fixedHeight: false,
		fixedWidth: false,
		wait: false,
		alwaysHide: false
	},

	initialize: function(){
		var params = Array.link(arguments, {'container': Element.type, 'options': Object.type, 'togglers': $defined, 'elements': $defined});
		this.parent(params.elements, params.options);
		this.togglers = $$(params.togglers);
		this.container = $(params.container);
		this.previous = -1;
		if (this.options.alwaysHide) this.options.wait = true;
		if ($chk(this.options.show)){
			this.options.display = false;
			this.previous = this.options.show;
		}
		if (this.options.start){
			this.options.display = false;
			this.options.show = false;
		}
		this.effects = {};
		if (this.options.opacity) this.effects.opacity = 'fullOpacity';
		if (this.options.width) this.effects.width = this.options.fixedWidth ? 'fullWidth' : 'offsetWidth';
		if (this.options.height) this.effects.height = this.options.fixedHeight ? 'fullHeight' : 'scrollHeight';
		for (var i = 0, l = this.togglers.length; i < l; i++) this.addSection(this.togglers[i], this.elements[i]);
		this.elements.each(function(el, i){
			if (this.options.show === i){
				this.fireEvent('active', [this.togglers[i], el]);
			} else {
				for (var fx in this.effects) el.setStyle(fx, 0);
			}
		}, this);
		if ($chk(this.options.display)) this.display(this.options.display);
	},

	addSection: function(toggler, element, pos){
		toggler = $(toggler);
		element = $(element);
		var test = this.togglers.contains(toggler);
		var len = this.togglers.length;
		this.togglers.include(toggler);
		this.elements.include(element);
		if (len && (!test || pos)){
			pos = $pick(pos, len - 1);
			toggler.inject(this.togglers[pos], 'before');
			element.inject(toggler, 'after');
		} else if (this.container && !test){
			toggler.inject(this.container);
			element.inject(this.container);
		}
		var idx = this.togglers.indexOf(toggler);
		toggler.addEvent('click', this.display.bind(this, idx));
		if (this.options.height) element.setStyles({'padding-top': 0, 'border-top': 'none', 'padding-bottom': 0, 'border-bottom': 'none'});
		if (this.options.width) element.setStyles({'padding-left': 0, 'border-left': 'none', 'padding-right': 0, 'border-right': 'none'});
		element.fullOpacity = 1;
		if (this.options.fixedWidth) element.fullWidth = this.options.fixedWidth;
		if (this.options.fixedHeight) element.fullHeight = this.options.fixedHeight;
		element.setStyle('overflow', 'hidden');
		if (!test){
			for (var fx in this.effects) element.setStyle(fx, 0);
		}
		return this;
	},

	display: function(index){
		index = ($type(index) == 'element') ? this.elements.indexOf(index) : index;
		if ((this.timer && this.options.wait) || (index === this.previous && !this.options.alwaysHide)) return this;
		this.previous = index;
		var obj = {};
		this.elements.each(function(el, i){
			obj[i] = {};
			var hide = (i != index) || (this.options.alwaysHide && (el.offsetHeight > 0));
			this.fireEvent(hide ? 'background' : 'active', [this.togglers[i], el]);
			for (var fx in this.effects) obj[i][fx] = hide ? 0 : el[this.effects[fx]];
		}, this);
		return this.start(obj);
	}

});
/* 
 * flowplayer.js 3.1.4. The Flowplayer API
 * 
 * Copyright 2009 Flowplayer Oy
 * 
 * This file is part of Flowplayer.
 * 
 * Flowplayer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Flowplayer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Flowplayer.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Date: 2009-02-25 21:24:29 +0000 (Wed, 25 Feb 2009)
 * Revision: 166 
 */
(function(){function g(o){console.log("$f.fireEvent",[].slice.call(o))}function k(q){if(!q||typeof q!="object"){return q}var o=new q.constructor();for(var p in q){if(q.hasOwnProperty(p)){o[p]=k(q[p])}}return o}function m(t,q){if(!t){return}var o,p=0,r=t.length;if(r===undefined){for(o in t){if(q.call(t[o],o,t[o])===false){break}}}else{for(var s=t[0];p<r&&q.call(s,p,s)!==false;s=t[++p]){}}return t}function c(o){return document.getElementById(o)}function i(q,p,o){if(typeof p!="object"){return q}if(q&&p){m(p,function(r,s){if(!o||typeof s!="function"){q[r]=s}})}return q}function n(s){var q=s.indexOf(".");if(q!=-1){var p=s.substring(0,q)||"*";var o=s.substring(q+1,s.length);var r=[];m(document.getElementsByTagName(p),function(){if(this.className&&this.className.indexOf(o)!=-1){r.push(this)}});return r}}function f(o){o=o||window.event;if(o.preventDefault){o.stopPropagation();o.preventDefault()}else{o.returnValue=false;o.cancelBubble=true}return false}function j(q,o,p){q[o]=q[o]||[];q[o].push(p)}function e(){return"_"+(""+Math.random()).substring(2,10)}var h=function(t,r,s){var q=this;var p={};var u={};q.index=r;if(typeof t=="string"){t={url:t}}i(this,t,true);m(("Begin*,Start,Pause*,Resume*,Seek*,Stop*,Finish*,LastSecond,Update,BufferFull,BufferEmpty,BufferStop").split(","),function(){var v="on"+this;if(v.indexOf("*")!=-1){v=v.substring(0,v.length-1);var w="onBefore"+v.substring(2);q[w]=function(x){j(u,w,x);return q}}q[v]=function(x){j(u,v,x);return q};if(r==-1){if(q[w]){s[w]=q[w]}if(q[v]){s[v]=q[v]}}});i(this,{onCuepoint:function(x,w){if(arguments.length==1){p.embedded=[null,x];return q}if(typeof x=="number"){x=[x]}var v=e();p[v]=[x,w];if(s.isLoaded()){s._api().fp_addCuepoints(x,r,v)}return q},update:function(w){i(q,w);if(s.isLoaded()){s._api().fp_updateClip(w,r)}var v=s.getConfig();var x=(r==-1)?v.clip:v.playlist[r];i(x,w,true)},_fireEvent:function(v,y,w,A){if(v=="onLoad"){m(p,function(B,C){if(C[0]){s._api().fp_addCuepoints(C[0],r,B)}});return false}A=A||q;if(v=="onCuepoint"){var z=p[y];if(z){return z[1].call(s,A,w)}}if(y&&"onBeforeBegin,onMetaData,onStart,onUpdate,onResume".indexOf(v)!=-1){i(A,y);if(y.metaData){if(!A.duration){A.duration=y.metaData.duration}else{A.fullDuration=y.metaData.duration}}}var x=true;m(u[v],function(){x=this.call(s,A,y,w)});return x}});if(t.onCuepoint){var o=t.onCuepoint;q.onCuepoint.apply(q,typeof o=="function"?[o]:o);delete t.onCuepoint}m(t,function(v,w){if(typeof w=="function"){j(u,v,w);delete t[v]}});if(r==-1){s.onCuepoint=this.onCuepoint}};var l=function(p,r,q,t){var s={};var o=this;var u=false;if(t){i(s,t)}m(r,function(v,w){if(typeof w=="function"){s[v]=w;delete r[v]}});i(this,{animate:function(y,z,x){if(!y){return o}if(typeof z=="function"){x=z;z=500}if(typeof y=="string"){var w=y;y={};y[w]=z;z=500}if(x){var v=e();s[v]=x}if(z===undefined){z=500}r=q._api().fp_animate(p,y,z,v);return o},css:function(w,x){if(x!==undefined){var v={};v[w]=x;w=v}r=q._api().fp_css(p,w);i(o,r);return o},show:function(){this.display="block";q._api().fp_showPlugin(p);return o},hide:function(){this.display="none";q._api().fp_hidePlugin(p);return o},toggle:function(){this.display=q._api().fp_togglePlugin(p);return o},fadeTo:function(y,x,w){if(typeof x=="function"){w=x;x=500}if(w){var v=e();s[v]=w}this.display=q._api().fp_fadeTo(p,y,x,v);this.opacity=y;return o},fadeIn:function(w,v){return o.fadeTo(1,w,v)},fadeOut:function(w,v){return o.fadeTo(0,w,v)},getName:function(){return p},getPlayer:function(){return q},_fireEvent:function(w,v,x){if(w=="onUpdate"){var y=q._api().fp_getPlugin(p);if(!y){return}i(o,y);delete o.methods;if(!u){m(y.methods,function(){var A=""+this;o[A]=function(){var B=[].slice.call(arguments);var C=q._api().fp_invoke(p,A,B);return C==="undefined"||C===undefined?o:C}});u=true}}var z=s[w];if(z){z.apply(o,v);if(w.substring(0,1)=="_"){delete s[w]}}}})};function b(o,t,z){var E=this,y=null,x,u,p=[],s={},B={},r,v,w,D,A,q;i(E,{id:function(){return r},isLoaded:function(){return(y!==null)},getParent:function(){return o},hide:function(F){if(F){o.style.height="0px"}if(y){y.style.height="0px"}return E},show:function(){o.style.height=q+"px";if(y){y.style.height=A+"px"}return E},isHidden:function(){return y&&parseInt(y.style.height,10)===0},load:function(F){if(!y&&E._fireEvent("onBeforeLoad")!==false){m(a,function(){this.unload()});x=o.innerHTML;if(x&&!flashembed.isSupported(t.version)){o.innerHTML=""}flashembed(o,t,{config:z});if(F){F.cached=true;j(B,"onLoad",F)}}return E},unload:function(){if(x.replace(/\s/g,"")!==""){if(E._fireEvent("onBeforeUnload")===false){return E}try{if(y){y.fp_close();E._fireEvent("onUnload")}}catch(F){}y=null;o.innerHTML=x}return E},getClip:function(F){if(F===undefined){F=D}return p[F]},getCommonClip:function(){return u},getPlaylist:function(){return p},getPlugin:function(F){var H=s[F];if(!H&&E.isLoaded()){var G=E._api().fp_getPlugin(F);if(G){H=new l(F,G,E);s[F]=H}}return H},getScreen:function(){return E.getPlugin("screen")},getControls:function(){return E.getPlugin("controls")},getConfig:function(F){return F?k(z):z},getFlashParams:function(){return t},loadPlugin:function(I,H,K,J){if(typeof K=="function"){J=K;K={}}var G=J?e():"_";E._api().fp_loadPlugin(I,H,K,G);var F={};F[G]=J;var L=new l(I,null,E,F);s[I]=L;return L},getState:function(){return y?y.fp_getState():-1},play:function(G,F){function H(){if(G!==undefined){E._api().fp_play(G,F)}else{E._api().fp_play()}}if(y){H()}else{E.load(function(){H()})}return E},getVersion:function(){var G="flowplayer.js 3.1.4";if(y){var F=y.fp_getVersion();F.push(G);return F}return G},_api:function(){if(!y){throw"Flowplayer "+E.id()+" not loaded when calling an API method"}return y},setClip:function(F){E.setPlaylist([F]);return E},getIndex:function(){return w}});m(("Click*,Load*,Unload*,Keypress*,Volume*,Mute*,Unmute*,PlaylistReplace,ClipAdd,Fullscreen*,FullscreenExit,Error,MouseOver,MouseOut").split(","),function(){var F="on"+this;if(F.indexOf("*")!=-1){F=F.substring(0,F.length-1);var G="onBefore"+F.substring(2);E[G]=function(H){j(B,G,H);return E}}E[F]=function(H){j(B,F,H);return E}});m(("pause,resume,mute,unmute,stop,toggle,seek,getStatus,getVolume,setVolume,getTime,isPaused,isPlaying,startBuffering,stopBuffering,isFullscreen,toggleFullscreen,reset,close,setPlaylist,addClip,playFeed").split(","),function(){var F=this;E[F]=function(H,G){if(!y){return E}var I=null;if(H!==undefined&&G!==undefined){I=y["fp_"+F](H,G)}else{I=(H===undefined)?y["fp_"+F]():y["fp_"+F](H)}return I==="undefined"||I===undefined?E:I}});E._fireEvent=function(O){if(typeof O=="string"){O=[O]}var P=O[0],M=O[1],K=O[2],J=O[3],I=0;if(z.debug){g(O)}if(!y&&P=="onLoad"&&M=="player"){y=y||c(v);A=y.clientHeight;m(p,function(){this._fireEvent("onLoad")});m(s,function(Q,R){R._fireEvent("onUpdate")});u._fireEvent("onLoad")}if(P=="onLoad"&&M!="player"){return}if(P=="onError"){if(typeof M=="string"||(typeof M=="number"&&typeof K=="number")){M=K;K=J}}if(P=="onContextMenu"){m(z.contextMenu[M],function(Q,R){R.call(E)});return}if(P=="onPluginEvent"){var F=M.name||M;var G=s[F];if(G){G._fireEvent("onUpdate",M);G._fireEvent(K,O.slice(3))}return}if(P=="onPlaylistReplace"){p=[];var L=0;m(M,function(){p.push(new h(this,L++,E))})}if(P=="onClipAdd"){if(M.isInStream){return}M=new h(M,K,E);p.splice(K,0,M);for(I=K+1;I<p.length;I++){p[I].index++}}var N=true;if(typeof M=="number"&&M<p.length){D=M;var H=p[M];if(H){N=H._fireEvent(P,K,J)}if(!H||N!==false){N=u._fireEvent(P,K,J,H)}}m(B[P],function(){N=this.call(E,M,K);if(this.cached){B[P].splice(I,1)}if(N===false){return false}I++});return N};function C(){if($f(o)){$f(o).getParent().innerHTML="";w=$f(o).getIndex();a[w]=E}else{a.push(E);w=a.length-1}q=parseInt(o.style.height,10)||o.clientHeight;if(typeof t=="string"){t={src:t}}r=o.id||"fp"+e();v=t.id||r+"_api";t.id=v;z.playerId=r;if(typeof z=="string"){z={clip:{url:z}}}if(typeof z.clip=="string"){z.clip={url:z.clip}}z.clip=z.clip||{};if(o.getAttribute("href",2)&&!z.clip.url){z.clip.url=o.getAttribute("href",2)}u=new h(z.clip,-1,E);z.playlist=z.playlist||[z.clip];var F=0;m(z.playlist,function(){var H=this;if(typeof H=="object"&&H.length){H={url:""+H}}m(z.clip,function(I,J){if(J!==undefined&&H[I]===undefined&&typeof J!="function"){H[I]=J}});z.playlist[F]=H;H=new h(H,F,E);p.push(H);F++});m(z,function(H,I){if(typeof I=="function"){if(u[H]){u[H](I)}else{j(B,H,I)}delete z[H]}});m(z.plugins,function(H,I){if(I){s[H]=new l(H,I,E)}});if(!z.plugins||z.plugins.controls===undefined){s.controls=new l("controls",null,E)}s.canvas=new l("canvas",null,E);t.bgcolor=t.bgcolor||"#000000";t.version=t.version||[9,0];t.expressInstall="http://www.flowplayer.org/swf/expressinstall.swf";function G(H){if(!E.isLoaded()&&E._fireEvent("onBeforeClick")!==false){E.load()}return f(H)}x=o.innerHTML;if(x.replace(/\s/g,"")!==""){if(o.addEventListener){o.addEventListener("click",G,false)}else{if(o.attachEvent){o.attachEvent("onclick",G)}}}else{if(o.addEventListener){o.addEventListener("click",f,false)}E.load()}}if(typeof o=="string"){flashembed.domReady(function(){var F=c(o);if(!F){throw"Flowplayer cannot access element: "+o}else{o=F;C()}})}else{C()}}var a=[];function d(o){this.length=o.length;this.each=function(p){m(o,p)};this.size=function(){return o.length}}window.flowplayer=window.$f=function(){var p=null;var o=arguments[0];if(!arguments.length){m(a,function(){if(this.isLoaded()){p=this;return false}});return p||a[0]}if(arguments.length==1){if(typeof o=="number"){return a[o]}else{if(o=="*"){return new d(a)}m(a,function(){if(this.id()==o.id||this.id()==o||this.getParent()==o){p=this;return false}});return p}}if(arguments.length>1){var r=arguments[1];var q=(arguments.length==3)?arguments[2]:{};if(typeof o=="string"){if(o.indexOf(".")!=-1){var t=[];m(n(o),function(){t.push(new b(this,k(r),k(q)))});return new d(t)}else{var s=c(o);return new b(s!==null?s:o,r,q)}}else{if(o){return new b(o,r,q)}}}return null};i(window.$f,{fireEvent:function(){var o=[].slice.call(arguments);var q=$f(o[0]);return q?q._fireEvent(o.slice(1)):null},addPlugin:function(o,p){b.prototype[o]=p;return $f},each:m,extend:i});if(typeof jQuery=="function"){jQuery.prototype.flowplayer=function(q,p){if(!arguments.length||typeof arguments[0]=="number"){var o=[];this.each(function(){var r=$f(this);if(r){o.push(r)}});return arguments.length?o[arguments[0]]:new d(o)}return this.each(function(){$f(this,k(q),p?k(p):{})})}}})();(function(){var e=typeof jQuery=="function";var i={width:"100%",height:"100%",allowfullscreen:true,allowscriptaccess:"always",quality:"high",version:null,onFail:null,expressInstall:null,w3c:false,cachebusting:false};if(e){jQuery.tools=jQuery.tools||{};jQuery.tools.flashembed={version:"1.0.4",conf:i}}function j(){if(c.done){return false}var l=document;if(l&&l.getElementsByTagName&&l.getElementById&&l.body){clearInterval(c.timer);c.timer=null;for(var k=0;k<c.ready.length;k++){c.ready[k].call()}c.ready=null;c.done=true}}var c=e?jQuery:function(k){if(c.done){return k()}if(c.timer){c.ready.push(k)}else{c.ready=[k];c.timer=setInterval(j,13)}};function f(l,k){if(k){for(key in k){if(k.hasOwnProperty(key)){l[key]=k[key]}}}return l}function g(k){switch(h(k)){case"string":k=k.replace(new RegExp('(["\\\\])',"g"),"\\$1");k=k.replace(/^\s?(\d+)%/,"$1pct");return'"'+k+'"';case"array":return"["+b(k,function(n){return g(n)}).join(",")+"]";case"function":return'"function()"';case"object":var l=[];for(var m in k){if(k.hasOwnProperty(m)){l.push('"'+m+'":'+g(k[m]))}}return"{"+l.join(",")+"}"}return String(k).replace(/\s/g," ").replace(/\'/g,'"')}function h(l){if(l===null||l===undefined){return false}var k=typeof l;return(k=="object"&&l.push)?"array":k}if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){}})}function b(k,n){var m=[];for(var l in k){if(k.hasOwnProperty(l)){m[l]=n(k[l])}}return m}function a(r,t){var q=f({},r);var s=document.all;var n='<object width="'+q.width+'" height="'+q.height+'"';if(s&&!q.id){q.id="_"+(""+Math.random()).substring(9)}if(q.id){n+=' id="'+q.id+'"'}if(q.cachebusting){q.src+=((q.src.indexOf("?")!=-1?"&":"?")+Math.random())}if(q.w3c||!s){n+=' data="'+q.src+'" type="application/x-shockwave-flash"'}else{n+=' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'}n+=">";if(q.w3c||s){n+='<param name="movie" value="'+q.src+'" />'}q.width=q.height=q.id=q.w3c=q.src=null;for(var l in q){if(q[l]!==null){n+='<param name="'+l+'" value="'+q[l]+'" />'}}var o="";if(t){for(var m in t){if(t[m]!==null){o+=m+"="+(typeof t[m]=="object"?g(t[m]):t[m])+"&"}}o=o.substring(0,o.length-1);n+='<param name="flashvars" value=\''+o+"' />"}n+="</object>";return n}function d(m,p,l){var k=flashembed.getVersion();f(this,{getContainer:function(){return m},getConf:function(){return p},getVersion:function(){return k},getFlashvars:function(){return l},getApi:function(){return m.firstChild},getHTML:function(){return a(p,l)}});var q=p.version;var r=p.expressInstall;var o=!q||flashembed.isSupported(q);if(o){p.onFail=p.version=p.expressInstall=null;m.innerHTML=a(p,l)}else{if(q&&r&&flashembed.isSupported([6,65])){f(p,{src:r});l={MMredirectURL:location.href,MMplayerType:"PlugIn",MMdoctitle:document.title};m.innerHTML=a(p,l)}else{if(m.innerHTML.replace(/\s/g,"")!==""){}else{m.innerHTML="<h2>Flash version "+q+" or greater is required</h2><h3>"+(k[0]>0?"Your version is "+k:"You have no flash plugin installed")+"</h3>"+(m.tagName=="A"?"<p>Click here to download latest version</p>":"<p>Download latest version from <a href='http://www.adobe.com/go/getflashplayer'>here</a></p>");if(m.tagName=="A"){m.onclick=function(){location.href="http://www.adobe.com/go/getflashplayer"}}}}}if(!o&&p.onFail){var n=p.onFail.call(this);if(typeof n=="string"){m.innerHTML=n}}if(document.all){window[p.id]=document.getElementById(p.id)}}window.flashembed=function(l,m,k){if(typeof l=="string"){var n=document.getElementById(l);if(n){l=n}else{c(function(){flashembed(l,m,k)});return}}if(!l){return}if(typeof m=="string"){m={src:m}}var o=f({},i);f(o,m);return new d(l,o,k)};f(window.flashembed,{getVersion:function(){var m=[0,0];if(navigator.plugins&&typeof navigator.plugins["Shockwave Flash"]=="object"){var l=navigator.plugins["Shockwave Flash"].description;if(typeof l!="undefined"){l=l.replace(/^.*\s+(\S+\s+\S+$)/,"$1");var n=parseInt(l.replace(/^(.*)\..*$/,"$1"),10);var r=/r/.test(l)?parseInt(l.replace(/^.*r(.*)$/,"$1"),10):0;m=[n,r]}}else{if(window.ActiveXObject){try{var p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7")}catch(q){try{p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");m=[6,0];p.AllowScriptAccess="always"}catch(k){if(m[0]==6){return m}}try{p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash")}catch(o){}}if(typeof p=="object"){l=p.GetVariable("$version");if(typeof l!="undefined"){l=l.replace(/^\S+\s+(.*)$/,"$1").split(",");m=[parseInt(l[0],10),parseInt(l[2],10)]}}}}return m},isSupported:function(k){var m=flashembed.getVersion();var l=(m[0]>k[0])||(m[0]==k[0]&&m[1]>=k[1]);return l},domReady:c,asString:g,getHTML:a});if(e){jQuery.fn.flashembed=function(l,k){var m=null;this.each(function(){m=flashembed(this,l,k)});return l.api===false?this:m}}})(); Error = new Class({
	Implements: Options,
	
	options: {
		'msg':false,
		'exists':false
	},
	
	initialize: function(options){
	
		//set data members
		this.setOptions(options);
	
	},
	
	getMsg: function(){return this.options.msg;},
	isError: function(){return this.options.exists;}
}); 
window.getWidth = function()
{
        var x = 0;
        if (self.innerHeight)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        return x;
}
 
window.getHeight = function()
{
        var y = 0;
        if (self.innerHeight)
        {
                y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                y = document.documentElement.clientHeight;
        }
        else if (document.body)
        {
                y = document.body.clientHeight;
        }
        return y;
}


Box = new Class({
	Implements: Options,
	
	options: {
		'width':200,
		'height':100,
		'position':'center',
		'top':false,
		'left':false,
		'tail':false,
		'background':true,
		'closeable': true,
		'unique_id': 0,
		'onClose': function(){$empty();}
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		//generate HTML
		this.temp_container = new Element('div',{'class':'temp_container'});
		this.background = new Element('div',{'class':'box_background'});
		this.box = new Element('div',{'class':'box'});
		this.box_tl = new Element('div',{'class':'box_tl'});
		this.box_tr = new Element('div',{'class':'box_tr'});
		this.box_bl = new Element('div',{'class':'box_bl'});
		this.box_br = new Element('div',{'class':'box_br'});
		this.box_t  = new Element('div',{'class':'box_t'});
		this.box_r  = new Element('div',{'class':'box_r'});
		this.box_l  = new Element('div',{'class':'box_l'});
		this.box_b= new Element('div',{'class':'box_bml'});
		this.box_m  = new Element('div',{'class':'box_m'});
		this.box_close_btn = new Element('img',{'src':'/obray/images/box/boxClose_btn.png','class':'box_close_btn'});
		this.loader = new Loader(this.box_m,{'text':'Loading...','height':75,'width':300});
		this.box_content = new Element('div',{'class':'box_content'});
		this.stack = new Chain();
		this.br = new Element('br',{'class':'clearboth'});
		
		//effects
		this.box_fx = new Fx.Morph(this.box,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
		this.background_fx = new Fx.Morph(this.background,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
		this.box_t_fx = new Fx.Morph(this.box_t,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
		this.box_b_fx = new Fx.Morph(this.box_b,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
		this.box_m_fx = new Fx.Morph(this.box_m,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
		this.box_content_fx = new Fx.Morph(this.box_content,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
		
		//set styles
		var tempWidth = (this.options.width/2-17);
		this.box.setStyles({'position':'fixed','top':'50%','left':'50%','z-index':'5002','display':'block','margin-left':-164,'margin-top':-65,'opacity':0});
		this.background.setStyles({'position':'fixed','z-index':'5001','margin':'0 auto','background-color':'#ffffff','opacity':0,'height':'100%','width':'100%','display':'block','top':'0px','left':'0px'});
		this.temp_container.setStyles({'position':'absolute','height':2000,'width':2000,'overflow':'hidden','left':-4000,'top':-4000});
		this.box_content.setStyles({'position':'absolute'});
		this.box_close_btn.setStyles({'position':'absolute','right':'-5px','top':'-5px','cursor':'pointer'});
		this.box_tl.setStyles({'float':'left','height':'28px','width':'28px','background-image':'url(/obray/images/shelf/shelf_box_tl.png)'});
		this.box_t.setStyles({'float':'left','height':'28px','width':'300px','background-image':'url(/obray/images/shelf/shelf_box_t.png)'});
		this.box_tr.setStyles({'float':'left','height':'28px','width':'28px','background-image':'url(/obray/images/shelf/shelf_box_tr.png)'});
		this.box_l.setStyles({'clear':'both','float':'left','padding-left':'28px','background-image':'url(/obray/images/shelf/shelf_box_l.png)','background-repeat':'repeat-y'});
		this.box_m.setStyles({'background-color':'#ffffff','width':'300px','overflow':'hidden'});
		this.box_r.setStyles({'padding-right':'28px','background-image':'url(/obray/images/shelf/shelf_box_r.png)','background-repeat':'repeat-y','background-position':'right'})
		this.box_bl.setStyles({'clear':'both','float':'left','height':'28px','width':'28px','background-image':'url(/obray/images/shelf/shelf_box_bl.png)'});
		this.box_b.setStyles({'float':'left','height':'28px','width':'300px','background-image':'url(/obray/images/shelf/shelf_box_b.png)'});
		this.box_br.setStyles({'float':'left','height':'28px','width':'28px','background-image':'url(/obray/images/shelf/shelf_box_br.png)'});
		this.br.setStyles({'clear':'both'});
			
		//construct HT
		this.temp_container.inject(document.body);
		this.box_content.inject(this.temp_container);
		if(this.options.closeable){this.box_close_btn.inject(this.box);}
		this.box_tl.inject(this.box);
		this.box_t.inject(this.box);
		this.box_tr.inject(this.box);
		this.br.clone().inject(this.box);
		this.box_l.inject(this.box);
		this.box_r.inject(this.box_l);
		this.box_m.inject(this.box_r);
		this.br.clone().inject(this.box);
		this.box_bl.inject(this.box);
		this.box_b.inject(this.box);
		this.box_br.inject(this.box);
		this.br.clone().inject(this.box);
		this.background.inject($(document.body));
		this.box.inject($(document.body));

		this.box_close_btn.addEvent('click',function(){
			this.options.onClose();
			this.close();
		}.bind(this));
		
	},
	
	
	close: function(){
		this.box.destroy();
		this.background.destroy();
	},
	
	open: function(transition){
		this.stack.chain(this.showBackground.bind(this));
		this.stack.chain(this.showBox.bind(this));
		this.stack.chain(this.adjustSize.bind(this));
		this.stack.chain(this.showContents.bind(this));
		this.stack.callChain();
	},
	
	showBackground: function(){
		this.background_fx.start({'opacity':.8});
		this.background_fx.addEvent('onComplete',function(){
			this.stack.callChain();
		}.bind(this));
	},
	
	showBox: function(){
		this.box_fx.start({'opacity':1});
		this.box_fx.addEvent('onComplete',function(){
			this.box_fx.removeEvents('onComplete');
			this.stack.callChain();										   
		}.bind(this));
		
	},
	
	showContents: function(){
		this.box_content.setStyles({'opacity':'0'});
		this.box_content.inject(this.box_m);
		this.box_content_fx.start({'opacity':1});
		
	},
	
	adjustSize: function(){
		this.loader.destroy();
		var h = this.box_content.getCoordinates().height;
		var w = this.box_content.getCoordinates().width;
		if(w > document.window.getCoordinates().width){
			w=document.window.getCoordinates().width-100;
		}
		var left = -((w+54)/2);
		var top = -((h+54)/2);
		
		this.box_fx.pause();
		if(this.options.position == 'absolute'){
			this.box.setStyles({'position':'absolute','top':10,'margin-top':0});
			this.box_fx.start({'margin-left':left});
		} else {
			this.box_fx.start({'margin-top':top,'margin-left':left});
		}
		this.box_t_fx.start({'width':w});
		this.box_b_fx.start({'width':w});
		
		this.box_m_fx.start({'width':w,'height':h});
		this.box_m_fx.addEvent('onComplete',function(){
			this.stack.callChain();
		}.bind(this))
	},
	
	hideLoader: function(){
		this.loader.destroy();
	},
	
	get: function(){
		return this.box;
	}
});


ImageBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'id':0,
		'image_id': 0,
		'image_name':'obray_placeHolder',
		'image_ext': '.jpg',
		'description':'Place Holder',
		'window_height': 461,
		'window_width': 392,
		'window_max_width': 392,
		'window_max_height': 461,
		'zoom_level': 300,
		'resizable': false,
		'offset_x': 0,
		'offset_y': 0,
		'onSave':this.onSave,
		'src':'obray/images/obray_placeHolder.jpg',
		'description_long':'',
		'deletefn': false,
		'onDelete':$empty
	},
	
	initialize: function(options){
		
		//data emembers
		this.setOptions(options);
		this.parent(options);
		
		//generate HTML
		this.product_image_container = new Element('div',{'class':'product_image_container'});
		this.product_image_editor = new ImageEditor(this.stack,{
			'image_id': 			this.options.image_id,
			'image_name':			this.options.image_name,
			'image_ext': 			this.options.image_ext,
			'description':			this.options.description,
			'window_height': 		this.options.window_height,
			'window_width': 		this.options.window_width,
			'window_max_width': 	this.options.window_max_width,
			'window_max_height': 	this.options.window_max_height,
			'zoom_level': 			this.options.zoom_level,
			'resizable': 			this.options.resizable,
			'offset_x': 			this.options.offset_x,
			'offset_y': 			this.options.offset_y,
			'onSave': 				this.options.onSave,
			'src':					this.options.src,
			'description_long':		this.options.description_long,
			'thumb_size_x': 		90,
			'thumb_size_y': 		68,
			'delete':				this.options.deletefn,
			'onDelete':				this.options.onDelete
		});
		
		//construct HTML
		
		this.stack.chain(function(){
			this.product_image_editor.get().inject(this.product_image_container);
			this.product_image_container.inject(this.box_content);
			
			//this.box_content.set('html','Hello')
		}.bind(this));
		this.stack.callChain();
	
	},
	
	onSave: function(response){
		eval(response);
		var color_id = this.product_image_editor.colors.value;
		this.linkProductAndImage = new Request({'url':'index.cfm?action=pages.cp&component=products&do=linkProductImage&image_id='+image_id + '&product_id=' + this.options.id + '&product_color_id='+color_id,'onComplete':function(){
			this.close();
		}.bind(this)}).send();
	}
	
});


ConfirmBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'message':'Are you sure?',
		'onCancel':function(){$empty();},
		'onClose':function(){$empty();},
		'onConfirm':function(){$empty();}
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		
		//genereate HTML
		this.confirm_container = new Element('div',{'class':'confirm_container'});
		this.confirm_message = new Element('div',{'class':'confirm_message'});
		this.confirm_buttons = new Element('div',{'class':'confirm_buttons'});
		this.confirm_cancel_btn = new Element('div',{'class':'confirm_cancel_btn'});
		this.confirm_btn = new Element('div',{'class':'confirm_btn'});
		this.br = new Element('br',{'class':'clear'});
		
		//set properties
		this.confirm_message.set('html',this.options.message);
		this.confirm_cancel_btn.set('html','Cancel');
		this.confirm_btn.set('html','Continue');
		
		//set styles
		this.confirm_container.setStyles({'padding-top':'10px'});
		this.confirm_message.setStyles({'color':'#000000','width':'400px','margin':'0 auto','font-family':'arial','font-size':'14px','text-align':'center'});
		this.confirm_buttons.setStyles({'margin':'0 auto','width':'180px','padding':'10px','padding-top':'20px','color':'#888888','font-family':'Arial'});
		this.confirm_cancel_btn.setStyles({'float':'left','width':'60px','text-align':'left','padding-left':'20px','padding-right':'10px','cursor':'pointer'});
		this.confirm_btn.setStyles({'float':'left','width':'60px','text-align':'right','padding-right':'20px','padding-left':'10px','cursor':'pointer','cursor':'pointer'});
		this.br.setStyles({'clear':'both'})
		
		//construct HTML
		this.confirm_container.inject(this.box_content);
		this.confirm_message.inject(this.confirm_container);
		this.confirm_btn.inject(this.confirm_buttons);
		this.confirm_cancel_btn.inject(this.confirm_buttons);
		this.confirm_buttons.inject(this.confirm_container);
		this.br.inject(this.confirm_buttons);
		
		//add event
		this.confirm_cancel_btn.addEvent('click',function(){
			this.options.onClose();
			this.close();
		}.bind(this));
		this.confirm_cancel_btn.addEvent('mouseenter',function(){
			this.confirm_cancel_btn.setStyles({'color':'#333333'});
		}.bind(this));
		this.confirm_cancel_btn.addEvent('mouseleave',function(){
			this.confirm_cancel_btn.setStyles({'color':'#888888'});
		}.bind(this));
		this.confirm_btn.addEvent('click',function(){
			this.options.onConfirm();
			this.close();
		}.bind(this));
		this.confirm_btn.addEvent('mouseenter',function(){
			this.confirm_btn.setStyles({'color':'#333333'});
		}.bind(this));
		this.confirm_btn.addEvent('mouseleave',function(){
			this.confirm_btn.setStyles({'color':'#888888'});
		}.bind(this));
	}
});


HTMLBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'page':0,
		'onClose':function(){$empty();}
	},
	
	initialize: function(options){
		//data members
		this.setOptions(options);
		this.parent(options);
		//genereate HTML
		this.request = new Request.HTML({'url':'index.cfm?action=pages.getBoxHTML&&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true&page='+this.options.page,'update':this.box_content,'onComplete':function(response){
		}.bind(this)}).send();
	}
});

ImgBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'src': 0,
		'onClose':function(){$empty();},
		'height':'auto',
		'width':'auto'
	},
	
	initialize: function(options){
		//data members
		this.setOptions(options);
		this.parent(options);
		
		this.box_content.set('html','<img width="'+this.options.width+'" height="'+this.options.height+'" src="'+this.options.src+'">');
	}
});


URLBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.parent(options);
		//genreate HTML
		this.request = new Request({'url':'reading-speed/VISUALLINK/test.html','evalScripts':true,'method':'get','onComplete':function(response){
			this.box_content.set('html',response);
		}.bind(this)}).send();
	}
})





SelectParentBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'page_id': 0,
		'message':'Are you sure?',
		'onClose':function(){$empty();}
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		
		//generate HTML
		this.select_loader = new Loader(this.box_m,{'height':120,'width':400,'image':'medium','color':'#ffffff','border':true,'text':'Loading list of pages...'});
		this.select_container = new Element('div',{'class':'select_container'});
		this.select_input = new Element('select',{'class':'select_input'});
		this.select_instructions = new Element('div',{'class':'select_instructions'});
		this.select_buttons = new Element('div',{'class':'select_buttons'});
		this.select_btn = new Element('div',{'class':'select_btn'});
		this.br = new Element('br',{'class':'clear'});
		
		//set Styles
		this.select_container.setStyles({'font-family':'arial','color':'#ffffff','font-size':'12px','line-height':'18px'});
		this.select_instructions.setStyles({'padding':'20px','text-align':'left'});
		this.select_buttons.setStyles({'position':'absolute','bottom':'10px','left':'50%','margin-left':'-60px','width':'75px','padding':'10px','padding-top':'20px','color':'#cccccc','font-family':'Arial'});
		this.select_btn.setStyles({'text-align':'center','padding-right':'10px','padding-left':'10px','cursor':'pointer','font-size':'16px'});
		
		//set properties
		this.select_instructions.set('html','To move this page select page you would like to list it under and press the move.');
		this.select_btn.set('html','Move');
		
		//construct HTML
		this.select_loader.get().inject(this.select_container);
		this.select_container.inject(this.box_m);
		this.getPageOptions = new Request({'url':'index.cfm?action=pages.getPageOptions','onComplete':function(response){
			var children = [];
			var children = window.map.getChildren(this.options.page_id);
			eval(response);
			this.select_loader.destroy();
			
			//construct HTML
			this.select_instructions.inject(this.select_container);
			this.select_input.inject(this.select_container);
			this.select_btn.inject(this.select_buttons);
			this.select_buttons.inject(this.select_container);
		
		}.bind(this)}).send();
		
		//add event
		this.select_btn.addEvent('click',function(){
			this.box_m.set('html','');
			this.select_loader = new Loader(this.box_m,{'height':120,'width':400,'image':'small','color':'#ffffff','border':true,'text':'Moving page, stand by...'});
			this.select_loader.get().inject(this.box_m);
			
			this.setPageParent = new Request({'url':'index.cfm?action=pages.setPageParent','data':'&page_id='+this.options.page_id+'&parent_id='+this.select_input.getProperty('value'),'onComplete':function(response){
				eval(response)
				this.options.onComplete(this.select_input.getProperty('value'),newOrder);
				this.select_loader.destroy();
				this.close();
			}.bind(this)}).send();
			
		}.bind(this));
		this.select_btn.addEvent('mouseenter',function(){
			this.select_btn.setStyles({'color':'#ffffff'});
		}.bind(this));
		this.select_btn.addEvent('mouseleave',function(){
			this.select_btn.setStyles({'color':'#cccccc'});
		}.bind(this));
	}
});




PictureBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'page_id': 0,
		'message':'Are you sure?',
		'onClose':function(){$empty();}
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
	
		//generate HTML
		this.picture_loader = new Loader(this.picture_container,{'height':120,'width':this.options.width,'image':'small','color':'#ffffff','border':true,'text':'Loading image editor, please standby...'});
		this.picture_container = new Element('div',{'class':'select_container'});
		
		
		//set Styles
		this.picture_container.setStyles({'font-family':'arial','color':'#ffffff','font-size':'12px','line-height':'18px','height':'500px'});
		this.box.setStyles({'position':'absolute','top':'300px'});
				
		//construct HTML
		this.picture_loader.get().inject(this.picture_container);
		this.picture_container.inject(this.window_m);
		
		var imageEditor = new ImageEditor(this.stack,{
			'window_width':900
		});
	
		imageEditor.get().inject(this.picture_container);
		
		this.picture_loader.destroy();
		
		
		
	}
});










Tag = new Class({
	Implements: Options,
	
	options:{
		'onClick':$empty
	},
	
	initialize: function(name,id,options){
		
		//data members
		this.setOptions(options);
		this.name = name;
		this.id = id;
		
		//construct HTML
		this.option = new Element('div',{'closs':'option'});
		this.option.set('html',this.name);
		
		//set styles
		this.option.setStyles({'color':'#aaaaaa','font-family':'arial','font-size':'14px','float':'left','padding':'5px'});
		
		this.option.addEvent('click',function(){
			this.options.onClick();
			this.option.destroy();
			this.id = 0;
			this.name ='';
		}.bind(this))
		
	},
	
	get: function(){return this.name;},
	
	getId: function(){return this.id;},
	
	getEl: function(){return this.option;}
})





VideoBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'id':0,
		'image_id': 0,
		'image_name':'obray_placeHolder',
		'image_ext': '.jpg',
		'description':'Place Holder',
		'window_height': 461,
		'window_width': 392,
		'window_max_width': 392,
		'window_max_height': 461,
		'zoom_level': 300,
		'resizable': false,
		'offset_x': 0,
		'offset_y': 0,
		'onSave':this.onSave,
		'src':'obray/images/obray_placeHolder.jpg',
		'description_long':'',
		'deletefn': false,
		'onDelete':$empty,
		'user_id':0,
		'categories':[],
		'categoryid':[],
		'assigned_category':0,
		'embed':'',
		'tags':[],
		'tagid':[],
		'assigned_tags':[],
		'media_id':0
	},
	
	initialize: function(options){
		
		//data emembers
		this.setOptions(options);
		this.parent(options);
		this.upload_target = $('upload_target');
		this.tags = [];
		this.form_submit = false;
		
		
		//generate HTML
		this.video_image_container = new Element('div',{'class':'product_image_container'});
		this.video_image_editor = new ImageEditor(this.stack,{
			'image_id': this.options.image_id,
			'image_name':this.options.image_name,
			'image_ext': this.options.image_ext,
			'description':this.options.description,
			'window_height': this.options.window_height,
			'window_width': this.options.window_width,
			'window_max_width': this.options.window_max_width,
			'window_max_height': this.options.window_max_height,
			'zoom_level': this.options.zoom_level,
			'resizable': this.options.resizable,
			'offset_x': this.options.offset_x,
			'offset_y': this.options.offset_y,
			'onSave': this.onSave.bind(this),
			'src':this.options.src,
			'description_long':this.options.description_long,
			'thumb_size_x': 90,
			'thumb_size_y': 68,
			'delete':this.options.deletefn,
			'onDelete':this.options.onDelete,
			'embed':'',
			'media_id':0
		});
		
		this.stack.chain(function(){
		this.video_upload_form = new Element('form',{'action':'index.cfm?action=videos.uploadVideo','encoding':'multipart/form-data','enctype':'multipart/form-data','target':'upload_target','method':'post'})
		this.video_description = new Element('input',{'name':'description','type':'hidden','value':this.options.description});
		this.video_description_long = new Element('input',{'name':'description_long','type':'hidden','value':this.options.description_long});
		this.video_image_id = new Element('input',{'name':'image_id','type':'hidden','value':this.options.image_id});
		this.video_user_id = new Element('input',{'name':'user_id','type':'hidden','value':this.options.user_id});
		this.video_category_container = new Element('div',{'class':'category_container'});
		this.video_category_label = new Element('div',{'class':'category_label'});
		this.video_category_input = new Element('select',{'class':'category_input'});
		this.video_tag_container = new Element('div',{'class':'tag_container'});
		this.video_tag_label = new Element('div',{'class':'tag_label'});
		this.video_tag_input = new Element('select',{'class':'tag_input'});
		this.video_assigned_container = new Element('div',{'class':'tag_container'});
		this.video_assigned_label = new Element('div',{'class':'tag_label'});
		this.video_assigned_input = new Element('div',{'class':'tag_input'});
		this.video_embed_container = new Element('div',{'class':'embed_container'});
		this.video_embed_label = new Element('div',{'class':'embed_label'});
		this.video_embed_input = new Element('input',{'type':'text','name':'embed','class':'embed_input'});
		this.video_embed_input.setProperty('value',this.options.embed);
		this.video_upload_container = new Element('div',{'class':'video_upload_container'});
		this.video_upload_label = new Element('div',{'class':'video_upload_label'});
		this.video_upload_input = new Element('input',{'name':'upload_file','type':'file','class':'video_upload_input'});
		this.br = new Element('br',{'class':'clearboth'});
		this.video_image_editor.editor_save_btn.removeEvents();
		this.video_category_id = 0;

		for(var i=0;i<this.options.assigned_tags.length;++i){
			
			this.box_m.setStyles({'height':'auto'});
			var tagName = '';
			for(var j=0;j<this.options.tagid.length;++j){
				if(this.options.assigned_tags[i] == this.options.tagid[j]){
					tagName = this.options.tags[j];
				}
			}
			this.tags[this.tags.length] = new Tag(tagName,this.options.assigned_tags[i],{'onClick':function(i){
				var removeTag = new Request({'url':'index.cfm?action=videos.removeTag&mediaId='+this.options.media_id + '&tagId=' + this.options.assigned_tags[i]}).send();
			}.bind(this,i)});
			this.tags[this.tags.length-1].getEl().inject(this.video_assigned_input);
		}
		
		
		//category options
		this.option = new Element('option',{'value':''});
		this.option.set('html','Select a Category');
		this.option.inject(this.video_category_input);
		this.select_html = '<select id="category_input" name="video_category_input" class="category_input">';
		for(var i=0;i<this.options.categories.length;++i){
			
			//this.option = new Element('option',{'value':this.options.categoryid[i]});
			//this.option.setProperty('value',this.options.categoryid[i]);
			//this.option.value = this.options.categoryid[i];
			if(this.options.categoryid[i] == this.options.assigned_category){
				this.select_html = this.select_html + '<option value="'+this.options.categoryid[i]+'" selected>'+this.options.categories[i]+'</value>';
				//this.option.setProperty('selected','selected');
			} else {
				this.select_html = this.select_html + '<option value="'+this.options.categoryid[i]+'">'+this.options.categories[i]+'</value>';	
			}
			//this.option.set('html',this.options.categories[i]);
			//this.option.inject(this.video_category_input);
		}
		this.select_html = this.select_html + '</select>';
		this.video_category_input_div = new Element('div');
		this.video_category_input_div.set('html',this.select_html);
		this.video_category_input = this.video_category_input_div.getFirst();
		
		//tag options
		this.option = new Element('option',{'value':''});
		this.option.set('html','Select a tag');
		this.option.inject(this.video_tag_input);
		for(var i=0;i<this.options.tags.length;++i){
			this.option = new Element('option',{'value':i});
			this.option.set('html',this.options.tags[i]);
			this.option.inject(this.video_tag_input);
		}
			
		//set styles
		this.video_upload_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_upload_input.setStyles({'float':'left'});
		this.video_upload_label.set('html','Video File:');
		this.video_upload_container.setStyles({'padding':'5px'});
		this.video_category_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_category_input.setStyles({'float':'left','width':'50%'});
		this.video_category_label.set('html','Select Category:');
		this.video_tag_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_tag_input.setStyles({'float':'left','width':'50%'});
		this.video_tag_label.set('html','Select Tag:');
		this.video_tag_container.setStyles({'padding':'5px'});
		this.video_assigned_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_assigned_input.setStyles({'float':'left','width':'50%'});
		this.video_assigned_label.set('html','Assigned Tags:');
		this.video_assigned_container.setStyles({'padding':'5px'});
		this.video_embed_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_embed_input.setStyles({'float':'left','width':'50%'});
		this.video_embed_label.set('html','Embed YouTube Video:');
		this.video_embed_container.setStyles({'padding':'5px'});
		//this.box_m.setStyles({'height':'auto'})
		
		//construct HTML
		this.video_image_editor.get().inject(this.video_image_container);
		this.video_upload_form.inject(this.video_image_editor.editor_extra_container);
		this.video_description.inject(this.video_upload_form);
		this.video_description_long.inject(this.video_upload_form);
		this.video_image_id.inject(this.video_upload_form);
		this.video_user_id.inject(this.video_upload_form);
		this.video_category_container.inject(this.video_upload_form);
		this.video_category_label.inject(this.video_category_container);
		this.video_category_input_div.inject(this.video_category_container);
		this.br.clone().inject(this.video_category_container);
		this.video_tag_container.inject(this.video_upload_form);
		this.video_tag_label.inject(this.video_tag_container);
		this.video_tag_input.inject(this.video_tag_container);
		this.br.clone().inject(this.video_tag_container);
		this.video_assigned_container.inject(this.video_upload_form);
		this.video_assigned_label.inject(this.video_assigned_container);
		this.video_assigned_input.inject(this.video_assigned_container);
		this.br.clone().inject(this.video_assigned_container);
		this.video_embed_container.inject(this.video_upload_form);
		this.video_embed_label.inject(this.video_embed_container);
		this.video_embed_input.inject(this.video_embed_container);
		this.br.clone().inject(this.video_embed_container);
		this.video_upload_container.inject(this.video_upload_form);
		this.video_upload_label.inject(this.video_upload_container);
		this.video_upload_input.inject(this.video_upload_container);
		this.br.clone().inject(this.video_upload_container);
		
		this.video_image_container.inject(this.box_content);
		
		this.video_embed_input.addEvent('blur',function(){
			this.options.embed = this.video_embed_input.getProperty('value');
		}.bind(this));
		
		//get upload response
		this.upload_target.addEvent('load',function(){
			var frame = window.frames['upload_target'];
			var response = frame.document.getElementById('response').innerHTML;
			alert(response);
			eval(response);
			this.options.media_id = media_id;
			this.options.image_id = image_id;
			this.options.description = description;
			this.options.description_long = description_long;
			if(response_type == 'video'){
				if(isError){
					var alertBox = new AlertBox({'message':error_message,'width':300});
					alertBox.open('elastic');
				} else {
					this.video_image_editor.saveImage();
				}
			}
		}.bind(this));
		
		//add event
		this.video_tag_input.addEvent('change',function(){
			//this.box_m.setStyles({'height':'auto'});
			this.options.assigned_tags[this.options.assigned_tags.length] = this.video_tag_input.getProperty('value');
			this.tags[this.tags.length] = new Tag(this.options.tags[this.video_tag_input.getProperty('value')],this.options.tagid[this.video_tag_input.getProperty('value')],{'onClick':function(){
				
			}.bind(this)});
			this.tags[this.tags.length-1].getEl().inject(this.video_assigned_input);
		}.bind(this))
		
		this.video_category_input.addEvent('change',function(){
			this.video_category_id = this.video_category_input.getProperty('value');
		}.bind(this))
		
		this.video_image_editor.editor_save_btn.addEvent('click',function(){
			if(this.video_image_editor.editor_description_textarea.getProperty('value') == '' || this.video_image_editor.editor_long_textarea.getProperty('value') == ''){
				var alertBox = new AlertBox({'message':'Please enter and description and long description before uploading a video.','width':300});
				alertBox.open('elastic');
			} else {
				if(this.video_image_editor.options.image_id == 0){
					var alertBox = new AlertBox({'message':'Please upload an image to represent your video first.','width':300});
					alertBox.open('elastic');
				} else {
					if(this.options.assigned_tags.length == 0 || this.video_category_input.getProperty('value') == ''){
						var alertBox = new AlertBox({'message':'Please select a category and add tags before uploading a video','width':300});
						alertBox.open('elastic');
					} else {
						if(this.video_embed_input.getProperty('value') == '' && this.video_upload_input.getProperty('value') == ''){
							var alertBox = new AlertBox({'message':'Please enter the URL of the YouTube video you would like to embed or browse for you video file to upload','width':300});
							alertBox.open('elastic');
						} else {
							if(this.video_embed_input.getProperty('value') == ''){
								this.video_image_id.setProperty('value',this.video_image_editor.options.image_id);
								this.form_submit = true;
								this.video_upload_form.submit();
								var width = this.box_m.getCoordinates().width-5;
								var height = this.box_m.getCoordinates().height-5;
								this.box_m.setStyles({'height':height+5,'width':width+5});
								this.loader = new Loader(this.box_m,{'height':height,'width':width,'text':'Uploading Video, Please Wait','border':true});
								this.loader.get().setStyles({'position':'absolute','background-color':'white','left':'15px','top':'15px'});
								this.loader.get().inject(this.box_m);

							}else{
								this.video_image_id.setProperty('value',this.video_image_editor.options.image_id);
								this.video_image_editor.saveImage();	
							}
	
						}
					}
				}
			}													  
		}.bind(this));
		
		}.bind(this));
		this.stack.callChain();
	
	},
	
	onSave: function(response){
		eval(response);
		if(this.options.media_id == 0){
			var data = '&image_id=' + image_id
				  +'&user_id=' + this.options.user_id
				  +'&description=' + this.options.description
				  +'&description_long='+ this.options.description_long
				  +'&embed='+this.options.embed
				  +'&category='+this.video_category_id
				  +'&tags='+this.getTagIdList();
			var embedRequest = new Request({'data':data,'url':'index.cfm?action=videos.embedVideo','onComplete':function(response){
				window.location.reload();
			}.bind(this)}).send();
		} else {
			var data = '&image_id=' + image_id
				  +'&media_id=' + this.options.media_id
				  +'&user_id=' + this.options.user_id
				  +'&description=' + this.options.description
				  +'&description_long='+ this.options.description_long
				  +'&tags='+this.getTagIdList()
				  +'&embed='+this.options.embed
				  +'&category='+this.video_category_id
				  +'&remove_category=' + this.options.assigned_category
				  +'&tags='+this.getTagIdList();
			var embedRequest = new Request({'data':data,'url':'index.cfm?action=videos.updateVideo','onComplete':function(response){
				window.location.reload();
			}.bind(this)}).send();
		}
	},
	
	getTagList: function(){
		var list = '';
		for(var i=0;i<this.tags.length;++i){
			if(i==0){
				if(this.tags[i].getId() != 0){list = list + this.tags[i].get();}
			} else {
				if(this.tags[i].getId() != 0){list = list + ',' + this.tags[i].get();}
			}
		}
		return list;
	},
	
	getTagIdList: function(){
		var list = '';
		for(var i=0;i<this.tags.length;++i){
			//list = list + this.tags[i].getId();
			if(i==0){
				if(this.tags[i].getId() != 0){list = list + this.tags[i].getId();}
			} else {
				if(this.tags[i].getId() != 0){list = list + ',' + this.tags[i].getId();}
			}
		}
		return list;
	},
	
	getOldTagIdList: function(){
		var list = '';
		for(var i=0;i<this.options.assigned_tags.length;++i){
			if(i==0){
				if(this.options.assigned_tags[i] != 0){list = list + this.options.assigned_tags[i];}
			} else {
				if(this.options.assigned_tags[i] != 0){list = list + ',' + this.options.assigned_tags[i];}
			}
		}
		return list;
	},
	
	removeVideoUpload: function(){
		this.video_upload_container.destroy();
	}
});




PictureBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'id':0,
		'image_id': 0,
		'image_name':'obray_placeHolder',
		'image_ext': '.jpg',
		'description':'Place Holder',
		'window_height': 461,
		'window_width': 392,
		'window_max_width': 392,
		'window_max_height': 461,
		'zoom_level': 300,
		'resizable': false,
		'offset_x': 0,
		'offset_y': 0,
		'onSave':this.onSave,
		'src':'obray/images/obray_placeHolder.jpg',
		'description_long':'',
		'deletefn': false,
		'onDelete':$empty,
		'categories':[],
		'categoryid':[],
		'assigned_category':0,
		'tags':[],
		'tagid':[],
		'assigned_tags':[]
	},
	
	initialize: function(options){
		
		//data emembers
		this.setOptions(options);
		this.parent(options);
		this.tags = [];
		this.category_id = 0;
		
		//generate HTML
		this.picture_image_container = new Element('div',{'class':'product_image_container'});
		this.picture_image_editor = new ImageEditor(this.stack,{
			'image_id': 			this.options.image_id,
			'image_name':			this.options.image_name,
			'image_ext': 			this.options.image_ext,
			'description':			this.options.description,
			'window_height': 		this.options.window_height,
			'window_width': 		this.options.window_width,
			'window_max_width': 	this.options.window_max_width,
			'window_max_height': 	this.options.window_max_height,
			'zoom_level': 			this.options.zoom_level,
			'resizable': 			this.options.resizable,
			'offset_x': 			this.options.offset_x,
			'offset_y': 			this.options.offset_y,
			'onSave': 				this.onSave.bind(this),
			'src':					this.options.src,
			'description_long':		this.options.description_long,
			'thumb_size_x': 		90,
			'thumb_size_y': 		68,
			'delete':				this.options.deletefn,
			'onDelete':				this.options.onDelete
		});
		this.video_category_container = new Element('div',{'class':'category_container'});
		this.video_category_label = new Element('div',{'class':'category_label'});
		this.video_category_input = new Element('select',{'class':'category_input'});
		this.video_tag_container = new Element('div',{'class':'tag_container'});
		this.video_tag_label = new Element('div',{'class':'tag_label'});
		this.video_tag_input = new Element('select',{'class':'tag_input'});
		this.video_assigned_container = new Element('div',{'class':'tag_container'});
		this.video_assigned_label = new Element('div',{'class':'tag_label'});
		this.video_assigned_input = new Element('div',{'class':'tag_input'});
		this.br = new Element('br',{'class':'clearboth'})
		
		
								  

		//assigned tags
		for(var i=0;i<this.options.assigned_tags.length;++i){
			
			
			var tagName = '';
			for(var j=0;j<this.options.tagid.length;++j){
				if(this.options.assigned_tags[i] == this.options.tagid[j]){
					tagName = this.options.tags[j];
				}
			}
			this.tags[this.tags.length] = new Tag(tagName,this.options.assigned_tags[i],{'onClick':function(i){
				var removeTag = new Request({'url':'index.cfm?action=videos.removeTag&mediaId='+this.options.media_id + '&tagId=' + this.options.assigned_tags[i]}).send();
			}.bind(this,i)});
			this.tags[this.tags.length-1].getEl().inject(this.video_assigned_input);
		}
		
		//category options
		this.option = new Element('option',{'value':''});
		this.option.set('html','Select a Category');
		this.option.inject(this.video_category_input);
		for(var i=0;i<this.options.categories.length;++i){
			this.option = new Element('option',{'value':this.options.categoryid[i]});
			if(this.options.categoryid[i] == this.options.assigned_category){
				this.option.setProperty('selected','selected');
			}
			this.option.set('html',this.options.categories[i]);
			this.option.inject(this.video_category_input);
		}
		
		//tag options
		this.option = new Element('option',{'value':''});
		this.option.set('html','Select a tag');
		this.option.inject(this.video_tag_input);
		for(var i=0;i<this.options.tags.length;++i){
			this.option = new Element('option',{'value':i});
			this.option.set('html',this.options.tags[i]);
			this.option.inject(this.video_tag_input);
		}
		
		//set styles
		this.video_category_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_category_input.setStyles({'float':'left','width':'50%'});
		this.video_category_label.set('html','Select Category:');
		this.video_tag_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_tag_input.setStyles({'float':'left','width':'50%'});
		this.video_tag_label.set('html','Select Tag:');
		this.video_tag_container.setStyles({'padding':'5px'});
		this.video_assigned_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_assigned_input.setStyles({'float':'left','width':'50%'});
		this.video_assigned_label.set('html','Assigned Tags:');
		this.video_assigned_container.setStyles({'padding':'5px'});
		
		
		
		//construct HTML
		this.stack.chain(function(){
			this.picture_image_editor.get().inject(this.picture_image_container);
			this.picture_image_container.inject(this.box_content);
			this.video_category_container.inject(this.picture_image_editor.editor_extra_container);
			this.video_category_label.inject(this.video_category_container);
			this.video_category_input.inject(this.video_category_container);
			this.br.clone().inject(this.video_category_container);
			this.video_tag_container.inject(this.picture_image_editor.editor_extra_container);
			this.video_tag_label.inject(this.video_tag_container);
			this.video_tag_input.inject(this.video_tag_container);
			this.br.clone().inject(this.video_tag_container);
			this.video_assigned_container.inject(this.picture_image_editor.editor_extra_container);
			this.video_assigned_label.inject(this.video_assigned_container);
			this.video_assigned_input.inject(this.video_assigned_container);
			this.br.clone().inject(this.video_assigned_container);
		}.bind(this));
		this.stack.callChain();
		//add event
		this.video_tag_input.addEvent('change',function(){
			this.options.assigned_tags[this.options.assigned_tags.length] = this.video_tag_input.getProperty('value');
			this.tags[this.tags.length] = new Tag(this.options.tags[this.video_tag_input.getProperty('value')],this.options.tagid[this.video_tag_input.getProperty('value')],{'onClick':function(){
				
			}.bind(this)});
			this.tags[this.tags.length-1].getEl().inject(this.video_assigned_input);
		}.bind(this));
		
		this.picture_image_editor.editor_save_btn.removeEvents();
		this.picture_image_editor.editor_save_btn.addEvent('click',function(e){
			if(this.picture_image_editor.editor_description_textarea.getProperty('value') == '' || this.picture_image_editor.editor_long_textarea.getProperty('value') == ''){
				var alertBox = new AlertBox({'message':'Please enter and description and long description before uploading a photo.','width':300});
				alertBox.open('elastic');
			} else {
				if(this.picture_image_editor.options.image_id == 0){
					var alertBox = new AlertBox({'message':'Please upload an photo first.','width':300});
					alertBox.open('elastic');
				} else {
					if(this.options.assigned_tags.length == 0 || this.video_category_input.getProperty('value') == ''){
						var alertBox = new AlertBox({'message':'Please select a category and add tags before uploading a photo','width':300});
						alertBox.open('elastic');
					} else {
						this.category_id = this.video_category_input.getProperty('value');
						this.picture_image_editor.saveImage();	
					}
				}
			}		
		}.bind(this));
	},
	
	onSave: function(response){
		eval(response);
		if(this.options.media_id == 0){
			var data = '&image_id=' + image_id
					  +'&user_id=' + this.options.user_id
					  +'&description=' + this.options.description
					  +'&description_long='+ this.options.description_long
					  +'&category='+this.video_category_input.getProperty('value')
					  +'&tags='+this.getTagIdList();
					  
			
			var metaData = new Request({'data':data,'url':'index.cfm?action=images.addData&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','onComplete':function(){
				window.location.reload(true);																															 
			}}).send();
		} else {
			var data = '&image_id=' + image_id
					  +'&user_id=' + this.options.user_id
					  +'&description=' + this.options.description
					  +'&description_long='+ this.options.description_long
					  +'&category='+this.category_id
					  +'&remove_category=' + this.options.assigned_category
					  +'&tags='+this.getTagIdList();
					  
			var metaData = new Request({'data':data,'url':'index.cfm?action=images.updateData&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','onComplete':function(){
				window.location.reload(true);
			}}).send();
		}
	},
	
	getTagList: function(){
		var list = '';
		for(var i=0;i<this.tags.length;++i){
			if(i==0){
				if(this.tags[i].getId() != 0){list = list + this.tags[i].get();}
			} else {
				if(this.tags[i].getId() != 0){list = list + ',' + this.tags[i].get();}
			}
		}
		return list;
	},
	
	getTagIdList: function(){
		var list = '';
		for(var i=0;i<this.tags.length;++i){
			//list = list + this.tags[i].getId();
			if(i==0){
				if(this.tags[i].getId() != 0){list = list + this.tags[i].getId();}
			} else {
				if(this.tags[i].getId() != 0){list = list + ',' + this.tags[i].getId();}
			}
		}
		return list;
	},
	
	getOldTagIdList: function(){
		var list = '';
		for(var i=0;i<this.options.assigned_tags.length;++i){
			if(i==0){
				if(this.options.assigned_tags[i] != 0){list = list + this.options.assigned_tags[i];}
			} else {
				if(this.options.assigned_tags[i] != 0){list = list + ',' + this.options.assigned_tags[i];}
			}
		}
		return list;
	}
	
});







TravelBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'id':0,
		'image_id': 0,
		'image_name':'obray_placeHolder',
		'image_ext': '.jpg',
		'description':'Place Holder',
		'window_height': 461,
		'window_width': 392,
		'window_max_width': 392,
		'window_max_height': 461,
		'zoom_level': 300,
		'resizable': false,
		'offset_x': 0,
		'offset_y': 0,
		'onSave':this.onSave,
		'media_id':0,
		'src':'obray/images/obray_placeHolder.jpg',
		'description_long':'',
		'deletefn': false,
		'onDelete':$empty,
		'categories':[],
		'categoryid':[],
		'assigned_category':0,
		'tags':[],
		'tagid':[],
		'assigned_tags':[],
		'link':false,
		'follow_link':false
	},
	
	initialize: function(options){
		
		//data emembers
		this.setOptions(options);
		this.parent(options);
		this.tags = [];
		
		//generate HTML
		this.picture_image_container = new Element('div',{'class':'product_image_container'});
		this.picture_image_editor = new ImageEditor(this.stack,{
			'image_id': this.options.image_id,
			'image_name':this.options.image_name,
			'image_ext': this.options.image_ext,
			'description':this.options.description,
			'window_height': this.options.window_height,
			'window_width': this.options.window_width,
			'window_max_width': this.options.window_max_width,
			'window_max_height': this.options.window_max_height,
			'zoom_level': this.options.zoom_level,
			'resizable': this.options.resizable,
			'offset_x': this.options.offset_x,
			'offset_y': this.options.offset_y,
			'onSave': this.onSave.bind(this),
			'src':this.options.src,
			'description_long':this.options.description_long,
			'thumb_size_x': 90,
			'thumb_size_y': 68,
			'delete':this.options.deletefn,
			'onDelete':this.options.onDelete,
			'link': this.options.link,
			'follow_link':this.options.follow_link,
			'price_per_night':0
		});
		this.video_category_container = new Element('div',{'class':'category_container'});
		this.video_category_label = new Element('div',{'class':'category_label'});
		this.video_category_input = new Element('select',{'class':'category_input'});
		this.video_tag_container = new Element('div',{'class':'tag_container'});
		this.video_tag_label = new Element('div',{'class':'tag_label'});
		this.video_tag_input = new Element('select',{'class':'tag_input'});
		this.video_assigned_container = new Element('div',{'class':'tag_container'});
		this.video_assigned_label = new Element('div',{'class':'tag_label'});
		this.video_assigned_input = new Element('div',{'class':'tag_input'});
		this.video_price_container = new Element('div',{'class':'tag_container'});
		this.video_price_label = new Element('div',{'class':'tag_label'});
		this.video_price_input = new Element('input',{'name':'video_price_input','type':'text','class':'tag_input'});
		
		this.br = new Element('br',{'class':'clearboth'})
		
		//assigned tags
		for(var i=0;i<this.options.assigned_tags.length;++i){
			
			this.box_m.setStyles({'height':'auto'});
			var tagName = '';
			for(var j=0;j<this.options.tagid.length;++j){
				if(this.options.assigned_tags[i] == this.options.tagid[j]){
					tagName = this.options.tags[j];
				}
			}
			this.tags[this.tags.length] = new Tag(tagName,this.options.assigned_tags[i],{'onClick':function(i){
				var removeTag = new Request({'url':'index.cfm?action=videos.removeTag&mediaId='+this.options.media_id + '&tagId=' + this.options.assigned_tags[i]}).send();
			}.bind(this,i)});
			this.tags[this.tags.length-1].getEl().inject(this.video_assigned_input);
		}
		
		//category options
		this.option = new Element('option',{'value':''});
		this.option.set('html','Select a Category');
		this.option.inject(this.video_category_input);
		for(var i=0;i<this.options.categories.length;++i){
			this.option = new Element('option',{'value':this.options.categoryid[i]});
			if(this.options.categoryid[i] == this.options.assigned_category){
				this.option.setProperty('selected','selected');
			}
			this.option.set('html',this.options.categories[i]);
			this.option.inject(this.video_category_input);
		}
		this.video_price_input.setProperty('value',this.options.price_per_night);
		
		//tag options
		this.option = new Element('option',{'value':''});
		this.option.set('html','Select a tag');
		this.option.inject(this.video_tag_input);
		for(var i=0;i<this.options.tags.length;++i){
			this.option = new Element('option',{'value':i});
			this.option.set('html',this.options.tags[i]);
			this.option.inject(this.video_tag_input);
		}
		
		//set styles
		this.video_category_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_category_input.setStyles({'float':'left','width':'50%'});
		this.video_category_label.set('html','Select Category:');
		this.video_tag_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_tag_input.setStyles({'float':'left','width':'50%'});
		this.video_tag_label.set('html','Select Tag:');
		this.video_tag_container.setStyles({'padding':'5px'});
		this.video_assigned_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_assigned_input.setStyles({'float':'left','width':'50%'});
		this.video_assigned_label.set('html','Assigned Tags:');
		this.video_assigned_container.setStyles({'padding':'5px'});
		this.video_price_label.setStyles({'float':'left','font-family':'arial','font-size':'14px','color':'#aaaaaa','width':'40%','text-align':'right','padding-top':'3px'});
		this.video_price_input.setStyles({'float':'left','width':'50%'});
		this.video_price_label.set('html','Price Per Night:');
		this.video_price_container.setStyles({'padding':'5px'});
		
		//construct HTML
		this.stack.chain(function(){
			this.picture_image_editor.get().inject(this.picture_image_container);
			this.picture_image_container.inject(this.box_content);
			this.video_category_container.inject(this.picture_image_editor.editor_extra_container);
			this.video_category_label.inject(this.video_category_container);
			this.video_category_input.inject(this.video_category_container);
			this.br.clone().inject(this.video_category_container);
			this.video_tag_container.inject(this.picture_image_editor.editor_extra_container);
			this.video_tag_label.inject(this.video_tag_container);
			this.video_tag_input.inject(this.video_tag_container);
			this.br.clone().inject(this.video_tag_container);
			this.video_assigned_container.inject(this.picture_image_editor.editor_extra_container);
			this.video_assigned_label.inject(this.video_assigned_container);
			this.video_assigned_input.inject(this.video_assigned_container);
			this.br.clone().inject(this.video_assigned_container);
			this.video_price_container.inject(this.picture_image_editor.editor_extra_container);
			this.video_price_label.inject(this.video_assigned_container);
			this.video_price_input.inject(this.video_assigned_container);
			this.br.clone().inject(this.video_price_container);
		}.bind(this));
		this.stack.callChain();
		
		//add event
		this.video_tag_input.addEvent('change',function(){
			this.box_m.setStyles({'height':'auto'});
			this.options.assigned_tags[this.options.assigned_tags.length] = this.video_tag_input.getProperty('value');
			this.tags[this.tags.length] = new Tag(this.options.tags[this.video_tag_input.getProperty('value')],this.options.tagid[this.video_tag_input.getProperty('value')],{'onClick':function(){
				
			}.bind(this)});
			this.tags[this.tags.length-1].getEl().inject(this.video_assigned_input);
		}.bind(this));
	},
	
	onSave: function(response){
		eval(response);
			
			if(this.options.media_id == 0){
			var data = '&image_id=' + image_id
					  +'&user_id=' + this.options.user_id
					  +'&description=' + this.options.description
					  +'&description_long='+ this.options.description_long
					  +'&category='+this.video_category_input.getProperty('value')
					  +'&tags='+this.getTagIdList()
					  +'&price_per_night='+this.video_price_input.getProperty('value');
			var metaData = new Request({'data':data,'url':'index.cfm?action=travel.addData','onComplete':function(){window.location.reload(true);}}).send();
		} else {
			var data = '&image_id=' + image_id
					  +'&user_id=' + this.options.user_id
					  +'&description=' + this.options.description
					  +'&description_long='+ this.options.description_long
					  +'&category='+this.video_category_input.getProperty('value')
					  +'&remove_category=' + this.options.assigned_category
					  +'&tags='+this.getTagIdList()
					  +'&price_per_night='+this.video_price_input.getProperty('value')
					  +'&media_id='+this.options.media_id;
			var metaData = new Request({'data':data,'url':'index.cfm?action=travel.updateData','onComplete':function(){window.location.reload(true);}}).send();
		}
		
	},
	
	getTagList: function(){
		var list = '';
		for(var i=0;i<this.tags.length;++i){
			if(i==0){
				if(this.tags[i].getId() != 0){list = list + this.tags[i].get();}
			} else {
				if(this.tags[i].getId() != 0){list = list + ',' + this.tags[i].get();}
			}
		}
		return list;
	},
	
	getTagIdList: function(){
		var list = '';
		for(var i=0;i<this.tags.length;++i){
			//list = list + this.tags[i].getId();
			if(i==0){
				if(this.tags[i].getId() != 0){list = list + this.tags[i].getId();}
			} else {
				if(this.tags[i].getId() != 0){list = list + ',' + this.tags[i].getId();}
			}
		}
		return list;
	},
	
	getOldTagIdList: function(){
		var list = '';
		for(var i=0;i<this.options.assigned_tags.length;++i){
			if(i==0){
				if(this.options.assigned_tags[i] != 0){list = list + this.options.assigned_tags[i];}
			} else {
				if(this.options.assigned_tags[i] != 0){list = list + ',' + this.options.assigned_tags[i];}
			}
		}
		return list;
	}
	
});


MessageBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'message': "message..."
	},
	
	initialize: function(options){
		
		//data emembers
		this.setOptions(options);
		this.parent(options);
		
		
		this.box_message = new Element('div',{'class':'box_message'});
		this.box_message.set('html',this.options.message);
		
		//set styles
		this.box_message.setStyles({'font-family':'Arial','font-size':'14px','padding':'10px'});
		
		this.box_message.inject(this.box_content);
		
	}
})

LoadingBox = new Class({
	Extends: Box,
	
	Implements: Options,
	
	options:{
		'message': "message..."
	},
	
	initialize: function(options){
		
		//data emembers
		this.setOptions(options);
		this.parent(options);
		
		this.container = new Element('div',{'class':'box_container'});
		this.box_message = new Element('div',{'class':'box_message'});
		this.box_animation = new Element('img',{'src':'obray/images/loaders/loading_animation_25x25.gif'});
		this.box_message.set('html',this.options.message);
		
		//set styles
		this.container.setStyles({'width':'580px'});
		this.box_message.setStyles({'float':'left','font-family':'Arial','font-size':'18px','padding':'3px','padding-left':'25px','width':'500px'});
		this.box_animation.setStyles({'float':'left','width':'25px'});
		
		this.box_animation.inject(this.container);
		this.box_message.inject(this.container);
		this.container.inject(this.box_content);
	}
});



/***********************************************
	fBox - Fixed Position Box
************************************************/
fBox = new Class({
	Implements: Options,
	
	options: {
		'content_width':800
	},
	
	initialize: function(options){
		//set options
		this.setOptions(options);
		//fbox
		this.fbox = new Element('div',{'class':'fbox'});
		this.fbox.setStyles({'position':'fixed','top':50,'left':50,'padding':10,'width':document.body.getCoordinates().width-120,'height':document.body.getCoordinates().height-120,'background-color':'#1b1b19','border':'0px solid #4b4b49','z-index':5000});
		
		this.fbox_window = new Element('div',{'class':'fbox-window'});
		this.fbox_window.setStyles({'position':'relative','width':document.body.getCoordinates().width-120,'height':document.body.getCoordinates().height-120,'border':'0px solid #4b4b49','overflow':'hidden'});
		this.fbox_window.inject(this.fbox);
		
		this.fbox_content = new Element('div',{'class':'fbox-content'});
		this.fbox_content.setStyles({'width':this.options.content_width,'margin':'0 auto','border':'0px solid #4b4b49'});
		this.fbox_content.inject(this.fbox_window);
		
		window.addEvent('resize',function(){
			this.fbox.setStyles({'width':document.body.getCoordinates().width-100,'height':document.body.getCoordinates().height-100});
			this.fbox_window.setStyles({'width':document.body.getCoordinates().width-120,'height':document.body.getCoordinates().height-120});
			if(this.fbox_window.getCoordinates().width < this.fbox_content.getCoordinates().width || this.fbox_window.getCoordinates().height < this.fbox_content.getCoordinates().height){
				this.fbox_window.setStyles({'overflow':'scroll'});
			} else {
				this.fbox_window.setStyles({'overflow':'hidden'});
			}
		}.bind(this));
	},
	
	readjust: function(){
		this.fbox.setStyles({'width':document.body.getCoordinates().width-100,'height':document.body.getCoordinates().height-100});
		this.fbox_window.setStyles({'width':document.body.getCoordinates().width-120,'height':document.body.getCoordinates().height-120});
		if(this.fbox_window.getCoordinates().width < this.fbox_content.getCoordinates().width || this.fbox_window.getCoordinates().height < this.fbox_content.getCoordinates().height){
			this.fbox_window.setStyles({'overflow':'scroll'});
		} else {
			this.fbox_window.setStyles({'overflow':'hidden'});
		}
	},
	
	open: function(){
		this.fbox.inject(document.body);
	},
	
	close: function(){
		this.fbox.destroy();
	}
});

/***********************************************
	fBox - Fixed Position Box
************************************************/
pBox = new Class({
	Implements: Options,
	
	options: {
		'content_width':800,
		'position_x':0,
		'position_y':0
	},
	
	initialize: function(options){
		//set options
		this.setOptions(options);
		//fbox
		this.pbox = new Element('div',{'class':'fbox'});
		this.pbox.setStyles({'position':'fixed','top':50,'left':50,'padding':10,'width':document.body.getCoordinates().width-120,'height':document.body.getCoordinates().height-120,'background-color':'#1b1b19','border':'0px solid #4b4b49','z-index':5000});
		
		this.pbox_window = new Element('div',{'class':'fbox-window'});
		this.pbox_window.setStyles({'position':'relative','width':document.body.getCoordinates().width-120,'height':document.body.getCoordinates().height-120,'border':'0px solid #4b4b49','overflow':'hidden'});
		this.pbox_window.inject(this.pbox);
		
		this.pbox_content = new Element('div',{'class':'fbox-content'});
		this.pbox_content.setStyles({'width':this.options.content_width,'margin':'0 auto','border':'0px solid #4b4b49'});
		this.pbox_content.inject(this.pbox_window);
		
		window.addEvent('resize',function(){
			this.pbox.setStyles({'width':document.body.getCoordinates().width-100,'height':document.body.getCoordinates().height-100});
			this.pbox_window.setStyles({'width':document.body.getCoordinates().width-120,'height':document.body.getCoordinates().height-120});
			if(this.pbox_window.getCoordinates().width < this.pbox_content.getCoordinates().width || this.pbox_window.getCoordinates().height < this.pbox_content.getCoordinates().height){
				this.pbox_window.setStyles({'overflow':'scroll'});
			} else {
				this.pbox_window.setStyles({'overflow':'hidden'});
			}
		}.bind(this));
		
		
	},
	
	readjust: function(){
		this.pbox.setStyles({'width':document.body.getCoordinates().width-100,'height':document.body.getCoordinates().height-100});
		this.pbox_window.setStyles({'width':document.body.getCoordinates().width-120,'height':document.body.getCoordinates().height-120});
		if(this.pbox_window.getCoordinates().width < this.pbox_content.getCoordinates().width || this.pbox_window.getCoordinates().height < this.pbox_content.getCoordinates().height){
			this.pbox_window.setStyles({'overflow':'scroll'});
		} else {
			this.pbox_window.setStyles({'overflow':'hidden'});
		}
	},
	
	open: function(){
		this.pbox.inject(document.body);
	},
	
	close: function(){
		this.pbox.destroy();
	}
});

scrollBox = new Class({
	Implements: Options,
	
	options: {
		'width':500,
		'height':500,
		'background_color':'rgb(26, 26, 26)'
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.scroll_position = 0;
        this.scroll_size = 0;
        this.interval = 0;
		        
		this.box = new Element('div',{'class':'oscrollbox'});
		this.box.setStyles({'width':this.options.width,'height':this.options.height,'position':'relative'});
		
		this.content = new Element('div',{'class':'oscrollbox-content'});
		this.content.setStyles({'position':'relative','width':'100%','height':'100%','overflow-x':'hidden','overflow-y':'hidden','background-color':this.options.background_color});
		this.content.inject(this.box);
		this.contentScroll = new Fx.Scroll(this.content,{'duration':10});
		
		this.scrollbar = new Element('div',{'class':'oscroll'});
        this.scrollbar.setStyles({'background-position':'-15px 0px','position':'absolute','opacity':0,'right':-7,'top':0,'width':15,'cursor':'pointer','background-image':'url(obray/images/box/sbox/scrollbar-bg.png)'});
        this.scrollbar.inject(this.box);
       
        this.scrollbar_handle = new Element('div',{'class':'oscroll-handle'});
        this.scrollbar_handle.setStyles({'background-image':'url(obray/images/box/sbox/scrollbar.png)','width':14,'height':64,'overflow':'hidden'});
        this.scrollbar_handle.inject(this.scrollbar);
        this.scrollbar_handle.addEvent('mouseenter',function(){ this.scrollbar_handle.setStyles({'background-position':'-15px 0px'}); }.bind(this));
        this.scrollbar_handle.addEvent('mouseleave',function(){ this.scrollbar_handle.setStyles({'background-position':'0px 0px'}); }.bind(this));

        this.scrollbar_top = new Element('div',{'class':'oscroll-top'});
        this.scrollbar_top.setStyles({'position':'absolute','right':6,'top':0,'width':3,'height':4,'background-image':'url(obray/images/box/sbox/scrollbar-top.png)'});
        this.scrollbar_top.inject(this.scrollbar);
        
        this.scrollbar_bottom = new Element('div',{'class':'oscroll-bottom'});
        this.scrollbar_bottom.setStyles({'position':'absolute','right':6,'bottom':2,'width':3,'height':4,'background-image':'url(obray/images/box/sbox/scrollbar-bottom.png)'});
        this.scrollbar_bottom.inject(this.scrollbar);
        
         this.content.addEvent('mousewheel',function(e){
            this.scroll_position = this.scroll_position-e.wheel;
            try{this.scrollbar_slider.set(this.scroll_position);} catch(err){}
        }.bind(this));
        
	},
	
	adjustScrollHeight: function(){
        if(this.scroll_size != this.content.getScrollSize().y-this.options.height){
            this.scrollbar.setStyles({'opacity':1});
            this.scrollbar_slider = new Slider(this.scrollbar,this.scrollbar_handle,{'mode':'vertical','steps':this.content.getScrollSize().y-this.options.height,'onChange':function(step){
                this.contentScroll.set(0,step);
                this.scroll_position = step;
            }.bind(this)});
            this.scroll_size = this.content.getScrollSize().y-this.options.height;
            this.scrollbar_slider.set(this.scroll_position);
        }
        if(this.content.getScrollSize().y-this.options.height <= 0){
            this.scrollbar.setStyles({'opacity':0});
        }
    },
    
    scrollUp: function(distance){
        this.contentScroll.pause();
        var scroll_to = this.content.getScrollSize().y-this.options.height+distance-50;
    },
    
    scrollDown: function(distance){
        this.contentScroll.pause();
        var scroll_to = (this.content.getScrollSize().y-this.options.height-distance-15);
        this.contentScroll.toBottom()
    },

    center: function(){
        var x = document.body.getCoordinates().width/2;
        var y = document.body.getCoordinates().height/2;
        return {'x':x-20,'y':y};
    },
	
	inject: function(el){
		this.box.inject(el);
		this.scrollbar.setStyles({'height':this.options.height});
		$clear(this.interval);
		this.interval = this.adjustScrollHeight.periodical(500,this);
	}
})
				


sbox = new Class({
    Implements: Options,
    
    options: {
        'width':500,
        'height':500,
        'startx':($(window).getCoordinates().width/2),
        'starty':($(window).getCoordinates().height/2),
        'scroll':true,
        'zIndex':4999,
        'primary_color':'#101010',
        'secondary_color':'#1a1a1a',
        'close':$empty,
        'scrollable':true,
		'show-close-btn':true,
		'show_overflow':false,
		'unique_id':0,
		'sbox_class':'sbox'
    },
    
    initialize: function(options){
        
        this.setOptions(options);
        
        this.scroll_position = 0;
        this.br = new Element('br',{'class':'clear'});
        this.scroll_size = 0;
        // background
        
        this.body = $$('body');
        
        this.box_background = new Element('div',{'class':'sbox-background'});
        this.box_background.setStyles({'display':'none','position':'fixed','background-image':'url(obray/images/box/sbox/bg.png)','left':0,'top':0,'width':document.body.getCoordinates().width,'height':document.body.getCoordinates().height+9,'z-index':4998});
        // box
        this.box = new Element('div',{'class':this.options.sbox_class,'id':'sbox'+this.options.unique_id});
        this.box.setStyles({'position':'fixed','width':0,'height':0,'left':this.options.startx,'top':this.options.starty,'margin-left':0,'background-color':'transparent','z-index':this.options.zIndex,'-webkit-border-bottom-left-radius':'5px','-webkit-border-bottom-right-radius': '5px','-webkit-border-top-left-radius': '5px','-webkit-border-top-right-radius': '5px','-moz-border-radius':'5px 5px 5px 5px','background-color':this.options.primary_color,'padding':10,'opacity':0});
        // content
        this.content = new Element('div',{'class':'box-content'});
		if(this.options.show_overflow == true) this.content.setStyles({'position':'relative','width':'100%','height':'100%','overflow-x':'visible','overflow-y':'visible','overflow':'visible','scrollbar-base-color':'#369','background-color':this.options.secondary_color});
		else this.content.setStyles({'position':'relative','width':'100%','height':'100%','overflow-x':'hidden','overflow-y':'hidden','scrollbar-base-color':'#369','background-color':this.options.secondary_color});
        this.content.inject(this.box);
        this.contentScroll = new Fx.Scroll(this.content,{'duration':10});
        
        this.scrollbar = new Element('div',{'class':'oscroll'});
        this.scrollbar.setStyles({'background-position':'-15px 0px','position':'absolute','opacity':0,'right':5,'top':15,'width':15,'cursor':'pointer','background-image':'url(obray/images/box/sbox/scrollbar-bg.png)'});
        this.scrollbar.inject(this.box);
       
        this.scrollbar_handle = new Element('div',{'class':'oscroll-handle'});
        this.scrollbar_handle.setStyles({'background-image':'url(obray/images/box/sbox/scrollbar.png)','width':14,'height':64,'overflow':'hidden'});
        this.scrollbar_handle.inject(this.scrollbar);
        this.scrollbar_handle.addEvent('mouseenter',function(){ this.scrollbar_handle.setStyles({'background-position':'-15px 0px'}); }.bind(this));
        this.scrollbar_handle.addEvent('mouseleave',function(){ this.scrollbar_handle.setStyles({'background-position':'0px 0px'}); }.bind(this));

        this.scrollbar_top = new Element('div',{'class':'oscroll-top'});
        this.scrollbar_top.setStyles({'position':'absolute','right':6,'top':0,'width':3,'height':4,'background-image':'url(obray/images/box/sbox/scrollbar-top.png)'});
        this.scrollbar_top.inject(this.scrollbar);
        
        this.scrollbar_bottom = new Element('div',{'class':'oscroll-bottom'});
        this.scrollbar_bottom.setStyles({'position':'absolute','right':6,'bottom':2,'width':3,'height':4,'background-image':'url(obray/images/box/sbox/scrollbar-bottom.png)'});
        this.scrollbar_bottom.inject(this.scrollbar);
                
        this.content.addEvent('mousewheel',function(e){
            this.scroll_position = this.scroll_position-e.wheel;
            try{this.scrollbar_slider.set(this.scroll_position);} catch(err){}
        }.bind(this));
        
        this.interval = 0;
        
        this.boxFx = new Fx.Morph(this.box,{'duration':800,'transition':Fx.Transitions.Quint.easeOut,'onComplete':function(){
            this.scrollbar.setStyles({'height':this.options.height});
            $clear(this.interval);
            this.interval = this.adjustScrollHeight.periodical(500,this);
        }.bind(this)});
        
        // close button
		if(this.options['show-close-btn'] == true){
			this.close_btn = new Element('div',{'class':'close-btn'});
			this.close_btn.setStyles({'position':'absolute','right':-10,'top':-10,'background-image':'url(obray/images/box/boxClose_btn.png)','width':30,'height':30,'cursor':'pointer','z-index':5010});
			this.close_btn.inject(this.box);
			this.close_btn.addEvent('click',function(){ this.close(); }.bind(this));
		}
        // adjust for changing scroll height
        
        // resize event
        window.addEvent('resize',function(){
            this.box_background.setStyles({'width':document.body.getCoordinates().width,'height':document.body.getCoordinates().height+9})
            this.box.setStyles({'left':this.center().x,'top':this.center().y});
        }.bind(this))
        
        
        
    },
    
    adjustScrollHeight: function(){
        if(this.scroll_size != this.content.getScrollSize().y-this.options.height){
            this.scrollbar.setStyles({'opacity':1});
            this.scrollbar_slider = new Slider(this.scrollbar,this.scrollbar_handle,{'mode':'vertical','steps':this.content.getScrollSize().y-this.options.height,'onChange':function(step){
                this.contentScroll.set(0,step);
                this.scroll_position = step;
            }.bind(this)});
            this.scroll_size = this.content.getScrollSize().y-this.options.height;
            this.scrollbar_slider.set(this.scroll_position);
        }
        if(this.content.getScrollSize().y-this.options.height <= 0){
            this.scrollbar.setStyles({'opacity':0});
        }
    },
    
    scrollUp: function(distance){
        this.contentScroll.pause();
        var scroll_to = this.content.getScrollSize().y-this.options.height+distance-50;
    },
    
    scrollDown: function(distance){
        this.contentScroll.pause();
        var scroll_to = (this.content.getScrollSize().y-this.options.height-distance-15);
        this.contentScroll.toBottom()
    },

    center: function(){
        var x = document.body.getCoordinates().width/2;
        var y = document.body.getCoordinates().height/2;
        return {'x':x-20,'y':y};
    },
    
    open: function(){
        var body = $(document.body);
        this.box.inject(body);
        this.box_background.inject(body);
        document.body.setStyles({'overflow':'hidden'})
        this.box_background.setStyles({'display':'block'});
        this.box.setStyles({'display':'block'});
        //document.body.setStyles({'overflow-y':'hidden'});
        this.boxFx.pause();
        this.boxFx.start({'left':this.center().x,'top':this.center().y,'width':this.options.width,'height':this.options.height,'opacity':1,'margin-left':-(this.options.width/2),'margin-top':-(this.options.height/2)});
    },
    
    close: function(){
        this.options.close();
        this.boxFx.pause();
        this.boxFx.start({'left':this.options.startx,'top':this.options.starty,'width':0,'height':0,'opacity':0,'margin-left':0,'margin-top':0}).chain(function(){}.bind(this));
        this.box_background.setStyles({'display':'none'});
        if(this.options.scroll){document.body.setStyles({'overflow':'scroll'});}
    }
});

sboxConfirm = new Class({
	Implements: Options,
	
	options:{
		'confirm-message':'Are you sure you want to do that?',
		'onConfirm':$empty
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.box = new Element('div',{'class':'sboxconfirm'});
		this.box.setStyles({'position':'fixed','background-color':'#000000','height':150,'width':300,'-webkit-border-radius':'5px 5px 5px 5px','-moz-border-radius':'5px 5px 5px 5px','z-index':6000,'opacity':.90});
		
		this.box_content = new Element('div',{'class':'sboxconfirm'});
		this.box_content.set('html',this.options['confirm-message']);
		this.box_content.setStyles({'border-bottom':'1px solid #222222','font-family':'Arial,Helvetica','font-size':14,'position':'relative','width':280,'height':90,'padding':10,'text-align':'center','color':'#a5a5a5'});
		this.box_content.inject(this.box);
		
		this.confirm_btn = new Element('input',{'type':'button','class':'sboxconfirm-btn','value':'Yes'});
		this.confirm_btn.setStyles({'cursor':'pointer','position':'absolute','bottom':-40,'left':0,'font-size':14,'font-family':'Arial,Helvetica','border':'1px outset #353535','background-color':'#222222','color':'#858585','-webkit-border-radius':'5px 5px 5px 5px','-moz-border-radius':'5px 5px 5px 5px','padding':5,'margin':5,'width':150});
		this.confirm_btn.inject(this.box_content);
		
		this.confirm_btn.addEvent('click',function(){
			this.options.onConfirm();
			this.close();
		}.bind(this));
		
		this.cancel_btn = new Element('input',{'type':'button','class':'sboxconfirm-cancel-btn','value':'No'})
		this.cancel_btn.setStyles({'cursor':'pointer','position':'absolute','bottom':-40,'left':240,'font-size':14,'font-family':'Arial,Helvetica','border':'1px outset #353535','background-color':'#222222','color':'#858585','-webkit-border-radius':'5px 5px 5px 5px','-moz-border-radius':'5px 5px 5px 5px','padding':5,'margin':5,'width':50});
		this.cancel_btn.inject(this.box_content);
		
		this.cancel_btn.addEvent('click',function(){
			this.close();
		}.bind(this));
	},
	
	open: function(){
		this.box.setStyles({'left':this.center().x-150,'top':this.center().y-75})
        var body = $(document.body);
        this.box.inject(body);
        this.box.setStyles({'display':'block'});
	},
	
	close: function(){
		this.box.setStyles({'display':'none'});
	},
	
	center: function(){
		
        var x = window.getWidth()/2;
        var y = window.getHeight()/2;
        return {'x':x-20,'y':y};
    }
});




AlertBox = new Class({
	Extends: sbox,
	
	Implements: Options,
	
	options:{
		'message':'Are you sure?',
		'onClose':function(){$empty();},
		'primary_color':'#ffffff',
		'secondary_color':'#ffffff',
		'width':400,
		'height':200
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		
		this.options.width = 450;
		this.options.height = 200;
		
		//genereate HTML
		this.alert_container = new Element('div',{'class':'alert_container','id':'alert_container'+this.options.unique_id});
		this.alert_icon = new Element('img',{'src':'obray/images/box/icon_error.png','class':'alert_icon'});
		this.alert_message = new Element('div',{'class':'alert_message'});
		this.alert_buttons = new Element('div',{'class':'alert_buttons'});
		this.alert_btn = new Element('div',{'class':'alert_btn'});
		this.br = new Element('br',{'class':'clear'});
		
		//set properties
		this.alert_message.set('html',this.options.message);
		this.alert_btn.set('html','Close');
		
		//set styles
		this.alert_container.setStyles({'padding-top':'10px','width':500})
		this.alert_icon.setStyles({'float':'left','margin':'10px'});
		this.alert_message.setStyles({'text-align':'left','float':'left','width':this.options.width-57-40,'color':'#000000','margin':'0 auto','font-family':'arial','padding':'10px','font-size':'12px'});
		this.alert_buttons.setStyles({'margin':'0 auto','width':'100px','padding':'10px','padding-top':'20px','color':'#888888','font-family':'Arial'});
		this.alert_btn.setStyles({'text-align':'center','padding-right':'10px','padding-left':'10px','cursor':'pointer'});
		
		//construct HTML
		this.alert_container.inject(this.content);
		this.alert_icon.inject(this.alert_container);
		this.alert_message.inject(this.alert_container);
		this.alert_btn.inject(this.alert_buttons);
		this.alert_buttons.inject(this.alert_container);
		this.br.inject(this.alert_container);
		
		//add event
		this.alert_btn.addEvent('click',function(){
			this.options.onClose();
			this.close();
		}.bind(this));
		this.alert_btn.addEvent('mouseenter',function(){
			this.alert_btn.setStyles({'color':'#333333'});
		}.bind(this));
		this.alert_btn.addEvent('mouseleave',function(){
			this.alert_btn.setStyles({'color':'#888888'});
		}.bind(this));
	}
});


StatusBox = new Class({
	Extends: sbox,
	
	Implements: Options,
	
	options:{
		'message':'Loading...',
		'onClose':function(){$empty();},
		'primary_color':'#000000',
		'secondary_color':'#000000',
		'width':200,
		'height':75
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		
		
		this.close_btn
		
		//genereate HTML
		this.alert_container = new Element('div',{'class':'alert_container','id':'alert_container'+this.options.unique_id});
		this.alert_icon = new Element('img',{'src':'obray/images/loaders/loader-standard.gif','class':'alert_icon'});
		this.alert_message = new Element('div',{'class':'alert_message'});
		this.br = new Element('br',{'class':'clear'});
		
		//set properties
		this.alert_message.set('html',this.options.message);
		
		//set styles
		this.alert_container.setStyles({'padding-top':'10px','width':this.options.width,'opacity':.75,'color':'#ffffff'});
		this.alert_icon.setStyles({'float':'left','margin':'10px'});
		this.alert_message.setStyles({'text-align':'left','float':'left','width':this.options.width-57-40,'color':'#ffffff','margin':'0 auto','font-family':'arial','padding':'10px','font-size':'12px'});
		
		//construct HTML
		this.alert_container.inject(this.content);
		this.alert_icon.inject(this.alert_container);
		this.alert_message.inject(this.alert_container);
		this.br.inject(this.alert_container);
		
	}
}); cabox = new Class({
    Implements: Options,
    
    options: {
        'width':500,
        'height':500,
        'startx':($(window).getCoordinates().width/2),
        'starty':($(window).getCoordinates().height/2),
        'scroll':true,
        'zIndex':4999,
        'primary_color':'#101010',
        'secondary_color':'#1a1a1a',
		'page_id':0,
        'close':$empty,
        'scrollable':true,
		'show-close-btn':true,
		'show_overflow':false,
		'unique_id':0,
		'sbox_class':'sbox',
		'ext_parameter':'',
		'submit_once':false,
		'box_content':'',
		'url':''
    },
    
    initialize: function(options){
        
        this.setOptions(options);
        this.submitted = 0;
        this.scroll_position = 0;
        this.br = new Element('br',{'class':'clear'});
        this.scroll_size = 0;
        // background
        
        this.body = $$('body');
        
        this.box_background = new Element('div',{'class':'sbox-background'});
        this.box_background.setStyles({'display':'none','position':'fixed','background-image':'url(obray/images/box/sbox/bg.png)','left':0,'top':0,'width':document.body.getCoordinates().width,'height':document.body.getCoordinates().height+9,'z-index':4998});
        // box
        this.box = new Element('div',{'class':this.options.sbox_class,'id':'sbox'+this.options.unique_id});
        this.box.setStyles({'position':'fixed','width':0,'height':0,'left':this.options.startx,'top':this.options.starty,'margin-left':0,'background-color':'transparent','z-index':this.options.zIndex,'-webkit-border-bottom-left-radius':'5px','-webkit-border-bottom-right-radius': '5px','-webkit-border-top-left-radius': '5px','-webkit-border-top-right-radius': '5px','-moz-border-radius':'5px 5px 5px 5px','background-color':this.options.primary_color,'padding':10,'opacity':0});
        // content
        this.content = new Element('div',{'class':'box-content'});
		if(this.options.show_overflow == true) this.content.setStyles({'position':'relative','width':'100%','height':'100%','overflow-x':'visible','overflow-y':'visible','overflow':'visible','scrollbar-base-color':'#369','background-color':this.options.secondary_color});
		else this.content.setStyles({'position':'relative','width':'100%','height':'100%','overflow-x':'hidden','overflow-y':'hidden','scrollbar-base-color':'#369','background-color':this.options.secondary_color});
		if(this.options.url != '') var myRequest = new Request.HTML({'url':'/index.cfm?action=pages.popupContentArea&page_id='+this.options.page_id, 'evalScripts':true, 'update':this.content}).send();
		
        this.content.inject(this.box);
        this.contentScroll = new Fx.Scroll(this.content,{'duration':10});
        
        this.scrollbar = new Element('div',{'class':'oscroll'});
        this.scrollbar.setStyles({'background-position':'-15px 0px','position':'absolute','opacity':0,'right':5,'top':15,'width':15,'cursor':'pointer','background-image':'url(obray/images/box/sbox/scrollbar-bg.png)'});
        this.scrollbar.inject(this.box);
       
        this.scrollbar_handle = new Element('div',{'class':'oscroll-handle'});
        this.scrollbar_handle.setStyles({'background-image':'url(obray/images/box/sbox/scrollbar.png)','width':14,'height':64,'overflow':'hidden'});
        this.scrollbar_handle.inject(this.scrollbar);
        this.scrollbar_handle.addEvent('mouseenter',function(){ this.scrollbar_handle.setStyles({'background-position':'-15px 0px'}); }.bind(this));
        this.scrollbar_handle.addEvent('mouseleave',function(){ this.scrollbar_handle.setStyles({'background-position':'0px 0px'}); }.bind(this));

        this.scrollbar_top = new Element('div',{'class':'oscroll-top'});
        this.scrollbar_top.setStyles({'position':'absolute','right':6,'top':0,'width':3,'height':4,'background-image':'url(obray/images/box/sbox/scrollbar-top.png)'});
        this.scrollbar_top.inject(this.scrollbar);
        
        this.scrollbar_bottom = new Element('div',{'class':'oscroll-bottom'});
        this.scrollbar_bottom.setStyles({'position':'absolute','right':6,'bottom':2,'width':3,'height':4,'background-image':'url(obray/images/box/sbox/scrollbar-bottom.png)'});
        this.scrollbar_bottom.inject(this.scrollbar);
                
        this.content.addEvent('mousewheel',function(e){
            this.scroll_position = this.scroll_position-e.wheel;
            try{this.scrollbar_slider.set(this.scroll_position);} catch(err){}
        }.bind(this));
        
        this.interval = 0;
        
        this.boxFx = new Fx.Morph(this.box,{'duration':800,'transition':Fx.Transitions.Quint.easeOut,'onComplete':function(){
            this.scrollbar.setStyles({'height':this.options.height});
            $clear(this.interval);
            this.interval = this.adjustScrollHeight.periodical(500,this);
        }.bind(this)});
        
        // close button
		if(this.options['show-close-btn'] == true){
			this.close_btn = new Element('div',{'class':'close-btn'});
			this.close_btn.setStyles({'position':'absolute','right':-10,'top':-10,'background-image':'url(obray/images/box/boxClose_btn.png)','width':30,'height':30,'cursor':'pointer','z-index':5010});
			this.close_btn.inject(this.box);
			this.close_btn.addEvent('click',function(){ this.close(); }.bind(this));
		}
        // adjust for changing scroll height
        
        // resize event
        window.addEvent('resize',function(){
            this.box_background.setStyles({'width':document.body.getCoordinates().width,'height':document.body.getCoordinates().height+9})
            this.box.setStyles({'left':this.center().x,'top':this.center().y});
        }.bind(this))
        
        
        
    },
    
    adjustScrollHeight: function(){
        if(this.scroll_size != this.content.getScrollSize().y-this.options.height){
            this.scrollbar.setStyles({'opacity':1});
            this.scrollbar_slider = new Slider(this.scrollbar,this.scrollbar_handle,{'mode':'vertical','steps':this.content.getScrollSize().y-this.options.height,'onChange':function(step){
                this.contentScroll.set(0,step);
                this.scroll_position = step;
            }.bind(this)});
            this.scroll_size = this.content.getScrollSize().y-this.options.height;
            this.scrollbar_slider.set(this.scroll_position);
        }
        if(this.content.getScrollSize().y-this.options.height <= 0){
            this.scrollbar.setStyles({'opacity':0});
        }
    },
    
    scrollUp: function(distance){
        this.contentScroll.pause();
        var scroll_to = this.content.getScrollSize().y-this.options.height+distance-50;
    },
    
    scrollDown: function(distance){
        this.contentScroll.pause();
        var scroll_to = (this.content.getScrollSize().y-this.options.height-distance-15);
        this.contentScroll.toBottom()
    },

    center: function(){
        var x = document.body.getCoordinates().width/2;
        var y = document.body.getCoordinates().height/2;
        return {'x':x-20,'y':y};
    },
    
    open: function(){
		if(this.options.submit_once && this.submitted == 1) return;
		if(this.options.box_content != '') {
			//this.content.set('html', document.getElementById(this.options.box_content).clone().innerHTML);
			window[this.options.box_content].inject(this.content,true);
		}
        var body = $(document.body);
        this.box.inject(body);
        this.box_background.inject(body);
        document.body.setStyles({'overflow':'hidden'})
        this.box_background.setStyles({'display':'block'});
        this.box.setStyles({'display':'block'});
        //document.body.setStyles({'overflow-y':'hidden'});
        this.boxFx.pause();
		this.submitted = 1;
        this.boxFx.start({'left':this.center().x,'top':this.center().y,'width':this.options.width,'height':this.options.height,'opacity':1,'margin-left':-(this.options.width/2),'margin-top':-(this.options.height/2)});
    },
    submitClose: function() {
		this.submitted = 1;
		this.options.close();
        this.boxFx.pause();
        this.boxFx.start({'left':this.options.startx,'top':this.options.starty,'width':0,'height':0,'opacity':0,'margin-left':0,'margin-top':0}).chain(function(){}.bind(this));
        this.box_background.setStyles({'display':'none'});
        if(this.options.scroll){document.body.setStyles({'overflow':'scroll'});}
	},
	
    close: function(){
		this.submitted = 0;
        this.options.close();
        this.boxFx.pause();
        this.boxFx.start({'left':this.options.startx,'top':this.options.starty,'width':0,'height':0,'opacity':0,'margin-left':0,'margin-top':0}).chain(function(){}.bind(this));
        this.box_background.setStyles({'display':'none'});
        if(this.options.scroll){document.body.setStyles({'overflow':'scroll'});}
    }
}); /***********************************
	Contact Classes
	/obray/javascript/contact.js
************************************/
OMiniContact = new Class({
    Implements: Options,
    
    options: {
		'sbox-width':300,
		'sbox-height':300,
		'url':''
    },
    
	initialize: function(options){
		this.setOptions(options);
		
		/*** error / success notification div ***/
		this.notification_div = new Element('div',{'class':'Ohidden'});
		this.notification_div.setStyles({
			'width':'100%',
			'margin':'5px 0px 5px 0px',
			'text-align':'center'
		});
		
		var mini_contact = new sbox({'width':this.options['sbox-width'],'height':this.options['sbox-height']});
			
		var miniContactForm = new OForm({
			'url':this.options['url'],
			'button':new Element('input',{'type':'button','value':'Send Message'}),
			'input-color':'#ffffff',
			'input-width':260,
			'padding-top':2,
			'padding-left':8,
			'margin-top': 5,
			'margin-right':10,
			'margin-bottom':4,
			'margin-left':10,
			'btn-width':120,
			'btn-value':'Send Message',
			'label-color':'#ffffff',
			'btn-position':'right',
			'orientation':'vertical',
			'label-display':'inside',
			'onComplete':function(json){
				this.notification_div.removeClass('Ohidden').fade('in');
				this.notification_div.set('html','<div class="notification-box-valid"><h4>'+json.response.error_message+'</h4></div>').highlight('#060');
			}.bind(this),
			'onError': function(json){
				this.notification_div.removeClass('Ohidden').fade('in');
				this.notification_div.set('html','<div class="notification-box-error"><h4>'+json.response.error_message+'</h4></div>').highlight('#f00');
			}.bind(this)
		});
		
		miniContactForm.addElement(new OFText({'label':'Name','name':'contact_name'}));
		miniContactForm.addElement(new OFText({'label':'Email','name':'contact_email'}));
		miniContactForm.addElement(new OFText({'label':'Your Message','name':'contact_message','text-area':true,'text-area-input-height':.50}));
		
		this.notification_div.inject(mini_contact.content);
		miniContactForm.inject(mini_contact.content);

		mini_contact.open();
	}
}); Loader = new Class({
	Implements: Options,
	
	options: {
		'height': false,
		'width': false,
		'text': false,
		'image': false,
		'logo': false,
		'color': false,
		'border':false,
		'onComplete': $empty
	},
	
	initialize: function(parent,options){
		this.setOptions(options);
		this.parent = parent;
		this.cancel = false;
		this.loading = false;
		//Generate HTML
		this.loader_container = new Element('div',{'class':'loader_container'})
		this.loader = new Element('div',{'class':'loader'});
		this.logo_container = new Element('div',{'class':'Obray Logo'});
		this.loader_animation_container = new Element('div',{'class':'loader_animation_container'});
		this.loader_animation = new Element('img');
		if(this.options.text != false){this.loader_animation.setProperty('alt',this.options.text);} else {this.loader_animation.setProperty('alt','Loading...');}
		this.loader_text = new Element('div',{'class':'loader_txt'});
		if(this.options.text != false){this.loader_text.set('html',this.options.text);}
		this.br = new Element('br',{'class':'clear'});
		
		//determine Loading Animation
		this.preLoadImages = []
		if(this.options.image == 'huge') {
			this.loader_animation.setProperty('alt','obray/images/loaders/loading_animation_100x100.gif');
			this.preLoadImages[0] = 'obray/images/loaders/loading_animation_100x100.gif';
			this.loader_text.setStyles({'font-size':'100px'});
		} else if(this.options.image == 'big') {
			this.loader_animation.setProperty('src','obray/images/loaders/loading_animation_50x50.gif');
			this.preLoadImages[0] = 'obray/images/loaders/loading_animation_50x50.gif';
			this.loader_text.setStyles({'font-size':'50px'});
		} else if(this.options.image == 'medium') {
			this.loader_animation.setProperty('src','obray/images/loaders/loading_animation_25x25.gif');
			this.preLoadImages[0] = 'obray/images/loaders/loading_animation_25x25.gif';
			this.loader_text.setStyles({'font-size':'20px'});
		} else if(this.options.image == 'small') {
			this.loader_animation.setProperty('src','obray/images/loaders/loading_animation_20x20.gif');
			this.preLoadImages[0] = 'obray/images/loaders/loading_animation_20x20.gif';
			this.loader_text.setStyles({'font-size':'15px'});
		} else if(this.options.image == 'tiny') {
			this.loader_animation.setProperty('src','obray/images/loaders/loading_animation_15x15.gif');
			this.preLoadImages[0] = 'obray/images/loaders/loading_animation_15x15.gif';
			this.loader_text.setStyles({'font-size':'12px'});
		} else if(this.options.image != false){
			this.loader_animation.setProperty('src',this.options.image);
			this.preLoadImages[0] = this.options.image;
		}else {
			this.loader_animation.setProperty('src','obray/images/loaders/loading_animation_25x25.gif');
			this.preLoadImages[0] = 'obray/images/loaders/loading_animation_25x25.gif';
			this.loader_text.setStyles({'font-size':'20px'});
		}
				
		//determine logo
		if(this.options.logo == 'huge') {
			this.logo_image.setProperty('src','obray/images/loaders/obray_txt_228x100.gif');
			this.preLoadImages[1] = 'obray/images/loaders/obray_txt_228x100.gif';
		} else if(this.options.logo == 'big') {
			this.logo_image.setProperty('src','obray/images/loaders/obray_txt_114x50.gif');
			this.preLoadImages[1] = 'obray/images/loaders/obray_txt_114x50.gif';
		} else if(this.options.logo == 'medium') {
			this.logo_image.setProperty('src','obray/images/loaders/obray_txt_57x25.gif');
			this.preLoadImages[1] = 'obray/images/loaders/obray_txt_57x25.gif';
		} else if(this.options.logo == 'small') {
			this.logo_image.setProperty('src','obray/images/loaders/obray_txt_46x20.gif');
			this.preLoadImages[1] = 'obray/images/loaders/obray_txt_46x20.gif';
		} else if(this.options.logo == 'tiny') {
			this.logo_image.setProperty('src','obray/images/loaders/obray_txt_35x15.gif');
			this.preLoadImages[1] = 'obray/images/loaders/obray_txt_35x15.gif';
		} else if(this.options.logo != false){
			this.logo_image.setProperty('src',this.options.logo);
			this.preLoadImages[1] = this.options.logo;
		}

		//set styles
		if(this.options.width != false && this.options.height != false){
			this.loader_container.setStyles({'position':'relative','width':this.options.width,'height':this.options.height});
		} else {
			this.loader_container.setStyles({'position':'relative'});
		}
		this.loader_animation_container.setStyles({'float':'left'});
		this.loader_text.setStyles({'float':'left','font-family':'"Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif','padding-left':'15px','padding-top':'0px'})
		if(this.options.color != false){
			this.loader_text.setStyles({'color':this.options.color});
		}
		if(this.options.border != false){
			this.loader_animation_container.setStyles({'background-color':'#ffffff','padding':'3px','border':'1px solid #777777'})
			this.loader_text.setStyles({'padding':'3px'});
		}
		
		//preload images
		this.loading = true;
		var loaderImage = new Asset.images(this.preLoadImages,{onComplete:function(){	
			this.loading = false;
			if(this.cancel == false){
				//Construct loader
				if(this.options.width != false && this.options.height != false){
					this.loader.inject(this.loader_container);
				}
				if(this.options.logo != false){
					this.logo_image.inject(this.loader);
				}
				this.loader_animation_container.inject(this.loader);
				this.loader_animation.inject(this.loader_animation_container);
				this.loader_text.inject(this.loader);
				this.br.inject(this.loader);
				if(this.options.width != false && this.options.height != false){
					this.loader_container.inject(this.parent);
				} else {
					this.loader.inject(this.parent);
				}
				
				//center loader
				if(this.options.width != false){
					var loader_text_width = this.loader_text.getSize().x + 10;
					var loader_animation_width = this.loader_animation_container.getSize().x;
					this.loader.setStyles({'width':loader_text_width + loader_animation_width,'position':'absolute','left':'50%','margin-left':-(loader_text_width+loader_animation_width)/2});
					
					var loader_animation_height = this.loader_animation_container.getSize().y;
					this.loader.setStyles({'height':loader_animation_height,'position':'absolute','top':'50%','margin-top':-(loader_animation_height)/2});
				}
				this.options.onComplete();
			} else {
				this.cancel = false;
			}
			
		}.bind(this)});
	},
	
	destroy: function(){
		if(this.loading == true){this.cancel = true;}
		if(this.options.width != false && this.options.height != false){
			this.loader_container.destroy();
		} else {
			this.loader.destroy();
		}
	},
	
	get: function(){
		if(this.options.width != false && this.options.height != false){
			return this.loader_container;
		} else {
			return this.loader;
		}	
	}
}); /******************************************************

	Title: Login
	Author: Nate Obray <nate@adventcreative.com>
	Description: Login using OForms
	File: shared/obray/javascript/login_v2.js

******************************************************/
OLogin = new Class({
	
	Implements: Options,
	
	options: {
		'input-background-image':'url(/obray/images/login_input.png)',
		'input-background-image-highlight':'url(/obray/images/login_input_active.png)',
		'input-width':238,
		'input-height':25,
		'padding-left':15,
		'padding-top':4,
		'padding-bottom':4,
		'padding-right':15,
		'margin-right':15,
		'input-font-size':15,
		'input-color':'#555555',
		'border':'0px solid transparent',
		'btn-background-image':'url(/obray/images/login_btn.png)',
		'btn-height':30,
		'btn-width':78,
		'btn-color':'#ffffff',
		'btn-label-color':'#ffffff',
		'btn-font-size': 14,
		'btn-label':'Forgot Password?',
		'btn-background-color':'transparent',
		'btn-border':'0px solid transparent',
		'btn-position':'right',
		'button':new Element('input',{'type':'button','value':'Submit','class':'ologin-login-button'}),
		'btn-value':'Login',
		'btn-label-text-align':'left',
		'container-width':280,
		'container-height':200,
		'container-margin-top':10,
		'container-margin-right':0,
		'container-margin-bottom':10,
		'container-margin-left':0,
		'label-color':'#aaa000',
		//'label-position':'absolute',
		'label-display':'inside',
		'label-z-index':10,
		'redirect':'',
		'username_label':'Username',
		'password_label':'Password',
		'forgot_password_input_label':'Enter Your Email Address'
	},
	
	initialize: function(options){
		//set data members
		this.setOptions(options);
		
		// container
        this.container = new Element('div',{'class':'login-wrapper'});
		
		// container styles
		this.container.setStyles({
			'width':this.options['container-width'],
			'height':this.options['container-height'],
			'margin-top':this.options['container-margin-top'],
			'margin-right':this.options['container-margin-right'],
			'margin-bottom':this.options['container-margin-bottom'],
			'margin-left':this.options['container-margin-left']
			//'border':'solid 1px #f00'
		});
		
		// error notification
		this.login_notification_box = new Element('div',{'class':'login-notification-box Ohidden'});
		this.login_notification_box.setStyles({
			'width':'90%',
			'min-height':10,
			'color':'#f00',
			'font-weight':'bold',
			'margin-top':10,
			'margin-bottom':10,
			'padding':10,
			'background-color':'#ffffff',
			'border':'1px solid #f00'
		})
		
		
		
		// containing div for form and all login elements
		// lets us hide form if needed
		this.login_form_wrapper = new Element('div',{'class':'login-form-wrapper'});
		
		// define login form
		
		this.login_form = new OForm({
									'id':'login-form',
									'class':'ologin-form',
									'orientation':'vertical',
									'button':this.options['button'],
									'btn-value':this.options['btn-value'],
									'url':'index.cfm?action=sec.obraysignin&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true',
									'method':'post',
									'onComplete':function(json){
										if(this.options['redirect'] == "") {
											window.location = json.response.location;
										} else {
											
											window.location = this.options['redirect'];	
										}
										
									}.bind(this),
									'onError': function(json){
										$$('.login-notification-box').removeClass('Ohidden').fade('in');
										$$('.login-notification-box').set('html',json.response.error_message).highlight('#f00');
									},
									'input-background-image':this.options['input-background-image'],
									'input-background-image-highlight':this.options['input-background-image-highlight'],
									'input-width':this.options['input-width'],
									'input-height':this.options['input-height'],
									'padding-left':this.options['padding-left'],
									'padding-top':this.options['padding-top'],
									'padding-bottom':this.options['padding-bottom'],
									'padding-right':this.options['padding-right'],
									'margin-right':this.options['margin-right'],
									'input-font-size':this.options['input-font-size'],
									'input-color':this.options['input-color'],
									'border':this.options['border'],
									'btn-background-image':this.options['btn-background-image'],
									'btn-height':this.options['btn-height'],
									'btn-width':this.options['btn-width'],
									'btn-color':this.options['btn-color'],
									'btn-label-color':this.options['btn-label-color'],
									'btn-font-size':this.options['btn-font-size'],
									'btn-label':'Forgot Password?',
									'btn-background-color':this.options['btn-background-color'],
									'btn-border':this.options['btn-border'],
									'btn-position':this.options['btn-position'],
									'btn-label-text-align':this.options['btn-label-text-align'],
									'label-color':this.options['label-color'],
									'label-font-size':this.options['input-font-size'],
									'label-display':this.options['label-display'],
									'label-z-index':this.options['label-z-index']
		});
		
		// username
		this.login_form.addElement(new OFText({
											'input_id':'user-email',
											'name':'user_email',
											'class':'login-userName-input',
											'type':'text',
											'label':this.options.username_label
		}));
		
		// password
		var password_field = this.login_form.addElement(new OFText({
											'input_id':'user-password',
											'name':'user_password',
											'class':'login-password-input',
											'type':'password',
											'label':this.options.password_label
		}));
		
		// inject form into container
		
		
		// inject container
		
		
		
		// containing div for form and all forgot password elements
		// lets us hide form if needed
		this.forgot_form_wrapper = new Element('div',{'class':'forgot-form-wrapper Ohidden'});
		
		// define forgot password form
		this.forgot_form = new OForm({
									'id':'forgot-form',
									'orientation':'vertical',
									'button':new Element('input',{'type':'button','value':'','class':'ologin-submit-password-button'}),
									'btn-value':this.options['btn-value'],
									'url':'index.cfm?action=sec.obraysigninReset&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true',
									'onComplete':function(json){
										this.forgot_form.options.button_label.fireEvent('click');
										$$('.login-notification-box').removeClass('Ohidden').set('html',json.response.error_message);
									}.bind(this),
									'onError': function(json){
										$$('.login-notification-box').removeClass('Ohidden').fade('in');
										$$('.login-notification-box').set('html',json.response.error_message).highlight('#f00');
									},
									'input-background-image':this.options['input-background-image'],
									'input-background-image-highlight':this.options['input-background-image-highlight'],
									'input-width':this.options['input-width'],
									'input-height':this.options['input-height'],
									'padding-left':this.options['padding-left'],
									'padding-top':this.options['padding-top'],
									'padding-bottom':this.options['padding-bottom'],
									'padding-right':this.options['padding-right'],
									'margin-right':this.options['margin-right'],
									'input-font-size':this.options['input-font-size'],
									'input-color':this.options['input-color'],
									'border':this.options['border'],
									'btn-background-image':this.options['btn-background-image'],
									'btn-height':this.options['btn-height'],
									'btn-width':this.options['btn-width'],
									'btn-color':this.options['btn-color'],
									'btn-label-color':this.options['btn-label-color'],
									'btn-font-size':this.options['btn-font-size'],
									'btn-label':'Back to Login',
									'btn-background-color':this.options['btn-background-color'],
									'btn-border':this.options['btn-border'],
									'btn-position':this.options['btn-position'],
									'btn-label-text-align':this.options['btn-label-text-align'],
									'label-color':this.options['label-color'],
									'label-font-size':this.options['input-font-size'],
									'label-display':this.options['label-display']
		});
		
		// username
		this.forgot_form.addElement(new OFText({
											'input_id':'user-email',
											'name':'user_email',
											'class':'login-userName-input',
											'type':'text',
											'label':this.options.forgot_password_input_label
		}));

		// inject form into container
		
		
		// inject container
		
		
		
		//forgot password rollover
		this.login_form.options.button_label.addEvent('mouseover',function(e){
			e.preventDefault();
			this.login_form.options.button_label.setStyles({
				'color':this.options['btn-label-color'],
				'text-decoration':'underline'
			});
		}.bind(this));
		
		//forgot password rollover
		this.login_form.options.button_label.addEvent('mouseout',function(e){
			e.preventDefault();
			this.login_form.options.button_label.setStyles({
				'color':this.options['btn-label-color'],
				'text-decoration':'none',
				'cursor':'pointer'
			});
		}.bind(this));
		
		//forgot password on click
		this.login_form.options.button_label.addEvent('click',function(e){
			try{ e.preventDefault(); } catch(err){}
			this.login_notification_box.fade('in').addClass('Ohidden');
			this.login_form_wrapper.addClass('Ohidden');
			this.forgot_form_wrapper.removeClass('Ohidden');
		}.bind(this));
		
		//back to login rollover
		this.login_form.options.button_label.addEvent('mouseover',function(e){
			e.preventDefault();
			this.forgot_form.options.button_label.setStyles({
				'color':this.options['btn-label-color'],
				'text-decoration':'underline'
			});
		}.bind(this));
		
		//back to login rollover
		this.login_form.options.button_label.addEvent('mouseout',function(e){
			try{ e.preventDefault(); } catch(err){}
			this.forgot_form.options.button_label.setStyles({
				'color':this.options['btn-label-color'],
				'text-decoration':'none'
			});
		}.bind(this));
		
		//back to login on click
		this.forgot_form.options.button_label.addEvent('click',function(e){
			try{ e.preventDefault(); } catch(err){}
			this.login_notification_box.fade('in').addClass('Ohidden');
			this.forgot_form_wrapper.addClass('Ohidden');
			this.login_form_wrapper.removeClass('Ohidden');
		}.bind(this));
		

	},
	
	setStyles: function(){
		this.container.setStyles(style_options)
	},
	
	inject: function(el,position){
		
		this.container.inject(el,position);
		this.login_notification_box.inject(this.container);
		
		this.login_form_wrapper.inject(this.container);
		this.login_form.inject(this.login_form_wrapper);
		
		this.forgot_form_wrapper.inject(this.container);
		
		this.forgot_form.inject(this.forgot_form_wrapper);
		
    }
});

/***************************************

***************************************/
Zoomer = new Class({
	Implements: Options,
	
	options:{
		zoom_max : 1024,
		zoom_min : 50,
		zoom_start : 50,
		offset_x : 0,
		offset_y : 0,
		onStep : function(){return 0;}
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.zoom_level = this.options.zoom_start;
		
		//genreate HTML
		this.zoom_container = new Element('div',{'class':'zoom_container'});
		this.zoom = new Element('div',{'class':'zoom'});
		this.zoom_left = new Element('div',{'class':'zoom_left'});
		this.zoom_track = new Element('div',{'class':'zoom_track'});
		this.zoom_right = new Element('div',{'class':'zoom_right'});
		this.zoom_handle = new Element('div',{'class':'zoom_handle'});
		this.zoom_percent = new Element('div',{'class':'zoom_percent'});
		this.zoom_percent.set('html','100%');
		this.br = new Element('div',{'class':'clear'});
		
		//set styles
		this.zoom_left.setStyles({'float':'left','background-image':'url(obray/images/ImageEditor/zoom_track_left.png)','height':'5px','width':'4px','margin-top':'5px'});
		this.zoom_track.setStyles({'float':'left','background-image':'url(obray/images/ImageEditor/zoom_track.png)','height':'5px','width':'266px','margin-top':'5px'});
		this.zoom_right.setStyles({'float':'left','background-image':'url(obray/images/ImageEditor/zoom_track_right.png)','height':'5px','width':'4px','margin-top':'5px'});
		this.zoom_handle.setStyles({'top':'-3px','left':'-5px','height':'19px','width':'19px','background-image':'url(obray/images/ImageEditor/zoom_knob.png)','cursor':'move'});
		this.zoom.setStyles({'float':'left','width':'280px','height':'5px','border':'0px solid black'});
		this.zoom_percent.setStyles({'float':'left','font-family':'Arial','font-size':'10px','color':'#676765'});
		
		if(Browser.Engine.trident){
			this.zoom_handle.setStyles({'top':'-13px'});
		}
		
		var zoom_images = new Asset.images(['obray/images/ImageEditor/zoom_track_left.png',
			'obray/images/ImageEditor/zoom_track.png',
			'obray/images/ImageEditor/zoom_track_right.png',
			'obray/images/ImageEditor/zoom_knob.png'],{
		onComplete:function(){
				
			//construct HTML
			this.zoom_left.inject(this.zoom);
			this.zoom_track.inject(this.zoom);
			this.zoom_right.inject(this.zoom);
			this.zoom_handle.inject(this.zoom);
			this.zoom.inject(this.zoom_container);
			this.zoom_percent.inject(this.zoom_container);
			this.br.inject(this.zoom_container);
			this.zoomer = new Slider(this.zoom,this.zoom_handle,{'range':[this.options.zoom_min,this.options.zoom_max],wheel:'true',onChange:function(step){
				this.zoom_level = step;
				this.zoom_percent.set('html',(((this.zoom_level-this.options.zoom_min)/(this.options.zoom_max-this.options.zoom_min))*100).toInt() + '%');
				this.options.onStep(step);
				
				//this.setOptions({'range':[this.options.min-this.options.offset_x,this.options.zoom_max]});
			}.bind(this)});
			
			this.zoomer.set(this.options.zoom_start);
			/****
			window.obray.pictureBox.setOptions({'onClose':function(){
				this.zoomer.drag.detach();
				this.zoomer.drag.stop();
				this.zoom.removeEvents();
				this.zoom_handle.removeEvents();
			}.bind(this)})
			****/
		}.bind(this)});
	},
	
	get: function(){
		return this.zoom_container;
	},	
	
	initiateZoomer: function(){
		
	}
});
/***************************************

***************************************/
iWindow = new Class({
	Implements: (Options),
	
	Extends: Zoomer,
	
	options:{
		window_height: 50,
		window_width: 50,
		window_max_width: false,
		window_min_width: false,
		window_max_height: false,
		window_min_height: false,
		offset_x: 0,
		offset_y: 0,
		canvas_height: false,
		canvas_width: false,
		canvas_max_width: false,
		canvas_max_height: false,
		resizable: true,
		onDrag: false
	},
	
	initialize: function(img,options){
		
		//data members
		this.setOptions(options);
		//generate HTML
		this.window_container = new Element('div',{'class':'window_container'});
		this.window = new Element('div',{'class':'window'});
		this.window_canvas = img;
		this.window_handle = new Element('div',{'class':'window_handle'});
		this.window_position = new Element('div',{'class':'window_position'});
		//set styles
		var position_left = -(this.options.window_width/2);
		this.window_position.setStyles({'position':'absolute','left':'50%','margin-left':position_left+'px'});
		this.window.setStyles({'position':'relative','height':this.options.window_height+'px','width':this.options.window_width+'px','border':'0px solid black','overflow':'hidden'});
		this.window_canvas.setStyles({'position':'absolute','top':this.options.offset_y+'px','left':this.options.offset_x+'px','cursor':'move'});
		this.window_handle.setStyles({'position':'absolute','bottom':'0px','right':'0px','height':'13px','width':'13px','background-image':'url(obray/images/ImageEditor/resize_handle.png)','cursor':'SE-resize'});
		this.window_container.setStyles({'margin':'0 auto','position':'relative','height':(parseInt(this.options.window_height)+20)+'px','width':parseInt(this.options.window_width+20)});

		this.maxWidth = this.getMaxDimensions().width;
		this.maxHeight = this.getMaxDimensions().height;
		
		if(this.options.canvas_max_width != false){
			this.maxWidth = this.options.canvas_max_width;
		}
		if(this.options.canvas_max_height != false){
			this.maxHeight = this.options.canvas_max_height;
		}
		if(this.options.canvas_width != false){
			this.zoom_start = this.options.canvas_width;
		} else {
			this.zoom_start = this.getMinWidth();	
		}
		
		this.parent({'zoom_max':this.maxWidth,'zoom_min':this.getMinWidth(),'zoom_start':this.zoom_start});
		//construct HTML
		
		this.window_canvas.inject(this.window);
		if(this.options.resizable){this.window_handle.inject(this.window);}
		this.window.inject(this.window_position);
		this.window_position.inject(this.window_container);
		this.zoom_container.inject(this.window_container);
		this.zoom_container.setStyles({'position':'absolute','bottom':'0px','left':'50%','margin-left':'-145px','margin-bottom':'10px'})
		
		
		this.options.onStep = function(step){
			this.window_canvas.setStyles({'width':step+'px','height':step/this.getRatio()+'px'});
			if(this.window_canvas.getSize().x + this.window_canvas.getStyle('left').toInt() < this.window.getSize().x){
				
				this.window_canvas.setStyle('left',this.window_canvas.getStyle('left').toInt() + this.window.getSize().x - (this.window_canvas.getSize().x + this.window_canvas.getStyle('left').toInt()))
			}
			if(this.window_canvas.getSize().y + this.window_canvas.getStyle('top').toInt() < this.window.getSize().y){
				this.window_canvas.setStyle('top',this.window_canvas.getStyle('top').toInt() + this.window.getSize().y - (this.window_canvas.getSize().y + this.window_canvas.getStyle('top').toInt()))
			}
			
		}.bind(this);
		
		if(this.options.resizable){
			this.resize = this.window.makeResizable({
				'handle':this.window_handle,
				'limit': {'x':[this.options.window_min_width,this.options.window_max_width],'y':[this.options.window_min_height,this.options.window_max_height]},
				'onComplete':function(){
					var width = this.window_canvas.getCoordinates().width;
				}.bind(this)
			});
		}
		
		this.drag = new Drag(this.window_canvas,{
			'limit': {'x':[(this.window.getSize().x - this.window_canvas.getSize().x),0],'y':[(this.window.getSize().y - this.window_canvas.getSize().y-2).toInt(),0]},
			'onComplete':function(){
			}.bind(this)
		});

		this.window_canvas.addEvent('mousedown',function(e){
			this.drag.setOptions({'limit': {'x':[(this.window.getSize().x - this.window_canvas.getSize().x),0],'y':[(this.window.getSize().y - this.window_canvas.getSize().y-2).toInt(),0]}})
			this.drag.start(e);
		}.bind(this));
		
		this.window_canvas.addEvent('mouseup',function(){
			this.drag.stop();
		}.bind(this));
		
		
	},
	
	getMaxDimensions: function(){
		if(this.window_canvas.getSize().x != 0){
			var width = this.window_canvas.getSize().x;
			var height = this.window_canvas.getSize().y;
		}  else {
			var hasParent = false;
			if($defined(this.window_canvas.getParent())){
				var parent = this.window_canvas.getParent();
			}
			
			var oldx = this.window_canvas.getStyle('left');
			var oldy = this.window_canvas.getStyle('top');
			this.window_canvas.setStyles({'top':'10000px','left':'10000px'});
			this.window_canvas.inject($('obray'));
			var width = this.window_canvas.getSize().x
			var height = this.window_canvas.getSize().y
			var temp = this.window_canvas.clone();
			this.window_canvas.destroy();
			this.window_canvas = temp;
			this.window_canvas.setStyles({'top':oldy,'left':oldx});
			if(!$defined(this.window_canvas.getProperty('top'))){
				this.window_canvas.setStyles({'top':this.options.offset_y+'px','left':this.options.offset_x+'px'});
			}
			
			if(hasParent){
				this.window_canvas.inject(parent);
			}
		}
		return {'width':width,'height':height};
	},
	
	getRatio: function(){
		return this.maxWidth / this.maxHeight;
	},
	
	getMinWidth: function(){
		wr = (this.options.window_width/this.options.window_height)
		cr = this.getRatio();
		if(wr < cr){
			return this.options.window_height * this.getRatio();
		} else {
			return this.options.window_width;
		}
	},
	
	startLoading: function(){
		this.loader = new Loader(this.window_container,{'width':this.window_container.getSize().x,'height':this.window_container.getSize().y,'text':'Loading Image...','image':'small'});
		this.loader.get().setStyles({'z-index':'2010','position':'absolute','top':'0px','left':'0px','background-color':'#ffffff'});	
	},
	
	stopLoading: function(){
		this.loader.destroy();
	},
	
	setImage: function(img,newWidth,newHeight){
		this.assets = new Asset.images([img],{onComplete:function(){	
			this.maxWidth = newWidth;
			this.maxHeight = newHeight
			this.window_canvas.setProperty('src',img);
			this.loader.destroy();
			this.window_canvas.setStyles({'left':'0px','top':'-2px'});
			this.setOptions({'zoom_min':this.getMinWidth(),'zoom_max':this.maxWidth});
			this.zoomer.setOptions({'range':[this.getMinWidth(),this.maxWidth]});
			this.zoomer.setRange(this.maxWidth-this.getMinWidth(),this.maxWidth,this.getMinWidth());
			this.zoomer.set(this.getMinWidth());
			
		}.bind(this)});
	},
	
	get: function(){
		return this.window_container;
	}
	
});
/***************************************

***************************************/
iWindow = new Class({
	Implements: (Options),
	
	Extends: Zoomer,
	
	options:{
		window_height: 50,
		window_width: 50,
		window_max_width: false,
		window_min_width: false,
		window_max_height: false,
		window_min_height: false,
		offset_x: 0,
		offset_y: 0,
		canvas_height: false,
		canvas_width: false,
		canvas_max_width: false,
		canvas_max_height: false,
		resizable: true,
		onDrag: false
	},
	
	initialize: function(img,options){
		
		//data members
		this.setOptions(options);
		//generate HTML
		this.window_container = new Element('div',{'class':'window_container'});
		this.window = new Element('div',{'class':'window'});
		this.window_canvas = img;
		this.window_handle = new Element('div',{'class':'window_handle'});
		this.window_position = new Element('div',{'class':'window_position'});
		//set styles
		var position_left = -(this.options.window_width/2);
		this.window_position.setStyles({'position':'absolute','left':'50%','margin-left':position_left+'px'});
		this.window.setStyles({'position':'relative','height':this.options.window_height+'px','width':this.options.window_width+'px','border':'0px solid black','overflow':'hidden'});
		this.window_canvas.setStyles({'position':'absolute','top':this.options.offset_y+'px','left':this.options.offset_x+'px','cursor':'move'});
		this.window_handle.setStyles({'position':'absolute','bottom':'0px','right':'0px','height':'13px','width':'13px','background-image':'url(obray/images/ImageEditor/resize_handle.png)','cursor':'SE-resize'});
		this.window_container.setStyles({'margin':'0 auto','position':'relative','height':(parseInt(this.options.window_height)+20)+'px','width':parseInt(this.options.window_width+20)});

		this.maxWidth = this.getMaxDimensions().width;
		this.maxHeight = this.getMaxDimensions().height;
		
		if(this.options.canvas_max_width != false){
			this.maxWidth = this.options.canvas_max_width;
		}
		if(this.options.canvas_max_height != false){
			this.maxHeight = this.options.canvas_max_height;
		}
		if(this.options.canvas_width != false){
			this.zoom_start = this.options.canvas_width;
		} else {
			this.zoom_start = this.getMinWidth();	
		}
		
		this.parent({'zoom_max':this.maxWidth,'zoom_min':this.getMinWidth(),'zoom_start':this.zoom_start});
		//construct HTML
		
		this.window_canvas.inject(this.window);
		if(this.options.resizable){this.window_handle.inject(this.window);}
		this.window.inject(this.window_position);
		this.window_position.inject(this.window_container);
		this.zoom_container.inject(this.window_container);
		this.zoom_container.setStyles({'position':'absolute','bottom':'0px','left':'50%','margin-left':'-145px','margin-bottom':'10px'})
		
		
		this.options.onStep = function(step){
			this.window_canvas.setStyles({'width':step+'px','height':step/this.getRatio()+'px'});
			if(this.window_canvas.getSize().x + this.window_canvas.getStyle('left').toInt() < this.window.getSize().x){
				
				this.window_canvas.setStyle('left',this.window_canvas.getStyle('left').toInt() + this.window.getSize().x - (this.window_canvas.getSize().x + this.window_canvas.getStyle('left').toInt()))
			}
			if(this.window_canvas.getSize().y + this.window_canvas.getStyle('top').toInt() < this.window.getSize().y){
				this.window_canvas.setStyle('top',this.window_canvas.getStyle('top').toInt() + this.window.getSize().y - (this.window_canvas.getSize().y + this.window_canvas.getStyle('top').toInt()))
			}
			
		}.bind(this);
		
		if(this.options.resizable){
			this.resize = this.window.makeResizable({
				'handle':this.window_handle,
				'limit': {'x':[this.options.window_min_width,this.options.window_max_width],'y':[this.options.window_min_height,this.options.window_max_height]},
				'onComplete':function(){
					var width = this.window_canvas.getCoordinates().width;
				}.bind(this)
			});
		}
		
		this.drag = new Drag(this.window_canvas,{
			'limit': {'x':[(this.window.getSize().x - this.window_canvas.getSize().x),0],'y':[(this.window.getSize().y - this.window_canvas.getSize().y-2).toInt(),0]},
			'onComplete':function(){
			}.bind(this)
		});

		this.window_canvas.addEvent('mousedown',function(e){
			this.drag.setOptions({'limit': {'x':[(this.window.getSize().x - this.window_canvas.getSize().x),0],'y':[(this.window.getSize().y - this.window_canvas.getSize().y-2).toInt(),0]}})
			this.drag.start(e);
		}.bind(this));
		
		this.window_canvas.addEvent('mouseup',function(){
			this.drag.stop();
		}.bind(this));
		
		
	},
	
	getMaxDimensions: function(){
		if(this.window_canvas.getSize().x != 0){
			var width = this.window_canvas.getSize().x;
			var height = this.window_canvas.getSize().y;
		}  else {
			var hasParent = false;
			if($defined(this.window_canvas.getParent())){
				var parent = this.window_canvas.getParent();
			}
			
			var oldx = this.window_canvas.getStyle('left');
			var oldy = this.window_canvas.getStyle('top');
			this.window_canvas.setStyles({'top':'10000px','left':'10000px'});
			this.window_canvas.inject($('obray'));
			var width = this.window_canvas.getSize().x
			var height = this.window_canvas.getSize().y
			var temp = this.window_canvas.clone();
			this.window_canvas.destroy();
			this.window_canvas = temp;
			this.window_canvas.setStyles({'top':oldy,'left':oldx});
			if(!$defined(this.window_canvas.getProperty('top'))){
				this.window_canvas.setStyles({'top':this.options.offset_y+'px','left':this.options.offset_x+'px'});
			}
			
			if(hasParent){
				this.window_canvas.inject(parent);
			}
		}
		return {'width':width,'height':height};
	},
	
	getRatio: function(){
		return this.maxWidth / this.maxHeight;
	},
	
	getMinWidth: function(){
		wr = (this.options.window_width/this.options.window_height)
		cr = this.getRatio();
		if(wr < cr){
			return this.options.window_height * this.getRatio();
		} else {
			return this.options.window_width;
		}
	},
	
	startLoading: function(){
		this.loader = new Loader(this.window_container,{'width':this.window_container.getSize().x,'height':this.window_container.getSize().y,'text':'Loading Image...','image':'small'});
		this.loader.get().setStyles({'z-index':'2010','position':'absolute','top':'0px','left':'0px','background-color':'#ffffff'});	
	},
	
	stopLoading: function(){
		this.loader.destroy();
	},
	
	setImage: function(img,newWidth,newHeight){
		this.assets = new Asset.images([img],{onComplete:function(){	
			this.maxWidth = newWidth;
			this.maxHeight = newHeight
			this.window_canvas.setProperty('src',img);
			this.loader.destroy();
			this.window_canvas.setStyles({'left':'0px','top':'-2px'});
			this.setOptions({'zoom_min':this.getMinWidth(),'zoom_max':this.maxWidth});
			this.zoomer.setOptions({'range':[this.getMinWidth(),this.maxWidth]});
			this.zoomer.setRange(this.maxWidth-this.getMinWidth(),this.maxWidth,this.getMinWidth());
			this.zoomer.set(this.getMinWidth());
			
		}.bind(this)});
	},
	
	get: function(){
		return this.window_container;
	}
	
});
/***************************************

***************************************/
ImageEditor = new Class({
	Implements: Options,
	
	options:{
		'image_id': 0,
		'image_name':'obray_placeHolder',
		'image_ext': '.jpg',
		'description':'Place Holder',
		'description_long':false,
		'canvas_height': 611,
		'canvas_width': false,
		'canvas_max_width': false,
		'canvas_max_height': false,
		'window_height': 300,
		'window_width': 300,
		'window_max_width': false,
		'window_max_height': false,
		'zoom_level': 300,
		'resizable': true,
		'offset_x': 0,
		'offset_y': 0,
		'src': 'obray/images/obray_placeHolder.jpg',
		'onSave':$empty,
		'link': '',
		'link_follow':false,
		'thumb_size_x':90,
		'thumb_size_y':105,
		'deletefn': false,
		'onDelete':$empty
	},
	
	
	
	initialize: function(stack,options){
		
		//data members
		this.setOptions(options)
		this.upload_target = $('upload_target');
		this.stack = stack;
		//genreate HTML
		this.stack.chain(function(){
		
			this.img = new Element('img',{'class':'window_canvas','src':this.options.src});
			this.editor = new Element('div',{'class':'image_editor'});
			this.editor_fields = new Element('div',{'class':'editor_fields'});
			this.editor_file_container = new Element('div',{'class':'editor_file_container'});
			this.editor_file_label = new Element('div',{'class':'editor_file_label'});
			this.editor_file_label.set('html','Image:')
			this.editor_file = new Element('input',{'type':'file','name':'image_file'});
			this.editor_description_container = new Element('div',{'class':'description_container'});
			this.editor_description_label = new Element('div',{'class':'description_label'});
			this.editor_description_textarea = new Element('input',{'class':'description_textarea','name':'content_text'});
			this.editor_long_container = new Element('div',{'class':'long_container'});
			this.editor_long_label = new Element('div',{'class':'long_label'});
			this.editor_long_textarea = new Element('textarea',{'class':'long_textarea','name':'content_text'});
			this.editor_long_label.set('html','Long Description:');
			this.editor_link_container = new Element('div',{'class':'description_container'});
			this.editor_link_label = new Element('div',{'class':'description_label'});
			this.editor_link_textarea = new Element('input',{'class':'description_textarea','name':'content_text'});
			this.editor_link_label.set('html','Link Address:')
			this.editor_link_follow = new Element('div',{'class':'image_default'})
			this.editor_link_follow_label = new Element('div',{'class':'image_default_label'});
			this.editor_link_follow_input = new Element('input',{'type':'checkbox','class':'image_default_input'});
			this.editor_link_follow_label.set('html','Allow search engines to follow link');
			this.editor_extra_container = new Element('div',{'class':'extra_container'});
			this.editor_save_container = new Element('div',{'class':'save_container'});
			this.editor_save_btn = new Element('input',{'type':'button','value':'Save'});
			this.editor_delete_container = new Element('div',{'class':'delete_container'});
			this.editor_delete_btn = new Element('input',{'type':'button','class':'delete_btn','value':'delete'});
			this.editor_description_label.set('html','Description:');
			this.editor_form = new Element('form',{'action':'index.cfm?action=images.uploadImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','encoding':'multipart/form-data','enctype':'multipart/form-data','target':'upload_target','method':'post'});
			this.editor_form_image_id = new Element('input',{'type':'hidden','value':this.options.image_id,'name':'image_id'});
			this.loader = new Loader(this.editor,{'width':this.options.width,'height':200,'image':'big'});
			this.br = new Element('div',{'class':'clearboth'});
			//construct HTML
			this.loadExtra = $empty;
			this.assets = new Asset.images([this.options.src],{onComplete:function(){
				this.editor_window = new iWindow(this.img,{
					'resizable':this.options.resizable,
					'window_width':this.options.window_width,
					'window_height':this.options.window_height,
					'window_max_height':this.options.canvas_height,
					'window_max_width':this.options.window_max_width,
					'canvas_width':this.options.zoom_level,
					'canvas_max_width':this.options.canvas_max_width,
					'canvas_max_height':this.options.canvas_max_height,
					'offset_x':this.options.offset_x,
					'offset_y':this.options.offset_y,
					'zoom_level':this.options.zoom_level
				});
				
				this.editor_window.get().inject(this.editor);
				
				this.loader.destroy();
				this.editor_file_label.inject(this.editor_file_container);
				this.editor_file.inject(this.editor_file_container);
				this.editor_form_image_id.inject(this.editor_form);
				this.editor_file_container.inject(this.editor_form);
				this.editor_form.inject(this.editor_fields);
				this.editor_description_textarea.setProperty('value',this.options.description);
				this.editor_description_label.inject(this.editor_description_container);
				this.editor_description_textarea.inject(this.editor_description_container);
				this.editor_description_textarea.setProperty('value',this.options.description)
				this.br.clone().inject(this.editor_description_container);
				this.editor_description_container.inject(this.editor_fields);
				this.editor_long_textarea.setProperty('value',this.options.description_long);
				this.editor_long_textarea.set('html',this.options.description_long);
				this.editor_long_label.inject(this.editor_long_container);
				this.editor_long_textarea.inject(this.editor_long_container);
				this.br.clone().inject(this.editor_long_container);
				this.editor_long_container.inject(this.editor_fields);
				
				if(this.options.link != ''){
					this.editor_link_textarea.setProperty('value',this.options.link);
					this.editor_link_label.inject(this.editor_link_container);
					this.editor_link_textarea.inject(this.editor_link_container);
					this.br.clone().inject(this.editor_link_container);
					this.editor_link_container.inject(this.editor_fields);
					//set properties
					if(this.options.link_follow){
						this.editor_link_follow_input.checked = true;
						this.editor_link_follow_input.defaultChecked = true;
					} else {
						this.editor_link_follow_input.checked = false;
						this.editor_link_follow_input.defaultChecked = false;
					}
					this.editor_link_follow_input.inject(this.editor_link_follow);
					this.editor_link_follow_label.inject(this.editor_link_follow);
					this.br.clone().inject(this.editor_link_follow);
				}
				this.editor_link_follow.inject(this.editor_fields);
				this.editor_save_container.inject(this.editor_fields);
				if(this.options.deletefn == true){
					this.editor_delete_container.inject(this.editor_fields);
					this.editor_delete_btn.inject(this.editor_save_container);
				}
				this.editor_extra_container.inject(this.editor_save_container);
				this.editor_save_btn.inject(this.editor_save_container);
				
				this.editor_fields.inject(this.editor);
				
				this.loadExtra();
				
				this.stack.callChain();
			}.bind(this)});
			
			//set styles
			this.editor_fields.setStyles({'width':500});
			this.editor_file_container.setStyles({'padding':'5px','margin-bottom':'5px'});
			this.editor_file_label.setStyles({'float':'left','font-family':'arial','color':'#aaaaaa','width':'40%','text-align':'right'});
			this.editor_description_textarea.setStyles({'float':'left','width':'50%','float':'left'});
			this.editor_description_label.setStyles({'float':'left','font-family':'Arial','padding-top':'1px','width':'40%','text-align':'right'});
			this.editor_description_container.setStyles({'padding':'5px','margin-bottom':'7px','color':'#aaaaaa'});
			this.editor_long_textarea.setStyles({'float':'left','width':'50%','float':'left','height':'100px'});
			this.editor_long_label.setStyles({'float':'left','font-family':'Arial','padding-top':'1px','width':'40%','text-align':'right'});
			this.editor_long_container.setStyles({'padding':'5px','margin-bottom':'7px','color':'#aaaaaa'});
			this.editor_link_textarea.setStyles({'float':'left','width':'50%','float':'left'});
			this.editor_link_label.setStyles({'float':'left','color':'#aaaaaa','font-family':'Arial','padding-top':'1px','width':'40%','text-align':'right'});
			this.editor_link_container.setStyles({'padding':'5px','margin-bottom':'7px','color':'#aaaaaa'});
			this.editor_save_container.setStyles({'text-align':'right','width':''});
			this.editor_save_btn.setStyles({'width':'100px'});
			this.editor_delete_btn.setStyles({'width':'100px','float':'left'});
			
			this.editor_link_follow.setStyles({'padding':'3px','margin-bottom':'5px','margin-left':'40%'});
			this.editor_link_follow_label.setStyles({'float':'left','color':'#aaaaaa','font-family':'arial'});
			this.editor_link_follow_input.setStyles({'float':'left'});
			
			//get upload response
			this.upload_target.addEvent('load',function(){
				
				var frame = window.frames['upload_target'];
				var response = frame.document.getElementById('response').innerHTML;
				response = JSON.decode(response);
				this.options.image_id = response.image.image_id;
				this.editor_form_image_id = response.image.image_id;
				this.options.src = response.image.image_location;
				this.options.image_name = response.image.image_name;
				this.options.image_description = response.image.image_description;
				this.options.image_ext = response.image.image_ext;
				var editorImage = new Asset.images([this.options.src],{onComplete:function(){
					this.editor_window.setImage(this.options.src,response.image.image_width,response.image.image_height);
				}.bind(this)});
				
			}.bind(this));
			
			//upload image on file input change
			this.editor_file.addEvent('change',function(){
				this.editor_window.startLoading();
				this.editor_form.submit();
			}.bind(this));
			
			//submit information to server
			this.editor_save_btn.addEvent('click',function(){
				this.saveImage();
			}.bind(this));
			
			
			
			this.editor_link_follow_input.addEvent('click',function(){
				if(this.options.link_follow){
					this.options.link_follow = false;
				} else {
					this.options.link_follow = true;
				}
			}.bind(this));
			
			this.editor_delete_btn.addEvent('click',function(){
				this.deleteRequest = new Request({'url':'index.cfm?action=image.delete&image_id='+this.options.image_id}).send();
				this.options.onDelete();
			}.bind(this));
		
		}.bind(this));
		
	},
	
	saveImage: function(){
		this.setOptions({
			'crop_x':this.editor_window.window_canvas.getStyle('left').toInt(),
			'crop_y':this.editor_window.window_canvas.getStyle('top').toInt(),
			'window_width':this.editor_window.window.getSize().x,
			'window_height':this.editor_window.window.getSize().y,
			'crop_width':this.editor_window.window_canvas.getSize().x,
			'description':this.editor_description_textarea.getProperty('value')
		});
		var data = '&image_id='+this.options.image_id
				  +'&image_name='+this.options.image_name
				  +'&image_ext='+this.options.image_ext
				  +'&image_x='+this.options.crop_x
				  +'&image_y='+this.options.crop_y
				  +'&image_width='+this.options.window_width
				  +'&image_height='+this.options.window_height
				  +'&image_zoom='+this.options.crop_width
				  +'&image_description='+this.options.description
				  +'&image_location='+this.options.src
				  +'&image_link='+this.editor_link_textarea.getProperty('value')
				  +'&image_follow='+this.options.link_follow
				  +'&image_description_long='+this.editor_long_textarea.getProperty('value')
				  +'&thumb_size_x=' + this.options.thumb_size_x
				  +'&thumb_size_y=' + this.options.thumb_size_y;
		var oldHeight = this.editor_window.get().getSize().x;
		var oldWidth = this.editor_window.get().getSize().y;
		this.parent = this.editor.getParent();
		this.parent.set('html','');
		this.edit_image_loader = new Loader(this.parent,{'width':oldHeight,'height':oldWidth,'text':'Saving Image...','image':'medium'});
		this.saveImage = new Request({'url':'index.cfm?action=images.saveImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','method':'post','data':data,'onComplete':function(response){	
			this.options.onSave(response);
		}.bind(this)}).send();
	},
	
	get: function(){
		return this.editor;
	}
						
}); formBase = new Class({	Implements: Options,		options:{		},		initialize: function(options){		this.setOptions(options);				this.element = new Element('div',{'class':'example-element'});		this.element.setStyles({});		this.addEvent('click',function(){				});		this.element.inject();			}})OForm = new Class({    Implements: Options,        options:{        'orientation':'horizontal',        'class_list':'',        'id':'',        'url':'',        'button':new Element('input',{'type':'button','value':'Submit'}),        'onComplete':$empty,		'onError':false,		'width':'auto',		'process_response':true,        //styles        //Borders        'border':'1px solid #555555',        'radius':5,        //colors        'background-color':'transparent',        'input-color':'#e5e5e5',        'label-color':'#858585',        'highlight-color':'#353535',        //font        'label-font-style':'normal',        'label-font-weight':'normal',        'label-font-size':12,        'input-font-style':'normal',        'input-font-weight':'normal',        'input-font-size':12,        'label-font-family':'Arial,Helvetica',        'input-font-family':'Arial,Helvetica',        //padding        'padding-left':4,        'padding-right':4,        'padding-top':4,        'padding-bottom':4,        //margin        'margin-left':2,        'margin-right':2,        'margin-top':2,        'margin-bottom':2,        //dimensions        'label-width':'auto',        'label-height':'auto',        'input-width':200,        'input-height':'auto',        'btn-background-color':'#252525',        'btn-background-image':'none',        'btn-color':'#858585',        'btn-border':'2px outset #353535',        'btn-font':'Arial,Helvetica',        'btn-font-size':12,        'btn-value':'Submit',        'btn-width':100,        'btn-height':'auto',        'btn-label':false,        'btn-position':'left',		'btn-label-color':'#ffffff',		'btn-label-text-align':'left',		//loader		'loader_img':'/obray/images/loaders/loader-standard.gif',		'loader_message':'Processing...',		//images		'input-background-image':'none',		'input-background-image-highlight':'none',		'input-background-position':'top left',		'input-background-repeat':'no-repeat',		//label position		//label position set here could be overridden further down based on value of "label-display" passed in by form 		'label-position':'absolute',		'label-display':'outside',		'label-z-index':10,		'enable_styling':true,				'label-style':false,		'input-style':false,		'button-style':false    },        initialize: function(options){		this.sectionNames = [];		this.sectionIds = [];		this.sectioncount = 0;        this.setOptions(options);        this.elements = [];        this.br = new Element('div',{'class':'clear'});        this.request = new Request({'url':this.options.url,'method':'post'});        this.label_position = this.options['label-position'];				this.options.button.addClass('submit-btn');        this.options.button.setStyles({        	'float':'left',            'cursor':'pointer',            'background-color':this.options['btn-background-color'],            'color':this.options['btn-color'],            'font-family':this.options['btn-font'],            '-webkit-border-bottom-left-radius':    this.options['radius'] + 'px',            '-webkit-border-bottom-right-radius':   this.options['radius'] + 'px',            '-webkit-border-top-left-radius':       this.options['radius'] + 'px',            '-webkit-border-top-right-radius':      this.options['radius'] + 'px',            '-moz-border-radius':                   this.options['radius'] + 'px ' + this.options['radius'] + 'px '+ this.options['radius'] + 'px '+ this.options['radius'] + 'px',            'padding-left':this.options['padding-left'],            'padding-right':this.options['padding-right'],            'padding-top':this.options['padding-top'],            'padding-bottom':this.options['padding-bottom'],            'width':this.options['btn-width'],            'height':this.options['btn-height'],            'margin-left':this.options['margin-left'],            'margin-right':this.options['margin-right'],            'margin-top':this.options['margin-top'],            'margin-bottom':this.options['margin-bottom'],            'background-image':this.options['btn-background-image'],            'border':this.options['btn-border'],            'font-size': this.options['btn-font-size']        });        if(this.options['btn-position'] == 'right'){this.options.button.setStyles({'float':'right'});}        this.options.button.set('value',this.options['btn-value']);        		//thinking about putting the submit button and loader into the same div so I can toggle the visibilty between the two and keep position		//inject button & loader into a div		//this.button_wrapper = new Element('div',{'class':'submit-button-wrapper'});				this.options.button.addEvent('click',function(){			//hide submit button and replace with loader			this.options.button.fade('out');			this.loader = new Element('img', {'src':this.options['loader_img']});			this.loader.setStyles({'float':'right','font-size':'10px'});			this.loader.inject(this.form).fade('in');			            var data = '';            for(var i=0;i<this.elements.length;++i){ data = data + '&' + this.elements[i].name + '=' + this.elements[i].getProperty('value'); }            this.request.removeEvents();            this.request.setOptions({'data':data,'onComplete':function(response){                //destroy loader & show submit button				this.loader.destroy();				//this.options.button.removeClass('Ohidden');				this.options.button.fade('in');				if(this.options['process_response']){									var json = JSON.decode(response);					                if(json.response.error == 'false' || json.response.error == false){                    this.options.onComplete(json);                } else {                    if(this.options.onError == false){                        alert(json.response.error_message);                    } else {                        this.options.onError(json);                    }                }                } else {                	this.options.onComplete();                }            }.bind(this)}).send();                    }.bind(this))        this.options.button_label = new Element('label',{'class':'btn-label'});        this.options.button_label.set('html',this.options['btn-label']);        this.options.button_label.setStyles({            'float':'left',            'padding-left':this.options['padding-left'],            'padding-right':this.options['padding-right'],            'padding-top':this.options['padding-top'],            'padding-bottom':this.options['padding-bottom'],            'margin-left':this.options['margin-left'],            'margin-right':this.options['margin-right'],            'margin-top':this.options['margin-top'],            'margin-bottom':this.options['marign-bottom'],            'border':'1px solid transparent',            'width':this.options['label-width'],			'color':this.options['btn-label-color'],			'text-align':this.options['btn-label-text-align']        })        this.options.button_label.set('html','&nbsp;')    },        // get css function (gets css for all my forms css elements)    getCSS: function(){        var css = [];        for(var i=0;i<this.elements.length;++i){            if(!css.contains(this.elements[i].type)){                css[css.length] = this.elements[i].type;            }        }        var data = '&css=';        for(var i=0;i<css.length;++i){            data = data + css[i]+',';        }        //var asset = new Asset.css('index.cfm?action=pages.getFormCSS'+data+'&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true');    },		            addElement: function(el){    	        this.elements[this.elements.length] = el;				//set label position (relative or absolute) based on value of label-display		if(this.options['label-display'] == 'inside'){			var label_position = 'absolute';		} else if(this.options['label-display'] == 'outside'){			var label_position = 'relative';		} else {			var label_position = this.options['label-position']		}				try{			el.addEvent('keypress',function(e){				if(e.code == 13){ e.preventDefault(); this.options.button.fireEvent('click'); }			}.bind(this));		} catch(err){				}        el.setStyles({            'border':this.options['border'],            'radius':this.options['radius'],            'background-color':this.options['background-color'],            'color':this.options['color'],            'highlight-color':this.options['highlight-color'],            'padding-left':this.options['padding-left'],            'padding-right':this.options['padding-right'],            'padding-top':this.options['padding-top'],            'padding-bottom':this.options['padding-bottom'],            'margin-left':this.options['margin-left'],            'margin-right':this.options['margin-right'],            'margin-top':this.options['margin-top'],            'margin-bottom':this.options['margin-bottom'],            'label-font-size':this.options['label-font-size'],            'label-font-weight':this.options['label-font-weight'],            'label-font-style':this.options['label-font-style'],            'input-font-size':this.options['input-font-size'],            'input-font-weight':this.options['input-font-weight'],            'input-font-style':this.options['input-font-style'],            'input-color':this.options['input-color'],            'label-color':this.options['label-color'],            'label-font-family':this.options['label-font-family'],            'input-font-family':this.options['input-font-family'],            'label-width':this.options['label-width'],            'input-width':this.options['input-width'],            'input-background-image':this.options['input-background-image'],            'input-background-image-highlight':this.options['input-background-image-highlight'],            'input-height':this.options['input-height'],			'input-background-position':this.options['input-background-position'],			'input-background-repeat':this.options['input-background-repeat'],			'label-position':label_position,			'label-z-index':this.options['label-z-index']        });		el.setLabelDisplay(this.options['label-display']);    },    	    inject: function(el,inject){         //1.  get form css        //this.getCSS();                this.form = new Element('form',{'class':this.options.class_list,'id':this.options.id});        this.form.setStyles({'display':'block','width':this.options['width']});        this.form.inject(el);        if(inject != false){			for(var i=0;i<this.elements.length;++i){				this.elements[i].inject(this.form);				if(this.options.orientation == 'vertical'){					this.br.clone().inject(this.form);				}			}        }        this.options.button_label.set('html',this.options['btn-label']);        if(this.options['btn-label'] != false){this.options.button_label.inject(this.form);}        this.options.button.inject(this.form);                this.br.clone().inject(this.form);            },        reset: function(){    	for(var i=0;i<this.elements.length;++i){ this.elements[i].setProperty('value',''); }    	this.elements[0].text_input.focus();    }});OForm2 = new Class({    Implements: Options,        options:{        'orientation':'horizontal',        'class_list':'',        'id':'',        'url':'',        'button':new Element('input',{'type':'button','value':''}),		'button2':false,		'button_cancel':false,		'button_cancel_text':'cancel',		'button_cancel_action':'',		'button_cancel_class':'oform-button-cancel',        'onComplete':$empty,		'onError':false,		'width':'auto',		'process_response':true,        //styles        //Borders        'border':'1px solid #555555',        'radius':5,        //colors        'background-color':'transparent',        'input-color':'#e5e5e5',        'label-color':'#858585',        'highlight-color':'#353535',        //font        'label-font-style':'normal',        'label-font-weight':'normal',        'label-font-size':12,        'input-font-style':'normal',        'input-font-weight':'normal',        'input-font-size':12,        'label-font-family':'Arial,Helvetica',        'input-font-family':'Arial,Helvetica',        //padding        'padding-left':4,        'padding-right':4,        'padding-top':4,        'padding-bottom':4,        //margin        'margin-left':2,        'margin-right':2,        'margin-top':2,        'margin-bottom':2,        //dimensions        'label-width':'auto',        'label-height':'auto',        'input-width':200,        'input-height':'auto',        'btn-background-color':'#252525',        'btn-background-image':'none',        'btn-color':'#858585',        'btn-border':'2px outset #353535',        'btn-font':'Arial,Helvetica',        'btn-font-size':12,        'btn-value':'',        'btn-width':100,        'btn-height':'auto',        'btn-label':false,        'btn-position':'left',		'btn-label-color':'#ffffff',		'btn-label-text-align':'left',		//loader		'loader_img':'/obray/images/loaders/loader-standard.gif',		'loader_message':'Processing...',		//images		'input-background-image':'none',		'input-background-image-highlight':'none',		'input-background-position':'top left',		'input-background-repeat':'no-repeat',		//label position		//label position set here could be overridden further down based on value of "label-display" passed in by form 		'label-position':'absolute',		'label-display':'outside',		'label-z-index':10,		'enable_styling':true,				'label-style':false,		'input-style':false,		'button-style':false,		'form_id':0    },        initialize: function(options){		this.sectionNames = [];		this.sectionIds = [];		this.sectioncount = 0;        this.setOptions(options);        this.elements = [];        this.br = new Element('div',{'class':'clear'});        this.request = new Request({'url':this.options.url,'method':'post'});        this.label_position = this.options['label-position'];						if(this.options.button2 == true) {			this.button2 = new Element('input',{'id':'oform-button2-'+this.options.form_id,'class':'oform-button2-'+this.options.form_id,'type':'button','value':'Submit'});			this.button2.set('value',this.options['btn-value']);			this.button2.addEvent('click',function(){				//hide submit button and replace with loader				this.button2.fade('out');				this.loader = new Element('img', {'src':this.options['loader_img']});				this.loader.setStyles({'float':'right','font-size':'10px'});				this.loader.inject(this.form).fade('in');			            	var data = '';            	for(var i=0;i<this.elements.length;++i){ data = data + '&' + this.elements[i].name + '=' + this.elements[i].getProperty('value'); }				data = data + '&thecoolsubmitbutton=button2';            	this.request.removeEvents();            	this.request.setOptions({'data':data,'onComplete':function(response){            	    //destroy loader & show submit button					this.loader.destroy();					//this.options.button.removeClass('Ohidden');					this.button2.fade('in');					if(this.options['process_response']){											var json = JSON.decode(response);					            	    	if(json.response.error == 'false' || json.response.error == false){               	     		this.options.onComplete(json);               	 		} else {               	    		if(this.options.onError == false){               	        		alert(json.response.error_message);               	     		} else {               	        		this.options.onError(json);                    		}                  		}                	} else {                		this.options.onComplete();                	}            	  }.bind(this)}).send();                    	}.bind(this))        			}										/*CANEL BUTTON*/		if(this.options.button_cancel == true) {			this.button_cancel = new Element(				'input',{					'id':'oform-button-cancel-'+this.options.form_id,					'class':this.options.button_cancel_class,					'type':'button','value':this.options.button_cancel_text,					'onclick':this.options.button_cancel_action				}			);						if(this.options['btn-position'] == 'right'){				this.button_cancel.setStyles({'float':'right'});			} else {				this.button_cancel.setStyles({'float':'left'});			}					}		/*CANEL BUTTON*/								        //this.options.button.setStyles({        	//'float':'left',            //'background-image':'url('+this.options['btn-background-image']+')',        //});		if(this.options.button != false) {			if(this.options['btn-position'] == 'right'){this.options.button.setStyles({'float':'right','cursor':'pointer'});}						this.options.button.set('value',this.options['btn-value']);			this.options.button.set('id','submit-button');						//thinking about putting the submit button and loader into the same div so I can toggle the visibilty between the two and keep position			//inject button & loader into a div			//this.button_wrapper = new Element('div',{'class':'submit-button-wrapper'});						this.options.button.addEvent('click',function(){				//hide submit button and replace with loader				this.options.button.fade('out');				this.loader = new Element('img', {'src':this.options['loader_img']});				this.loader.setStyles({'float':'right','font-size':'10px'});				this.loader.inject(this.form).fade('in');								var data = '';				for(var i=0;i<this.elements.length;++i){ data = data + '&' + this.elements[i].name + '=' + this.elements[i].getProperty('value'); }				data = data + '&thecoolsubmitbutton=button1';				this.request.removeEvents();				this.request.setOptions({'data':data,'onComplete':function(response){					//destroy loader & show submit button					this.loader.destroy();					//this.options.button.removeClass('Ohidden');					this.options.button.fade('in');					if(this.options['process_response']){											var json = JSON.decode(response);											if(json.response.error == 'false' || json.response.error == false){						this.options.onComplete(json);					} else {						if(this.options.onError == false){							alert(json.response.error_message);						} else {							this.options.onError(json);						}					}					} else {						this.options.onComplete();					}				}.bind(this)}).send();							}.bind(this))			this.options.button_label = new Element('label',{'class':'btn-label'});			this.options.button_label.set('html',this.options['btn-label']);			this.options.button_label.setStyles({				'float':'left',				'padding-left':this.options['padding-left'],				'padding-right':this.options['padding-right'],				'padding-top':this.options['padding-top'],				'padding-bottom':this.options['padding-bottom'],				'margin-left':this.options['margin-left'],				'margin-right':this.options['margin-right'],				'margin-top':this.options['margin-top'],				'margin-bottom':this.options['marign-bottom'],				'border':'1px solid transparent',				'width':this.options['label-width'],				'color':this.options['btn-label-color'],				'text-align':this.options['btn-label-text-align']			})			this.options.button_label.set('html','&nbsp;')		}    },        // get css function (gets css for all my forms css elements)    getCSS: function(){        var css = [];        for(var i=0;i<this.elements.length;++i){            if(!css.contains(this.elements[i].type)){                css[css.length] = this.elements[i].type;            }        }        var data = '&css=';        for(var i=0;i<css.length;++i){            data = data + css[i]+',';        }        var asset = new Asset.css('index.cfm?action=pages.getFormCSS'+data+'&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true');    },		            addElement: function(el){        this.elements[this.elements.length] = el;				//set label position (relative or absolute) based on value of label-display		if(this.options['label-display'] == 'inside'){			var label_position = 'absolute';		} else if(this.options['label-display'] == 'outside'){			var label_position = 'relative';		} else {			var label_position = this.options['label-position']		}				try{			el.addEvent('keypress',function(e){				if(e.code == 13){ e.preventDefault(); this.options.button.fireEvent('click'); }			}.bind(this));		} catch(err){				}		/*        el.setStyles({            'border':this.options['border'],            'radius':this.options['radius'],            'background-color':this.options['background-color'],            'color':this.options['color'],            'highlight-color':this.options['highlight-color'],            'padding-left':this.options['padding-left'],            'padding-right':this.options['padding-right'],            'padding-top':this.options['padding-top'],            'padding-bottom':this.options['padding-bottom'],            'margin-left':this.options['margin-left'],            'margin-right':this.options['margin-right'],            'margin-top':this.options['margin-top'],            'margin-bottom':this.options['margin-bottom'],            'label-font-size':this.options['label-font-size'],            'label-font-weight':this.options['label-font-weight'],            'label-font-style':this.options['label-font-style'],            'input-font-size':this.options['input-font-size'],            'input-font-weight':this.options['input-font-weight'],            'input-font-style':this.options['input-font-style'],            'input-color':this.options['input-color'],            'label-color':this.options['label-color'],            'label-font-family':this.options['label-font-family'],            'input-font-family':this.options['input-font-family'],            'label-width':this.options['label-width'],            'input-width':this.options['input-width'],            'input-background-image':this.options['input-background-image'],            'input-background-image-highlight':this.options['input-background-image-highlight'],            'input-height':this.options['input-height'],			'input-background-position':this.options['input-background-position'],			'input-background-repeat':this.options['input-background-repeat'],			'label-position':label_position,			'label-z-index':this.options['label-z-index']        })		*/				el.setLabelDisplay(this.options['label-display']);    },    	    inject: function(el,inject){         //1.  get form css        this.getCSS();                this.form = new Element('form',{'class':this.options.class_list,'id':this.options.id});        this.form.setStyles({'display':'block','width':this.options['width']});        if(inject != false){			for(var i=0;i<this.elements.length;++i){				this.elements[i].inject(this.form);				if(this.options.orientation == 'vertical'){					this.br.clone().inject(this.form);				}			}        }        this.options.button_label.set('html',this.options['btn-label']);        if(this.options['btn-label'] != false){this.options.button_label.inject(this.form);}        		if(this.options.button_cancel == true) {			this.button_cancel.inject(this.form);		}				this.options.button.inject(this.form);				if(this.options.button2 == true) {			this.button2.inject(this.form);		}		        this.br.clone().inject(this.form);        this.form.inject(el);    }});/*************************************************

*************************************************/


OFSelect = new Class({
    Implements: Options,
    
    options:{
        'padding':0,
        'padding-left':0,
        'padding-right':0,
        'padding-top':0,
        'padding-bottom':0,
        'margin':0,
        'font_size':12,
        'color':'#000000',
        'width':100,
		'options_container_height':300,
        'background_color':'#ffffff',
        'background-color':'#ffffff',
        'background_highlight':'#eeeeee',
        'highlight-color':'#eeeeee',
        'float':'right',
        'border':'1px solid #000000',
        'default_value':'Select&nbsp;One',
        'blur':$empty,
        'change':$empty,
        'name':'',
        'label':'',
        'labels':[],
        'values':[],
        'value':-1,
        'class_names':[],
        'arrow':false
    },
    
    initialize: function(options){
        
        this.setOptions(options);
        
        
        this.isOpen = false;
        this.current_index = 0;
        this.value = 0;
        if(this.options.value != -1){ this.value = this.options.value; }
        this.name = this.options.name;
        this.has_focus = false;
        this.is_mouse_down_in_items = false;
        //create select box
        this.select = new Element('div',{'class':'select'});
        this.select.setStyles({'cursor':'pointer','font-family':'Arial, Helvetica','position':'relative','min-height':10,'background-color':this.options.background_color,'float':this.options.float,'padding':this.options.padding,'margin':this.options.margin,'font-size':this.options.font_size,'color':this.options.color,'width':this.options.width,'border':this.options.border,'-webkit-border-bottom-left-radius':'5px','-webkit-border-bottom-right-radius':'5px','-webkit-border-top-left-radius':'5px','-webkit-border-top-right-radius':'5px','-moz-border-radius':'5px 5px 5px 5px'});
        this.select.set('html','<span style="width:auto;">'+this.options.default_value+'</span>');
        this.select.addEvent('click',function(){
            if(this.isOpen){
                this.items_container.setStyles({'display':'none','top':this.select.getCoordinates().height});
                this.isOpen = false;
            } else {
                this.items_container.setStyles({'display':'block','top':this.select.getCoordinates().height,'min-width':this.options.width});
                this.isOpen = true;
            }
            this.select_input.focus();
        }.bind(this));
        this.select.addEvent('mouseenter',function(){
                this.select.setStyles({'background-color':this.options['highlight-color']});
        }.bind(this));
        this.select.addEvent('mouseleave',function(){
            if(!this.has_focus){
                this.select.setStyles({'background-color':this.options['background-color']});
            }
        }.bind(this));
        
        
        
        this.select_label = new Element('label');
        
        if(this.options.label != ''){
            this.select_label.set('html',this.options.label);
            this.select_label.setStyles({'float':'left'});
        } 
        
        //select input (allows us to call onBlur and onFocus
        this.select_input = new Element('input',{'type':'text','value':this.value});
        this.select_input.setStyles({'position':'absolute','left':-5000,'height':1,'width':1,'padding':0,'margin':0,'border':0,'z-index':10000});
        this.select_input.inject(this.select);
        this.select_input.addEvent('keydown',function(e){
            if(e.key == 'down'){
                ++this.current_index;
                if(this.current_index > this.items.length){
                    this.current_index = 1;
                }
                this.items[this.current_index-1].fireEvent('mousedown');
            } else if(e.key == 'up'){
                --this.current_index;
                if(this.current_index - 1 < 0){
                    this.current_index = this.items.length;
                }
                this.items[this.current_index-1].fireEvent('mousedown');
            }
        }.bind(this));
        this.select_input.addEvent('focus',function(){
            this.has_focus = true;
            this.select.setStyles({'background-color':this.options['highlight-color']});
        }.bind(this));
        this.select_input.addEvent('blur',function(){
			if(this.is_mouse_down_in_items == false){
				this.has_focus = false;
				this.select.setStyles({'background-color':this.options['background-color']});
				this.items_container.setStyles({'display':'none','top':this.select.getCoordinates().height});
				this.isOpen = false;
				this.options.blur(this.getProperty('value'));
			}
        }.bind(this));
        
        //Handle Items
        this.items = [];
        this.items_container = new Element('div',{'class':'options-container'});
        this.items_container.setStyles({'position':'absolute','left':0,'display':'none','background-color':this.options.background_color,'z-index':5000,'height':this.options.options_container_height,'width':200,'overflow-y':'scroll'});
		this.items_container.addEvent('mousedown',function(){ this.is_mouse_down_in_items = true; }.bind(this));
        this.items_container.addEvent('mouseup',function(){
        	this.is_mouse_down_in_items = false;
        	this.select_input.focus();
        }.bind(this));
        this.items_container.inject(this.select);
        for(var i=0;i<this.options.labels.length;++i){ this.addOption(this.options.labels[i],this.options.values[i]); }
        
        this.arrow = new Element('div',{'class':'ofselect-arrow'});
       	this.arrow.setStyles({'position':'absolute'});
        this.arrow.inject(this.select)
    },
    
    setStyles: function(style_options){
    
        this.select.setStyles({
            'float':'left',
            'border':style_options.border,
            '-webkit-border-bottom-left-radius':	style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':	style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':		style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':		style_options['radius'] + 'px',
            '-moz-border-radius':       			style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'border-radius':						style_options['radius'] + 'px',
            'padding-left':             			style_options['padding-left']+1 + 'px',
            'padding-right':            			style_options['padding-right']+1 + 'px',
            'padding-top':              			style_options['padding-top']+1 + 'px',
            'padding-bottom':           			style_options['padding-bottom']+1 + 'px',
            'margin-left':              			style_options['margin-left'] + 'px',
            'margin-right':             			style_options['margin-right'] + 'px',
            'margin-top':               			style_options['margin-top'] + 'px',
            'margin-bottom':            			style_options['margin-bottom'] + 'px',
            'font-size':                			style_options['input-font-size'] + 'px',
            'font-weight':              			style_options['input-font-weight'],
            'font-style':               			style_options['input-font-style'],
            'background-color':         			style_options['background-color'],
            'color':                    			style_options['input-color'],
            'width':								style_options['input-width']
        })
        
       
        this.select_label.setStyles({
            'float':'left',
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 'px',
            'padding-right':style_options['padding-right'] + 'px',
            'padding-top':style_options['padding-top'] + 'px',
            'padding-bottom':style_options['padding-bottom'] + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'background-color':style_options['background-color'],
            'color':style_options['label-color'],
            'width':style_options['label-width']
        });
        
        this.items_container.setStyles({
            'background-color':style_options['background-color'],
            'border':style_options.border,
            '-webkit-border-bottom-left-radius':style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':style_options['radius'] + 'px',
            '-moz-border-radius': style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'border-radius':style_options['radius'] + 'px',
            'padding-left':style_options['margin-left'],
            'padding-right':style_options['margin-right'],
            'padding-top':style_options['margin-top'],
            'padding-bottom':style_options['margin-bottom'],
            'background-color':style_options['background-color']
        })
        this.options['background-color'] = style_options['background-color'];
        this.options['highlight-color'] = style_options['highlight-color'];
        this.options['color'] = style_options['input-color'];
        for(var i=0;i<this.items.length;++i){
            this.items[i].setStyles({
                'padding-left':style_options['padding-left'],
                'padding-right':style_options['padding-right'],
                'padding-top':style_options['padding-top'],
                'padding-bottom':style_options['padding-bottom'],
                'text-align':'left',
                'color':style_options['input-color']
            })
            this.options['padding'] = style_options['padding-left'];
        }
    },
    
    inject: function(el){
        this.select.inject(el);
        if(this.options.label != ''){ this.select_label.inject(this.select,'before'); }
        for(var i=0;i<this.items.length;++i){
        	if(this.items[i].value == this.options.value){ this.items[i].fireEvent('mousedown'); }
        }
    },
            
    addOption: function(label,value,level){
    	level = typeof(level) != 'undefined' ? level : 0;
    	var padding_left = level*5+5;
        this.items[this.items.length] = new Element('div',{'class':'item'});
        if(this.options.class_names.length != 0){ this.items[this.items.length-1].addClass(this.options.class_names[this.items.length-1]); }
        this.items[this.items.length-1].setStyles({'padding':this.options['padding'],'padding-left':padding_left,'cursor':'pointer','text-align':'left','color':this.options['color']});
        this.items[this.items.length-1].value = value;
        this.items[this.items.length-1].label = label;
        this.items[this.items.length-1].set('html',label);
        this.items[this.items.length-1].inject(this.items_container);
        this.items[this.items.length-1].highlight_color = this.options['highlight-color'];
        this.items[this.items.length-1].background_color = this.options['background-color'];
        this.items[this.items.length-1].addEvent('mouseenter',function(options){this.setStyles({'background-color':options['highlight-color']});}.pass(this.options,this.items[this.items.length-1]));
        this.items[this.items.length-1].addEvent('mouseleave',function(options){this.setStyles({'background-color':options['background-color']});}.pass(this.options,this.items[this.items.length-1]));
        this.items[this.items.length-1].addEvent('mousedown',function(input){
            this.getParent().getParent().getFirst().set('text',this.label);
            this.getParent().getParent().getFirst().getNext().setProperty('value',this.value);
        });
        this.items[this.items.length-1].addEvent('mousedown',function(item){
        	if(item.value != this.options.value){
        		this.options.change.delay(250,'',item.value);
        		this.options.value = -1;
        	}
        }.bind(this,this.items[this.items.length-1]));
    },
    
    addEvent: function(type,fn){
	    //this.select.addEvent(type,fn);
	},
    
    getProperty: function(property){
        if(property == 'value'){
            return this.select_input.getProperty('value');
        }
    },
    
    clear: function(){
    	this.items_container.set('html',''); 
    	this.items = [];
    },
    
    setLabelDisplay: $empty
    
});

// MonkeyPhysics: DatePicker
// this is a minified version, for production use
// source, updates and documentation available @ http://www.monkeyphysics.com/mootools

var DatePicker=new Class({Implements:Options,d:'',today:'',choice:{},bodysize:{},limit:{},attachTo:null,picker:null,slider:null,oldContents:null,newContents:null,input:null,visual:null,options:{pickerClass:'datepicker',days:['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],months:['January','February','March','April','May','June','July','August','September','October','November','December'],dayShort:2,monthShort:3,startDay:1,timePicker:false,timePickerOnly:false,yearPicker:true,yearsPerPage:20,format:'d-m-Y',allowEmpty:false,inputOutputFormat:'U',animationDuration:400,useFadeInOut:!Browser.Engine.trident,startView:'month',positionOffset:{x:0,y:0},minDate:null,maxDate:null,debug:false,toggleElements:null,onShow:$empty,onClose:$empty,onSelect:$empty},initialize:function(attachTo,options){this.attachTo=attachTo;this.setOptions(options).attach();if(this.options.timePickerOnly){this.options.timePicker=true;this.options.startView='time';}
this.formatMinMaxDates();document.addEvent('mousedown',this.close.bind(this));},formatMinMaxDates:function(){if(this.options.minDate&&this.options.minDate.format){this.options.minDate=this.unformat(this.options.minDate.date,this.options.minDate.format);}
if(this.options.maxDate&&this.options.maxDate.format){this.options.maxDate=this.unformat(this.options.maxDate.date,this.options.maxDate.format);this.options.maxDate.setHours(23);this.options.maxDate.setMinutes(59);this.options.maxDate.setSeconds(59);}},attach:function(){if($chk(this.options.toggleElements)){var togglers=$$(this.options.toggleElements);document.addEvents({'keydown':function(e){if(e.key=="tab"){this.close(null,true);}}.bind(this)});};$$(this.attachTo).each(function(item,index){if(item.retrieve('datepicker'))return;if($chk(item.get('value'))){var init_clone_val=this.format(new Date(this.unformat(item.get('value'),this.options.inputOutputFormat)),this.options.format);}else if(!this.options.allowEmpty){var init_clone_val=this.format(new Date(),this.options.format);}else{var init_clone_val='';}
var display=item.getStyle('display');var clone=item.setStyle('display',this.options.debug?display:'none').store('datepicker',true).clone().store('datepicker',true).removeProperty('name').setStyle('display',display).set('value',init_clone_val).inject(item,'after');if($chk(this.options.toggleElements)){togglers[index].setStyle('cursor','pointer').addEvents({'click':function(e){this.onFocus(item,clone);}.bind(this)});clone.addEvents({'blur':function(){item.set('value',clone.get('value'));}});}else{clone.addEvents({'keydown':function(e){if(this.options.allowEmpty&&(e.key=="delete"||e.key=="backspace")){item.set('value','');e.target.set('value','');this.close(null,true);}else if(e.key=="tab"){this.close(null,true);}else{e.stop();}}.bind(this),'focus':function(e){this.onFocus(item,clone);}.bind(this)});}}.bind(this));},onFocus:function(original_input,visual_input){var init_visual_date,d=visual_input.getCoordinates();if($chk(original_input.get('value'))){init_visual_date=this.unformat(original_input.get('value'),this.options.inputOutputFormat).valueOf();}else{init_visual_date=new Date();if($chk(this.options.maxDate)&&init_visual_date.valueOf()>this.options.maxDate.valueOf()){init_visual_date=new Date(this.options.maxDate.valueOf());}
if($chk(this.options.minDate)&&init_visual_date.valueOf()<this.options.minDate.valueOf()){init_visual_date=new Date(this.options.minDate.valueOf());}}
this.show({left:d.left+this.options.positionOffset.x,top:d.top+d.height+this.options.positionOffset.y},init_visual_date);this.input=original_input;this.visual=visual_input;this.options.onShow();},dateToObject:function(d){return{year:d.getFullYear(),month:d.getMonth(),day:d.getDate(),hours:d.getHours(),minutes:d.getMinutes(),seconds:d.getSeconds()};},dateFromObject:function(values){var d=new Date();d.setDate(1);['year','month','day','hours','minutes','seconds'].each(function(type){var v=values[type];if(!$chk(v))return;switch(type){case'day':d.setDate(v);break;case'month':d.setMonth(v);break;case'year':d.setFullYear(v);break;case'hours':d.setHours(v);break;case'minutes':d.setMinutes(v);break;case'seconds':d.setSeconds(v);break;}});return d;},show:function(position,timestamp){this.formatMinMaxDates();if($chk(timestamp)){this.d=new Date(timestamp);}else{this.d=new Date();}
this.today=new Date();this.choice=this.dateToObject(this.d);this.mode=(this.options.startView=='time'&&!this.options.timePicker)?'month':this.options.startView;this.render();this.picker.setStyles(position);},render:function(fx){if(!$chk(this.picker)){this.constructPicker();}else{var o=this.oldContents;this.oldContents=this.newContents;this.newContents=o;this.newContents.empty();}
var startDate=new Date(this.d.getTime());this.limit={right:false,left:false};if(this.mode=='decades'){this.renderDecades();}else if(this.mode=='year'){this.renderYear();}else if(this.mode=='time'){this.renderTime();this.limit={right:true,left:true};}else{this.renderMonth();}
this.picker.getElement('.previous').setStyle('visibility',this.limit.left?'hidden':'visible');this.picker.getElement('.next').setStyle('visibility',this.limit.right?'hidden':'visible');this.picker.getElement('.titleText').setStyle('cursor',this.allowZoomOut()?'pointer':'default');this.d=startDate;if(this.picker.getStyle('opacity')==0){this.picker.tween('opacity',0,1);}
if($chk(fx))this.fx(fx);},fx:function(fx){if(fx=='right'){this.oldContents.setStyles({left:0,opacity:1});this.newContents.setStyles({left:this.bodysize.x,opacity:1});this.slider.setStyle('left',0).tween('left',0,-this.bodysize.x);}else if(fx=='left'){this.oldContents.setStyles({left:this.bodysize.x,opacity:1});this.newContents.setStyles({left:0,opacity:1});this.slider.setStyle('left',-this.bodysize.x).tween('left',-this.bodysize.x,0);}else if(fx=='fade'){this.slider.setStyle('left',0);this.oldContents.setStyle('left',0).set('tween',{duration:this.options.animationDuration/2}).tween('opacity',1,0);this.newContents.setStyles({opacity:0,left:0}).set('tween',{duration:this.options.animationDuration}).tween('opacity',0,1);}},constructPicker:function(){this.picker=new Element('div',{'class':this.options.pickerClass}).inject(document.body);if(this.options.useFadeInOut){this.picker.setStyle('opacity',0).set('tween',{duration:this.options.animationDuration});}
var h=new Element('div',{'class':'header'}).inject(this.picker);var titlecontainer=new Element('div',{'class':'title'}).inject(h);new Element('div',{'class':'previous'}).addEvent('click',this.previous.bind(this)).set('text','«').inject(h);new Element('div',{'class':'next'}).addEvent('click',this.next.bind(this)).set('text','»').inject(h);new Element('div',{'class':'closeButton'}).addEvent('click',this.close.bindWithEvent(this,true)).set('text','x').inject(h);new Element('span',{'class':'titleText'}).addEvent('click',this.zoomOut.bind(this)).inject(titlecontainer);var b=new Element('div',{'class':'body'}).inject(this.picker);this.bodysize=b.getSize();this.slider=new Element('div',{styles:{position:'absolute',top:0,left:0,width:2*this.bodysize.x,height:this.bodysize.y}}).set('tween',{duration:this.options.animationDuration,transition:Fx.Transitions.Quad.easeInOut}).inject(b);this.oldContents=new Element('div',{styles:{position:'absolute',top:0,left:this.bodysize.x,width:this.bodysize.x,height:this.bodysize.y}}).inject(this.slider);this.newContents=new Element('div',{styles:{position:'absolute',top:0,left:0,width:this.bodysize.x,height:this.bodysize.y}}).inject(this.slider);},renderTime:function(){var container=new Element('div',{'class':'time'}).inject(this.newContents);if(this.options.timePickerOnly){this.picker.getElement('.titleText').set('text','Select a time');}else{this.picker.getElement('.titleText').set('text',this.format(this.d,'j M, Y'));}
new Element('input',{type:'text','class':'hour'}).set('value',this.leadZero(this.d.getHours())).addEvents({mousewheel:function(e){var i=e.target,v=i.get('value').toInt();i.focus();if(e.wheel>0){v=(v<23)?v+1:0;}else{v=(v>0)?v-1:23;}
i.set('value',this.leadZero(v));e.stop();}.bind(this)}).set('maxlength',2).inject(container);new Element('input',{type:'text','class':'minutes'}).set('value',this.leadZero(this.d.getMinutes())).addEvents({mousewheel:function(e){var i=e.target,v=i.get('value').toInt();i.focus();if(e.wheel>0){v=(v<59)?v+1:0;}else{v=(v>0)?v-1:59;}
i.set('value',this.leadZero(v));e.stop();}.bind(this)}).set('maxlength',2).inject(container);new Element('div',{'class':'separator'}).set('text',':').inject(container);new Element('input',{type:'submit',value:'OK','class':'ok'}).addEvents({click:function(e){e.stop();this.select($merge(this.dateToObject(this.d),{hours:this.picker.getElement('.hour').get('value').toInt(),minutes:this.picker.getElement('.minutes').get('value').toInt()}));}.bind(this)}).set('maxlength',2).inject(container);},renderMonth:function(){var month=this.d.getMonth();this.picker.getElement('.titleText').set('text',this.options.months[month]+' '+this.d.getFullYear());this.d.setDate(1);while(this.d.getDay()!=this.options.startDay){this.d.setDate(this.d.getDate()-1);}
var container=new Element('div',{'class':'days'}).inject(this.newContents);var titles=new Element('div',{'class':'titles'}).inject(container);var d,i,classes,e,weekcontainer;for(d=this.options.startDay;d<(this.options.startDay+7);d++){new Element('div',{'class':'title day day'+(d%7)}).set('text',this.options.days[(d%7)].substring(0,this.options.dayShort)).inject(titles);}
var available=false;var t=this.today.toDateString();var currentChoice=this.dateFromObject(this.choice).toDateString();for(i=0;i<42;i++){classes=[];classes.push('day');classes.push('day'+this.d.getDay());if(this.d.toDateString()==t)classes.push('today');if(this.d.toDateString()==currentChoice)classes.push('selected');if(this.d.getMonth()!=month)classes.push('otherMonth');if(i%7==0){weekcontainer=new Element('div',{'class':'week week'+(Math.floor(i/7))}).inject(container);}
e=new Element('div',{'class':classes.join(' ')}).set('text',this.d.getDate()).inject(weekcontainer);if(this.limited('date')){e.addClass('unavailable');if(available){this.limit.right=true;}else if(this.d.getMonth()==month){this.limit.left=true;}}else{available=true;e.addEvent('click',function(e,d){if(this.options.timePicker){this.d.setDate(d.day);this.d.setMonth(d.month);this.mode='time';this.render('fade');}else{this.select(d);}}.bindWithEvent(this,{day:this.d.getDate(),month:this.d.getMonth(),year:this.d.getFullYear()}));}
this.d.setDate(this.d.getDate()+1);}
if(!available)this.limit.right=true;},renderYear:function(){var month=this.today.getMonth();var thisyear=this.d.getFullYear()==this.today.getFullYear();var selectedyear=this.d.getFullYear()==this.choice.year;this.picker.getElement('.titleText').set('text',this.d.getFullYear());this.d.setMonth(0);var i,e;var available=false;var container=new Element('div',{'class':'months'}).inject(this.newContents);for(i=0;i<=11;i++){e=new Element('div',{'class':'month month'+(i+1)+(i==month&&thisyear?' today':'')+(i==this.choice.month&&selectedyear?' selected':'')}).set('text',this.options.monthShort?this.options.months[i].substring(0,this.options.monthShort):this.options.months[i]).inject(container);if(this.limited('month')){e.addClass('unavailable');if(available){this.limit.right=true;}else{this.limit.left=true;}}else{available=true;e.addEvent('click',function(e,d){this.d.setDate(1);this.d.setMonth(d);this.mode='month';this.render('fade');}.bindWithEvent(this,i));}
this.d.setMonth(i);}
if(!available)this.limit.right=true;},renderDecades:function(){while(this.d.getFullYear()%this.options.yearsPerPage>0){this.d.setFullYear(this.d.getFullYear()-1);}
this.picker.getElement('.titleText').set('text',this.d.getFullYear()+'-'+(this.d.getFullYear()+this.options.yearsPerPage-1));var i,y,e;var available=false;var container=new Element('div',{'class':'years'}).inject(this.newContents);if($chk(this.options.minDate)&&this.d.getFullYear()<=this.options.minDate.getFullYear()){this.limit.left=true;}
for(i=0;i<this.options.yearsPerPage;i++){y=this.d.getFullYear();e=new Element('div',{'class':'year year'+i+(y==this.today.getFullYear()?' today':'')+(y==this.choice.year?' selected':'')}).set('text',y).inject(container);if(this.limited('year')){e.addClass('unavailable');if(available){this.limit.right=true;}else{this.limit.left=true;}}else{available=true;e.addEvent('click',function(e,d){this.d.setFullYear(d);this.mode='year';this.render('fade');}.bindWithEvent(this,y));}
this.d.setFullYear(this.d.getFullYear()+1);}
if(!available){this.limit.right=true;}
if($chk(this.options.maxDate)&&this.d.getFullYear()>=this.options.maxDate.getFullYear()){this.limit.right=true;}},limited:function(type){var cs=$chk(this.options.minDate);var ce=$chk(this.options.maxDate);if(!cs&&!ce)return false;switch(type){case'year':return(cs&&this.d.getFullYear()<this.options.minDate.getFullYear())||(ce&&this.d.getFullYear()>this.options.maxDate.getFullYear());case'month':var ms=(''+this.d.getFullYear()+this.leadZero(this.d.getMonth())).toInt();return cs&&ms<(''+this.options.minDate.getFullYear()+this.leadZero(this.options.minDate.getMonth())).toInt()||ce&&ms>(''+this.options.maxDate.getFullYear()+this.leadZero(this.options.maxDate.getMonth())).toInt()
case'date':return(cs&&this.d<this.options.minDate)||(ce&&this.d>this.options.maxDate);}},allowZoomOut:function(){if(this.mode=='time'&&this.options.timePickerOnly)return false;if(this.mode=='decades')return false;if(this.mode=='year'&&!this.options.yearPicker)return false;return true;},zoomOut:function(){if(!this.allowZoomOut())return;if(this.mode=='year'){this.mode='decades';}else if(this.mode=='time'){this.mode='month';}else{this.mode='year';}
this.render('fade');},previous:function(){if(this.mode=='decades'){this.d.setFullYear(this.d.getFullYear()-this.options.yearsPerPage);}else if(this.mode=='year'){this.d.setFullYear(this.d.getFullYear()-1);}else if(this.mode=='month'){this.d.setMonth(this.d.getMonth()-1);}
this.render('left');},next:function(){if(this.mode=='decades'){this.d.setFullYear(this.d.getFullYear()+this.options.yearsPerPage);}else if(this.mode=='year'){this.d.setFullYear(this.d.getFullYear()+1);}else if(this.mode=='month'){this.d.setMonth(this.d.getMonth()+1);}
this.render('right');},close:function(e,force){if(!$(this.picker))return;var clickOutside=($chk(e)&&e.target!=this.picker&&!this.picker.hasChild(e.target)&&e.target!=this.visual);if(force||clickOutside){if(this.options.useFadeInOut){this.picker.set('tween',{duration:this.options.animationDuration/2,onComplete:this.destroy.bind(this)}).tween('opacity',1,0);}else{this.destroy();}}},destroy:function(){this.picker.destroy();this.picker=null;this.options.onClose();},select:function(values){this.choice=$merge(this.choice,values);var d=this.dateFromObject(this.choice);this.input.set('value',this.format(d,this.options.inputOutputFormat));this.visual.set('value',this.format(d,this.options.format));this.options.onSelect(d);this.close(null,true);},leadZero:function(v){return v<10?'0'+v:v;},format:function(t,format){var f='';var h=t.getHours();var m=t.getMonth();for(var i=0;i<format.length;i++){switch(format.charAt(i)){case'\\':i++;f+=format.charAt(i);break;case'y':f+=(100+t.getYear()+'').substring(1);break
case'Y':f+=t.getFullYear();break;case'm':f+=this.leadZero(m+1);break;case'n':f+=(m+1);break;case'M':f+=this.options.months[m].substring(0,this.options.monthShort);break;case'F':f+=this.options.months[m];break;case'd':f+=this.leadZero(t.getDate());break;case'j':f+=t.getDate();break;case'D':f+=this.options.days[t.getDay()].substring(0,this.options.dayShort);break;case'l':f+=this.options.days[t.getDay()];break;case'G':f+=h;break;case'H':f+=this.leadZero(h);break;case'g':f+=(h%12?h%12:12);break;case'h':f+=this.leadZero(h%12?h%12:12);break;case'a':f+=(h>11?'pm':'am');break;case'A':f+=(h>11?'PM':'AM');break;case'i':f+=this.leadZero(t.getMinutes());break;case's':f+=this.leadZero(t.getSeconds());break;case'U':f+=Math.floor(t.valueOf()/1000);break;default:f+=format.charAt(i);}}
return f;},unformat:function(t,format){var d=new Date();var a={};var c,m;t=t.toString();for(var i=0;i<format.length;i++){c=format.charAt(i);switch(c){case'\\':r=null;i++;break;case'y':r='[0-9]{2}';break;case'Y':r='[0-9]{4}';break;case'm':r='0[1-9]|1[012]';break;case'n':r='[1-9]|1[012]';break;case'M':r='[A-Za-z]{'+this.options.monthShort+'}';break;case'F':r='[A-Za-z]+';break;case'd':r='0[1-9]|[12][0-9]|3[01]';break;case'j':r='[1-9]|[12][0-9]|3[01]';break;case'D':r='[A-Za-z]{'+this.options.dayShort+'}';break;case'l':r='[A-Za-z]+';break;case'G':case'H':case'g':case'h':r='[0-9]{1,2}';break;case'a':r='(am|pm)';break;case'A':r='(AM|PM)';break;case'i':case's':r='[012345][0-9]';break;case'U':r='-?[0-9]+$';break;default:r=null;}
if($chk(r)){m=t.match('^'+r);if($chk(m)){a[c]=m[0];t=t.substring(a[c].length);}else{if(this.options.debug)alert("Fatal Error in DatePicker\n\nUnexpected format at: '"+t+"' expected format character '"+c+"' (pattern '"+r+"')");return d;}}else{t=t.substring(1);}}
for(c in a){var v=a[c];switch(c){case'y':d.setFullYear(v<30?2000+v.toInt():1900+v.toInt());break;case'Y':d.setFullYear(v);break;case'm':case'n':d.setMonth(v-1);break;case'M':v=this.options.months.filter(function(item,index){return item.substring(0,this.options.monthShort)==v}.bind(this))[0];case'F':d.setMonth(this.options.months.indexOf(v));break;case'd':case'j':d.setDate(v);break;case'G':case'H':d.setHours(v);break;case'g':case'h':if(a['a']=='pm'||a['A']=='PM'){d.setHours(v==12?0:v.toInt()+12);}else{d.setHours(v);}break;case'i':d.setMinutes(v);break;case's':d.setSeconds(v);break;case'U':d=new Date(v.toInt()*1000);}};return d;}});

OFDate = new Class({
    Implements: Options,
        
    options: {
        'selector_id':'date',
        'timePicker':false,
        'format':'m/d/Y h:i A',
        //'submit-format':'m/d/Y h:i A',
        'width':137,
        'label':'',
        'name':'',
        'value':'',
        'onClick':$empty,
        'input_id':'',
        'input_class':'date-input'
    },
    
    initialize: function(options){
        this.setOptions(options);
        
        this.type = 'date';
        this.name = this.options.name;
        
        this.date_picker = new Element('div',{'class':'date-picker'});
        this.date_picker.setStyles({'float':'left'})
        
        this.date_label = new Element('label');
        if(this.options.label != ''){
            this.date_label = new Element('label');
            this.date_label.set('html',this.options.label);
            this.date_label.setStyles({'float':'left'});
            this.date_label.inject(this.date_picker);
        }
        
        this.date_input = new Element('input',{'id':this.options.input_id,'type':'text','class':this.options.input_class,'value':this.options.value});
        this.date_input.setStyles({'float':'left','width':this.options.width});
        this.date_input.inject(this.date_picker);
        
        this.date_icon = new Element('img',{'src':'/obray/images/calendar-icon.png','id':this.options.selector_id});
        this.date_icon.setStyles({'float':'left','display':'block','margin':2,'margin-left':0,'cursor':'pointer'});
        this.date_icon.inject(this.date_picker);
        
        this.br = new Element('br',{'class':'clear'});
        this.br.clone().inject(this.date_picker);
        
        this.date_selector = new DatePicker(this.date_input,{'pickerClass':'datepicker_vista','toggleElements':this.date_icon,'timePicker':this.options.timePicker,'format':this.options.format,'inputOutputFormat':this.options.format})
        
        this.date_input.addEvent('click',function(){
            this.options.onClick();
        }.bind(this));
    },
    
    inject: function(el){
        this.date_picker.inject(el);
    },
    
    addEvent: function(type,fn){
	    
	},
    
    setStyles: function(style_options){
        //set input styles
        this.date_input.getNext().setStyles({
            'float':                                'left',
            'border':                               style_options.border,
            '-webkit-border-bottom-left-radius':    style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':   style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':       style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':      style_options['radius'] + 'px',
            '-moz-border-radius':                   style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'border-radius':                        style_options['radius'] + 'px',
            'padding-left':                         style_options['padding-left'] + 'px',
            'padding-right':                        style_options['padding-right'] + 'px',
            'padding-top':                          style_options['padding-top'] + 'px',
            'padding-bottom':                       style_options['padding-bottom'] + 'px',
            'margin-left':                          style_options['margin-left'] + 'px',
            'margin-right':                         style_options['margin-right'] + 'px',
            'margin-top':                           style_options['margin-top'] + 'px',
            'margin-bottom':                        style_options['margin-bottom'] + 'px',
            'font-size':                            style_options['input-font-size'] + 'px',
            'font-weight':                          style_options['input-font-weight'],
            'font-style':                           style_options['input-font-style'],
            'color':                                style_options['input-color'],
            'background-color':						style_options['background-color']
        });
        
        //set label styles
        this.date_label.setStyles({
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 'px',
            'padding-right':style_options['padding-right'] + 'px',
            'padding-top':style_options['padding-top'] + 'px',
            'padding-bottom':style_options['padding-bottom'] + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'color':style_options['label-color'],
            'width':style_options['label-width']
        });
    },
    
    getProperty: function(property){
        if(property == 'value'){ return this.date_input.getNext().getProperty('value'); }
    },
    
    setLabelDisplay: $empty
});


OFCheck = new Class({
    Implements: Options,
    
    options: {
        'class':'',
        'checked':false,
        'height':9,
        'width':9,
        'check-color':'#41e011',
        'label':'',
		'label-width':0,
        'name':'default_check',
		'returntype':'boolean'
    },
    
    initialize: function(options){
        this.setOptions(options);
        if(this.options.checked == '1') {
        	this.is_checked = true;
		} else {
			this.is_checked = false;
		}
        this.name = this.options.name;
        
        this.checkbox_label = new Element('label',{'class':'ocheck-label'});
        this.checkbox_label.set('html',this.options.label);
        
        this.checkbox = new Element('div',{'class':this.options['class']});
        this.checkbox.setStyles({'float':'left','width':15,'height':15,'border':'1px solid #d5d5d5'});
        this.checkbox.addEvent('mouseenter',function(){ this.checkbox.setStyles({'background-color':this.options['highlight-color']}); }.bind(this));
        this.checkbox.addEvent('mouseleave',function(){ this.checkbox.setStyles({'background-color':this.options['background-color']}); }.bind(this));
        this.checkbox.addEvent('click',function(){
            if(this.is_checked){ 
                this.is_checked = false;
                this.check.setStyles({'display':'none'});
            } else { 
                this.is_checked = true; 
                this.check.setStyles({'display':'block'});
            }
        }.bind(this));
        
        this.check = new Element('div',{'class':'checkbox-check'});
        this.check.setStyles({'display':'block','background-color':this.options['check-color'],'width':9,'height':9});
        this.check.inject(this.checkbox);
        this.check.addEvent('click',function(){
            this.checkbox.fireEvent.bind(this,'click');
        }.bind(this));
        
        

        if(!this.options['checked'] || this.options['checked'] == 0){
            this.check.setStyles({'display':'none'})
        } 
		if(this.is_checked) {
			this.check.setStyles({'display':'block'})
		}
    },
    
    setStyles: function(style_options){
    
        this.checkbox.setStyles({
            'cursor':           'pointer',
            'border':           style_options['border'],
            'background-color': style_options['background-color'],
            'color':            style_options['color'],
            'width':            this.options['width'],
            'height':           this.options['height'],
            'margin-left':      style_options['margin-left'] + style_options['label-width'] + style_options['margin-left']*2 + style_options['margin-right'] + style_options['padding-left']*2 + style_options['padding-right'],
            'margin-right':     style_options['margin-right'],
            'margin-top':       style_options['margin-top'] + 4,
            'margin-bottom':    style_options['margin-bottom'] + 4,
            'padding-left':     2,
            'padding-right':    2,
            'padding-top':      2,
            'padding-bottom':   2,
            '-webkit-border-bottom-left-radius':2 + 'px',
            '-webkit-border-bottom-right-radius':2 + 'px',
            '-webkit-border-top-left-radius':2 + 'px',
            '-webkit-border-top-right-radius':2 + 'px',
            '-moz-border-radius': 2 + 'px ' + 2 + 'px '+ 2 + 'px '+ 2 + 'px',
            'border-radius': 2 + 'px'
        });
        this.options['highlight-color'] = style_options['highlight-color'];
        
        this.check.setStyles({
            '-webkit-border-bottom-left-radius': 2 + 'px',
            '-webkit-border-bottom-right-radius': 2 + 'px',
            '-webkit-border-top-left-radius': 2 + 'px',
            '-webkit-border-top-right-radius': 2 + 'px',
            '-moz-border-radius': 2 + 'px ' + 2 + 'px '+ 2 + 'px '+ 2 + 'px',
            'border-radius': 2 + 'px'
        })
        
        //set label styles
        this.checkbox_label.setStyles({
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 1 + 'px',
            'padding-right':style_options['padding-right'] + 1 + 'px',
            'padding-top':style_options['padding-top'] + 1 + 'px',
            'padding-bottom':style_options['padding-bottom'] + 1 + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'color':style_options['label-color'],
            'text-align':'left'
        });
		
		if (this.options['label-width'] != 0){
			this.checkbox_label.setStyles({'width':this.options['label-width']});
		}else{
			this.checkbox_label.setStyles({'width':style_options['label-width']});
		}
    },
    
    inject: function(el){
        this.checkbox.inject(el);
        if(this.options.label != ''){ this.checkbox_label.inject(el); }
    },
    
    addEvent: function(type,fn){
	    this.checkbox.addEvent(type,fn);
	},
    
    getProperty: function(value){
        if(this.options.returntype == "boolean") return this.is_checked;
		else if(this.options.returntype == "number") {
			if(this.is_checked) return 1;
			else return 0;	
		}
		
    },
    
    setLabelDisplay: $empty
});


OFRadio = new Class({
    Implements: Options,
    
    options: {
        'class':'',
        'checked':false,
        'height':9,
        'width':9,
        'check-color':'#41e011'
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.is_checked = this.options['checked'];
        this.pixels = [];
        
        this.radiobox = new Element('div',{'class':this.options['class']});
        this.radiobox.setStyles({'float':'left','position':'relative','width':15,'height':15,'margin-top':'5px','border':'1px solid #f5f5f5'});
        
        for(var i=0;i<15;++i){
            this.pixels[i] = []
            for(var j=0;j<15;++j){
                this.pixels[i][j] = new Element('span',{'class':'radio-pixel'});
                this.pixels[i][j].setStyles({'position':'absolute','display':'block','top':i,'left':j,'background-color':'#888888','height':1,'width':1,'opacity':0});
                this.pixels[i][j].inject(this.radiobox);
            }
        }
        
        
        this.drawCircle(7,7,6,1);
        
        
        
        
        /****
        this.radiobox.addEvent('mouseenter',function(){ this.radiobox.setStyles({'background-color':this.options['highlight-color']}); }.bind(this));
        this.radiobox.addEvent('mouseleave',function(){ this.radiobox.setStyles({'background-color':this.options['background-color']}); }.bind(this));
        this.radiobox.addEvent('click',function(){
            if(this.is_checked){ 
                this.is_checked = false;
                this.check.setStyles({'display':'none'});
            } else { 
                this.is_checked = true; 
                this.check.setStyles({'display':'block'});
            }
        }.bind(this));
        
        this.check = new Element('div',{'class':'checkbox-check'});
        this.check.setStyles({'background-color':this.options['check-color'],'width':9,'height':9});
        this.check.inject(this.radiobox);
        this.check.addEvent('click',function(){
            this.radiobox.fireEvent.bind(this,'click');
        }.bind(this));
        
        if(!this.options['checked']){
            this.check.setStyles({'display':'none'});
        }
        ****/
    },
   
    
    drawCircle: function(x0,y0,radius,opacity){
        
        var o1 = .15;
        var o2 = .45;
        var o3 = 1;
        
        var f = 1 - radius;
        var ddF_x = 1;
        var ddF_y = -2 * radius;
        var x = 0;
        var y = radius;
        //bottom right quadrant
        if(this.pixels[x0 - 2][y0+radius].getStyle('opacity') < o1){this.pixels[x0 - 2][y0+radius].setStyles({'opacity':o1});}
        if(this.pixels[x0 + 2][y0+radius].getStyle('opacity') < o1){this.pixels[x0 + 2][y0+radius].setStyles({'opacity':o1});}
        if(this.pixels[x0 - 1][y0+radius].getStyle('opacity') < o2){this.pixels[x0 - 1][y0+radius].setStyles({'opacity':o2});}
        if(this.pixels[x0 + 1][y0+radius].getStyle('opacity') < o2){this.pixels[x0 + 1][y0+radius].setStyles({'opacity':o2});}
        this.pixels[x0][y0+radius].setStyles({'opacity':o3});
                
        //bottom left quadrant
        if(this.pixels[x0 - 2][y0-radius].getStyle('opacity') < o1){this.pixels[x0 - 2][y0-radius].setStyles({'opacity':o1});}
        if(this.pixels[x0 + 2][y0-radius].getStyle('opacity') < o1){this.pixels[x0 + 2][y0-radius].setStyles({'opacity':o1});}
        if(this.pixels[x0 - 1][y0-radius].getStyle('opacity') < o2){this.pixels[x0 - 1][y0-radius].setStyles({'opacity':o2});}
        if(this.pixels[x0 + 1][y0-radius].getStyle('opacity') < o2){this.pixels[x0 + 1][y0-radius].setStyles({'opacity':o2});}
        this.pixels[x0][y0-radius].setStyles({'opacity':o3});
        
        //bottom left quadrant
        if(this.pixels[x0 + radius][y0 - 2].getStyle('opacity') < o1){this.pixels[x0 + radius][y0 - 2].setStyles({'opacity':o1});}
        if(this.pixels[x0 + radius][y0 + 2].getStyle('opacity') < o1){this.pixels[x0 + radius][y0 + 2].setStyles({'opacity':o1});}
        if(this.pixels[x0 + radius][y0 - 1].getStyle('opacity') < o2){this.pixels[x0 + radius][y0 - 1].setStyles({'opacity':o2});}
        if(this.pixels[x0 + radius][y0 + 1].getStyle('opacity') < o2){this.pixels[x0 + radius][y0 + 1].setStyles({'opacity':o2});}
        this.pixels[x0 + radius][y0].setStyles({'opacity':o3});
        
        //top right quadrant
        if(this.pixels[x0 - radius][y0 - 2].getStyle('opacity') < o1){this.pixels[x0 - radius][y0 - 2].setStyles({'opacity':o1});}
        if(this.pixels[x0 - radius][y0 + 2].getStyle('opacity') < o1){this.pixels[x0 - radius][y0 + 2].setStyles({'opacity':o1});}
        if(this.pixels[x0 - radius][y0 - 1].getStyle('opacity') < o2){this.pixels[x0 - radius][y0 - 2].setStyles({'opacity':o2});}
        if(this.pixels[x0 - radius][y0 + 1].getStyle('opacity') < o2){this.pixels[x0 - radius][y0 + 2].setStyles({'opacity':o2});}
        this.pixels[x0 - radius][y0].setStyles({'opacity':opacity});
        
        while(x < y){
            if(f >= 0){
                y--;
                ddF_y += 2;
                f += ddF_y;
            }
            x++;
            ddF_x += 2;
            f += ddF_x;    
            
            //bottom right quadrant top half
            if(this.pixels[x0 + x - 2][y0 + y].getStyle('opacity') < o1){this.pixels[x0 + x - 2][y0 + y].setStyles({'opacity':o1});}
            if(this.pixels[x0 + x + 2][y0 + y].getStyle('opacity') < o1){this.pixels[x0 + x + 2][y0 + y].setStyles({'opacity':o1});}
            if(this.pixels[x0 + x - 1][y0 + y].getStyle('opacity') < o2){this.pixels[x0 + x - 1][y0 + y].setStyles({'opacity':o2});}
            if(this.pixels[x0 + x + 1][y0 + y].getStyle('opacity') < o2){this.pixels[x0 + x + 1][y0 + y].setStyles({'opacity':o2});}
            this.pixels[x0 + x][y0 + y].setStyles({'opacity':o3});
            
            //Top right quadrant bottom half
            if(this.pixels[x0 - x - 2][y0 + y].getStyle('opacity') < o1){this.pixels[x0 - x - 2][y0 + y].setStyles({'opacity':o1});}
            if(this.pixels[x0 - x + 2][y0 + y].getStyle('opacity') < o1){this.pixels[x0 - x + 2][y0 + y].setStyles({'opacity':o1});}
            if(this.pixels[x0 - x - 1][y0 + y].getStyle('opacity') < o2){this.pixels[x0 - x - 1][y0 + y].setStyles({'opacity':o2});}
            if(this.pixels[x0 - x + 1][y0 + y].getStyle('opacity') < o2){this.pixels[x0 - x + 1][y0 + y].setStyles({'opacity':o2});}
            this.pixels[x0 - x][y0 + y].setStyles({'opacity':o3});
            
            //bottom left top half
            if(this.pixels[x0 + x - 2][y0 - y].getStyle('opacity') < o1){this.pixels[x0 + x - 2][y0 - y].setStyles({'opacity':o1});}
            if(this.pixels[x0 + x + 2][y0 - y].getStyle('opacity') < o1){this.pixels[x0 + x + 2][y0 - y].setStyles({'opacity':o1});}
            if(this.pixels[x0 + x - 1][y0 - y].getStyle('opacity') < o2){this.pixels[x0 + x - 1][y0 - y].setStyles({'opacity':o2});}
            if(this.pixels[x0 + x + 1][y0 - y].getStyle('opacity') < o2){this.pixels[x0 + x + 1][y0 - y].setStyles({'opacity':o2});}
            this.pixels[x0 + x][y0 - y].setStyles({'opacity':o3});
            
            if(this.pixels[x0 + x - 2][y0 - y].getStyle('opacity') < o1){this.pixels[x0 + x - 2][y0 - y].setStyles({'opacity':o1});}
            if(this.pixels[x0 + x + 2][y0 - y].getStyle('opacity') < o1){this.pixels[x0 + x + 2][y0 - y].setStyles({'opacity':o1});}
            if(this.pixels[x0 + x - 1][y0 - y].getStyle('opacity') < o2){this.pixels[x0 + x - 1][y0 - y].setStyles({'opacity':o2});}
            if(this.pixels[x0 + x + 1][y0 - y].getStyle('opacity') < o2){this.pixels[x0 + x + 1][y0 - y].setStyles({'opacity':o2});}
            this.pixels[x0 - x][y0 - y].setStyles({'opacity':opacity});
            
            //bottom right quadrant bottom half
            if(this.pixels[x0 + y][y0 + x - 2].getStyle('opacity') < o1){this.pixels[x0 + y][y0 + x - 2].setStyles({'opacity':o1});}
            if(this.pixels[x0 + y][y0 + x + 2].getStyle('opacity') < o1){this.pixels[x0 + y][y0 + x + 2].setStyles({'opacity':o1});}
            if(this.pixels[x0 + y][y0 + x - 1].getStyle('opacity') < o2){this.pixels[x0 + y][y0 + x - 1].setStyles({'opacity':o2});}
            if(this.pixels[x0 + y][y0 + x + 1].getStyle('opacity') < o2){this.pixels[x0 + y][y0 + x + 1].setStyles({'opacity':o2});}    
            this.pixels[x0 + y][y0 + x].setStyles({'opacity':o3});
            
            
            //this.pixels[x0 - y][y0 + x].setStyles({'opacity':opacity});
            //this.pixels[x0 + y][y0 - x].setStyles({'opacity':opacity});
            //this.pixels[x0 - y][y0 - x].setStyles({'opacity':opacity});
        }
        
        
        
       
    },
    
    setStyles: function(style_options){
        /*****
        this.radiobox.setStyles({
            'cursor':           'pointer',
            'border':           style_options['border'],
            'background-color': style_options['background-color'],
            'color':            style_options['color'],
            'width':            this.options['width'],
            'height':           this.options['height'],
            'margin-left':      style_options['margin-left'],
            'margin-right':     style_options['margin-right'],
            'margin-top':       style_options['margin-top'] + 4,
            'margin-bottom':    style_options['margin-bottom'] + 4,
            'padding-left':     2,
            'padding-right':    2,
            'padding-top':      2,
            'padding-bottom':   2,
            '-webkit-border-bottom-left-radius': 7 + 'px',
            '-webkit-border-bottom-right-radius': 7 + 'px',
            '-webkit-border-top-left-radius': 7 + 'px',
            '-webkit-border-top-right-radius': 7 + 'px',
            '-moz-border-radius': 7 + 'px ' + 7 + 'px '+ 7 + 'px '+ 7 + 'px',
            'border-radius':7 + 'px'
        })
        this.options['highlight-color'] = style_options['highlight-color'];
        
        this.check.setStyles({
            '-webkit-border-bottom-left-radius':5 + 'px',
            '-webkit-border-bottom-right-radius':5 + 'px',
            '-webkit-border-top-left-radius':5 + 'px',
            '-webkit-border-top-right-radius':5 + 'px',
            '-moz-border-radius': 5 + 'px ' + 5 + 'px '+ 5 + 'px '+ 5 + 'px',
            'border-radius':7 + 'px'
        })
        ****/
    },
    
    inject: function(el){
        this.radiobox.inject(el);
    },
    
    addEvent: function(type,fn){
	    
	},
    
    getProperty: function(value){
        return this.is_checked;
    },
    
    setLabelDisplay: $empty
});
OProgressBar = new Class({	Implements: Options,		options:{			},		initialize: function(options){		this.setOptions(options);				this.bar_container = new Element('div',{'class':'oprogress-bar-container'});		this.bar_container.setStyles({'overflow':'hidden'});				this.bar = new Element('div',{'class':'oprogress-bar'});		this.bar.setStyles({'width':0});		this.bar.inject(this.bar_container);	},		inject: function(el){		this.bar_container.inject(el);	},		setProgress: function(percent,tweak){		var width = this.bar_container.getCoordinates().width-tweak;		progress_width = (width/100) * percent;				this.bar.setStyles({'width':progress_width});		this.bar.set('html','<em>'+percent+'% </em>');	},		show: function(){		this.bar_container.setStyles({'display':'block'});	},		hide: function(){		this.bar_container.setStyles({'display':'none'});	}});// obray file form elementOFFile = new Class({    Implements: Options,        'options':{        'label':'',        'blah':'blah',        'uploadSuccess':$empty,        'upload_url':'index.cfm?action=videos.uploadvideo',        'extensions':'',        'name':'',        'file_name':'',        'file_ext':'',        'file_size':0,        'file_types': {},        'host_name':window.location.hostname    },        initialize: function(options){        this.setOptions(options);                this.upload_target = $('upload_target');        this.json = {'response':{'server_file_name':this.options.file_name,'server_file_ext':this.options.file_ext,'file_size':this.options.file_size}};        this.load_state = 'waiting';        this.name = this.options.name;                // file input container        this.file_container = new Element('div',{'class':'ofile-container'});        this.file_container.setStyles({'position':'relative','float':'left'})                // file label        this.file_label = new Element('label',{'class':'ofile-label'});        this.file_label.set('html',this.options.label);        if(this.options.label != ''){ this.file_label.inject(this.file_container); }                this.upload_status = new Element('div',{'class':'upload-status'});        this.upload_status.inject(this.file_container);        this.upload_status.setStyles({'float':'left'});                this.upload_btn = new Element('div',{'class':'upload-button-wrapper'});        this.upload_btn.inject(this.upload_status);        this.upload_btn.set('html','<span>Upload File</span>');        this.upload_btn.setStyles({'height':20,'width':150,'background-color':'black','display':'none','font-family':'Helvetica,Arial','font-size':12,'color':'#ffffff','text-align':'center',        	'background-color':'#252525',        	'background-image':'none',			'border': '2px outset #353535',			'border-bottom-left-radius': '5px 5px',			'border-bottom-right-radius': '5px 5px',			'border-top-left-radius': '5px 5px',			'border-top-right-radius': '5px 5px',			'color': '#858585',			'cursor': 'pointer',			'float': 'left',			'font-family': 'Arial, Helvetica',			'font-size': '12px',			'height': 'auto',			'margin-bottom': '2px',			'margin-left': '2px',			'margin-right': '2px',			'margin-top': '2px',			'padding-bottom': '4px',			'padding-left': '4px',			'padding-right': '4px',			'padding-top': '4px',			'width': '100px'        });                this.progress_bar = new OProgressBar();        this.progress_bar.inject(this.upload_status);        this.progress_bar.hide();                this.upload_error = new Element('div',{'class':'upload-status-response error'});        this.upload_error.inject(this.upload_status);        this.upload_error.setStyles({'display':'none','font-family':'Helvetica,Arial','color':'#858585','padding':8,'font-size':12,'color':'#AA0000'});                this.upload_success = new Element('div',{'class':'upload-status-response success'});        this.upload_success.inject(this.upload_status);        this.upload_success.setStyles({'display':'none','font-family':'Helvetica,Arial','color':'#858585','padding':8,'font-size':12,'color':'#00AA00'});                this.setLoadState('ready');	 		// Uploader instance		this.swf = new Swiff.Uploader({			path: '/obray/config/Swiff.Uploader.swf',			url: 'http://'+window.location.hostname+'/index.cfm?action=forms.uploadFile&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true&requesttimeout=5000',			verbose: true,			queued: false,			multiple: false,			method: 'post',			target: this.upload_status,			instantStart: true,			typeFilter: this.options.file_types,			fileSizeMax: 2 * 1024 * 1024 * 1024 * 1024,			onSelectSuccess: function(files) {				if (Browser.Platform.linux) window.alert('Warning: Due to a misbehaviour of Adobe Flash Player on Linux,\nthe browser will probably freeze during the upload process.\nSince you are prepared now, the upload will start right away ...');				this.swf.setEnabled(false);				this.setLoadState('uploading');			}.bind(this),			onSelectFail: function(files) {				alert('' + files[0].name + ' was not added!, Please select an image smaller than 2 Mb. (Error: #' + files[0].validationError + ')');			},			appendCookieData: false,			onQueue: this.progress.bind(this),			onFileComplete: function(file) {				if (file.response.error) {					alert(file.response.error + ' - ' + file.response.code);					if(this.swf.fileList[0].name.length > 18){						var file_name = this.swf.fileList[0].name.substring(0,18) + '...';					} else {						var file_name= this.swf.fileList[0].name;					}					file_name = '"' + file_name + '"'					this.upload_error.set('html','' + file_name + ' failed.');					this.try_again = new Element('span');					this.try_again.set('html',' (Try Again)');					this.try_again.setStyles({'color':'#d5d5d5'});					this.try_again.inject(this.upload_error);					this.setLoadState('error');				} else {					this.json = JSON.decode(file.response.text);										if(this.json.response.server_file.length > 20){						var file_name = this.json.response.server_file.substring(0,20) + '...';					} else {						var file_name=this.json.response.server_file;					}					file_name = '"' + file_name + '"';										this.upload_success.set('html','' + file_name + ' (' + (this.json.response.file_size/1024/1024).toFixed(2) + ' MB)' );					this.setLoadState('finished');				}	 				file.remove();				this.swf.setEnabled(true);			}.bind(this),			onComplete: function() {							}		});	 		// Button state		this.upload_btn.addEvents({			click: function() {				return false;			},			mouseenter: function() {				this.upload_btn.addClass('hover');				this.swf.reposition();			}.bind(this),			mouseleave: function() {				this.removeClass('hover');				this.blur();			},			mousedown: function() {				this.focus();			}		});                		    },        progress: function(){    	if (!this.swf.uploading) return;			var size = Swiff.Uploader.formatUnit(this.swf.size, 'b');			//link.set('html', '<span class="small">' + swf.percentLoaded + '% of ' + size + '</span>');			this.progress_bar.setProgress(this.swf.percentLoaded,13);    },        setLoadState: function(state){        if(state == 'uploading'){        	this.upload_btn.setStyles({'display':'none'});        	this.upload_success.setStyles({'display':'none'});        	this.upload_error.setStyles({'display':'none'});        	this.progress_bar.show();        } else if (state == 'finished'){        	this.upload_btn.setStyles({'display':'none'});        	this.upload_success.setStyles({'display':'block'});        	this.upload_error.setStyles({'display':'none'});        	this.progress_bar.hide();        } else if (state == 'error'){        	this.upload_btn.setStyles({'display':'none'});        	this.upload_success.setStyles({'display':'none'});        	this.upload_error.setStyles({'display':'block'});        	this.progress_bar.hide();        } else if (state == 'ready'){			this.upload_btn.setStyles({'display':'block'});        	this.upload_success.setStyles({'display':'none'});        	this.upload_error.setStyles({'display':'none'});        	this.progress_bar.hide();        }    },        setStyles: function(style_options){        	this.progress_bar.bar_container.setStyles({'overflow':'hidden','width':206,'border':'1px solid #454545','padding':2,'border-radius':'3px 3px 3px 3px','margin':2});    	this.progress_bar.bar.setStyles({'width':0,'height':9,'background-color':'#41E011','border-radius':'2px 2px 2px 2px','text-align':'center','padding':3,'font-family':'Helvetica,Arial'});    	        //set label styles        this.file_label.setStyles({            'border':style_options['border'],            'border-color':'transparent',            'padding-left':style_options['padding-left'] + 1 + 'px',            'padding-right':style_options['padding-right'] + 1 + 'px',            'padding-top':style_options['padding-top'] + 1 + 'px',            'padding-bottom':style_options['padding-bottom'] + 1 + 'px',            'margin-left':style_options['margin-left'] + 'px',            'margin-right':style_options['margin-right'] + 'px',            'margin-top':style_options['margin-top'] + 'px',            'margin-bottom':style_options['margin-bottom'] + 'px',            'font-size':style_options['label-font-size'] + 'px',            'font-weight':style_options['label-font-weight'],            'font-style':style_options['label-font-style'],            'color':style_options['label-color'],            'width':style_options['label-width']        });    },        getProperty: function(property){        if(this.json != ''){            return encodeURIComponent(this.json.response.server_file_name) + '&file_ext=' + encodeURIComponent(this.json.response.server_file_ext) + '&file_size=' + encodeURIComponent(this.json.response.file_size)+'&full_file_name='+encodeURIComponent(this.json.response.server_file_name)+'.'+encodeURIComponent(this.json.response.server_file_ext);        } else {            return '&file_ext=&file_size=';        }    },        inject: function(el){        this.file_container.inject(el);    },        addEvent: function(type,fn){	    	},        setLabelDisplay: $empty});OFText = new Class({    Implements: Options,        options: {        'label':'',        'text-area':false,		'type':'text',        'blur':$empty,        'focus':$empty,        'name':'',        'value':'',		'text-area-input-height':.50,		'text-area-background-image':''    },        initialize: function(options){    	    	// container		// place label and input field into a div to give us control over absolute positioning for label        this.container = new Element('div',{'class':'input-wrapper'});		this.container.setStyles({'width':'100%'});		// container styles		this.container.setStyles({			'position':'relative'		});    			this.setOptions(options);        this.name = this.options.name;                this.text_label = new Element('label',{'class':'otext-label'});        this.text_label.set('html',this.options.label);        this.text_label.setStyles({'text-align':'right'});        if(this.options['text-area']){            this.text_input = new Element('textarea',{'class':'otext-input','value':this.options.value});            this.text_input.set('html',this.options.value);        } else {            //this.text_input = new Element('input',{'class':'otext-input','value':this.options.value});			this.text_input = new Element('input',{'type':this.options.type, 'class':'otext-input','value':this.options.value});        }                this.text_input.addEvent('blur',this.options.blur);        this.text_input.addEvent('focus',this.options.focus);								//inject element and label into container		if(this.options.label != ''){ this.text_label.inject(this.container); }                /******/    },        setStyles: function(style_options){                //if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * .50).toInt() }				//if background images are NOT images then text area height is a calculation based on width of input boxes		//else text area height is option value		if(this.options['text-area'] && style_options['input-height'] == 'auto')		{			style_options['input-height'] = (style_options['input-width'] * this.options['text-area-input-height']).toInt();		} else if(this.options['text-area'] && this.options['text-area-background-image'] != ''){			style_options['input-height'] = this.options['text-area-input-height'];		}        		//if text-area is true, then set background image to option, otherwise background is style_option		if(this.options['text-area-background-image'] != ''){			this.input_background_image = this.options['text-area-background-image'];		} else {			this.input_background_image = style_options['input-background-image'];		}		        // set input styles        this.text_input.setStyles({			'resize':								'none',			'float':                                'left',			'position':								'relative',            'border':                               style_options.border,            '-webkit-border-bottom-left-radius':    style_options['radius'] + 'px',            '-webkit-border-bottom-right-radius':   style_options['radius'] + 'px',            '-webkit-border-top-left-radius':       style_options['radius'] + 'px',            '-webkit-border-top-right-radius':      style_options['radius'] + 'px',            '-moz-border-radius':                   style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',            'border-radius':                        style_options['radius'] + 'px',            'padding-left':                         style_options['padding-left'] + 'px',            'padding-right':                        style_options['padding-right'] + 'px',            'padding-top':                          style_options['padding-top'] + 'px',            'padding-bottom':                       style_options['padding-bottom'] + 'px',            'margin-left':                          style_options['margin-left'] + 'px',            'margin-right':                         style_options['margin-right'] + 'px',            'margin-top':                           style_options['margin-top'] + 'px',            'margin-bottom':                        style_options['margin-bottom'] + 'px',            'font-size':                            style_options['input-font-size'] + 'px',            'font-weight':                          style_options['input-font-weight'],            'font-style':                           style_options['input-font-style'],            'font-family':                          style_options['input-font-family'],            'color':                                style_options['input-color'],            'background-color':                     style_options['background-color'],            'width':                                style_options['input-width'],            'height':                               style_options['input-height'],            'background-image':                     this.input_background_image,			'background-position':					style_options['input-background-position'],			'background-repeat':					style_options['input-background-repeat']        });        		if(style_options['input-background-image-highlight'] != 'none'){            this.text_input.addEvent('focus',function(){                this.text_input.setStyles({'background-image':style_options['input-background-image-highlight']})            }.bind(this));                        this.text_input.addEvent('blur',function(){                this.text_input.setStyles({'background-image':style_options['input-background-image']})            }.bind(this));        };        		//alert(style_options['label-position']);				if(style_options['label-position'] == 'absolute'){			this.text_label.setStyles({				'position':style_options['label-position'],				'top':style_options['padding-top'] + 'px',				'left':style_options['padding-left'] + 1-15 + 'px',				'z-index':style_options['label-z-index']			});		}				// set label styles        this.text_label.setStyles({			'float':'left',            'border':style_options['border'],            'border-color':'transparent',            'padding-left':style_options['padding-left'] + 1 + 'px',            'padding-right':style_options['padding-right'] + 1 + 'px',            'padding-top':style_options['padding-top'] + 1 + 'px',            'padding-bottom':style_options['padding-bottom'] + 1 + 'px',            'margin-left':style_options['margin-left'] + 'px',            'margin-right':style_options['margin-right'] + 'px',            'margin-top':style_options['margin-top'] + 'px',            'margin-bottom':style_options['margin-bottom'] + 'px',            'font-size':style_options['label-font-size'] + 'px',            'font-weight':style_options['label-font-weight'],            'font-style':style_options['label-font-style'],            'font-family':style_options['label-font-family'],            'color':style_options['label-color'],            'width':style_options['label-width']        });		    },    	setLabelDisplay: function(label_position){		if(label_position == 'inside'){			this.text_input.addEvent('focus',function(){				this.text_label.addClass('Ohidden');			}.bind(this));						this.text_input.addEvent('blur',function(){				if(this.text_input.getProperty('value') ==''){					this.text_label.removeClass('Ohidden');				}			}.bind(this));						this.text_label.addEvent('click',function(){				this.text_label.addClass('Ohidden');				this.text_input.focus();			}.bind(this));		}	},		addEvent: function(type,fn){		if(!(type == "keypress" && this.options['text-area'])){	    	this.text_input.addEvent(type,fn);	    }	},	    // get property    getProperty: function(){ return encodeURIComponent(this.text_input.getProperty('value')); },        // set property    setProperty: function(property,value){ this.text_input.setProperty(property,value); },        inject: function(el){        //if(this.options.label != ''){ this.text_label.inject(el); }        //this.text_input.inject(el);		this.container.inject(el);		this.text_input.inject(this.container);    }});/***********************************************
	Product Images
************************************************/
GeneralImageEditor = new Class({
	Implements: Options,
	
	options:{
		'resizable':true,
		'max_width':1024,
		'max_height':768,
		'image_width': 1024,
		'image_height': 768,
		'image_src':'',
		'image_name':'Untitled',
		'image_description':'',
		'image_description_long':'',
		'image_ext':'jpg',
		'image_x':0,
		'image_y':0,
		'image_zoom':0,
		'image_link':'',
		'image_follow':false,
		'image_thumb_x':0,
		'image_thumb_y':0,
		'content_order':0,
		'blog':false,
		'onSave':$empty,
		'onComplete':$empty,
		'corner_radius':5
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.container = new Element('div',{'class':'editor-container'});
	},
	
	loadEditor: function(){
	    
	    
		this.window = new Window({
			'window_width':this.options.image_width,
			'window_height':this.options.image_height,
			'window_canvas_width':this.getImageWidth(),
			'window_canvas_height':this.getImageHeight(),
			'window_canvas_x':this.options.image_x,
			'window_canvas_y':this.options.image_y,
			'window_resizable':this.options.resizable,
			'window_canvas_zoom':this.zoom
		});
		this.window.original_height = this.original_height;
		this.window.original_width = this.original_width;
		this.window.window.setStyles({'border':0});
		this.window.inject(this.container);
		this.image = new Element('img');
		
		if(this.options.image_src != ''){this.window.window.setStyles({'background-image':'none','border':0});}
		if(this.options.image_src != ''){
			this.image = new Element('img',{'src':this.options.image_src});
			this.image.setStyles({'width':'100%','height':'100%'});
			this.image.inject(this.window.window_canvas);
		}
		
		//upload btn
		this.image_upload_btn = new Element('div',{'class':'OImage-edit-btn'});
		this.image_upload_btn.setStyles({'position':'absolute','right':'-30px','top':'3px','background-image':'url(obray/images/image/edit-btn.png)','width':'25px','height':'25px','cursor':'pointer','overflow':'hidden'});
		this.image_upload_btn.inject(this.window.zoom_inner_container);
		//upload form
		this.image_form = new Element('form',{'action':'index.cfm?action=images.uploadImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','encoding':'multipart/form-data','enctype':'multipart/form-data','target':'upload_target','method':'post'});
		this.image_file = new Element('input',{'type':'file','name':'image_file'});
		this.image_form_image_id = new Element('input',{'type':'hidden','value':this.image_id,'name':'image_id'});
		this.image_form.setStyles({'position':'relative','top':'0px','left':'0px','background-color':'transparent','width':'100px','overflow':'hidden'});
		this.image_file.setStyles({'font-family':'arial','color':'#ffffff','opacity':0.01,'margin-left':'-175px'});
		this.image_file.inject(this.image_form);
		this.image_form_image_id.inject(this.image_form);
		this.image_form.inject(this.image_upload_btn);
		this.upload_target = $('upload_target');
		//event: Upload
		this.image_file.addEvent('change',function(e){
			this.image_form.submit();
			//get upload response
			this.upload_target.addEvent('load',function(){
				//get iFrame
				var frame = window.frames['upload_target'];
				//get Response
				var response = frame.document.getElementById('response').innerHTML;
				this.imagejson = JSON.decode(response);
				this.options.image_id = this.imagejson.image.image_id;
				this.options.image_location = this.imagejson.image.image_location;
				this.options.image_name = this.imagejson.image.image_name;
				this.options.image_description = this.imagejson.image.image_description;
				this.options.image_description_long = this.imagejson.image.image_description_long;
				this.options.image_ext = this.imagejson.image.image_ext;
				this.options.image_width = this.imagejson.image.image_width;
				this.options.image_height = this.imagejson.image.image_height;
				this.options.image_width = this.imagejson.image.image_width;
				this.options.image_height = this.imagejson.image.image_height;
				this.options.image_x = 0;
				this.options.image_y = 0;
				var img = new Asset.images([this.options.image_location],{onComplete:function(){
					this.window.setCanvasWidth(this.options.image_width);
					this.window.setCanvasHeight(this.options.image_height);
					//adjust window if it's smaller than the loaded image
					if(this.options.image_width < this.window.window.getCoordinates().width){
						this.window.window.setStyles({'width':this.options.image_width});
						this.window.options.window_width = this.options.image_width;
					}
					if(this.options.image_height < this.window.window.getCoordinates().height){
						this.window.window.setStyles({'height':this.options.image_height});
						this.window.options.window_height = this.options.image_height;
					}
					this.window.window.setStyles()
					this.image.destroy();
					if(this.options.image_location = "Amazon S3"){
						this.image = new Element('img',{'src':window.obray.amazon_location+this.options.image_name+'.'+this.options.image_ext});
					} else {
						this.image = new Element('img',{'src':'assets/images/'+this.options.image_name+'.'+this.options.image_ext});
					}
					this.image.setStyles({'width':'100%','height':'100%'});
					this.image.inject(this.window.window_canvas);
					this.upload_target.removeEvents();
					//get rid of background-image and border
					this.window.window.setStyles({'background-image':'none','border':0});
				}.bind(this)});
				
			}.bind(this));
		}.bind(this));
		
		//buttons
		this.image_save_btn = new Element('div',{'class':'OImage-save-btn'});
		this.image_save_btn_label = new Element('div',{'class':'OImage-save-btn-label'});
		this.image_save_btn_label.set('html','Save');
		this.image_save_btn_icon = new Element('div',{'class':'OImage-save-btn-icon'});
		this.image_delete_btn = new Element('div',{'class':'OImage-delete-btn'});
		this.image_edit_btn = new Element('div',{'class':'OImage-edit-btn'});
		this.image_options_btn = new Element('div',{'class':'OImage-style-btn'});
		this.image_options_btn_label = new Element('div',{'class':'OImage-option-btn-label'});
		this.image_options_btn_label.set('html','Options');
		this.image_options_btn_icon = new Element('div',{'class':'OImage-option-btn-icon'});
		this.image_save_btn.setStyles({'position':'absolute','left':'5px','top':'6px','background-image':'none','width':'59px','height':'19px','cursor':'pointer'});
		this.image_save_btn_label.setStyles({'float':'left','color':'#ffffff','font-family':'arial','font-size':'11px','padding':0,'padding-top':0,'line-height':19,'padding-left':'7px'});
		this.image_save_btn_icon.setStyles({'float':'left','height':'8px','width':'8px','background-image':'url(obray/images/image/red-dot-small.png)','margin':'6px'});
		if(this.options.image_id != 0){this.image_save_btn_icon.setStyles({'background-image':'url(obray/images/image/green-dot-small.png)'});}
		
		this.image_save_btn.inject(this.window.zoom_inner_container);
		this.image_save_btn_label.inject(this.image_save_btn);
		this.image_save_btn_icon.inject(this.image_save_btn);
		
		//event: save
		this.image_save_btn.addEvent('mouseenter',function(){
			this.image_save_btn.setStyles({'background-image':'url(obray/images/image/bg-control-btn.png)'});
		}.bind(this));
		this.image_save_btn.addEvent('mouseleave',function(){
			this.image_save_btn.setStyles({'background-image':'none'});
		}.bind(this));
		this.image_save_btn.addEvent('click',function(){
			//this.options.image_description = this.image_title_input.getProperty('value');
			//this.options.image_description_long = this.image_caption_input.getProperty('value');
			//this.options.image_link = this.image_link_input.getProperty('value');
			this.options.onSave();
		}.bind(this))
	},
	
	inject: function(el,position){
		this.container.inject(el,position);
		this.loadEditor();
	},
	
	getImageWidth: function(){
		if(this.options.image_zoom == 0){
			return this.options.image_width;
		} else {
			return this.options.image_zoom;
		}
	},
	
	getImageHeight: function(){
		if(this.options.image_src != '' && this.options.image_zoom > 0){
			var temp_img = new Element('img',{'src':this.options.image_src});
			temp_img.setStyles({'position':'absolute','left':-20000,'top':-20000});
			temp_img.inject(document.body);
			var height = temp_img.getCoordinates().height;
			var width = temp_img.getCoordinates().width;
			new_height = (this.options.image_zoom*height)/width;
			temp_img.destroy();
			return new_height;
		} else {
			return this.options.image_height;
		}
	},
	
	getImageId: function(){
	    return this.options.image_id;
	},
	
	getImageFile: function(){
	    return this.options.image_name + '.' + this.options.image_ext;
	},
	
	getImageThumbFile: function(){
	    return this.options.image_name + '_thumb.' + this.options.image_ext;
	}
})


OFImage = new Class({
    Implements: Options,
    
    options:{
        'image_id':0,
        'label':'',
        'image_width':500,
        'image_height':300,
        'image_name':'',
        'image_ext':'',
        'name':'default_image',
		'image_corner_radius':20
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.image_id = this.options.image_id;
        this.name = this.options.name;
        
        
        this.image_label = new Element('label',{'class':'ofimage-label'});
        this.image_label.set('html',this.options.label);
        
        this.image_container = new Element('div',{'class':'ofimage-container'});
        this.image_container.setStyles({'float':'left'});
        
        this.image_input = new Element('div',{'class':'ofimage-input'});
        this.image_input.setStyles({'position':'relative','float':'left','z-index':1000,'width':(this.options.image_width*.25),'height':(this.options.image_height*.25)});
        this.image_input.inject(this.image_container);
        
        this.br = new Element('br',{'class':'clear'});
        this.br.inject(this.image_container);
        
        this.image_btn = new Element('div',{'class':'ofimage-btn'});
        this.image_btn.setStyles({'position':'relative','float':'left','width':50,'height':15,'background-color':'#f1f1f1'});
        this.image_btn.set('html','Select Image <img src="/obray/images/image/edit-btn.png" height="16" width="16"/>');
        this.image_btn.getFirst().setStyles({'position':'absolute','top':1});
        this.image_btn.inject(this.image_container);
        
        this.image = new Element('img',{'src':'/obray/images/place-holder-image-small.jpg'});
        this.image.setStyles({'position':'absolute','left':-250,'margin-left':this.options.image_width*.25/2,'top':-187,'margin-top':this.options.image_height*.25/2,'z-index':5000});
        this.image.inject(this.image_input);
        
        this.image_input_fx = new Fx.Morph(this.image_input,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
        this.image_btn_fx = new Fx.Morph(this.image_btn,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
        
        if(this.options.image_name != '' && this.options.image_ext != ''){
            this.new_image = new Element('img',{'src':'/assets/images/'+this.options.image_name+'_thumb.'+this.options.image_ext});
            this.new_image.setStyles({'position':'absolute','top':0,'left':0,'z-index':5001,'width':this.options.image_width*.25,'height':this.options.image_height*.25});
            this.new_image.inject(this.image_input);
        }
        
    },
    
    setStyles: function(style_options){
        
        //set input styles
        this.image_input.setStyles({
            'float':                                'left',
            'border':                               style_options.border,
            '-webkit-border-bottom-left-radius':    style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':   style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':       style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':      style_options['radius'] + 'px',
            '-moz-border-radius':                   style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'border-radius':                        style_options['radius'] + 'px',
            //'padding-left':                         style_options['padding-left'] + 'px',
            //'padding-right':                        style_options['padding-right'] + 'px',
            //'padding-top':                          style_options['padding-top'] + 'px',
            //'padding-bottom':                       style_options['padding-bottom'] + 'px',
            'margin-left':                          style_options['margin-left'] + 'px',
            'margin-right':                         style_options['margin-right'] + 'px',
            'margin-top':                           style_options['margin-top'] + 'px',
            'margin-bottom':                        style_options['margin-bottom'] + 'px',
            'font-size':                            style_options['input-font-size'] + 'px',
            'font-weight':                          style_options['input-font-weight'],
            'font-style':                           style_options['input-font-style'],
            'color':                                style_options['input-color'],
            'background-color':                     'transparent',
            'cursor':                               'pointer',
            'overflow':                             'hidden'
        });
        
        this.image_btn.setStyles({
            'margin-left':                          style_options['margin-left'] + 'px',
            'margin-right':                         style_options['margin-right'] + 'px',
            'margin-top':                           style_options['margin-top'] + 'px',
            'margin-bottom':                        style_options['margin-bottom'] + 'px',
            'width':                                this.options.image_width*.25-6,
            'border':                               '1px solid transparent',
            '-webkit-border-bottom-left-radius':    style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':   style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':       style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':      style_options['radius'] + 'px',
            '-moz-border-radius':                   style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'background-color':                     '#343434',
            'color':                                '#f1f1f1',
            'font-family':                          'Arial,Helvetica',
            'padding':                              3,
            'text-align':                           'center',
            'cursor':                               'pointer'
        });
        this.image_btn.addEvent('mouseenter',function(){ this.image_btn.setStyles({'background-color':'#444444'}) }.bind(this));
        this.image_btn.addEvent('mouseleave',function(){ this.image_btn.setStyles({'background-color':'#343434'}) }.bind(this));
        this.image_btn.addEvent('click',function(){
                this.box = new sbox({'show_overflow':true,'width':this.options.image_width,'height':this.options.image_height,'startx':this.image_btn.getCoordinates().left,'starty':this.image_btn.getCoordinates().top});
                this.box.open();
                this.image_editor = new GeneralImageEditor({
                    'product_id':0,
                    'resizable':false,
                    'max_width':        this.options.image_width,
                    'max_height':       this.options.image_height,
                    'image_width':      this.options.image_width,
                    'image_height':     this.options.image_height,
                    'image_name':'Untitled',
                    'image_x':0,
                    'image_y':0,
                    'image_zoom':0,
                    'image_thumb_x':this.options.image_width*.25,
                    'image_thumb_y':this.options.image_height*.25,
                    'image_corner_radius':this.options.image_corner_radius,
                    'onSave':function(){
                        var data = '&image_id='                 + this.image_editor.options.image_id
                                 + '&image_name='               + this.image_editor.options.image_name
                                 + '&image_ext='                + this.image_editor.options.image_ext
                                 + '&image_location='           + this.image_editor.options.image_location
                                 + '&image_width='              + this.image_editor.window.getCanvasCoordinates().width
                                 + '&image_height='             + this.image_editor.window.getCanvasCoordinates().height
                                 + '&image_zoom='               + this.image_editor.window.getCanvasCoordinates().zoom
                                 + '&image_x='                  + this.image_editor.window.getCanvasCoordinates().x
                                 + '&image_y='                  + this.image_editor.window.getCanvasCoordinates().y
                                 + '&image_link='               + this.image_editor.options.image_link
                                 + '&image_follow='             + this.image_editor.options.image_follow
                                 + '&image_description='        + encodeURIComponent(this.image_editor.options.image_description)
                                 + '&image_description_long='   + encodeURIComponent(this.image_editor.options.image_description_long)
                                 + '&image_size_x='             + this.options.image_thumb_x
                                 + '&image_size_y='             + this.options.image_thumb_y
                                 + '&image_corner_radius='		+ this.image_editor.options.image_corner_radius;
                        var requets = new Request({'url':'index.cfm?action=images.saveImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','data':data,'onComplete':function(){
                            
                            if(this.options.image_location = "Amazon S3"){
								this.new_image = new Element('img',{'src':window.obray.amazon_location+this.image_editor.getImageThumbFile()});
							} else {
								this.new_image = new Element('img',{'src':'assets/images/'+this.image_editor.getImageThumbFile()});
							}
                            this.new_image.setStyles({'position':'absolute','top':0,'left':0,'z-index':5001,'width':this.options.image_width*.25,'height':this.options.image_height*.25});
                            this.new_image.inject(this.image_input);
                            this.box.close();
                            this.image_id = this.image_editor.options.image_id;
                        }.bind(this)}).send();
                        
                    }.bind(this)
                });
                this.image_editor.inject(this.box.content);
                
        }.bind(this))
        
        this.image_container.setStyles({
            '-webkit-border-bottom-left-radius':    style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':   style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':       style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':      style_options['radius'] + 'px',
            '-moz-border-radius':                   style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'padding':3,
            'background-color':style_options['highlight-color'],
            'margin-left':                          style_options['margin-left'],
            'margin-right':                         style_options['margin-right'],
            'margin-top':                           style_options['margin-top'],
            'margin-bottom':                        style_options['margin-bottom']
        });
        
        //set label styles
        this.image_label.setStyles({
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 1 + 'px',
            'padding-right':style_options['padding-right'] + 1 + 'px',
            'padding-top':style_options['padding-top'] + 1 + 'px',
            'padding-bottom':style_options['padding-bottom'] + 1 + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'color':style_options['label-color'],
            'width':style_options['label-width']
        });
    },
    
    inject: function(el){
        this.image_label.inject(el);
        this.image_container.inject(el);
        
    },
    
    getProperty: function(property){
        return this.image_id;
    },
    
    addEvent: function(type,fn){
	    
	},
    
    setDimensions: function(width,height){
        this.options.image_width = width;
        this.options.image_height = height;
        this.image_input_fx.start({'height':this.options.image_height*.25,'width':this.options.image_width*.25});
        this.image_btn_fx.start({'width':this.options.image_width*.25-6});
    },
    
    setLabelDisplay: $empty
});


OFImageSimple = new Class({
    Implements: Options,
    
    options:{
        'image_id':0,
        'label':'',
		'scalar':0.25,
        'image_width':440,
        'image_height':350,
        'image_name':'',
        'image_ext':'',
        'name':'default_image',
		'oform':false,
		'content_part_id':'',
		'field_id':'',
		'constrain_zoom':false,
		'uploadSuccess':$empty,
		'enable_thumbnail':true
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.name = this.options.name;
        this.image_width = this.options.image_width;
        this.image_height = this.options.image_height;
        this.value = 0;
        
        this.input_wrapper = new Element('div',{'class':'input-wrapper'});
        
        this.input_label = new Element('label',{'class':'ofimage-label'});
        this.input_label.set('html',this.options.label);
        this.input_label.inject(this.input_wrapper);
        
        this.input_btn = new Element('a',{'class':'ofimage-btn'});
        this.input_btn.set('html','Upload Image')
        this.input_btn.setStyles({'display':'block','float':'left','cursor':'pointer','padding':5,'margin':5,'position':'relative','font-size':12});
        this.input_btn.inject(this.input_wrapper);
        
        this.loader = new Element('img',{'src':'/obray/images/loaders/ajax-loader.gif'});
        this.loader.setStyles({'float':'left','opacity':0,'margin-top':15,'margin-bottom':15});
        this.loader.inject(this.input_wrapper);
        
        this.input_form = new Element('form',{'action':'index.cfm?action=images.uploadImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','encoding':'multipart/form-data','enctype':'multipart/form-data','target':'upload_target','method':'post'})
        this.input_form.inject(this.input_btn);
        
        this.input_form_image_id = new Element('input',{'type':'hidden','value':this.options.image_id,'name':'image_id'});
        this.input_form_image_id.inject(this.input_form);
        
        this.thumbnail = new Element('div',{'class':'ofimage-selct-simple-thumbnail'});
        this.thumbnail.setStyles({'background-position':'center center'});
        if(this.options.enable_thumbnail){ this.thumbnail.inject(this.input_wrapper); }
        
        this.input_file = new Element('input',{'type':'file','name':'image_file'});
        this.input_file.setStyles({'width':'100%','height':'100%','position':'absolute','top':0,'left':0});
        this.input_file.inject(this.input_form);
        
        this.input_file.addEvent('change',function(){
        	this.input_form.submit();
        	this.loader.setStyles({'opacity':1});
        	this.upload_target = $('upload_target');
        	this.upload_target.addEvent('load',function(){
				//get iFrame
				var frame = window.frames['upload_target'];
				//get Response
				var response = frame.document.getElementById('response').innerHTML;
				this.imagejson = JSON.decode(response);
				this.options.image_id = this.imagejson.image.image_id;
				this.options.image_name = this.imagejson.image.image_name;
				this.options.image_ext = this.imagejson.image.image_ext;
				this.options.image_width = this.imagejson.image.image_width;
				this.options.image_height = this.imagejson.image.image_height;
				this.options.image_location = this.imagejson.image.image_location;
				// save image
				if(this.options.image_height > this.options.image_width){ var image_height = this.image_width; var image_width = this.image_height; } else { var image_height = this.image_height; var image_width = this.image_width; }
				var data = '&image_id='                 + this.options.image_id
						 + '&image_name='               + this.options.image_name
						 + '&image_ext='                + this.options.image_ext
						 + '&image_location='           + this.options.image_location
						 + '&image_width='              + image_width
						 + '&image_height='             + image_height
						 + '&image_zoom='               + image_width
						 + '&image_x='                  + 0
						 + '&image_y='                  + 0
						 + '&image_link='               + ''
						 + '&image_follow='             + ''
						 + '&image_description='        + ''
						 + '&image_description_long='   + ''
						 + '&image_corner_radius='		+ 0
						 + '&constrain_zoom='			+ this.options.constrain_zoom;
                        var requets = new Request({'url':'index.cfm?action=images.saveImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','data':data,'onComplete':function(){
                        	this.value = this.options.image_id;
                        	this.loader.setStyles({'opacity':0});
                        	if(this.options.image_location == 'Amazon S3'){ this.image_thumb_location = window.obray.amazon_location+this.options.image_name+'_thumb.'+this.options.image_ext; } else { this.image_thumb_location = '/assets/images/'+this.options.image_name+'_thumb.'+this.options.image_ext; }
                        	this.thumbnail.setStyles({'background-image':'url('+this.options.image_location+')'});
                        	this.options.uploadSuccess();
                        }.bind(this) }).send();
			}.bind(this));
        }.bind(this));
        
    },
    
    setStyles: function(style_options){
        
        this.input_btn.setStyles({
            'margin-left':                          style_options['margin-left'] + 'px',
            'margin-right':                         style_options['margin-right'] + 'px',
            'margin-top':                           style_options['margin-top'] + 'px',
            'margin-bottom':                        style_options['margin-bottom'] + 'px',
            'width':                                this.options.image_width*.25-6,
            'border':                               '1px solid transparent',
            '-webkit-border-bottom-left-radius':    style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':   style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':       style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':      style_options['radius'] + 'px',
            '-moz-border-radius':                   style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'background-color':                     '#343434',
            'color':                                '#f1f1f1',
            'font-family':                          'Arial,Helvetica',
            'padding':                              3,
            'text-align':                           'center',
            'cursor':                               'pointer'
        });
        
        //set label styles
        this.input_label.setStyles({
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 1 + 'px',
            'padding-right':style_options['padding-right'] + 1 + 'px',
            'padding-top':style_options['padding-top'] + 1 + 'px',
            'padding-bottom':style_options['padding-bottom'] + 1 + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'color':style_options['label-color'],
            'width':style_options['label-width']
        });
    },
    
    inject: function(el){
        this.input_wrapper.inject(el);
        this.input_file.setStyles({'display':'block','height':20,'width':100,'opacity':.01,'cursor':'pointer'});
    },
    
    getProperty: function(property){ return encodeURIComponent(this.value); },
    
    addEvent: function(type,fn){
	    
	},
    
    setDimensions: function(width,height){
       
    },
    
    setLabelDisplay: $empty
});
OFHidden = new Class({
    Implements: Options,
    
    options:{
        'value':'',
        'name':''
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.name = this.options.name;
        
        this.hidden = new Element('input',{'type':'hidden','value':this.options.value});
    },
    
    getProperty: function(property){
        return encodeURIComponent(this.hidden.getProperty(property));
    },
    
    setStyles: function(){
    
    },
    
    inject: function(el){
        this.hidden.inject(el);
    },
    
    addEvent: function(type,fn){
	    this.hidden.addEvent(type,fn);
	},
    
    
    setLabelDisplay: $empty
});
/*************************************************

*************************************************/


OFSelect2 = new Class({
    Implements: Options,
    
    options:{
        'padding':0,
        'padding-left':0,
        'padding-right':0,
        'padding-top':0,
        'padding-bottom':0,
        'margin':0,
        'font_size':12,
        'color':'#000000',
        'width':150,
        'background_color':'',
        'background-color':'',
        'background_highlight':'',
        'highlight-color':'',
        'float':'right',
        'border':'1px solid #000000',
        'default_value':'',
        'blur':$empty,
        'name':'',
        'label':'',
        'labels':[],
        'values':[],
		'content_part_id':'',
		'field_id':'',
		'validate':true,
		'feed_from':0,
		'feed_to':0,
		'dependents':'',
		'class_name':''
    },
    
    initialize: function(options){
        
        this.setOptions(options);
        this.isOpen = false;
        this.current_index = 0;
        this.value = this.options.default_value;
        this.name = this.options.name;
        this.has_focus = false;
        this.feed_from = this.options.feed_from;
		this.feed_to = this.options.feed_to;
		this.is_mouse_down_in_items = false;
		this.selected_index = 0;
		this.options.dependents_list = new Array();
		if(this.options.dependents != "") {
			this.options.dependents_list = this.options.dependents.split(",");
		}
        //create select box
        this.select = new Element('div',{'class':'select'});
        //this.select.setStyles({'cursor':'pointer','font-family':'Arial, Helvetica','position':'relative','min-height':10,'background-color':this.options.background_color,'float':this.options.float,'padding':this.options.padding,'margin':this.options.margin,'font-size':this.options.font_size,'color':this.options.color,'width':this.options.width,'border':this.options.border,'-webkit-border-bottom-left-radius':'5px','-webkit-border-bottom-right-radius':'5px','-webkit-border-top-left-radius':'5px','-webkit-border-top-right-radius':'5px','-moz-border-radius':'5px 5px 5px 5px'});
        this.select.set('html','<span id="selectlabel'+this.options.field_id+'">'+this.value+'</span>');
        this.select.addEvent('click',function(){
            if(this.isOpen){
                this.items_container.setStyles({'display':'none','top':this.select.getCoordinates().top+this.select.getCoordinates().height,'left':this.select.getCoordinates().left,'overflow-y':'scroll','height':150});
                this.isOpen = false;
            } else {
                this.items_container.setStyles({'display':'block','top':this.select.getCoordinates().top+this.select.getCoordinates().height,'left':this.select.getCoordinates().left,'min-width':this.options.width,'overflow-y':'scroll','height':150});
                this.isOpen = true;
            }
            this.select_input.focus();
        }.bind(this));
        this.select.addEvent('mouseenter',function(){
                //this.select.setStyles({'background-color':this.options['highlight-color']});
        }.bind(this));
        this.select.addEvent('mouseleave',function(){
            if(!this.has_focus){
                //this.select.setStyles({'background-color':this.options['background-color']});
            }
        }.bind(this));
        
        
        
        this.select_label = new Element('label',{'class':'select-label'});
		this.select.getFirst().index = 0;
        
        if(this.options.label != ''){
            this.select_label.set('html',this.options.label);
        }
        
		//DROPDOWN ICON
		this.dropdown_icon = new Element('div',{'class':'dropdown-icon'});
		
		this.dropdown_icon.inject(this.select);
		
		
		
        //select input (allows us to call onBlur and onFocus
        this.select_input = new Element('input',{'type':'text','id':'form-element-'+this.options.field_id,'value':this.value});
        this.select_input.setStyles({'position':'absolute','left':-5000,'height':1,'width':1,'padding':0,'margin':0,'border':0,'z-index':1000});
        this.select_input.inject(this.select);
        this.select_input.addEvent('keydown',function(e){
        	if(e.key != 'tab'){ e.preventDefault(); }
            if(e.key == 'down'){
                ++this.current_index;
                if(this.current_index > this.items.length){ this.current_index = 1; }
                this.items[this.current_index-1].fireEvent('mousedown');
            } else if(e.key == 'up'){
                --this.current_index;
                if(this.current_index - 1 < 0){ this.current_index = this.items.length; }
                this.items[this.current_index-1].fireEvent('mousedown');
            } else {
            	for(var i=0;i<this.items.length;++i){
            		if(this.items[i].label[0] == e.key || this.items[i].label[0] == e.key.toUpperCase()){
            			if(i > this.select.getFirst().index){ this.items[i].fireEvent('mousedown'); break;}
            		}
            	}
            }
        }.bind(this));
        //this.select_input.addEvent('keypress',function(e){ if(e.key != 'tab'){ e.preventDefault(); } }.bind(this));
        //this.select_input.addEvent('keyup',function(e){ if(e.key != 'tab'){ e.preventDefault(); } }.bind(this));
        
        this.select_input.addEvent('focus',function(){
            this.has_focus = true;
            this.select.setStyles({'background-color':this.options['highlight-color']});
        }.bind(this));
        this.select_input.addEvent('blur',function(){
        	if(this.is_mouse_down_in_items == false){
				this.has_focus = false;
				this.select.setStyles({'background-color':this.options['background-color']});
				this.items_container.setStyles({'display':'none','top':this.select.getCoordinates().height});
				this.isOpen = false;
				if(this.value != null && this.options.validate) {
					var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
					var data = 'field_data=' + this.value;
					this.request = new Request({'url':url,'method':'post'});
					this.request.removeEvents();
					this.request.setOptions({'data':data,'onComplete':function(response){	
						var json = JSON.decode(response);
						if(json.response.error == 'false' || json.response.error == false){
							document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
							document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
						} else {
							document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
							document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
						}
						
					}.bind(this)}).send();	
				}
				this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.select_input.getProperty('value')));
            }
        }.bind(this).pass(this));
        
        //Handle Items
        this.items = [];
        this.items_container = new Element('div',{'class':'options-container ' + this.options.class_name,'id':'options-container-'+this.options.field_id});
        this.items_container.setStyles({'position':'absolute','left':0,'display':'none','z-index':5500});
        this.items_container.addEvent('mousedown',function(){ this.is_mouse_down_in_items = true; }.bind(this));
        this.items_container.addEvent('mouseup',function(){
        	this.is_mouse_down_in_items = false;
        	this.select_input.focus();
        }.bind(this));
        this.items_container.inject(document.body);
	    for(var i=0;i<this.options.labels.length;++i){
	        this.addOption(this.options.labels[i],this.options.values[i]);
	    }
		var vMsgId = 'input-vmsg-' + this.options.field_id;
		var vImgId = 'input-vimg-' + this.options.field_id;
		this.vMsg = new Element('div',{'id':vMsgId,'style':'','class':'input-vmsg'});
		this.vImg = new Element('div',{'id':vImgId,'style':'','class':'input-vimg'});
		
    },
    
    setStyles: function(style_options){
        
    },
    
    inject: function(el){
		this.container = new Element('div',{'class':'input-wrapper','id':'element-container-'+this.options.field_id});
		this.container.addClass(this.options.class_name);
        this.select.inject(this.container);
		this.container.inject(el);
        if(this.options.label != ''){ 
			this.select_label.inject(this.select,'before'); 
		}
		if(this.options.validate) {
			this.vImg.inject(this.select,'after');
			this.vMsg.inject(this.select,'after');
		}
		
		this.dropdown_icon.setStyles({
		 'position':'absolute',
		 'top':(this.select.getCoordinates().height-15)/2-1,
		 'right':5,
		 'height':15,
		 'width':15,
		 'background-image':'url(/obray/images/form/select/dropdown-icon.png)',
		 'background-position':'center center'
		 });
		 //try{ this.setDefaultValue.delay(3000,this); } catch (err){ alert(err); }
		 try{ this.setDefaultValue.delay(1000,this); } catch (err){ alert(err); }
    },
    
    setDefaultValue: function(){
    	this.items.each(function(el,i){
		 	if(el.value == this.options.default_value){ el.fireEvent('mousedown'); }
		 }.bind(this));
    },
            
    addOption: function(label,value,level){
    	level = typeof(level) != 'undefined' ? level : 0;
    	var padding_left = level*5+5;
        this.items[this.items.length] = new Element('div',{'class':'item'});
        //this.items[this.items.length-1].setStyles({'padding':this.options['padding'],'padding-left':padding_left,'cursor':'pointer','text-align':'left'});
        this.items[this.items.length-1].value = value;
        this.items[this.items.length-1].label = label;
        this.items[this.items.length-1].index = this.items.length-1;
        this.items[this.items.length-1].set('html',label);
        this.items[this.items.length-1].inject(this.items_container);
        //this.items[this.items.length-1].highlight_color = this.options['highlight-color'];
        //this.items[this.items.length-1].background_color = this.options['background-color'];
        this.items[this.items.length-1].addEvent('mouseenter',function(options){}.pass(this.options,this.items[this.items.length-1]));
        this.items[this.items.length-1].addEvent('mouseleave',function(options){}.pass(this.options,this.items[this.items.length-1]));
        this.items[this.items.length-1].addEvent('mousedown',function(options,obj){
            this.select.getFirst().set('text',obj.label);
            this.select.getFirst().index = obj.index;
            this.select_input.setProperty('value',obj.value);
			try {
				if(options.field_id != '') {
					window['signup_first_name'+options.field_id].select_input.value = obj.value;
					window['signup_first_name'+options.field_id].value = obj.value;
				}
				if(options.feed_to != 0) {
					window['signup_first_name'+options.feed_to].ajaxlyOperation(options.feed_from,obj.value, options.field_id);
				}
			
				for(var z = 0; z<options.dependents_list.length; z++) {
					window['dependent_fn_'+options.dependents_list[z]](obj.value);
				}
			} catch(err) {
					
			}
        }.pass([this.options,this.items[this.items.length-1]],this));
        
        this.items[this.items.length-1].addEvent('mouseup',function(options,obj){
        	this.items_container.setStyles({'display':'none','top':this.select.getCoordinates().height});
			this.isOpen = false;
        }.bind(this));
    },
	
	getFeedFrom: function() {
		return this.options.feed_from;
	},
	
	ajaxlyOperation: function(parent_item_id, value, parent_field_id){
		// Used for nifty country -> state -> county ajax calls.
		if(parent_item_id != "") {
		var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=getFieldValues&feed_from=' + parent_item_id + '&field_id=' + this.options.field_id+'&parent_field_id='+parent_field_id;
				var data = 'field_data=' + value;
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
				this.clear();
				if(this.select_input.value == '') {
					this.value=this.select_input.value= '';
				} else {
					this.value = this.select_input.value;
				}
				document.getElementById('selectlabel'+this.options.field_id).innerHTML = '';
				
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					this.options.feed_from = json.feed_from;
                	for(i = 0; i < json.listvalues.length; i++) {
						this.addOption(json.listvalues[i].name,json.listvalues[i].value);
					}
					try{ this.setDefaultValue.delay(20,this); } catch (err){ alert(err); }
            	}.bind(this)}).send();	
		}
		
	},
    
    addEvent: function(type,fn){
	    
	},
    
    getProperty: function(property){
        if(property == 'value'){
            return this.select_input.getProperty('value');
        }
    },
    
    clear: function(){
    	this.items_container.set('html',''); 
    	this.items = [];
    },
    
    setLabelDisplay: $empty
    
});

// MonkeyPhysics: DatePicker
// this is a minified version, for production use
// source, updates and documentation available @ http://www.monkeyphysics.com/mootools

var DatePicker2=new Class({Implements:Options,d:'',today:'',choice:{},bodysize:{},limit:{},attachTo:null,picker:null,slider:null,oldContents:null,newContents:null,input:null,visual:null,options:{field_id:'',validate:true,pickerClass:'datepicker',days:['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],months:['January','February','March','April','May','June','July','August','September','October','November','December'],dayShort:2,monthShort:3,startDay:1,timePicker:false,timePickerOnly:false,yearPicker:true,yearsPerPage:20,format:'d-m-Y',allowEmpty:false,inputOutputFormat:'U',animationDuration:400,useFadeInOut:!Browser.Engine.trident,startView:'month',positionOffset:{x:0,y:0},minDate:null,maxDate:null,debug:false,toggleElements:null,onShow:$empty,onClose:$empty,onSelect:$empty},initialize:function(attachTo,options){this.attachTo=attachTo;this.setOptions(options).attach();if(this.options.timePickerOnly){this.options.timePicker=true;this.options.startView='time';}
this.formatMinMaxDates();document.addEvent('mousedown',this.close.bind(this));},formatMinMaxDates:function(){if(this.options.minDate&&this.options.minDate.format){this.options.minDate=this.unformat(this.options.minDate.date,this.options.minDate.format);}
if(this.options.maxDate&&this.options.maxDate.format){this.options.maxDate=this.unformat(this.options.maxDate.date,this.options.maxDate.format);this.options.maxDate.setHours(23);this.options.maxDate.setMinutes(59);this.options.maxDate.setSeconds(59);}},attach:function(){if($chk(this.options.toggleElements)){var togglers=$$(this.options.toggleElements);document.addEvents({'keydown':function(e){if(e.key=="tab"){this.close(null,true);}}.bind(this)});};$$(this.attachTo).each(function(item,index){if(item.retrieve('datepicker'))return;if($chk(item.get('value'))){var init_clone_val=this.format(new Date(this.unformat(item.get('value'),this.options.inputOutputFormat)),this.options.format);}else if(!this.options.allowEmpty){var init_clone_val=this.format(new Date(),this.options.format);}else{var init_clone_val='';}
var display=item.getStyle('display');var clone=item.setStyle('display',this.options.debug?display:'none').store('datepicker',true).clone().store('datepicker',true).removeProperty('name').setStyle('display',display).set('value',init_clone_val).inject(item,'after');if($chk(this.options.toggleElements)){togglers[index].setStyle('cursor','pointer').addEvents({'click':function(e){this.onFocus(item,clone);}.bind(this)});clone.addEvents({'blur':function(){item.set('value',clone.get('value'));}});}else{clone.addEvents({'keydown':function(e){if(this.options.allowEmpty&&(e.key=="delete"||e.key=="backspace")){item.set('value','');e.target.set('value','');this.close(null,true);}else if(e.key=="tab"){this.close(null,true);}else{e.stop();}}.bind(this),'focus':function(e){this.onFocus(item,clone);}.bind(this)});}}.bind(this));},onFocus:function(original_input,visual_input){var init_visual_date,d=visual_input.getCoordinates();if($chk(original_input.get('value'))){init_visual_date=this.unformat(original_input.get('value'),this.options.inputOutputFormat).valueOf();}else{init_visual_date=new Date();if($chk(this.options.maxDate)&&init_visual_date.valueOf()>this.options.maxDate.valueOf()){init_visual_date=new Date(this.options.maxDate.valueOf());}
if($chk(this.options.minDate)&&init_visual_date.valueOf()<this.options.minDate.valueOf()){init_visual_date=new Date(this.options.minDate.valueOf());}}
this.show({left:d.left+this.options.positionOffset.x,top:d.top+d.height+this.options.positionOffset.y},init_visual_date);this.input=original_input;this.visual=visual_input;this.options.onShow();},dateToObject:function(d){return{year:d.getFullYear(),month:d.getMonth(),day:d.getDate(),hours:d.getHours(),minutes:d.getMinutes(),seconds:d.getSeconds()};},dateFromObject:function(values){var d=new Date();d.setDate(1);['year','month','day','hours','minutes','seconds'].each(function(type){var v=values[type];if(!$chk(v))return;switch(type){case'day':d.setDate(v);break;case'month':d.setMonth(v);break;case'year':d.setFullYear(v);break;case'hours':d.setHours(v);break;case'minutes':d.setMinutes(v);break;case'seconds':d.setSeconds(v);break;}});return d;},show:function(position,timestamp){this.formatMinMaxDates();if($chk(timestamp)){this.d=new Date(timestamp);}else{this.d=new Date();}
this.today=new Date();this.choice=this.dateToObject(this.d);this.mode=(this.options.startView=='time'&&!this.options.timePicker)?'month':this.options.startView;this.render();this.picker.setStyles(position);},render:function(fx){if(!$chk(this.picker)){this.constructPicker();}else{var o=this.oldContents;this.oldContents=this.newContents;this.newContents=o;this.newContents.empty();}
var startDate=new Date(this.d.getTime());this.limit={right:false,left:false};if(this.mode=='decades'){this.renderDecades();}else if(this.mode=='year'){this.renderYear();}else if(this.mode=='time'){this.renderTime();this.limit={right:true,left:true};}else{this.renderMonth();}
this.picker.getElement('.previous').setStyle('visibility',this.limit.left?'hidden':'visible');this.picker.getElement('.next').setStyle('visibility',this.limit.right?'hidden':'visible');this.picker.getElement('.titleText').setStyle('cursor',this.allowZoomOut()?'pointer':'default');this.d=startDate;if(this.picker.getStyle('opacity')==0){this.picker.tween('opacity',0,1);}
if($chk(fx))this.fx(fx);},fx:function(fx){if(fx=='right'){this.oldContents.setStyles({left:0,opacity:1});this.newContents.setStyles({left:this.bodysize.x,opacity:1});this.slider.setStyle('left',0).tween('left',0,-this.bodysize.x);}else if(fx=='left'){this.oldContents.setStyles({left:this.bodysize.x,opacity:1});this.newContents.setStyles({left:0,opacity:1});this.slider.setStyle('left',-this.bodysize.x).tween('left',-this.bodysize.x,0);}else if(fx=='fade'){this.slider.setStyle('left',0);this.oldContents.setStyle('left',0).set('tween',{duration:this.options.animationDuration/2}).tween('opacity',1,0);this.newContents.setStyles({opacity:0,left:0}).set('tween',{duration:this.options.animationDuration}).tween('opacity',0,1);}},constructPicker:function(){this.picker=new Element('div',{'class':this.options.pickerClass}).inject(document.body);if(this.options.useFadeInOut){this.picker.setStyle('opacity',0).set('tween',{duration:this.options.animationDuration});}
var h=new Element('div',{'class':'header'}).inject(this.picker);var titlecontainer=new Element('div',{'class':'title'}).inject(h);new Element('div',{'class':'previous'}).addEvent('click',this.previous.bind(this)).set('text','«').inject(h);new Element('div',{'class':'next'}).addEvent('click',this.next.bind(this)).set('text','»').inject(h);new Element('div',{'class':'closeButton'}).addEvent('click',this.close.bindWithEvent(this,true)).set('text','x').inject(h);new Element('span',{'class':'titleText'}).addEvent('click',this.zoomOut.bind(this)).inject(titlecontainer);var b=new Element('div',{'class':'body'}).inject(this.picker);this.bodysize=b.getSize();this.slider=new Element('div',{styles:{position:'absolute',top:0,left:0,width:2*this.bodysize.x,height:this.bodysize.y}}).set('tween',{duration:this.options.animationDuration,transition:Fx.Transitions.Quad.easeInOut}).inject(b);this.oldContents=new Element('div',{styles:{position:'absolute',top:0,left:this.bodysize.x,width:this.bodysize.x,height:this.bodysize.y}}).inject(this.slider);this.newContents=new Element('div',{styles:{position:'absolute',top:0,left:0,width:this.bodysize.x,height:this.bodysize.y}}).inject(this.slider);},renderTime:function(){var container=new Element('div',{'class':'time'}).inject(this.newContents);if(this.options.timePickerOnly){this.picker.getElement('.titleText').set('text','Select a time');}else{this.picker.getElement('.titleText').set('text',this.format(this.d,'j M, Y'));}
new Element('input',{type:'text','class':'hour'}).set('value',this.leadZero(this.d.getHours())).addEvents({mousewheel:function(e){var i=e.target,v=i.get('value').toInt();i.focus();if(e.wheel>0){v=(v<23)?v+1:0;}else{v=(v>0)?v-1:23;}
i.set('value',this.leadZero(v));e.stop();}.bind(this)}).set('maxlength',2).inject(container);new Element('input',{type:'text','class':'minutes'}).set('value',this.leadZero(this.d.getMinutes())).addEvents({mousewheel:function(e){var i=e.target,v=i.get('value').toInt();i.focus();if(e.wheel>0){v=(v<59)?v+1:0;}else{v=(v>0)?v-1:59;}
i.set('value',this.leadZero(v));e.stop();}.bind(this)}).set('maxlength',2).inject(container);new Element('div',{'class':'separator'}).set('text',':').inject(container);new Element('input',{type:'submit',value:'OK','class':'ok'}).addEvents({click:function(e){e.stop();this.select($merge(this.dateToObject(this.d),{hours:this.picker.getElement('.hour').get('value').toInt(),minutes:this.picker.getElement('.minutes').get('value').toInt()}));}.bind(this)}).set('maxlength',2).inject(container);},renderMonth:function(){var month=this.d.getMonth();this.picker.getElement('.titleText').set('text',this.options.months[month]+' '+this.d.getFullYear());this.d.setDate(1);while(this.d.getDay()!=this.options.startDay){this.d.setDate(this.d.getDate()-1);}
var container=new Element('div',{'class':'days'}).inject(this.newContents);var titles=new Element('div',{'class':'titles'}).inject(container);var d,i,classes,e,weekcontainer;for(d=this.options.startDay;d<(this.options.startDay+7);d++){new Element('div',{'class':'title day day'+(d%7)}).set('text',this.options.days[(d%7)].substring(0,this.options.dayShort)).inject(titles);}
var available=false;var t=this.today.toDateString();var currentChoice=this.dateFromObject(this.choice).toDateString();for(i=0;i<42;i++){classes=[];classes.push('day');classes.push('day'+this.d.getDay());if(this.d.toDateString()==t)classes.push('today');if(this.d.toDateString()==currentChoice)classes.push('selected');if(this.d.getMonth()!=month)classes.push('otherMonth');if(i%7==0){weekcontainer=new Element('div',{'class':'week week'+(Math.floor(i/7))}).inject(container);}
e=new Element('div',{'class':classes.join(' ')}).set('text',this.d.getDate()).inject(weekcontainer);if(this.limited('date')){e.addClass('unavailable');if(available){this.limit.right=true;}else if(this.d.getMonth()==month){this.limit.left=true;}}else{available=true;e.addEvent('click',function(e,d){if(this.options.timePicker){this.d.setDate(d.day);this.d.setMonth(d.month);this.mode='time';this.render('fade');}else{this.select(d);}}.bindWithEvent(this,{day:this.d.getDate(),month:this.d.getMonth(),year:this.d.getFullYear()}));}
this.d.setDate(this.d.getDate()+1);}
if(!available)this.limit.right=true;},renderYear:function(){var month=this.today.getMonth();var thisyear=this.d.getFullYear()==this.today.getFullYear();var selectedyear=this.d.getFullYear()==this.choice.year;this.picker.getElement('.titleText').set('text',this.d.getFullYear());this.d.setMonth(0);var i,e;var available=false;var container=new Element('div',{'class':'months'}).inject(this.newContents);for(i=0;i<=11;i++){e=new Element('div',{'class':'month month'+(i+1)+(i==month&&thisyear?' today':'')+(i==this.choice.month&&selectedyear?' selected':'')}).set('text',this.options.monthShort?this.options.months[i].substring(0,this.options.monthShort):this.options.months[i]).inject(container);if(this.limited('month')){e.addClass('unavailable');if(available){this.limit.right=true;}else{this.limit.left=true;}}else{available=true;e.addEvent('click',function(e,d){this.d.setDate(1);this.d.setMonth(d);this.mode='month';this.render('fade');}.bindWithEvent(this,i));}
this.d.setMonth(i);}
if(!available)this.limit.right=true;},renderDecades:function(){while(this.d.getFullYear()%this.options.yearsPerPage>0){this.d.setFullYear(this.d.getFullYear()-1);}
this.picker.getElement('.titleText').set('text',this.d.getFullYear()+'-'+(this.d.getFullYear()+this.options.yearsPerPage-1));var i,y,e;var available=false;var container=new Element('div',{'class':'years'}).inject(this.newContents);if($chk(this.options.minDate)&&this.d.getFullYear()<=this.options.minDate.getFullYear()){this.limit.left=true;}
for(i=0;i<this.options.yearsPerPage;i++){y=this.d.getFullYear();e=new Element('div',{'class':'year year'+i+(y==this.today.getFullYear()?' today':'')+(y==this.choice.year?' selected':'')}).set('text',y).inject(container);if(this.limited('year')){e.addClass('unavailable');if(available){this.limit.right=true;}else{this.limit.left=true;}}else{available=true;e.addEvent('click',function(e,d){this.d.setFullYear(d);this.mode='year';this.render('fade');}.bindWithEvent(this,y));}
this.d.setFullYear(this.d.getFullYear()+1);}
if(!available){this.limit.right=true;}
if($chk(this.options.maxDate)&&this.d.getFullYear()>=this.options.maxDate.getFullYear()){this.limit.right=true;}},limited:function(type){var cs=$chk(this.options.minDate);var ce=$chk(this.options.maxDate);if(!cs&&!ce)return false;switch(type){case'year':return(cs&&this.d.getFullYear()<this.options.minDate.getFullYear())||(ce&&this.d.getFullYear()>this.options.maxDate.getFullYear());case'month':var ms=(''+this.d.getFullYear()+this.leadZero(this.d.getMonth())).toInt();return cs&&ms<(''+this.options.minDate.getFullYear()+this.leadZero(this.options.minDate.getMonth())).toInt()||ce&&ms>(''+this.options.maxDate.getFullYear()+this.leadZero(this.options.maxDate.getMonth())).toInt()
case'date':return(cs&&this.d<this.options.minDate)||(ce&&this.d>this.options.maxDate);}},allowZoomOut:function(){if(this.mode=='time'&&this.options.timePickerOnly)return false;if(this.mode=='decades')return false;if(this.mode=='year'&&!this.options.yearPicker)return false;return true;},zoomOut:function(){if(!this.allowZoomOut())return;if(this.mode=='year'){this.mode='decades';}else if(this.mode=='time'){this.mode='month';}else{this.mode='year';}
this.render('fade');},previous:function(){if(this.mode=='decades'){this.d.setFullYear(this.d.getFullYear()-this.options.yearsPerPage);}else if(this.mode=='year'){this.d.setFullYear(this.d.getFullYear()-1);}else if(this.mode=='month'){this.d.setMonth(this.d.getMonth()-1);}
this.render('left');},next:function(){if(this.mode=='decades'){this.d.setFullYear(this.d.getFullYear()+this.options.yearsPerPage);}else if(this.mode=='year'){this.d.setFullYear(this.d.getFullYear()+1);}else if(this.mode=='month'){this.d.setMonth(this.d.getMonth()+1);}
this.render('right');},close:function(e,force){if(!$(this.picker))return;var clickOutside=($chk(e)&&e.target!=this.picker&&!this.picker.hasChild(e.target)&&e.target!=this.visual);if(force||clickOutside){if(this.options.useFadeInOut){this.picker.set('tween',{duration:this.options.animationDuration/2,onComplete:this.destroy.bind(this)}).tween('opacity',1,0);}else{this.destroy();}}},destroy:function(){this.picker.destroy();this.picker=null;this.options.onClose();},select:function(values){this.choice=$merge(this.choice,values);var d=this.dateFromObject(this.choice);if(this.options.validate) OFDate2Validation(this.options.field_id);this.input.set('value',this.format(d,this.options.inputOutputFormat));this.visual.set('value',this.format(d,this.options.format));this.options.onSelect(d);this.close(null,true);},leadZero:function(v){return v<10?'0'+v:v;},format:function(t,format){var f='';var h=t.getHours();var m=t.getMonth();for(var i=0;i<format.length;i++){switch(format.charAt(i)){case'\\':i++;f+=format.charAt(i);break;case'y':f+=(100+t.getYear()+'').substring(1);break
case'Y':f+=t.getFullYear();break;case'm':f+=this.leadZero(m+1);break;case'n':f+=(m+1);break;case'M':f+=this.options.months[m].substring(0,this.options.monthShort);break;case'F':f+=this.options.months[m];break;case'd':f+=this.leadZero(t.getDate());break;case'j':f+=t.getDate();break;case'D':f+=this.options.days[t.getDay()].substring(0,this.options.dayShort);break;case'l':f+=this.options.days[t.getDay()];break;case'G':f+=h;break;case'H':f+=this.leadZero(h);break;case'g':f+=(h%12?h%12:12);break;case'h':f+=this.leadZero(h%12?h%12:12);break;case'a':f+=(h>11?'pm':'am');break;case'A':f+=(h>11?'PM':'AM');break;case'i':f+=this.leadZero(t.getMinutes());break;case's':f+=this.leadZero(t.getSeconds());break;case'U':f+=Math.floor(t.valueOf()/1000);break;default:f+=format.charAt(i);}}
return f;},unformat:function(t,format){var d=new Date();var a={};var c,m;t=t.toString();for(var i=0;i<format.length;i++){c=format.charAt(i);switch(c){case'\\':r=null;i++;break;case'y':r='[0-9]{2}';break;case'Y':r='[0-9]{4}';break;case'm':r='0[1-9]|1[012]';break;case'n':r='[1-9]|1[012]';break;case'M':r='[A-Za-z]{'+this.options.monthShort+'}';break;case'F':r='[A-Za-z]+';break;case'd':r='0[1-9]|[12][0-9]|3[01]';break;case'j':r='[1-9]|[12][0-9]|3[01]';break;case'D':r='[A-Za-z]{'+this.options.dayShort+'}';break;case'l':r='[A-Za-z]+';break;case'G':case'H':case'g':case'h':r='[0-9]{1,2}';break;case'a':r='(am|pm)';break;case'A':r='(AM|PM)';break;case'i':case's':r='[012345][0-9]';break;case'U':r='-?[0-9]+$';break;default:r=null;}
if($chk(r)){m=t.match('^'+r);if($chk(m)){a[c]=m[0];t=t.substring(a[c].length);}else{if(this.options.debug)alert("Fatal Error in DatePicker\n\nUnexpected format at: '"+t+"' expected format character '"+c+"' (pattern '"+r+"')");return d;}}else{t=t.substring(1);}}
for(c in a){var v=a[c];switch(c){case'y':d.setFullYear(v<30?2000+v.toInt():1900+v.toInt());break;case'Y':d.setFullYear(v);break;case'm':case'n':d.setMonth(v-1);break;case'M':v=this.options.months.filter(function(item,index){return item.substring(0,this.options.monthShort)==v}.bind(this))[0];case'F':d.setMonth(this.options.months.indexOf(v));break;case'd':case'j':d.setDate(v);break;case'G':case'H':d.setHours(v);break;case'g':case'h':if(a['a']=='pm'||a['A']=='PM'){d.setHours(v==12?0:v.toInt()+12);}else{d.setHours(v);}break;case'i':d.setMinutes(v);break;case's':d.setSeconds(v);break;case'U':d=new Date(v.toInt()*1000);}};return d;}});

function OFDate2Validation(field_id) {
	document.getElementById('input-vimg-' + field_id).className = 'input-vimg-green';
}

OFDate2 = new Class({
    Implements: Options,
        
    options: {
        'selector_id':'date',
        'timePicker':false,
        'format':'m/d/Y h:i A',
        'width':137,
        'label':'',
        'name':'',
        'value':'',
        'onClick':$empty,
		'blur':$empty,
        'input_id':'',
        'input_class':'date-input',
		'field_id':'',
		'content_part_id':'',
		'validate':true
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.type = 'date';
        this.name = this.options.name;
        
        this.date_picker = new Element('div',{'class':'date-picker'});
        //this.date_picker.setStyles({'float':'left'})
        
        this.date_label = new Element('label');
        if(this.options.label != ''){
            this.date_label = new Element('label',{'class':'date-label'});
            this.date_label.set('html',this.options.label);
            //this.date_label.setStyles({'float':'left'});
            this.date_label.inject(this.date_picker);
        }
        
        this.date_input = new Element('input',{'id':this.options.input_id,'type':'text','class':this.options.input_class,'value':this.options.value});
		
		
		
        this.date_input.inject(this.date_picker);
        
        this.date_icon = new Element('img',{'src':'/obray/images/calendar-icon.png','id':this.options.selector_id,'class':'date-icon'});
        //this.date_icon.setStyles({'float':'left','display':'block','margin':2,'margin-left':0,'cursor':'pointer'});
        this.date_icon.inject(this.date_picker);
		var vMsgId = 'input-vmsg-' + this.options.field_id;
		var vImgId = 'input-vimg-' + this.options.field_id;
		this.vMsg = new Element('div',{'id':vMsgId,'style':'','class':'input-vmsg'});
		this.vImg = new Element('div',{'id':vImgId,'style':'','class':'input-vimg'});
		this.vMsg.inject(this.date_picker);
		this.vImg.inject(this.date_picker);
        
		
		
		
        this.br = new Element('br',{'class':'clear'});
        this.br.clone().inject(this.date_picker);
        
        this.date_selector = new DatePicker2(this.date_input,{'pickerClass':'datepicker_vista','field_id':this.options.field_id,'validate':this.options.validate,'toggleElements':this.date_icon,'timePicker':this.options.timePicker,'format':this.options.format,'inputOutputFormat':this.options.format})
		
		
		//this.date_input.addEvent('blur',this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.date_input.getProperty('value'))));
        
		
		
		
		
		
        
    },
    
    inject: function(el){
		this.container = this.container = new Element('div',{'class':'input-wrapper','id':'element-container-'+this.options.field_id});
		this.container.inject(el);
        this.date_picker.inject(this.container);
        

        
        this.date_label.getNext().getNext().addEvent('blur',function(){
			OFDate2Validation(this.options.field_id);
        }.bind(this));
    },
    
    addEvent: function(type,fn){
	    
	},
    
    setStyles: function(style_options){
        //set input styles
        /*
        this.date_input.getNext().setStyles({
            'float':                                'left',
            'border':                               style_options.border,
            '-webkit-border-bottom-left-radius':    style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':   style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':       style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':      style_options['radius'] + 'px',
            '-moz-border-radius':                   style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'border-radius':                        style_options['radius'] + 'px',
            'padding-left':                         style_options['padding-left'] + 'px',
            'padding-right':                        style_options['padding-right'] + 'px',
            'padding-top':                          style_options['padding-top'] + 'px',
            'padding-bottom':                       style_options['padding-bottom'] + 'px',
            'margin-left':                          style_options['margin-left'] + 'px',
            'margin-right':                         style_options['margin-right'] + 'px',
            'margin-top':                           style_options['margin-top'] + 'px',
            'margin-bottom':                        style_options['margin-bottom'] + 'px',
            'font-size':                            style_options['input-font-size'] + 'px',
            'font-weight':                          style_options['input-font-weight'],
            'font-style':                           style_options['input-font-style'],
            'color':                                style_options['input-color']
        });
		*/
		this.date_input.getNext().setStyles();
        
        //set label styles
		/*
        this.date_label.setStyles({
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 'px',
            'padding-right':style_options['padding-right'] + 'px',
            'padding-top':style_options['padding-top'] + 'px',
            'padding-bottom':style_options['padding-bottom'] + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'color':style_options['label-color'],
            'width':style_options['label-width']
        })
		*/
		this.date_label.setStyles()
    },
    
    getProperty: function(property){
        if(property == 'value'){ return this.date_input.getNext().getProperty('value'); }
    },
    
    setLabelDisplay: $empty
});
OFDateFields2 = new Class({
    Implements: Options,
    
    options: {
        'label':'',
		'type':'text',
        'blur':$empty,
        'focus':$empty,
        'name':'',
        'value':'',
		'content_part_id':'',
		'field_id':'',
		'validate':true,
		'vmsg':true,
		'depends_on':''
    },
    
    initialize: function(options){
		this.setOptions(options);
        this.name = this.options.name;       
        this.text_label = new Element('label',{'class':'otext-label'});
        this.text_label.set('html',this.options.label);
		this.depends_on = new Array();
		this.depends_on[0] = '';
		if(this.options.depends_on != '') this.depends_on = this.options.depends_on.split("<?>");
        this.values = this.options.value.split("-");
        var vMsgId = 'input-vmsg-' + this.options.field_id;
		var vImgId = 'input-vimg-' + this.options.field_id;
		this.vMsg = new Element('div',{'id':vMsgId,'style':'','class':'input-vmsg'});
		this.vImg = new Element('div',{'id':vImgId,'style':'','class':'input-vimg'});
		this.text_input = new Element('input',{'type':this.options.type, 'class':'otext-input year','value':this.values[0],'style':''});
		
		
		this.numer = new Element('input',{'class':'otext-input day','value':this.values[1],'style':'width:25px;'});
		this.denom = new Element('input',{'class':'otext-input month','value':this.values[2],'style':'width:30px;'});
		this.slash  = new Element('span',{'style':'','class':'year'});
		this.slash.set('html','/');
        
        this.text_input.addEvent('blur',function(){
			var integer = encodeURIComponent(this.text_input.getProperty('value'));
			if(integer == "") integer = ' ';
			var numerator = encodeURIComponent(this.numer.getProperty('value'));
			if(numerator == "") numerator = ' ';
			var denominator = encodeURIComponent(this.denom.getProperty('value'));
			if(denominator == "") denominator = '';
	
			this.value = integer + '-' + numerator + '-' + denominator; 
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						if(json.response.message != '') { this.vMsg.setStyles({'opacity':1}); } else { this.vMsg.setStyles({'opacity':0}); }
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						if(json.response.error_message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
		this.numer.addEvent('blur',function(){
			
	
			var integer = encodeURIComponent(this.text_input.getProperty('value'));
			if(integer == "") integer = ' ';
			var numerator = encodeURIComponent(this.numer.getProperty('value'));
			if(numerator == "") numerator = ' ';
			var denominator = encodeURIComponent(this.denom.getProperty('value'));
			if(denominator == "") denominator = '';
	
			this.value = integer + '-' + numerator + '-' + denominator; 
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						if(json.response.message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						if(json.response.error_message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
		this.denom.addEvent('blur',function(){
			
	
			var integer = encodeURIComponent(this.text_input.getProperty('value'));
			if(integer == "") integer = ' ';
			var numerator = encodeURIComponent(this.numer.getProperty('value'));
			if(numerator == "") numerator = ' ';
			var denominator = encodeURIComponent(this.denom.getProperty('value'));
			if(denominator == "") denominator = '';
	
			this.value = integer + '-' + numerator + '-' + denominator; 
			
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vmsg) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						if(json.response.message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vmsg) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						if(json.response.error_message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
        this.text_input.addEvent('focus',this.options.focus);
		
		// container
		// place label and input field into a div to give us control over absolute positioning for label
        this.container = new Element('div',{'class':'input-wrapper datefields','id':'element-container-'+this.options.field_id});
		// container styles
		this.container.setStyles({
			'position':'relative'
		});
		
		//inject element and label into container
		if(this.options.label != ''){ this.text_label.inject(this.container); }
        
		this.numer.inject(this.container);
		//this.slash.inject(this.container);
		this.denom.inject(this.container);
		this.text_input.inject(this.container);
		if(this.options.validate) {
			if(this.options.vmsg) {
				this.vMsg.inject(this.container);
			}
			this.vImg.inject(this.container);
		}
    },
    
    setStyles: function(style_options){
        
        //if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * .50).toInt() }
		if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * this.options['text-area-input-height']).toInt() }
        
		this.text_input.setStyles({'height':                               style_options['input-height']})
		this.text_label.setStyles();
    },
    
	setLabelDisplay: function(label_position){
		if(label_position == 'inside'){
			this.text_input.addEvent('focus',function(){
				this.text_label.addClass('Ohidden');
			}.bind(this));
			
			this.text_input.addEvent('blur',function(){
				if(this.text_input.getProperty('value') ==''){
					this.text_label.removeClass('Ohidden');
				}
			}.bind(this));
			
			this.text_label.addEvent('click',function(){
				this.text_label.addClass('Ohidden');
				this.text_input.focus();
			}.bind(this));
		}
	},
	
	addEvent: function(type,fn){
		if(!(type == "keypress" && this.options['text-area'])){
	    	this.text_input.addEvent(type,fn);
	    }
	},
	
    // get property
    getProperty: function(){ 
		var integer = encodeURIComponent(this.text_input.getProperty('value'));
		if(integer == "") integer = ' ';
		var numerator = encodeURIComponent(this.numer.getProperty('value'));
		if(numerator == "") numerator = ' ';
		var denominator = encodeURIComponent(this.denom.getProperty('value'));
		if(denominator == "") denominator = '';
	
		 return integer + '-' + numerator + '-' + denominator; 
		
	},
    
    // set property
    setProperty: function(property,value){ this.text_input.setProperty(property,value); },
    
    inject: function(el){
        //if(this.options.label != ''){ this.text_label.inject(el); }
        //this.text_input.inject(el);
		this.container.inject(el);
    }
});


OFCheck2 = new Class({
    Implements: Options,
    
    options: {
        'class':'',
        'checked':false,
        'height':9,
        'width':9,
        'check-color':'#41e011',
        'label':'',
        'name':'default_check',
		'content_part_id':'',
		'field_id':'',
		'validate':true
    },
    
    initialize: function(options){
        this.setOptions(options);
		if(this.options.checked == '1') {
        	this.is_checked = true;
		} else {
			this.is_checked = false;
		}
        this.name = this.options.name;
        
        this.checkbox_label = new Element('label',{'class':'ocheck-label'});
        this.checkbox_label.set('html',this.options.label);
        
        this.checkbox = new Element('div',{'class':'ocheck-box'});
        //this.checkbox.setStyles({'float':'left','width':15,'height':15,'border':'1px solid #d5d5d5'});
        this.checkbox.addEvent('mouseenter',function(){ this.checkbox.setStyles({'background-color':this.options['highlight-color']}); }.bind(this));
        this.checkbox.addEvent('mouseleave',function(){ this.checkbox.setStyles({'background-color':this.options['background-color']}); }.bind(this));
        this.checkbox.addEvent('click',function(){
            if(this.is_checked){ 
                this.is_checked = false;
                this.check.setStyles({'display':'none'});
            } else { 
                this.is_checked = true; 
                this.check.setStyles({'display':'block'});
            }
			var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
			var data = 'field_data=' + this.is_checked;
			if(this.options.validate) {
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
        	    this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
        	    	if(json.response.error == 'false' || json.response.error == false){
						document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	    	   	document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
             	}.bind(this)}).send();
			}
        }.bind(this));
        
        this.check = new Element('div',{'class':'checkbox-check'});
        this.check.setStyles({'background-color':this.options['check-color'],'width':9,'height':9});
        this.check.inject(this.checkbox);
		
        this.check.addEvent('click',function(){
            this.checkbox.fireEvent.bind(this,'click');
        }.bind(this));
        
        if(!this.options['checked']){
            this.check.setStyles({'display':'none'})
        }
		if(this.is_checked) {
			this.check.setStyles({'display':'block'})
		}
    },
    
    setStyles: function(style_options){
		this.checkbox_label.setStyles();
		this.checkbox.setStyles();
		/*
        this.checkbox.setStyles({
            'cursor':           'pointer',
            'border':           style_options['border'],
            'background-color': style_options['background-color'],
            'color':            style_options['color'],
            'width':            this.options['width'],
            'height':           this.options['height'],
            'margin-left':      style_options['margin-left'] + style_options['label-width'] + style_options['margin-left']*2 + style_options['margin-right'] + style_options['padding-left']*2 + style_options['padding-right'],
            'margin-right':     style_options['margin-right'],
            'margin-top':       style_options['margin-top'] + 4,
            'margin-bottom':    style_options['margin-bottom'] + 4,
            'padding-left':     2,
            'padding-right':    2,
            'padding-top':      2,
            'padding-bottom':   2,
            '-webkit-border-bottom-left-radius':2 + 'px',
            '-webkit-border-bottom-right-radius':2 + 'px',
            '-webkit-border-top-left-radius':2 + 'px',
            '-webkit-border-top-right-radius':2 + 'px',
            '-moz-border-radius': 2 + 'px ' + 2 + 'px '+ 2 + 'px '+ 2 + 'px',
            'border-radius': 2 + 'px'
        })
		*/
        this.options['highlight-color'] = style_options['highlight-color'];
        
        this.check.setStyles({
            '-webkit-border-bottom-left-radius': 2 + 'px',
            '-webkit-border-bottom-right-radius': 2 + 'px',
            '-webkit-border-top-left-radius': 2 + 'px',
            '-webkit-border-top-right-radius': 2 + 'px',
            '-moz-border-radius': 2 + 'px ' + 2 + 'px '+ 2 + 'px '+ 2 + 'px',
            'border-radius': 2 + 'px'
        })
        
		/*
        //set label styles
        this.checkbox_label.setStyles({
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 1 + 'px',
            'padding-right':style_options['padding-right'] + 1 + 'px',
            'padding-top':style_options['padding-top'] + 1 + 'px',
            'padding-bottom':style_options['padding-bottom'] + 1 + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'color':style_options['label-color'],
            'width':style_options['label-width'],
            'text-align':'left'
        });
		*/
    },
    
    inject: function(el){
		this.container = new Element('div',{'class':'input-wrapper','id':'element-container-'+this.options.field_id});
		this.container.inject(el);
        this.checkbox.inject(this.container);
        if(this.options.label != ''){ this.checkbox_label.inject(this.container); }
		var vMsgId = 'input-vmsg-' + this.options.field_id;
		var vImgId = 'input-vimg-' + this.options.field_id;
		this.vMsg = new Element('div',{'id':vMsgId,'style':'','class':'input-vmsg'});
		this.vImg = new Element('div',{'id':vImgId,'style':'','class':'input-vimg'});
		if(this.options.validate) {
			this.vMsg.inject(this.container);
			this.vImg.inject(this.container);
		}
    },
    
    addEvent: function(type,fn){
	    
	},
    
    getProperty: function(value){
        return this.is_checked;
    },
    
    setLabelDisplay: $empty
});


OFRadio2 = new Class({
    Implements: Options,
    
    options: {
        'class_name':'',
        'checked':'',
        'height':9,
        'width':9,
        'check-color':'#41e011',
        'label':'',
        'name':'default_radio',
		'labels':[],
		'values':[],
		'content_part_id':'',
		'field_id':'',
		'direction':'horizontal',
		'value':'',
		'dependents':'',
		'feed_from':0,
		'feed_to':0,
		'validate':true
    },
    
    initialize: function(options){
		this.setOptions(options);
        this.is_checked = this.options['checked'];
        this.name = this.options.name;
		this.val_num = -1;
		this.checkbox = new Array();
		this.check = new Array();
		this.check_label = new Array();
		this.dependents = new Array();
		if(this.options.dependents != "") {
			this.dependents = this.options.dependents.split(",");
		}
		var checkid;
		this.value = this.options.value;
		
		this.radio_input = new Element('input',{'type':'text','id':'form-element-'+this.options.field_id,'value':this.value});
        this.radio_input.setStyles({'position':'absolute','left':-5000,'height':1,'width':1,'padding':0,'margin':0,'border':0,'z-index':10000});

		//main radio label
        this.checkbox_label = new Element('label',{'class':'oradio-label'});
        this.checkbox_label.set('html',this.options.label);
		
		// container for all radio buttons
		this.buttoncontainer = new Element('div',{'class':'radio-container'});
		
		
        for(var i=0;i<this.options.labels.length;++i){
			
			checkid = 'oradio-check' + this.options.field_id + i;
			// MUST HAVE A VALUE TO SET THE CURRENT CHECKED ITEM
			if(this.options.values[i] == this.options.value) this.val_num = i;

			//inject checkbox
        	this.checkbox[i] = new Element('div',{'class':'oradio-button','id':'oradio-button-'+i});
			this.checkbox[i].setStyles({'width':this.options['width'],'height':this.options['height'],'cursor':'pointer'});
        	this.checkbox[i].inject(this.buttoncontainer);
			
			this.check[i] = new Element('div',{'class':'oradio-check','id':checkid,'style':'background-color:'+this.options['check-color']});
        	this.check[i].setStyles({'width':this.options['width'],'height':this.options['height'],'cursor':'pointer'});
			this.check[i].inject(this.checkbox[i]);
			
			//inject label
			this.check_label[i] = new Element('label',{'class':'radiobutton-label'});
        	this.check_label[i].set('html',this.options.labels[i]);
			this.check_label[i].inject(this.buttoncontainer);
			
        }
		
		// break for radio buttons container
		this.buttoncontainerbreak = new Element('div',{'class':'clear'});
		this.buttoncontainerbreak.inject(this.buttoncontainer);
		
		//loop through the recently created array of check marks and set the display to none if it's not default-selected as well as the style check color.
		this.check.each(function(el,i) {
			if(i != this.val_num){
        	    el.setStyles({'display':'none'})
        	}		
			el.setStyles({'background-color':this.options['check-color']});
		}.bind(this));
		
		//add events to radio buttons.  set the value based on the one that was just checked and clear the last button.
		this.checkbox.each(function(el,i){
			el.addEvent('mouseenter',function(){ 
														
				}.bind(this));
        	el.addEvent('mouseleave',function(){ 
															
				}.bind(this));
			this.check[i].addEvent('click',function(){
        	    el.fireEvent.bind(this,'click');
        	}.bind(this));
        	el.addEvent('click',function(){
				var checkid = 'oradio-check' + this.options.field_id + this.val_num;
				if(this.val_num != -1) document.getElementById(checkid).style.display = 'none';
				this.val_num = i;
				this.check[this.val_num].setStyles({'display':'block'});
				this.value = this.options.values[this.val_num];
				for(var z = 0; z<this.dependents.length; z++) {
					window['dependent_fn_'+this.dependents[z]](this.value);
				}
				if(this.options.feed_to != 0) {
				window['signup_first_name'+this.options.feed_to].ajaxlyOperation(this.options.feed_from,this.value,this.options.field_id);
				}
				if(this.options.validate) document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
			}.bind(this));
		}.bind(this))
		var vImgId = 'input-vimg-' + this.options.field_id;
		this.vImg = new Element('div',{'id':vImgId,'style':'','class':'input-vimg'});
		
		
    },
    
    setStyles: function(style_options){
		this.checkbox_label.setStyles();
		this.checkbox.setStyles();
		
        this.options['highlight-color'] = style_options['highlight-color'];
        
        this.check.setStyles({
            '-webkit-border-bottom-left-radius': 2 + 'px',
            '-webkit-border-bottom-right-radius': 2 + 'px',
            '-webkit-border-top-left-radius': 2 + 'px',
            '-webkit-border-top-right-radius': 2 + 'px',
            '-moz-border-radius': 2 + 'px ' + 2 + 'px '+ 2 + 'px '+ 2 + 'px',
            'border-radius': 2 + 'px'
        })
        
    },
    
    inject: function(el){
        //this.checkbox.inject(el);
        //if(this.options.label != ''){ this.checkbox_label.inject(el); }
		//var vMsgId = 'input-vmsg-' + this.options.field_id;
		//var vImgId = 'input-vimg-' + this.options.field_id;
		//this.vMsg = new Element('div',{'id':vMsgId,'style':'','class':'input-vmsg'});
		//this.vImg = new Element('div',{'id':vImgId,'style':'','class':'input-vimg'});
		//this.vMsg.inject(el);
		//this.vImg.inject(el);
		this.container = new Element('div',{'class':'input-wrapper','id':'element-container-'+this.options.field_id});
		this.container.addClass(this.options.class_name);
		
		this.container.inject(el);
		this.checkbox_label.inject(this.container);
		this.buttoncontainer.inject(this.container);
		if(this.options.validate) {
			this.vImg.inject(this.container);
		}
    },
	
    
    addEvent: function(type,fn){
	    
	},
    
    getProperty: function(value){
        return this.value;
    },
    
    setLabelDisplay: $empty
});

// obray file form element
OFFile2 = new Class({
    Implements: Options,
    
    'options':{
        'label':'',
        'upload_url':'index.cfm?action=videos.uploadvideo',
        'extensions':'',
        'onUploadSuccess':$empty,
        'name':'',
        'file_name':'',
        'file_ext':'',
        'file_size':0,
        'class':''
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.upload_target = $('upload_target');
        this.json = {'response':{'server_file_name':this.options.file_name,'server_file_ext':this.options.file_ext,'file_size':this.options.file_size}};
        this.load_state = 'waiting';
        this.name = this.options.name;
        
        // file input container
        this.file_container = new Element('div',{'class':'ofile-container'});
        this.file_container.setStyles({'position':'relative','float':'left'})
        
        // file label
        this.file_label = new Element('label',{'class':'ofile-label'});
        this.file_label.set('html',this.options.label);
        if(this.options.label != ''){ this.file_label.inject(this.file_container); }
        
        // file input        
        this.file_input = new Element('input',{'type':'text','value':this.options.file_name+'.'+this.options.file_ext});
        this.file_input.inject(this.file_container);
        this.file_input.addEvent('focus',function(e){ e.preventDefault(); this.upload_file.focus(); }.bind(this))
        this.file_input.addEvent('mousedown',function(e){ e.preventDefault(); this.upload_file.focus(); }.bind(this))
        
		// upload button
		this.upload_btn = new Element('img',{'class':'ovideo-edit-btn','src':'obray/images/image/edit-btn.png'});
		this.upload_btn.setStyles({'position':'relative','float':'left','width':16,'height':16});
		//this.upload_btn.setStyles({'position':'absolute','right':-25,'top':2,'background-image':'url(obray/images/image/edit-btn.png)','width':'25px','height':'25px','cursor':'pointer','overflow':'hidden','z-index':5000});
		this.upload_btn.inject(this.file_container);
		
		// file form
		this.upload_form = new Element('form',{'action':'index.cfm?action=forms.uploadFile&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','encoding':'multipart/form-data','enctype':'multipart/form-data','target':'upload_target','method':'post'});
		this.upload_form.setStyles({'position':'absolute','top':'0px','left':'0px','background-color':'transparent','width':'100px','overflow':'hidden'});
		this.upload_form.inject(this.file_container);
		
		// file input to be uploaded
		this.upload_file = new Element('input',{'type':'file','name':'file'});
		this.upload_file.setStyles({'font-family':'arial','color':'#ffffff','opacity':.01});
		this.upload_file.inject(this.upload_form);
		
		// list of valid file extensions
	    this.valid_extensions = new Element('input',{'type':'hidden','name':'valid_extensions','value':this.options.extensions});
	    this.valid_extensions.inject(this.upload_form);
		
		this.upload_file.addEvent('change',function(e){
		    // change loading state
		    this.toggleLoadState();
			// submit file for upload
			this.upload_form.submit();
			// get upload response
			this.upload_target.addEvent('load',function(){
				var frame = window.frames['upload_target'];
				// decode response
				var response = frame.document.getElementById('response').innerHTML;
				this.json = JSON.decode(response);
				// handle response
				this.file_input.setProperty('value',this.json.response.server_file_name + '.' + this.json.response.server_file_ext);
				if(this.json.response.error){ alert(this.json.response.error_message); } else { this.options.onUploadSuccess(); }
				// change load state
				this.toggleLoadState();
				this.upload_target.removeEvents();
			}.bind(this));
		}.bind(this));
		
    },
    
    toggleLoadState: function(){
        if(this.load_state == 'waiting'){
            this.upload_btn.setProperty('src','/obray/images/loaders/ajax-loader-1a1a1a.gif');
            this.load_state = 'loading';    
        } else {
            this.upload_btn.setProperty('src','obray/images/image/edit-btn.png');
            this.load_state = 'waiting';
        }
    },
    
    setStyles: function(style_options){
        //set input styles
        this.file_input.setStyles({
            'float':                                'left',
            'border':                               style_options.border,
            '-webkit-border-bottom-left-radius':    style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':   style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':       style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':      style_options['radius'] + 'px',
            '-moz-border-radius':                   style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'border-radius':                        style_options['radius'] + 'px',
            'padding-left':                         style_options['padding-left'] + 'px',
            'padding-right':                        style_options['padding-right'] + 'px',
            'padding-top':                          style_options['padding-top'] + 'px',
            'padding-bottom':                       style_options['padding-bottom'] + 'px',
            'margin-left':                          style_options['margin-left'] + 'px',
            'margin-right':                         style_options['margin-right'] + 'px',
            'margin-top':                           style_options['margin-top'] + 'px',
            'margin-bottom':                        style_options['margin-bottom'] + 'px',
            'font-size':                            style_options['input-font-size'] + 'px',
            'font-weight':                          style_options['input-font-weight'],
            'font-style':                           style_options['input-font-style'],
            'color':                                style_options['input-color'],
            'background-color':                     'transparent',
            'width':                                style_options['input-width'] - 16,
            'cursor':                               'pointer'
        });
        this.upload_btn.setStyles({'margin-top':(style_options['margin-top']*2+style_options['padding-top']*2+style_options['input-font-size'])/2-2-8/2});
        
        
        this.upload_file.setStyles({'width':style_options['input-width']+25});
        this.upload_form.setStyles({'width':style_options['input-width'] + 25,
            'left':style_options['label-width']+2*style_options['margin-left']+2*style_options['padding-left'],
            'padding-left':style_options['padding-left'] + 'px',
            'padding-right':                        style_options['padding-right'] + 'px',
            'padding-top':                          style_options['padding-top'] + 'px',
            'padding-bottom':                       style_options['padding-bottom'] + 'px',
            'margin-left':                          style_options['margin-left'] + 'px',
            'margin-right':                         style_options['margin-right'] + 'px',
            'margin-top':                           style_options['margin-top'] + 'px',
            'margin-bottom':                        style_options['margin-bottom'] + 'px',
            'z-index':                              5000,
            'cursor':                               'pointer'
        })
        
        this.upload_file.addEvent('mouseenter',function(){ this.file_input.setStyles({'background-color':style_options['highlight-color']}); }.bind(this));
        this.upload_file.addEvent('mouseleave',function(){ this.file_input.setStyles({'background-color':style_options['background-color']}); }.bind(this));
        this.upload_file.addEvent('focus',function(){ this.file_input.setStyles({'background-color':style_options['highlight-color']}); }.bind(this));
        this.upload_file.addEvent('blur',function(){ this.file_input.setStyles({'background-color':style_options['background-color']}); }.bind(this));
        
        this.file_input.addEvent('mouseover',function(){ this.file_input.setStyles({'background-color':style_options['highlight-color']}); }.bind(this));
        this.file_input.addEvent('mouseout',function(){ this.file_input.setStyles({'background-color':style_options['background-color']}); }.bind(this));
        
        //set label styles
        this.file_label.setStyles({
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 1 + 'px',
            'padding-right':style_options['padding-right'] + 1 + 'px',
            'padding-top':style_options['padding-top'] + 1 + 'px',
            'padding-bottom':style_options['padding-bottom'] + 1 + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'color':style_options['label-color'],
            'width':style_options['label-width']
        });
    },
    
    getProperty: function(property){
        if(this.json != ''){
            return encodeURIComponent(this.json.response.server_file_name) + '&file_ext=' + encodeURIComponent(this.json.response.server_file_ext) + '&file_size=' + encodeURIComponent(this.json.response.file_size);
        } else {
            return '&file_ext=&file_size=';
            
        }
    },
    
    inject: function(el){
        this.file_container.inject(el);
    },
    
    addEvent: function(type,fn){
	    
	},
    
    setLabelDisplay: $empty
});
OFText2 = new Class({
    Implements: Options,
    
    options: {
        'label':'',
        'text-area':false,
		'type':'text',
        'blur':$empty,
        'focus':$empty,
        'name':'',
        'value':'',
		'text-area-input-height':.50,
		'content_part_id':'',
		'field_id':'',
		'can_edit':true,
		'validate':true,
		'vMsg':true,
		'show_label':true,
		'values':[],
		'optionlabels':[],
		'depends_on':'',
		'class_name':'',
		'onchange':''
    },
    
    initialize: function(options){
		this.setOptions(options);
		this.depends_on = new Array();
		this.depends_on[0] = '';
		if(this.options.depends_on != '') {
			this.depends_on = this.options.depends_on.split("<?>");
		}
        this.name = this.options.name;       
        this.text_label = new Element('label',{'class':'otext-label'});
		if(this.options.show_label == false) {
			this.text_label.addClass('Ohidden');
		}
        this.text_label.set('html',this.options.label);
		if(this.options.can_edit == true) {
	        if(this.options['text-area']){
   	        	this.text_input = new Element('textarea',{'id':'otext-textarea-'+this.options.field_id,'class':'otext-input otext-textarea','value':this.options.value});
            	this.text_input.set('html',this.options.value);
        	} else {
            	//this.text_input = new Element('input',{'class':'otext-input','value':this.options.value});
				this.text_input = new Element('input',{'type':this.options.type, 'class':'otext-input','value':this.options.value});
        	}
		}
		else {
			this.text_input = new Element('input',{'type':'hidden', 'class':'otext-input','value':this.options.value});
		}
        this.text_input.addEvent('blur',function(){
			this.value = encodeURIComponent(this.text_input.getProperty('value'));
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vMsg) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vMsg) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
        this.text_input.addEvent('focus',this.options.focus);
		this.text_input.addEvent('keypress',function(){
			
        }.bind(this).pass(this));
		// container
		// place label and input field into a div to give us control over absolute positioning for label
        this.container = new Element('div',{'class':'input-wrapper','id':'element-container-'+this.options.field_id});
        this.container.addClass(this.options.class_name)
		var vMsgId = 'input-vmsg-' + this.options.field_id;
		var vImgId = 'input-vimg-' + this.options.field_id;
		this.vMsg = new Element('div',{'id':vMsgId,'style':'','class':'input-vmsg'});
		this.vImg = new Element('div',{'id':vImgId,'style':'','class':'input-vimg'});
		// container styles
		this.container.setStyles({
			'position':'relative'
		});
		
		
    },
	
	ajaxlyOperation: function(parent_item_id, value){
		// Used for nifty country -> state -> county ajax calls.
		
		var where = 0;
		for(i = 0; i<this.options.values.length; i++) {
			if(value == this.options.values[i]) {
				where = i;
				break;
			}
		}
		
		if(this.options.can_edit == true) {
			this.value = this.options.optionlabels[where];
		} else {
			this.text_inputcont.set('html',this.options.optionlabels[where]);
		}
		
	},
    
    setStyles: function(style_options){
        
        //if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * .50).toInt() }
		if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * this.options['text-area-input-height']).toInt() }
         /*
        // set input styles
        this.text_input.setStyles({
            'float':                                'left',
			'position':								'relative',
            'border':                               style_options.border,
            '-webkit-border-bottom-left-radius':    style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':   style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':       style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':      style_options['radius'] + 'px',
            '-moz-border-radius':                   style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'border-radius':                        style_options['radius'] + 'px',
            'padding-left':                         style_options['padding-left'] + 'px',
            'padding-right':                        style_options['padding-right'] + 'px',
            'padding-top':                          style_options['padding-top'] + 'px',
            'padding-bottom':                       style_options['padding-bottom'] + 'px',
            'margin-left':                          style_options['margin-left'] + 'px',
            'margin-right':                         style_options['margin-right'] + 'px',
            'margin-top':                           style_options['margin-top'] + 'px',
            'margin-bottom':                        style_options['margin-bottom'] + 'px',
            'font-size':                            style_options['input-font-size'] + 'px',
            'font-weight':                          style_options['input-font-weight'],
            'font-style':                           style_options['input-font-style'],
            'font-family':                          style_options['input-font-family'],
            'color':                                style_options['input-color'],
            'background-color':                     style_options['background-color'],
            'width':                                style_options['input-width'],
            'height':                               style_options['input-height'],
            'background-image':                     style_options['input-background-image'],
			'background-position':					style_options['input-background-position'],
			'background-repeat':					style_options['input-background-repeat']
        });
        
		if(style_options['input-background-image-highlight'] != 'none'){
            this.text_input.addEvent('focus',function(){
                this.text_input.setStyles({'background-image':style_options['input-background-image-highlight']})
            }.bind(this))
            
            this.text_input.addEvent('blur',function(){
                this.text_input.setStyles({'background-image':style_options['input-background-image']})
            }.bind(this))
        };
        		
		//alert(style_options['label-position']);
		
		if(style_options['label-position'] == 'absolute'){
			this.text_label.setStyles({
				'position':style_options['label-position'],
				'top':style_options['padding-top'] + 'px',
				'left':style_options['padding-left'] + 1-15 + 'px',
				'z-index':style_options['label-z-index']
			})
		}
		
        // set label styles
        this.text_label.setStyles({
			'float':'left',
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 1 + 'px',
            'padding-right':style_options['padding-right'] + 1 + 'px',
            'padding-top':style_options['padding-top'] + 1 + 'px',
            'padding-bottom':style_options['padding-bottom'] + 1 + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'font-family':style_options['label-font-family'],
            'color':style_options['label-color'],
            'width':style_options['label-width']
        });
		*/
		this.text_input.setStyles({'height':style_options['input-height']})
		this.text_label.setStyles();
    },
    
	setLabelDisplay: function(label_position){
		if(label_position == 'inside'){
			this.text_input.addEvent('focus',function(){
				this.text_label.addClass('Ohidden');
			}.bind(this));
			
			this.text_input.addEvent('blur',function(){
				if(this.text_input.getProperty('value') ==''){
					this.text_label.removeClass('Ohidden');
				}
			}.bind(this));
			
			this.text_label.addEvent('click',function(){
				this.text_label.addClass('Ohidden');
				this.text_input.focus();
			}.bind(this));
		}
	},
	
	addEvent: function(type,fn){
		if(!(type == "keypress" && this.options['text-area'])){
	    	this.text_input.addEvent(type,fn);
	    }
	},
	
    // get property
    getProperty: function(){ return encodeURIComponent(this.text_input.getProperty('value')); },
    
    // set property
    setProperty: function(property,value){ this.text_input.setProperty(property,value); },
    
    inject: function(el){
        //if(this.options.label != ''){ this.text_label.inject(el); }
        //this.text_input.inject(el);
		this.container.inject(el);
		//inject element and label into container
		if(this.options.label != ''){ this.text_label.inject(this.container); }
		if(this.options.can_edit == true) {
	        this.text_input.inject(this.container);
			if(this.options.validate) {
				if(this.options.vMsg) this.vMsg.inject(this.container);
				this.vImg.inject(this.container);
			}
		} else {
			this.text_inputcont = new Element('div',{'id':'static_text_input_'+this.options.field_id,'style':'','class':'static_text_input'});
			this.text_inputcont.set('html',this.options.value);
			this.text_inputcont.inject(this.container);
		}
    }
});
OFImage2 = new Class({
    Implements: Options,
    
    options:{
        'label':'',
		'scalar':0.25,
        'image_width':500,
        'image_height':300,
        'image_name':'',
        'image_ext':'',
        'name':'default_image',
		'oform':false,
		'content_part_id':'',
		'field_id':'',
		'value':0,
		'class':'',
		'enable_thumbnail':true,
		'image_location':''
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.name = this.options.name;
        
        this.image_width = this.options.image_width;
        this.image_height = this.options.image_height;
        this.value = this.options.value;
        
        this.input_wrapper = new Element('div',{'class':'input-wrapper'});
        this.input_wrapper.setStyles({'position':'relative'});
        
        this.input_label = new Element('label',{'class':'ofimage-label'});
        this.input_label.set('html',this.options.label);
        this.input_label.inject(this.input_wrapper);
        
        this.input_btn = new Element('a',{'class':'ofimage-btn'});
        this.input_btn.setStyles({'display':'block','float':'left','cursor':'pointer','z-index':2500});
        this.input_btn.inject(this.input_wrapper);
        
        this.loader = new Element('img',{'src':'/obray/images/loaders/ajax-loader.gif'});
        this.loader.setStyles({'float':'left','opacity':0,'margin-top':15,'margin-bottom':15});
        this.loader.inject(this.input_wrapper);
        
        this.input_form = new Element('form',{'action':'index.cfm?action=images.uploadImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','encoding':'multipart/form-data','enctype':'multipart/form-data','target':'upload_target','method':'post'})
        this.input_form.inject(this.input_btn);
        
        this.input_form_image_id = new Element('input',{'type':'hidden','value':this.options.image_id,'name':'image_id'});
        this.input_form_image_id.inject(this.input_form);
        
        this.thumbnail = new Element('div',{'class':'ofimage-selct-simple-thumbnail'});
        this.thumbnail.setStyles({'background-position':'center center','z-index':4999,'position':'absolute','top':0,'left':0});
        if(this.options.image_id != 0){
        	this.updateThumbnail.delay(500,this);
        }
        if(this.options.enable_thumbnail){ this.thumbnail.inject(this.input_wrapper); }
        
        this.input_file = new Element('input',{'type':'file','name':'image_file'});
        this.input_file.inject(this.input_form);
        
        this.input_file.addEvent('change',function(){
        	this.input_form.submit();
        	this.loader.setStyles({'opacity':1});
        	this.upload_target = $('upload_target');
        	this.upload_target.addEvent('load',function(){
				//get iFrame
				var frame = window.frames['upload_target'];
				//get Response
				var response = frame.document.getElementById('response').innerHTML;
				this.imagejson = JSON.decode(response);
				this.options.image_id = this.imagejson.image.image_id;
				this.options.image_name = this.imagejson.image.image_name;
				this.options.image_ext = this.imagejson.image.image_ext;
				this.options.image_width = this.imagejson.image.image_width;
				this.options.image_height = this.imagejson.image.image_height;
				this.options.image_location = this.imagejson.image.image_location;
				// save image
				if(this.options.image_height > this.options.image_width){ var image_height = this.image_width; var image_width = this.image_height; } else { var image_height = this.image_height; var image_width = this.image_width; }
				var data = '&image_id='                 + this.options.image_id
						 + '&image_name='               + this.options.image_name
						 + '&image_ext='                + this.options.image_ext
						 + '&image_location='           + this.options.image_location
						 + '&image_width='              + image_width
						 + '&image_height='             + image_height
						 + '&image_zoom='               + image_width
						 + '&image_x='                  + 0
						 + '&image_y='                  + 0
						 + '&image_link='               + ''
						 + '&image_follow='             + ''
						 + '&image_description='        + ''
						 + '&image_description_long='   + ''
						 + '&image_corner_radius='		+ 0;
                        var requets = new Request({'url':'index.cfm?action=images.saveImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','data':data,'onComplete':function(){
                        	// validate data
							var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
							var data = 'field_data=' + this.options.image_id;
							this.request = new Request({'url':url,'method':'post'});
							this.request.removeEvents();
							this.upload_target.removeEvents();
							this.request.setOptions({'data':data,'onComplete':function(response){	
								var json = JSON.decode(response);
								if(json.response.error == 'false' || json.response.error == false){
									document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
									document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
								} else {
									document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
									document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
								}
								this.value = this.options.image_id;
								if(this.options.image_location == 'Amazon S3'){ this.image_thumb_location = window.obray.amazon_location+this.options.image_name+'_thumb.'+this.options.image_ext; } else { this.image_thumb_location = '/assets/images/'+this.options.image_name+'_thumb.'+this.options.image_ext; }
                        		this.thumbnail.setStyles({'background-image':'url('+this.image_thumb_location+')'});
								this.loader.setStyles({'opacity':0});
							}.bind(this)}).send();	
                        }.bind(this) }).send();
			}.bind(this));
        }.bind(this));
        
		this.vMsg = new Element('div',{'id':'input-vmsg-' + this.options.field_id,'style':'','class':'input-vmsg'});
		this.vImg = new Element('div',{'id':'input-vimg-' + this.options.field_id,'style':'','class':'input-vimg'});
		this.vMsg.inject(this.input_wrapper);
		this.vImg.inject(this.input_wrapper);
    },
    
    setStyles: function(style_options){
    	
    },
    
    inject: function(el){
        this.input_wrapper.inject(el);
        this.input_file.setStyles({'z-index':2500,'display':'block','height':this.input_btn.getCoordinates().height,'width':this.input_btn.getCoordinates().width,'opacity':.01,'cursor':'pointer'});
    },
    
    getProperty: function(property){ return encodeURIComponent(this.value); },
    
    addEvent: function(type,fn){
	    
	},
    
    setDimensions: function(width,height){
       
    },
    
    updateThumbnail: function(){
    	if(this.options.image_location == 'Amazon S3'){ this.image_thumb_location = window.obray.amazon_location+this.options.image_name+'_thumb.'+this.options.image_ext; } else { this.image_thumb_location = '/assets/images/'+this.options.image_name+'_thumb.'+this.options.image_ext; }
    	this.thumbnail.setStyles({'background-image':'url('+this.image_thumb_location+')'});
    },
    
    setLabelDisplay: $empty
});
OFHidden2 = new Class({
    Implements: Options,
    
    options:{
        'value':'',
        'name':'',
		'id':''
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.name = this.options.name;
        
        this.hidden = new Element('input',{'id':this.options.id,'type':'hidden','value':this.options.value});
    },
    
    getProperty: function(property){
        return encodeURIComponent(this.hidden.getProperty(property));
    },
    
    setStyles: function(){
    
    },
    
    inject: function(el){
        this.hidden.inject(el);
    },
    
    addEvent: function(type,fn){
	    this.hidden.addEvent(type,fn);
	},
    
    
    setLabelDisplay: $empty
});
OFFraction2 = new Class({
    Implements: Options,
    
    options: {
        'label':'',
		'type':'text',
        'blur':$empty,
        'focus':$empty,
        'name':'',
        'value':'',
		'content_part_id':'',
		'field_id':'',
		'validate':true,
		'vmsg':true,
		'depends_on':'',
		'class':''
    },
    
    initialize: function(options){
		this.setOptions(options);
        this.name = this.options.name;       
        this.text_label = new Element('label',{'class':'otext-label'});
        this.text_label.set('html',this.options.label);
		this.depends_on = new Array();
		this.depends_on[0] = '';
		if(this.options.depends_on != '') this.depends_on = this.options.depends_on.split("<?>");
        this.values = this.options.value.split("-");
        var vMsgId = 'input-vmsg-' + this.options.field_id;
		var vImgId = 'input-vimg-' + this.options.field_id;
		this.vMsg = new Element('div',{'id':vMsgId,'style':'','class':'input-vmsg'});
		this.vImg = new Element('div',{'id':vImgId,'style':'','class':'input-vimg'});
			
		this.text_input = new Element('input',{'type':this.options.type, 'class':'otext-input fraction-integer','value':this.values[0],'style':''});
		this.numer = new Element('input',{'class':'otext-input numerator','value':this.values[1],'style':'width:25px;'});
		this.denom = new Element('input',{'class':'otext-input denominator','value':this.values[2],'style':'width:30px;'});
		this.slash  = new Element('span',{'style':'','class':'fractionslash'});
		this.slash.set('html','/');
        
        this.text_input.addEvent('blur',function(){
			var integer = encodeURIComponent(this.text_input.getProperty('value'));
			if(integer == "") integer = ' ';
			var numerator = encodeURIComponent(this.numer.getProperty('value'));
			if(numerator == "") numerator = ' ';
			var denominator = encodeURIComponent(this.denom.getProperty('value'));
			if(denominator == "") denominator = '';
	
			this.value = integer + '-' + numerator + '-' + denominator; 
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						if(json.response.message != '') { this.vMsg.setStyles({'opacity':1}); } else { this.vMsg.setStyles({'opacity':0}); }
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						if(json.response.error_message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
		this.numer.addEvent('blur',function(){
			
	
			var integer = encodeURIComponent(this.text_input.getProperty('value'));
			if(integer == "") integer = ' ';
			var numerator = encodeURIComponent(this.numer.getProperty('value'));
			if(numerator == "") numerator = ' ';
			var denominator = encodeURIComponent(this.denom.getProperty('value'));
			if(denominator == "") denominator = '';
	
			this.value = integer + '-' + numerator + '-' + denominator; 
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						if(json.response.message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						if(json.response.error_message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
		this.denom.addEvent('blur',function(){
			
	
			var integer = encodeURIComponent(this.text_input.getProperty('value'));
			if(integer == "") integer = ' ';
			var numerator = encodeURIComponent(this.numer.getProperty('value'));
			if(numerator == "") numerator = ' ';
			var denominator = encodeURIComponent(this.denom.getProperty('value'));
			if(denominator == "") denominator = '';
	
			this.value = integer + '-' + numerator + '-' + denominator; 
			
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vmsg) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						if(json.response.message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vmsg) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						if(json.response.error_message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
        this.text_input.addEvent('focus',this.options.focus);
		
		// container
		// place label and input field into a div to give us control over absolute positioning for label
        this.container = new Element('div',{'class':'input-wrapper','id':'element-container-'+this.options.field_id});
		// container styles
		this.container.setStyles({
			'position':'relative'
		});
		
		//inject element and label into container
		if(this.options.label != ''){ this.text_label.inject(this.container); }
        this.text_input.inject(this.container);
		this.numer.inject(this.container);
		this.slash.inject(this.container);
		this.denom.inject(this.container);
		if(this.options.validate) {
			if(this.options.vmsg) {
				this.vMsg.inject(this.container);
			}
			this.vImg.inject(this.container);
		}
    },
    
    setStyles: function(style_options){
        
        //if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * .50).toInt() }
		if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * this.options['text-area-input-height']).toInt() }
        
		this.text_input.setStyles({'height':                               style_options['input-height']})
		this.text_label.setStyles();
    },
    
	setLabelDisplay: function(label_position){
		if(label_position == 'inside'){
			this.text_input.addEvent('focus',function(){
				this.text_label.addClass('Ohidden');
			}.bind(this));
			
			this.text_input.addEvent('blur',function(){
				if(this.text_input.getProperty('value') ==''){
					this.text_label.removeClass('Ohidden');
				}
			}.bind(this));
			
			this.text_label.addEvent('click',function(){
				this.text_label.addClass('Ohidden');
				this.text_input.focus();
			}.bind(this));
		}
	},
	
	addEvent: function(type,fn){
		if(!(type == "keypress" && this.options['text-area'])){
	    	this.text_input.addEvent(type,fn);
	    }
	},
	
    // get property
    getProperty: function(){ 
		var integer = encodeURIComponent(this.text_input.getProperty('value'));
		if(integer == "") integer = ' ';
		var numerator = encodeURIComponent(this.numer.getProperty('value'));
		if(numerator == "") numerator = ' ';
		var denominator = encodeURIComponent(this.denom.getProperty('value'));
		if(denominator == "") denominator = '';
	
		 return integer + '-' + numerator + '-' + denominator; 
		
	},
    
    // set property
    setProperty: function(property,value){ this.text_input.setProperty(property,value); },
    
    inject: function(el){
        //if(this.options.label != ''){ this.text_label.inject(el); }
        //this.text_input.inject(el);
		this.container.inject(el);
    }
});
OFDateSelect2 = new Class({
    Implements: Options,
    
    options: {
        'label':'',
		'type':'text',
        'blur':$empty,
        'focus':$empty,
        'name':'',
        'value':'',
		'content_part_id':'',
		'field_id':'',
		'validate':true,
		'vmsg':true,
		'valid_years':['2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014'],
		'depends_on':'',
		'select_day':'01',
		'select_month':'01',
		'select_year':'2001'
    },
    
    initialize: function(options){
		this.setOptions(options);
        this.name = this.options.name;       
        this.text_label = new Element('label',{'class':'otext-label'});
        this.text_label.set('html',this.options.label);
		this.depends_on = new Array();
		this.depends_on[0] = '';
		if(this.options.depends_on != '') this.depends_on = this.options.depends_on.split("<?>");
        this.values = this.options.value.split("-");
        var vMsgId = 'input-vmsg-' + this.options.field_id;
		var vImgId = 'input-vimg-' + this.options.field_id;
		this.vMsg = new Element('div',{'id':vMsgId,'style':'','class':'input-vmsg'});
		this.vImg = new Element('div',{'id':vImgId,'style':'','class':'input-vimg'});
		this.day = new OFSelect2({
			'labels':['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'],
			'values':['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'],
			'validate':false,
			'class_name':'ofdateselect_day',
			'default_value':this.values[2]
		});
		this.month = new OFSelect2({
			'labels':['January','February','March','April','May','June','July','August','September','October','November','December'],
			'values':['01','02','03','04','05','06','07','08','09','10','11','12'],
			'validate':false,
			'class_name':'ofdateselect_month',
			'default_value':this.values[1]
		});
		this.year = new OFSelect2({
			'labels':this.options.valid_years,
			'values':this.options.valid_years,
			'validate':false,
			'class_name':'ofdateselect_year',
			'default_value':this.values[0]
		});
		this.slash  = new Element('span',{'style':'','class':'fractionslash'});
		this.slash.set('html','/');
        
        this.day.addEvent('blur',function(){
			var day = encodeURIComponent(this.day.getProperty('value'));
			if(day == "") day = ' ';
			var month = encodeURIComponent(this.month.getProperty('value'));
			if(month == "") month = ' ';
			var year = encodeURIComponent(this.year.getProperty('value'));
			if(year == "") year = '';
	
			this.value = year + '-' + month + '-' + day; 
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						if(json.response.message != '') { this.vMsg.setStyles({'opacity':1}); } else { this.vMsg.setStyles({'opacity':0}); }
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						if(json.response.error_message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            //this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
		this.month.addEvent('blur',function(){
			var day = encodeURIComponent(this.day.getProperty('value'));
			if(day == "") day = ' ';
			var month = encodeURIComponent(this.month.getProperty('value'));
			if(month == "") month = ' ';
			var year = encodeURIComponent(this.year.getProperty('value'));
			if(year == "") year = '';
	
			this.value = year + '-' + month + '-' + day; 
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						if(json.response.message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vmsg == true) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						if(json.response.error_message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            //this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
		this.year.addEvent('blur',function(){
			
	
			var day = encodeURIComponent(this.day.getProperty('value'));
			if(day == "") day = ' ';
			var month = encodeURIComponent(this.month.getProperty('value'));
			if(month == "") month = ' ';
			var year = encodeURIComponent(this.year.getProperty('value'));
			if(year == "") year = '';
	
			this.value = year + '-' + month + '-' + day; 
			
			if(this.value != null && this.options.validate) {
				var url = 'index.cfm?action=pages.cp&component=oform&content_part_id=' + this.options.content_part_id + '&global_component=true&do=validateField&field_id=' + this.options.field_id;
				var data = 'field_data=' + this.value;
				if(this.depends_on[0] != '') {
					data = data + '&' + window['signup_first_name'+this.depends_on[0]].name + '=' + window['signup_first_name'+this.depends_on[0]].value;
				}
				this.request = new Request({'url':url,'method':'post'});
				this.request.removeEvents();
            	this.request.setOptions({'data':data,'onComplete':function(response){	
					var json = JSON.decode(response);
					
                	if(json.response.error == 'false' || json.response.error == false){
						if(this.options.vmsg) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.message;
						if(json.response.message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-green';
        	    	} else {
        	       		if(this.options.vmsg) document.getElementById('input-vmsg-' + this.options.field_id).innerHTML = json.response.error_message;
						if(json.response.error_message != '') this.vMsg.setStyles({'opacity':1});
						else this.vMsg.setStyles({'opacity':0});
						document.getElementById('input-vimg-' + this.options.field_id).className = 'input-vimg-red';
            		}
                	
            	}.bind(this)}).send();	
			}
            //this.options.blur(this.options.content_part_id, this.options.field_id, encodeURIComponent(this.text_input.getProperty('value')));
        }.bind(this).pass(this));
        
		this.day.addEvent('focus',this.options.focus);
		
		// container
		// place label and input field into a div to give us control over absolute positioning for label
        this.container = new Element('div',{'class':'input-wrapper','id':'element-container-'+this.options.field_id});
		// container styles
		this.container.setStyles({
			'position':'relative'
		});
		
		//inject element and label into container
		if(this.options.label != ''){ 
		this.text_label.inject(this.container);
		}
		this.day.inject(this.container); 
		this.month.inject(this.container);
		//this.slash.inject(this.container);
		this.year.inject(this.container);
		//this.day.inject(this.container);
		if(this.options.validate) {
			if(this.options.vmsg) {
				this.vMsg.inject(this.container);
			}
			this.vImg.inject(this.container);
		}
    },
    
    setStyles: function(style_options){
        
        //if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * .50).toInt() }
		if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * this.options['text-area-input-height']).toInt() }
        
		this.day.setStyles({'height':                               style_options['input-height']})
		this.day.setStyles();
    },
    
	setLabelDisplay: function(label_position){
		if(label_position == 'inside'){
			this.day.addEvent('focus',function(){
				this.day.addClass('Ohidden');
			}.bind(this));
			
			this.day.addEvent('blur',function(){
				if(this.day.getProperty('value') ==''){
					this.day.removeClass('Ohidden');
				}
			}.bind(this));
			
			this.day.addEvent('click',function(){
				this.day.addClass('Ohidden');
				this.day.focus();
			}.bind(this));
		}
	},
	
	addEvent: function(type,fn){
		if(!(type == "keypress" && this.options['text-area'])){
	    	this.day.addEvent(type,fn);
	    }
	},
	
    // get property
    getProperty: function(){ 
		var day = encodeURIComponent(this.day.getProperty('value'));
		if(day == "") day = ' ';
		var month = encodeURIComponent(this.month.getProperty('value'));
		if(month == "") month = ' ';
		var year = encodeURIComponent(this.year.getProperty('value'));
		if(year == "") year = '';
	
		return year + '-' + month + '-' + day; 
		
	},
    
    // set property
    setProperty: function(property,value){ this.text_input.setProperty(property,value); },
    
    inject: function(el){
		this.container.inject(el);
    }
});

selectImage = new Class({
	Implements: Options,
	
	options:{
		'label':'',
		'value':0,
		'image':''
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.image = new Element('div',{'class':'select-image'});
		this.image.setStyles({'float':'left','background-image':'url('+this.options.image+')','border':'1px solid transparent','height':118,'width':118,'margin':5,'cursor':'pointer'});
		
	},
	
	addEvent: function(type,fn){
		this.image.addEvent(type,fn);
	},
	
	inject: function(el){
		this.image.inject(el);
	},
	
	getProperty: function(property){
		if(property == 'value'){
			return this.options.value;
		} else if(property  == 'label'){
			return this.options.label;
		} else if(property == 'image'){
			return this.options.image;
		}
	}
})

OFImageSelect = new Class({
	Implements: Options,
	
	options:{
		'value':'',
		'label':'',
		'values':[],
		'labels':[],
		'images':[],
		'width':285,
		'background_color':'#ffffff',
        'background-color':'#ffffff',
        'background_highlight':'#eeeeee',
        'highlight-color':'#eeeeee',
        'change':$empty
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.select_images = [];
		
		this.image_selected = '';
		
		this.open = false;
		
		this.image_select_container = new Element('div',{'class':'ofimageselect-container'});
		this.image_select_container.setStyles({'position':'relative'});
		
		this.input = new Element('input',{'type':'text','value':this.options.value});
		this.input.setStyles({'position':'absolute','opacity':.01,'left':0,'top':0});
		this.input.inject(this.image_select_container);
		this.input.addEvent('focus',function(){
			//this.images_container_fx.pause();
			//this.images_container_fx.start({'height':300});
		}.bind(this));
		
		this.input.addEvent('blur',function(){
			//this.images_container_fx.pause();
			//this.images_container_fx.start({'height':0});
		});
		
		this.select_label = new Element('label',{'class':'ofimageselect-label'});
		this.select_label.set('html',this.options.label);
		this.select_label.inject(this.image_select_container);
		
		this.image_select = new Element('div',{'class':'select'});
		this.image_select.setStyles({
			'border-bottom-left-radius': '5px 5px',
			'border-bottom-right-radius': '5px 5px',
			'border-top-left-radius': '5px 5px',
			'border-top-right-radius': '5px 5px',
			'font-family': 'Arial, Helvetica',
			'font-size': '12px',
			'width':this.options.width,
			'cursor':'pointer'
		});
		this.image_select.addEvent('mouseenter',function(){ this.image_select.setStyles({'background-color':this.options['highlight-color']}); }.bind(this))
		this.image_select.addEvent('click',function(){
			this.toggle();
			//this.input.focus();
		}.bind(this))
		this.image_select.set('html','Select One')		
		this.image_select.inject(this.image_select_container);
		
		this.br = new Element('br',{'class':'clear'}).inject(this.image_select_container);
		
		
		
		
		this.images_container = new Element('div',{'class':'ofimageselect-images-container'});
		this.images_container.setStyles({'height':0,'overflow':'hidden'});
		this.images_container.inject(this.image_select_container);
		
		this.scroll_box = new scrollBox({'width':this.options.width,'height':260,'background_color':'#ffffff'});
		this.scroll_box.inject(this.images_container);
		/***
		this.mousedown = false;
		
		this.image_select.addEvent('mouseenter',function(){
			this.mouse_down = true;
		}.bind(this))
		
		this.image_select.addEvent('mouseleave',function(){
			this.mouse_down = false;
		}.bind(this))
		
		this.scroll_box.scrollbar_handle.addEvent('mousedown',function(){
			this.mouse_down = true;
		}.bind(this))
		
		
		this.scroll_box.scrollbar_handle.addEvent('mouseup',function(){
			this.mousedown = false;
		}.bind(this))
		****/
		this.images_container_fx = new Fx.Morph(this.images_container,{duration:500,transition:Fx.Transitions.Quint.easeOut});

		for(var i=0;i<this.options.values.length;++i){
			this.addOption(this.options.labels[i],this.options.values[i],this.options.images[i]);
		}
	},
	
	toggle: function(){
		if(this.open){
			this.images_container_fx.pause();
			this.images_container_fx.start({'height':0});
			this.open = false;
		} else {
			this.images_container_fx.pause();
			this.images_container_fx.start({'height':300});
			this.open = true;
		}
	},
	
	addOption: function(label,value,image){
		this.select_images[this.select_images.length] = new selectImage({'label':label,'value':value,'image':image});
		this.select_images[this.select_images.length-1].addEvent('mousedown',function(el){
			this.input.setProperty('value',el.getProperty('value'));
			this.image_select.set('html',el.getProperty('label'));
			this.image_selected = el.getProperty('image');
			this.options.change();
		}.bind(this,this.select_images[this.select_images.length-1]))
		this.select_images[this.select_images.length-1].inject(this.scroll_box.content);
	},
	
	inject: function(el){
		this.image_select_container.inject(el);
	},
	
	getProperty: function(property){
		return this.input.getProperty('value');
	}
}); OFMultiSelectOption = new Class({
	Implements: Options,
	
	options:{
		'padding':0,
		'highlight-color':'#ffffff',
		'background-color':'#000000',
		'selected-color':'#ffffff',
		'onChange':$empty
	},
	
	initialize: function(label,value,img_src,options){
		this.setOptions(options);
		this.br = new Element('br',{'class':'clear'});
		this.selected = false;
		this.label = label;
		this.value = value;
		this.mouse_location = 'outside';
		this.submenu_buttons = [];
		this.populated = false;
		// option container
		this.multiselect_option = new Element('div',{'class':'ofmultiselect-option'});
		this.multiselect_option.setStyles({'margin':1,'border-radius':'3px','position':'relative','padding':this.options['padding']});
		
		// option image
		if(img_src.trim() != '' && img_src.trim() != '_'){
			this.multiselect_option.image = new Element('img',{'src':img_src,'width':40,'height':40});
			this.multiselect_option.image.setStyles({'border-radius':'3px'});
			this.multiselect_option.image.setStyles({'float':'left'});
			this.multiselect_option.image.inject(this.multiselect_option);
		}
		
		// option label
		this.multiselect_option.label_container = new Element('div',{'class':'ofmultiselect-label'});
		this.multiselect_option.label_container.setStyles({'float':'left','padding':this.options['padding'],'width':100,'text-align':'left'});
		this.multiselect_option.label_container.inject(this.multiselect_option);
		this.multiselect_option.label_container.set('html',label);
		this.br.clone().inject(this.multiselect_option);
		
		this.multiselect_option.setStyles({'cursor':'pointer'});
		this.multiselect_option.inject(this.multiselect_options_box_content);
		
		// sub menu
		this.sub_menu = new Element('div',{'class':'ofmultiselect-option-submenu'});
		this.sub_menu.setStyles({'display':'none'});
		this.sub_menu.inject(document.body);
		
		this.sub_menu_content = new Element('div',{'class':'ofmultiselect-option-submenu-content'});
		this.sub_menu_content.setStyles({'position':'relative','padding':this.options['padding']-1});
		this.sub_menu_content.inject(this.sub_menu);
		
		this.sub_menu_attacher = new Element('div',{'class':'ofmultiselect-option-submenu-attacher'});
		this.sub_menu_attacher.setStyles({'position':'absolute','left':-21,'top':0,'background-color':'transparent','width':25,'height':40,'z-index':5100,'background-image':'url(/obray/widgets/oshop/images/admin/gap_connector.png)','background-position':'7px 3px','background-repeat':'no-repeat'});
		this.sub_menu_attacher.inject(this.sub_menu_content);
		
		
		this.sub_menu.addEvent('mouseenter',function(){
			this.sub_menu.setStyles({'display':'block','position':'absolute','top':this.multiselect_option.getCoordinates().top,'left':this.multiselect_option.getCoordinates().left+this.multiselect_option.getCoordinates().width+10,'background-color':this.options['selected-color'],'border-radius':'5px','width':200,'z-index':5100});
		}.bind(this));
		
		this.sub_menu.addEvent('mouseleave',function(){
			this.sub_menu.setStyles({'display':'none'});
		}.bind(this))
		
		// mouseneter
		this.multiselect_option.addEvent('mouseenter',function(el){
			if(this.selected == false){ el.setStyles({'background-color':this.options['highlight-color']}); } else {
				this.sub_menu.setStyles({'display':'block','position':'absolute','top':this.multiselect_option.getCoordinates().top,'left':this.multiselect_option.getCoordinates().left+this.multiselect_option.getCoordinates().width+10,'background-color':this.options['selected-color'],'border-radius':'5px','width':200,'z-index':5100});
			}
		}.bind(this,this.multiselect_option));
		
		// mouseleave
		this.multiselect_option.addEvent('mouseleave',function(el){
			if(this.selected){
				el.setStyles({'background-color':this.options['selected-color']});
				this.sub_menu.setStyles({'display':'none'});
			} else {
				el.setStyles({'background-color':this.options['background-color']});
			}
		}.bind(this,this.multiselect_option));
		
		// click
		this.multiselect_option.addEvent('click',function(el){
			if(this.selected){
				this.selected = false;
				el.setStyles({'background-color':this.options['highlight-color']});
			} else {
				this.selected = true;
				el.setStyles({'background-color':this.options['selected-color']});
			}
			if(this.populated){ this.options.onChange(this.value,this.selected); }
		}.bind(this,this.multiselect_option));
		
		
		
		
	},
	
	addSubmenuButton: function(label,fn){
		this.submenu_buttons[this.submenu_buttons.length] = new Element('div',{'class':'ofmultiselect-option-submenu-btn'});
		this.submenu_buttons[this.submenu_buttons.length-1].set('html',label);
		this.submenu_buttons[this.submenu_buttons.length-1].setStyles({'margin':1,'padding':this.options['padding'],'background-color':'#1a1a1a','font-size':12,'font-family':'Helvetica,Arial','color':'#ffffff','border-radius':'3px','cursor':'pointer'});
		this.submenu_buttons[this.submenu_buttons.length-1].addEvent('mouseenter',function(el){ el.setStyles({'background-color':this.options['highlight-color']})  }.bind(this,this.submenu_buttons[this.submenu_buttons.length-1]))
		this.submenu_buttons[this.submenu_buttons.length-1].addEvent('mouseleave',function(el){ el.setStyles({'background-color':'#1a1a1a'})  }.bind(this,this.submenu_buttons[this.submenu_buttons.length-1]))
		this.submenu_buttons[this.submenu_buttons.length-1].addEvent('click',fn);
		this.submenu_buttons[this.submenu_buttons.length-1].inject(this.sub_menu_content);
	},
	
	fireEvent: function(event_type){
		this.multiselect_option.fireEvent(event_type);
	},
	
	inject: function(el){
		this.multiselect_option.inject(el);
		
	}
})


OFMultiSelect = new Class({
	Implements: Options,
	
	options:{
		'label':'untitled',
		'labels':[],
		'values':[],
		'selected':[],
		'selected-color':'#419011',
		'onChange':$empty
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.multiselect_options = [];
		this.number_selected = 0;
		this.opened = false;
		
		this.br = new Element('br',{'class':'clear'});
		
		this.multiselect_container = new Element('div',{'class':'ofmuliselect-wrapper'});
		this.multiselect_container.setStyles({'overflow':'hidden','font-family':'Helvetica,Arial','font-size':12,'position':'relative'});
		
		this.multiselect_label = new Element('label',{'class':'ofmultiselect-label'});
		this.multiselect_label.set('html',this.options.label);
		this.multiselect_label.inject(this.multiselect_container);
		
		this.multiselect = new Element('div',{'class':'ofmultiselect'});
		this.multiselect.setStyles({'overflow':'hidden','height':12});
		this.multiselect.inject(this.multiselect_container);
		this.br.clone().inject(this.multiselect_container);
		this.open_fx = new Fx.Morph(this.multiselect,{'duration':800,'transition':Fx.Transitions.Quint.easeOut});
		
		this.multiselect_input = new Element('input',{'class':'ofmultiselect-input'});
		this.multiselect_input.setStyles({'height':1,'width':1,'position':'absolute','top':0,'cursor':'pointer','opacity':.01});
		this.multiselect_input.inject(this.multiselect);
		
		this.multiselect_title = new Element('div',{'class':'ofmultislect-title'});
		this.multiselect_title.setStyles({'padding':1,'padding-bottom':3});
		this.multiselect_title.set('html',this.number_selected + ' Selected');
		
		this.multiselect_title.addEvent('click',function(){
			if(this.opened){
				this.opened = false;
				this.open_fx.pause();
				this.open_fx.start({'height':12})
			} else {
				this.opened = true;
				this.open_fx.pause();
				this.open_fx.start({'height':this.multiselect.getScrollSize().y})
			}
		}.bind(this))
		
		this.multiselect_title.inject(this.multiselect);
		
		this.multiselect_options_box = new scrollBox({'width':200,'height':300});
		this.multiselect_options_box.inject(this.multiselect);
		this.multiselect_options_box_content = this.multiselect_options_box.content;
		
		this.multiselect.addEvent('click',function(){ this.multiselect_input.focus(); }.bind(this));
		
		
		this.multiselect_input.addEvent('focus',function(){
			
		}.bind(this));
		
		this.multiselect_input.addEvent('blur',function(){
			
		}.bind(this));
		
		for(var i=0;i<this.options.labels.length;++i){ this.addOption(labels[i],values[i]); }
	},
	
	addOption: function(label,value,img_src){
		
		
		
		this.multiselect_options[this.multiselect_options.length] = new OFMultiSelectOption(label,value,img_src,{'padding':this.options['padding'],'highlight-color':this.options['highlight-color'],'background-color':this.options['background-color'],'selected-color':this.options['selected-color'],'onChange':function(value,selected){ this.getSelected(); this.options.onChange(value,selected); }.bind(this)});
		this.multiselect_options[this.multiselect_options.length-1].inject(this.multiselect_options_box_content);
		
		this.getSelected();
		return this.multiselect_options[this.multiselect_options.length-1];
	},
	
	 setStyles: function(style_options){
    
        this.multiselect.setStyles({
            'float':'left',
            'border':style_options.border,
            '-webkit-border-bottom-left-radius':	style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':	style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':		style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':		style_options['radius'] + 'px',
            '-moz-border-radius':       			style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'border-radius':						style_options['radius'] + 'px',
            'padding-left':             			style_options['padding-left']+1 + 'px',
            'padding-right':            			style_options['padding-right']+1 + 'px',
            'padding-top':              			style_options['padding-top']+1 + 'px',
            'padding-bottom':           			style_options['padding-bottom']+1 + 'px',
            'margin-left':              			style_options['margin-left'] + 'px',
            'margin-right':             			style_options['margin-right'] + 'px',
            'margin-top':               			style_options['margin-top'] + 'px',
            'margin-bottom':            			style_options['margin-bottom'] + 'px',
            'font-size':                			style_options['input-font-size'] + 'px',
            'font-weight':              			style_options['input-font-weight'],
            'font-style':               			style_options['input-font-style'],
            'background-color':         			style_options['background-color'],
            'color':                    			style_options['input-color'],
            'width':								style_options['input-width']
        })
       
        this.multiselect_label.setStyles({
            'float':'left',
            'border':style_options['border'],
            'border-color':'transparent',
            'padding-left':style_options['padding-left'] + 'px',
            'padding-right':style_options['padding-right'] + 'px',
            'padding-top':style_options['padding-top'] + 'px',
            'padding-bottom':style_options['padding-bottom'] + 'px',
            'margin-left':style_options['margin-left'] + 'px',
            'margin-right':style_options['margin-right'] + 'px',
            'margin-top':style_options['margin-top'] + 'px',
            'margin-bottom':style_options['margin-bottom'] + 'px',
            'font-size':style_options['label-font-size'] + 'px',
            'font-weight':style_options['label-font-weight'],
            'font-style':style_options['label-font-style'],
            'background-color':style_options['background-color'],
            'color':style_options['label-color'],
            'width':style_options['label-width']
        });
        /****
        this.items_container.setStyles({
            'background-color':style_options['background-color'],
            'border':style_options.border,
            '-webkit-border-bottom-left-radius':style_options['radius'] + 'px',
            '-webkit-border-bottom-right-radius':style_options['radius'] + 'px',
            '-webkit-border-top-left-radius':style_options['radius'] + 'px',
            '-webkit-border-top-right-radius':style_options['radius'] + 'px',
            '-moz-border-radius': style_options['radius'] + 'px ' + style_options['radius'] + 'px '+ style_options['radius'] + 'px '+ style_options['radius'] + 'px',
            'border-radius':style_options['radius'] + 'px',
            'padding-left':style_options['margin-left'],
            'padding-right':style_options['margin-right'],
            'padding-top':style_options['margin-top'],
            'padding-bottom':style_options['margin-bottom'],
            'background-color':style_options['background-color']
        })
        ***********/
        this.options['background-color'] = style_options['background-color'];
        this.options['highlight-color'] = style_options['highlight-color'];
        this.options['color'] = style_options['input-color'];
        this.options['padding'] = style_options['padding-left'];
        this.options['width'] = style_options['input-width'];
        for(var i=0;i<this.multiselect_options.length;++i){
            this.multiselect_options[i].setStyles({
                'padding-left':style_options['padding-left'],
                'padding-right':style_options['padding-right'],
                'padding-top':style_options['padding-top'],
                'padding-bottom':style_options['padding-bottom'],
                'text-align':'left',
                'color':style_options['input-color']
            });
            this.multiselect_options[i].label_container.setStyles({'padding':this.options['padding']});
            
        }
       
    },
    
    setPopulated: function(){
    	for(var i=0;i< this.multiselect_options.length;++i){
    		this.multiselect_options[i].populated = true;
    	}
    	this.getSelected();
    },
    
    getSelected: function(){
    	this.number_selected = 0;
    	this.value = "";
    	for(var i=0;i<this.multiselect_options.length;++i){
    		if(this.multiselect_options[i].selected){
    			++this.number_selected;
    			if(this.number_selected > 1){ this.value = this.value + "," + this.multiselect_options[i].value; } else { this.value = this.multiselect_options[i].value; }
    		}
    	}
    	this.multiselect_title.set('html',this.number_selected + ' Selected');  
    	return this.value;
    },
	
	inject: function(el){
		this.multiselect_container.inject(el);
	},
	
	setLabelDisplay: $empty
}) // JavaScript Document

Style = new Class({
	Implements: Options,
	
	options: {
	    'style_id':0,
	    'editable':false,
	    'style': {
	    /****
        'position':'relative',
		// font properties
		'font-family':'Arial,Helvetica',
		'font-style':'normal',                  // normal | italic | oblique
		'font-variant':'normal',                // normal | small-caps
		'font-weight':'normal',                 // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900  
		'font-size':12,                         // xx-small | x-small | small | medium | large | x-large | xx-large
		// color and background properties
		'color':'#000000',
		'background-color':'transparent',
		'background-image':'none',
		'background-repeat':'repeat',           // repeat | repeat-x | repeat-y | no-repeat
		'background-attachment':'scroll',       // scroll | fixed
		'background-position':'0% 0%',          // [<percentage> | <length>]{1,2} | [top | center | bottom] || [left | center | right]
		// text properties
		'word-spacing':'normal',                // normal | <length>
		'letter-spacing':'normal',              // normal | <length>
		'text-decoration':'none',               // none | [ underline || overline || line-through || blink ]
		'verticle-align':'baseline',            // baseline | sub | super | top | text-top | middle | bottom | text-bottom | <percentage> Description: alter the vertical positioning of an inline element, relative to its parent element or to the element's line
		'text-transform':'none',                // none | Capitalize | UPPERCASE | lowercase
		'text-alignment':'left',                // left | right | center | justify
		'text-indent':0,                        // <length> | <percentage>
		'line-height':'normal',                 // normal | <number> | <length> | <percentage>
		// box properties
		'margin-top':0,
		'margin-right':0,
		'margin-bottom':0,
		'margin-left':0,
		'padding-top':0,
		'padding-right':0,
		'padding-bottom':0,
		'padding-left':0,
		'border-top':0,
		'border-right':0,
		'border-bottom':0,
		'border-left':0,
		'width':'auto',
		'height':'auto',
		'float':'none',
		'clear':'none',
		// classification properites
		'display':'block',
		'whitespace':'normal',                 // normal | pre | nowrap
		'list-style-type':'disc',              // disc | circle | square | decimal | lower-roman | upper-roman | lower-alpha | upper-alpha | none
		'list-style-image':'none',             // <url> | none
		'list-style-position':'outside',
		'cursor':'normal',
		// extras (NOTE: these must be implemented by the object they are applied to)
		'rollover-background-color':'none',
		'rollover-background-image':'none',
		'border-radius-top-right':0,
		'border-radius-bottom-right':0,
		'border-radius-top-left':0,
		'border-radius-bottom-left':0
		****/
		}
	},
	
	initialize: function(options){
		//data members
		this.setOptions(options);
		
		this.options.style['-webkit-border-bottom-left-radius'] = this.options.style['border-radius-bottom-left'] + 'px';
		this.options.style['-webkit-border-bottom-right-radius'] = this.options.style['border-radius-bottom-right'] + 'px';
		this.options.style['-webkit-border-top-left-radius'] = this.options.style['border-radius-top-left'] + 'px';
		this.options.style['-webkit-border-top-right-radius'] = this.options.style['border-radius-top-right'] + 'px';
		this.options.style['-moz-border-radius'] = this.options.style['border-radius-top-left'] + 'px ' + this.options.style['border-radius-top-right'] + 'px '+ this.options.style['border-radius-bottom-right'] + 'px '+ this.options.style['border-radius-bottom-left'] + 'px',
		
		this.loaded = false;
	},
	
	load: function(x,y){
	    
	    this.style_box = new sbox({'startx':x,'starty':y,'width':400,'height':500});
	    this.style_form = new OForm({'url':'/index.cfm?action=obray.updateStyles'});
	    
	},
	
	getStyles: function(){
	    return this.options.style;
	}
});


OTabs = new Class({
    Implements: Options,
    
    options: {
        'open':0,
        'tabs':[],
        'tab-style':{},
        'active-tab-style':{},
        'container-style':'',
        'content-style':'',
        'rollover-tab-style':'',
        'onActive':$empty
    },
	
	initialize: function(tabs,content,options){
		this.setOptions(options);
		
		//check to see if tabs and content have the same number of elements
		if(tabs.length != content.length){alert('You don\'t have the same content elements as tab elements.');return;}
		
		//create array from html elements and turn into JSON 
		this.tabs = [];
		for(var i=0;i<tabs.length;++i){
			this.tabs[this.tabs.length] = {'tab':tabs[i],'content':content[i]};
		}
		
		//opens the tab, set in options, on initial page load
		this.tabs[this.options.open].content.removeClass('Ohidden');
		this.tabs[this.options.open].tab.setStyles(this.options['active-tab-style']);
		
		//for each tab, assign event ('click')
		//make all content hidden and tab image behind background box
		//show content for tab that was chosen
		this.tabs.each(function(obj,i){
		
			
			obj.tab.addEvent('click',function(i){
				
				location.hash = i;
					
				for(var i=0;i<this.tabs.length;++i){
					this.tabs[i].content.addClass('Ohidden');
					this.tabs[i].tab.set({style:'z-index:99;'});
					this.tabs[i].tab.setStyles(this.options['tab-style']);
				}
				
				
				obj.tab.setStyles(this.options['active-tab-style']);
				obj.content.removeClass('Ohidden');
				
			}.bind(this,i));
		}.bind(this));
	},
	
	setActiveTab: function(i){
		try{
		this.tabs[i].tab.fireEvent('click');
		} catch (err){
		
		}
	},
	
	setActiveTabSoft: function(tab_number){
		for(var i=0;i<this.tabs.length;++i){
			this.tabs[i].content.addClass('Ohidden');
			this.tabs[i].tab.set({style:'z-index:99;'});
			this.tabs[i].tab.setStyles(this.options['tab-style']);
		}
				
		this.tabs[tab_number].content.removeClass('Ohidden');
		this.tabs[tab_number].tab.setStyles(this.options['active-tab-style']);
	}
});



OTabsAnimate = new Class({
	Implements: Options,
	
	options:{
		'otabs_animate_start_index':0,
		'otabs_animate_duration':600,
		'otabs_animate_auto_rotate':true,
		'otabs_animate_rotation_timing':2000,
		'otabs_animate_transition_type':Fx.Transitions.Quint.easeOut,
		'pause_rotation':0,
		'tabs_content_part_id':0
	},

	initialize: function(tabs,content,options){
		this.setOptions(options);

		this.tabs = tabs;
		this.content = content;
		this.auto_rotate_index = this.options.otabs_animate_start_index;
		this.periodical = 0;
		this.fx_array = [];
		this.is_open = [];
		
		this.tab_length = tabs.length;
		
		this.tabs.each(function(el,index){
			this.fx_array[index] = new Fx.Morph(this.content[index],{'duration':this.options.otabs_animate_duration,'transition':this.options.otabs_animate_transition_type});
			el.setStyles({'cursor':'pointer'});
			if(this.options.otabs_animate_start_index == index){ 
				this.is_open[index] = true;
				this.content[index].setStyles({'opacity':1,'display':'block','left':0});
			} else {
				this.is_open[index] = false;
				this.content[index].setStyles({'opacity':0,'left':-5000});
			}
			el.addEvent('click',function(){
				this.setActive(index);
				this.clearPeriodical();
			}.bind(this));
			this.content[index].addEvent('click',function(){
				this.clearPeriodical();
			}.bind(this));
			
		}.bind(this));
		
		this.setActive.delay(1000,this,this.options.otabs_animate_start_index);
			
		// auto rotate
		
		if(this.tabs[0].periodical === undefined){ 
			this.tabs[0].periodical = [];
		}
		if(this.options.otabs_animate_auto_rotate){ this.tabs[0].periodical[this.tabs[0].periodical.length] = this.rotateBanner.periodical(this.options.otabs_animate_rotation_timing,this); }
		
	},
	
	clearPeriodical: function(){
		for(var i=0;i<this.tabs[0].periodical.length;++i){
			$clear(this.tabs[0].periodical[i]);
		}
	},
	
	setActive: function(index){
		for(var i=0;i<this.tabs.length;++i){
			if(this.is_open[i] && i != index){ 
				this.fx_array[i].pause(); this.fx_array[i].start({'opacity':0});
				this.content[i].setStyles({'left':-5000});
			}
			//this.content[i].setStyles({'z-index':3000,'display':'none'});
			this.tabs[i].removeClass('otabs-tab-active');
			//if(player != undefined) player.controls.pause();
			try{ eval('tab_cleanup_js'+this.options.tabs_content_part_id+'()');	} catch(err) { }
			//alert(this.options.tabs_content_part_id);
			this.is_open[i] = false;
			this.content[i].removeClass('otabs-content-active');
		}
		this.tabs[index].addClass('otabs-tab-active');
		this.is_open[index] = true;
		this.fx_array[index].pause();
		this.fx_array[index].start({'opacity':1,'display':'block'});
		this.content[index].setStyles({'z-index':4000,'display':'block','left':0});
		this.content[index].addClass('otabs-content-active');
		this.content[index].getParent().setStyles({'height':$(this.content[index]).getCoordinates().height});
	},
	
	pauseRotation: function() {
		this.options.pause_rotation = 1;
	},
	
	resumeRotation: function () {
		this.options.pause_rotation = 0;
	},
	
	rotateBanner: function(){
		if(this.options.pause_rotation != 1) {
			this.auto_rotate_index += 1;
			if(this.auto_rotate_index >= this.tab_length){ this.auto_rotate_index = 0; }
			this.setActive(this.auto_rotate_index);
		}
	}
	
});




OTabsDynamic = new Class({
    Implements: Options,
    
    options: {
        'default':0,
        'tabs':[],
        'tab-style':{},
        'active-tab-style':{},
        'container-style':'',
        'content-style':'',
        'rollover-tab-style':''
    },
    
	initialize: function(options){
		this.setOptions(options);
        this.tabs_array = [];
        this.content_array = [];
        
        this.request = new Request.HTML({'link':'cancel'});
        
        // create tabs
        this.tabs = new Element('ul',{'class':'OTabs'});
        this.tabs.setStyles(this.options['container-style']);
        
        // create content
        this.content = new Element('div',{'class':'OTabs-content'});
        this.content.setStyles({'position':'relative','z-index':500,'background-color':'#ffffff'});
        //this.content.setStyles(this.options['content-style']);
        
        this.br = new Element('br',{'class':'clear'});
        
        // create tabs and retrieve content
        for(var i=0;i<this.options.tabs.length;++i){
            this.tabs_array[this.tabs_array.length] = new Element('li',{'class':'OTab'});
            this.tabs_array[this.tabs_array.length-1].set('html',this.options.tabs[i].tab_label);
            this.tabs_array[this.tabs_array.length-1].setStyles(this.options['tab-style']);
            this.tabs_array[this.tabs_array.length-1].inject(this.tabs);
            this.content_array[this.content_array.length] = new Element('div',{'class':'OTab-content'});
            this.content_array[this.tabs_array.length-1].setStyles(this.options['content-style']);
            this.content_array[this.content_array.length-1].loaded = false;
            this.content_array[this.content_array.length-1].inject(this.content);
        }
        this.adjustEndStyles();
        
        this.br.clone().inject(this.tabs);
        
        this.tabs_array.each(function(el,i){
            el.addEvent('click',function(){
                if(this.content_array[i].loaded == false){
                    this.request.setOptions({'url':this.options.tabs[i].tab_url+'&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','update':this.content_array[i],'onComplete':function(){
                        this.content_array[i].loaded = true;
                    }.bind(this)}).send();
                }
                for(var j=0;j<this.content_array.length;++j){ this.content_array[j].setStyles({'display':'none'}); }
                this.content_array[i].setStyles({'display':'block'});
                for(var j=0;j<this.tabs_array.length;++j){
                    this.tabs_array[j].setStyles({'z-index':499}); 
                    this.tabs_array[j].setStyles(this.options['tab-style']);
                }
                
                this.tabs_array[i].setStyles({'z-index':501});
                this.tabs_array[i].setStyles(this.options['active-tab-style']);
                
                this.adjustEndStyles();
            }.bind(this))
        }.bind(this));
        
        // implement rollover
        if(this.options['tab-style']['rollover-background-color'] != 'none'){
            this.tabs_array.each(function(el){
                el.addEvent('mouseenter',function(){
                    el.setStyles(this.options['rollover-tab-style']);
                    this.adjustEndStyles();
                }.bind(this));
                el.addEvent('mouseleave',function(){
                    el.setStyles(this.options['tab-style']);
                    this.adjustEndStyles();
                }.bind(this));
            }.bind(this))
        }
        
        this.tabs_array[this.options['default']].fireEvent('click'); 
    },
    
    adjustEndStyles: function(){
        this.tabs_array[0].setStyles({'padding-left':this.options['tab-style']['padding-far-left'],'border-left':this.options['tab-style']['border-far-left']});
        this.tabs_array[this.tabs_array.length-1].setStyles({'padding-right':this.options['tab-style']['padding-far-right'],'border-right':this.options['tab-style']['border-far-right']});
    },
    
    inject: function(el,position){
        this.tabs.inject(el,position);
        this.content.inject(el,position);
    },
    
    setActiveTab: function(i){
		this.tabs[i].tab.fireEvent('click');
	}     
});



/**************************************************
	Ocategory
**************************************************/
OCategory = new Class({
	Implements: Options,
	
	options:{
		'ocategory_id':0,
		'ocategory_parent_id':0,
		'ocategory_name':'default',
		'ocategory_type':'oblog',
		'parent_list': new OFSelect(),
		'onAddCategory':$empty
	},
	
	initialize: function(ocategories,options){
		this.setOptions(options);
		
		this.is_open = false;
		
		this.category = new Element('li',{'class':'ocategory'});
		this.category.set('html','<span>'+this.options.ocategory_name+'</span>');
		this.category.setStyles({'position':'relative','line-height':13,'background-image':'none','display':'block','list-style':'none','padding':5,'padding-right':0,'padding-bottom':0,'margin':0,'margin-left':15,'font-family':'Arial,Helvetica','color':'#a5a5a5','text-align':'left'});
		
		this.category_toggler = this.category.getFirst();
		this.category_toggler.setStyles({'cursor':'pointer'})
		this.category_toggler.addEvent('click',function(){
			if(this.is_open){
				this.category_list.category_list.setStyles({'height':this.category_list.category_list.getCoordinates().height});
				this.category_fx.pause();
				this.category_fx.start({'height':0});
				this.is_open = false;
			} else {
				this.category_fx.pause();
				this.category_fx.start({'height':this.category_list.category_list.getScrollSize().y});
				this.is_open = true;
			}
		}.bind(this))
		
		this.category_check = new OFCheck({'name':this.options.ocategory_id,'value':this.options.ocategory_id});
		this.options.onAddCategory(this.category_check);
		this.category_check.checkbox.setStyles({'margin':0,'margin-right':4});
		this.category_check.inject(this.category,'top');
		
		this.category_delete_btn = new Element('img',{'src':'/obray/images/btn-small-delete.png','class':'ocategory-delete-btn'});
		this.category_delete_btn.setStyles({'position':'absolute','right':5,'top':2,'cursor':'pointer'});
		this.category_delete_btn.inject(this.category);
		this.category_delete_btn.addEvent('click',function(){
			var confirm_bx = new sboxConfirm({'confirm-message':'Are you sure you want to delete the category "'+this.options.ocategory_name+'"?','onConfirm':function(){
				var data = '&ocategory_id='+this.options.ocategory_id;
				this.delete_request = new Request({'url':'?action=ocategories.deleteCategory','data':data,'link':'cancel','method':'post','onComplete':function(){
					this.category.destroy();	
				}.bind(this)}).send();	
			}.bind(this)});
			confirm_bx.open();
		}.bind(this));
		
		this.category_list = new OCategoryList(ocategories,{'assign_form':this.options.assign_form,'ocategory_id':this.options.ocategory_id,'parent_list':this.options.parent_list,'onAddCategory':this.options.onAddCategory});
		this.category_list.inject(this.category);
		this.category_list.category_list.setStyles({'height':0,'overflow':'hidden'});
		this.category_fx = new Fx.Morph(this.category_list.category_list,{'duration':1000,'transition':Fx.Transitions.Quint.easeOut,'onComplete':function(){
            if(this.is_open){this.category_list.category_list.setStyles({'height':'auto'});}
        }.bind(this)});
	},
	
	inject: function(el){
		this.category.inject(el);
	}
});
/**************************************************
	Ocategory List
**************************************************/
OCategoryList = new Class({
	Implements: Options,
	
	options:{
		'ocategory_id':0,
		'parent_list': new OFSelect(),
		'onAddCategory':$empty
	},
	
	initialize: function(ocategories,options){
		this.setOptions(options);
		this.categories = [];
		// ocategory list
		this.category_list = new Element('ul',{'class':'ocategory-list'});
		this.category_list.setStyles({'margin':'0','padding':0,'padding-top':5,'display':'block'});
				
		for(var i=0;i<ocategories.length;++i){
			this.categories[this.categories.length] = new OCategory(ocategories[i].ocategories,{'ocategory_id':ocategories[i].ocategory_id,'ocategory_parent_id':ocategories[i].ocategory_parent_id,'ocategory_name':ocategories[i].ocategory_name,'ocategory_type':ocategories[i].ocategory_type,'parent_list':this.options.parent_list,'onAddCategory':this.options.onAddCategory});
			this.categories[this.categories.length-1].inject(this.category_list);
			this.options.parent_list.addOption(ocategories[i].ocategory_name,ocategories[i].ocategory_id);
		}
	},
	
	inject: function(el){
		this.category_list.inject(el);
	},
	
	addCategory: function(ocategory_id,ocategory_parent_id,ocategory_name,ocategory_type){
		if(this.options.ocategory_id == ocategory_parent_id){
			this.categories[this.categories.length] = new OCategory([],{'ocategory_id':ocategory_id,'ocategory_parent_id':ocategory_parent_id,'ocategory_name':ocategory_name,'ocategory_type':ocategory_type,'onAddCategory':this.options.onAddCategory});
			this.categories[this.categories.length-1].inject(this.category_list);
			this.options.parent_list.addOption(ocategory_name,ocategory_id);
		} else {
			for(var i=0;i<this.categories.length;++i){
				this.categories[i].category_list.addCategory(ocategory_id,ocategory_parent_id,ocategory_name,ocategory_type);
			}
		}
	}
});
/**************************************************
	Ocategories
**************************************************/
OCategories = new Class({
	Implements: Options,
	
	options:{
		'ocategory_type':'oblog',
		'assign_url':'/index.cfm?action=ocategories.linkCategories&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true',
		'startx':0,
		'starty':0,
		'ocategory_object_id':0,
		'linked_ids':[],
		'page_id':0
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.box = new sbox();
		this.category_form_container = new Element('div',{'class':'ocategories-form-container'});
		this.category_form_container.setStyles({'padding':10,'padding-left':5,'padding-right':5,'margin-left':0,'width':490});
		this.category_form_container.inject(this.box.content);
		
		// add category form
		this.category_form = new OForm({'url':'/index.cfm?action=ocategories.addCategory&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true&page_id='+this.options.page_id,'input-width':125,'button':new Element('input',{'type':'button'}),'onComplete':function(response){
			this.addCategory(response.response.ocategory_id,response.response.ocategory_parent_id,response.response.ocategory_name,response.response.ocategory_type);
			alert('category added');
		}.bind(this)});
		this.category_type = new OFHidden({'name':'ocategory_type','value':this.options.ocategory_type});
		this.category_name = new OFText({'label':'Category Name','name':'ocategory_name'});
		this.category_parent = new OFSelect({'label':'Category Parent','name':'ocategory_parent_id'});
		this.category_parent.addOption('No Parent',0);
		this.category_form.addElement(this.category_name);
		this.category_form.addElement(this.category_parent);
		this.category_form.addElement(this.category_type);
		this.category_form.inject(this.category_form_container);
		this.category_parent.select_label.destroy();
		
		this.category_list_container = new Element('div',{'class':'ocategory-list-container'});
		this.category_list_container.setStyles({'background-image':'url(/obray/images/bg-stripped.png)','background-position':'11px 5px'});
		this.category_list_container.inject(this.box.content);
		
		this.assign_form = new Element('div',{'class':'ocategory-assign-container'});
		this.assign_form.inject(this.box.content);
		
		// assign categories form
		this.assign_category_form = new OForm({'btn-position':'right','url':this.options.assign_url,'button':new Element('input',{'type':'button','value':'Assign Categories',
			'onComplete':function(){window.location.reload(true);
		}})});
		
		this.assign_category_form.addElement(new OFHidden({'name':'ocategory_object_id','value':this.options.ocategory_object_id}));
		this.assign_category_form.addElement(new OFHidden({'name':'ocategory_object_type','value':this.options.ocategory_type}));
		this.assign_category_form.addElement(new OFHidden({'name':'page_id','value':this.options.page_id}));
		if(this.options.ocategory_object_id != 0){
			this.assign_category_form.inject(this.assign_form); 
			this.assign_category_form.form.setStyles({'padding':10});
		}
		
	},
	
	open: function(){
		this.category_list_container.set('html','')
		var data = '&ocategory_type='+this.options.ocategory_type
			     + '&ocategory_parent_id=0';
		this.request = new Request({'url':'/index.cfm?action=ocategories.getCategoryJSON&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','link':'cancel','data':data,'method':'post','onComplete':function(response){
			this.json = JSON.decode(response);
			this.category_list = new OCategoryList(this.json.ocategories,{'ocategory_id':0,'parent_list':this.category_parent,'onAddCategory':function(el){
				if(this.options.ocategory_object_id != 0){
				for(var i=0;i<this.options.linked_ids.length;++i){
					if(el.options.name == this.options.linked_ids[i]){
						el.checkbox.fireEvent('click');
					}
				}
				this.assign_category_form.addElement(el);
				} else {
					el.checkbox.setStyles({'display':'none'});
				}
			}.bind(this)});
			this.category_list.inject(this.category_list_container);
		}.bind(this)}).send();
		this.box.open();
	},
	
	addCategory: function(ocategory_id,ocategory_parent_id,ocategory_name,ocategory_type){
		this.category_list.addCategory(ocategory_id,ocategory_parent_id,ocategory_name,ocategory_type);
	}
});
/*******************************************************
	Content Area v2
*******************************************************/
ContentAreaV2 = new Class({
	Implements: Options,
	
	options:{
		'content_area_id':0,
		'content_area_name':'',
		'content_area_level':'multipart',
		'content_parts':[]
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.content_parts = [];
		this.content_area = $(this.options.content_area_name);
		if(this.options.content_area_level == 'multipart' && this.options.content_part_types != "li"){
			this.droppable = new Droppable(this.content_area,false,{'content_area_id':this.options.content_area_id,'content_parent_id':0,'content_order':0,'siblings':this.getSiblings.bind(this)});
			this.droppable.inject('bottom');
			window.obray.addDroppable(this.droppable.get());
		}
		/********************************************************************
			Recursively get content parts and construct them into the page
		********************************************************************/
		for(var i=0;i<this.options.content_parts.length;++i){
			var additional_options = new Hash({'siblings':this.getSiblings});
			this.options.content_parts[i].siblings = this.getSiblings.bind(this);
			this.content_parts[this.content_parts.length] = new ContentPartV2(this.content_area,this.options.content_parts[i]);
			this.expandContent(this.content_parts[this.content_parts.length-1].el,this.options.content_parts[i].content_parts);
			if(this.options.content_area_level == 'multipart' && this.options.content_parts[i].content_part_type != "li"){
				var droppable = new Droppable(this.content_area,this.content_parts[this.content_parts.length-1],{'content_area_id':this.options.content_area_id,'content_parent_id':this.options.content_parts[i].content_part_parent_id,'content_order':this.options.content_parts[i].content_order,'siblings':this.getSiblings.bind(this),'content_part':this.content_parts[this.content_parts.length-1]});
				droppable.inject('bottom');
				window.obray.addDroppable(droppable.get());
			}
		}
		
		if(this.options.content_area_level == 'singlepart' && this.options.content_parts.length == 0){
			if(this.options.content_part_types == 'image'){
				image = new OImage({
					'max_width':this.options.content_area_width,
					'max_height':this.options.content_area_height,
					'resizable':false,
					'content_area_id':this.options.content_area_id,
					'content_order':0,
					'blog':false
				});
				image.inject(this.content_area,'bottom');
			} else {
				this.content_parts[this.content_parts.length] = new ContentPartV2(this.content_area,{
					'content_part_id':0,
					'content_area_id':this.options.content_area_id,
					'content_part_type':this.options.content_part_types,
					'content_language':window.obray.options.content_language,
					'content_part_parent_id':0,
					'content_order':0,
					'content_text':'Lorem ipsum dolor sit amet',
					'image':{'image_id':0},
					'video':{'video_id':0},
					'siblings':this.getSiblings.bind(this)
				});
			}
		}
	},
	
	getSiblings: function(){
		return this.content_parts;
	},
	
	expandContent: function(parent,content_parts){
		for(var i=0;i<content_parts.length;++i){
			this.content_parts[this.content_parts.length] = new ContentPartV2(parent,content_parts[i]);
			this.expandContent(this.content_parts[this.content_parts.length-1].el,content_parts[i].content_parts);	
			/***
			if(this.options.content_area_level == 'multipart' && content_parts[i].content_part_type != "li"){
				var droppable = new Droppable(this.content_area,this.content_parts[this.content_parts.length-1],{'content_area_id':this.options.content_area_id,'content_parent_id':content_parts[i].content_part_parent_id,'content_order':content_parts[i].content_order});
				droppable.inject('bottom');
				window.obray.addDroppable(droppable.get());
			}
			****/
		}
	}
}); /*******************************************************
	Content Part v2
*******************************************************/
ContentPartV2 = new Class({
	Implements: Options,
	
	options:{
		'siblings':$empty,
		'component_type':'application',
		'content_language':'en',
		'ext_parameter':''
	},
	
	initialize: function(parent,options){
		this.setOptions(options);
		this.parent = parent;
		if(this.options.content_part_id == 0){this.added = false;}else{this.added = true;}
		if(this.options.content_part_type == 'h1' || this.options.content_part_type == 'h2' || this.options.content_part_type == 'h3' || this.options.content_part_type == 'h4' || this.options.content_part_type == 'h5'){
			this.obj = new Header(this.options.content_part_type,this.options.content_part_id,this.options.content_area_id,this.options.content_part_parent_id,this.options.content_order,this.options.content_text,{'hasChildren':this.options.hasChildren,'blog':false,'onDelete':this.del.bind(this),'siblings':this.options.siblings,'content_language':this.options.content_language});
			this.el = this.obj.get();
			this.inject('bottom');
			if(this.options.content_part_id == 0){
				var header = this.el;
				//(function(){header.fireEvent('click');}).delay(200);
			}
		} else if(this.options.content_part_type == 'p'){
			this.obj = new Paragraph(this.options.content_part_id,this.options.content_area_id,this.options.content_part_parent_id,this.options.content_order,this.options.content_text,{'blog':false,'hasChildren':this.options.hasChildren,'onDelete':this.del.bind(this),'siblings':this.options.siblings,'content_language':this.options.content_language});
			this.el = this.obj.get();
			this.inject('bottom');
			if(this.options.content_part_id == 0){
				var paragraph = this.el;
				//(function(){paragraph.fireEvent('click');}).delay(200);
			}
		} else if(this.options.content_part_type == 'ul'){
			this.obj = new List(this.options.content_part_id,this.options.content_area_id,this.options.content_part_parent_id,this.options.content_order,{'hasChildren':this.options.hasChildren,'blog':false,'onDelete':this.del.bind(this),'siblings':this.options.siblings,'content_language':this.options.content_language});
			this.el = this.obj.get();
			this.inject('bottom');
			if(this.options.content_part_id == 0){
				var list = this.el;
				//(function(){list.getFirst().getNext().fireEvent('click');}).delay(200);
			}
		} else if(this.options.content_part_type == 'li'){
			this.obj = new ListItem(this.options.content_part_id,this.options.content_area_id,this.options.content_part_parent_id,this.options.content_order,this.options.content_text,{'blog':false,'onDelete':this.del.bind(this),'siblings':this.options.siblings,'content_language':this.options.content_language});
			this.el = this.obj.get();
			this.inject('bottom');
		} else if(this.options.content_part_type == 'image'){
			var max_width = this.options.image.image_width;
			var max_height = this.options.image.image_height;
			if($defined(this.parent)){if(this.options.image.image_width > this.parent.getCoordinates().width){max_width = this.parent.getCoordinates().width;}}
			var image_src = ""
			if(this.options.image.image_name != 'Untitled'){ image_src = 'assets/images/'+this.options.image.image_name+'.'+this.options.image.image_ext; } 
			if (this.options.image.image_location == "Amazon S3"){ image_src = window.obray.amazon_location+this.options.image.image_name+'.'+this.options.image.image_ext; }
			this.image = new OImage({
				'image_id':this.options.image.image_id,
				'content_area_id':this.options.content_area_id,
				'content_part_id':this.options.content_part_id,
				'content_language':this.options.content_language,
				'content_order':this.options.content_order,
				'resizable':true,
				'max_width':max_width,
				'max_height':max_height,
				'image_width': this.options.image.image_width,
				'image_height': this.options.image.image_height,
				'image_src':image_src,
				'image_name':this.options.image.image_name,
				'image_description':this.options.image.image_description,
				'image_description_long':this.options.image.image_description_long,
				'image_ext':this.options.image.image_ext,
				'image_x':this.options.image.image_x,
				'image_y':this.options.image.image_y,
				'image_zoom':this.options.image.image_zoom,
				'image_link':this.options.image.image_link,
				'image_follow':this.options.image.image_follow,
				'image_thumb_x':0,
				'image_thumb_y':0,
				'image_location':this.options.image.image_location,
				'blog':false});
			if($defined(this.parent)){
			    this.el = this.image;
			    this.inject('bottom');
			    //image.inject(this.parent);
			}
		} else if(this.options.content_part_type == 'video'){
			var video = new OVideo({
				'video_id':this.options.video.video_id,
				'content_area_id':this.options.content_area_id,
				'content_part_id':this.options.content_part_id,
				'content_language':this.options.content_language,
				'content_order':this.options.content_order,
				'video_title':this.options.video.video_title,
				'video_description':this.options.video.video_description,
				'video_name':this.options.video.video_name,
				'video_ext':this.options.video.video_ext,
				'video_image_id':this.options.video.video_image_id,
				'video_image_name':this.options.video.video_image_name,
				'video_image_ext':this.options.video.video_image_ext,
				'video_image_location':this.options.video.video_image_location,
				'video_width':this.options.video.video_width,
				'video_height':this.options.video.video_height,
				'video_size':this.options.video.video_size,
				'video_length':this.options.video.video_length,
				'video_autoplay':this.options.video.video_autoplay,
				'video_embed':this.options.video.video_embed,
				'video_share':this.options.video.video_share,
				'share_url':this.options.video.share_url
			});
			if($defined(this.parent)){
			    this.el = video;
			    this.inject('bottom');
			    video.injectInside(this.parent);
			}
		} else {
			var data = 'content_text=none';
			if(this.options.content_part_id == 0){
					var updateContent = new Request({
					'url':'index.cfm?action=pages.updateObrayContent&image_id=0&content_part_id=' + this.options.content_part_id + '&content_parent_id=' + this.options.content_part_parent_id + '&content_part_type='+this.options.content_part_type + '&content_area_id=' + this.options.content_area_id + '&content_order=' + this.options.content_order + '&blog=false&content_language='+this.options.content_language+'&ext_parameter='+this.options.ext_parameter,
					data: data,
					method:'get',
					onComplete: function(){
							var location = window.location.href.replace(window.location.hash,'');
							var location = location.replace('#','');
							window.location = location;
						}
					}).send();
			} else {
				this.el = new Element('div',{'class':'component'});
				if($chk(this.parent)){
					this.el.inject(this.parent);
				}
				window.obray.chain.chain(this.request.bind(this));
				//alert(window.obray.executing_request);
				if(window.obray.executing_request == false){
					window.obray.chain.callChain();
				}
			}
		}
	},
	
	request: function(){
		window.obray.executing_request = true;
		var str = window.location + ' ';
		var queryString = document.location.search.substring(1,str.length);
		queryString = queryString.replace("action=pages.account","");
		queryString = queryString.replace("action=pages.show","");
		queryString = queryString.replace("action=cart.thank-you","");
		queryString = queryString.replace("content_part_id=","");
		var HTMLRequest = new Request.HTML({'update':this.el,'evalScripts':true,'onComplete':function(){
				if($defined(this.el.getFirst()) && $defined(this.el.getNext())){
					this.el_float = this.el.getFirst().getStyle('float');
					this.el_width = this.el.getFirst().getCoordinates().width;
					var droppable = this.el.getNext();
					droppable.setStyles({'width':this.el_width,'float':this.el_float,'margin':this.el_margin});
				}
				window.obray.executing_request = false;
				//alert('executing request');
				window.obray.chain.callChain();
		}.bind(this)}).post('index.cfm?action=pages.getComponentHTML&component_name='+this.options.content_part_type+'&component_type='+this.options.component_type+'&content_part_id='+this.options.content_part_id+'&'+queryString.replace("action=pages.cp_dsp&",""));
		},
	
	inject: function(position){
		if(this.options.content_part_id == 0 && this.added == false){
			this.add();this.added=true;
		}
		this.el.inject(this.parent,position);
	},
	
	add: function(){
		var content = this.options.siblings();
		if(!(this.options.content_part_type == 'image' && this.options.content_part_id ==0)){
            for(var i=0;i<content.length;++i){
                if(content[i].options.content_order >= this.options.content_order){
                    content[i].options.content_order += 1;
                }
            }
		}
		content[content.length] = this;
	},
	
	del: function(){
		var content = this.options.siblings();
		for(var i=0;i<content.length;++i){
			if(content[i].options.content_order > this.options.content_order){
				content[i].options.content_order -= 1;
			}
		}
		content.erase(this);
		
		window.obray.toolbar.getDroppables().each(function(el){
			if(el.content_area_id == this.options.content_area_id && el.content_order > this.options.content_order){
				--el.content_order;
			}
		}.bind(this))
	},
	
	isFloated: function(){
		
	}
});

// JavaScript Document
Block = new Class({
	Implements: Options,
	
	options:{
		'margin_top':0,
		'margin_right':0,
		'margin_bottom':0,
		'margin_left':0,
		'height':50,
		'width':50
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.margin_top = this.options.margin_top;
		this.margin_right = this.options.margin_right;
		this.margin_bottom = this.options.margin_bottom;
		this.margin_left = this.options.margin_left;
		this.width = this.options.width;
		this.height = this.options.height;
		
		//Block
		this.block = new Element('div',{'class':'OBlock'});
		this.block_inner = new Element('div',{'class':'OBlock-inner'});
		this.block_inner.setStyles({'position':'relative'});
		this.block_inner.inject(this.block);
		
		/*** block margins ***/
		//top Margin
		this.top_margin = new Element('div',{'class':'OBlock-top-margin'});
		this.top_margin.setStyles({'border-top':'1px solid #000000','height':this.margin_top,'width':(this.width+this.margin_right+this.margin_left)});
		this.top_margin.inject(this.block_inner);
		//right margin
		this.right_margin = new Element('div',{'class':'OBlock-right-margin'});
		this.right_margin.setStyles({'border-right':'1px solid #000000','width':this.margin_right,'height':this.height});
		this.right_margin.inject(this.block_inner);
		//bottom margin
		this.bottom_margin = new Element('div',{'class':'OBlock-bottom-margin'});
		this.bottom_margin.setStyles({'border-bottom':'1px solid #000000','height':this.margin_bottom,'width':(this.width+this.margin_right+this.margin_left)});
		this.bottom_margin.inject(this.block_inner);
		//left margin
		this.left_margin = new Element('div',{'class':'OBlock-left-margin'});
		this.left_margin.setStyles({'border-left':'1px solid #000000','width':this.margin_left,'height':this.height});
		this.left_margin.inject(this.block_inner);
		
		
	}
}); // JavaScript Document

Header = new Class({
	Implements: Options,
	
	options: {
		'hasChildren': false,
		'blog':false,
		'content_part':false,
		'onDelete':$empty,
		'onCreate':$empty
	},
	
	initialize: function(header_type,content_part_id,content_area_id,content_parent_id,content_order,text,options){
		//data members
		
		this.setOptions(options);
		this.text = text;
		this.content_part_id = content_part_id;
		this.content_area_id = content_area_id;
		this.content_parent_id = content_parent_id;
		this.content_order = content_order;
		this.content_text = text;
		this.header_type = header_type;
		if(this.text == ''){this.text = 'replace this text';}
		//generate HTML
		this.header = new Element(this.header_type,{'class':'oparagraph'});
		this.textarea = new Element('textarea',{'class':'otextarea'});
		this.header.set('html',this.text);
		//assign events
		this.assignEvents();
		if(Browser.Engine.webkit){ this.edit_offset = 4; } else { this.edit_offset = 0; }
	},
	
	resetStyles: function(){
		this.width = this.header.getSize().x;
		this.height = this.header.getCoordinates().height;
		this.border_left = this.header.getStyle('border-left');
		this.border_right = this.header.getStyle('border-right');
		this.border_top = this.header.getStyle('border-top');
		this.border_bottom = this.header.getStyle('border-bottom');
		this.margin = this.header.getStyle('margin');
		this.padding = this.header.getStyle('padding');
		this.background = this.header.getStyle('background');
		if(this.background == ''){this.background = 'transparent';}
		this.font_family = this.header.getStyle('font-family');
		this.font_size = this.header.getStyle('font-size');
		this.font_weight = this.header.getStyle('font-weight');
		this.color = this.header.getStyle('color');
		this.text_align = this.header.getStyle('text-align');
		this.line_height = this.header.getStyle('line-height');
		//create element
		this.textarea = new Element('textarea');
		//set Styles
		this.textarea.setStyle('width',this.width+5);
		this.textarea.setStyle('height',this.height - this.header.getStyle('padding-top').toInt() - this.header.getStyle('padding-bottom').toInt());
		this.textarea.setStyle('border-left',this.border_left);
		this.textarea.setStyle('border-right',this.border_right);
		this.textarea.setStyle('border-top',this.border_top);
		this.textarea.setStyle('border-bottom',this.border_bottom);
		this.textarea.setStyle('margin',this.margin);
		this.textarea.setStyle('padding',this.padding);
		this.textarea.setStyle('background',this.background);
		this.textarea.setStyle('font-family',this.font_family);
		this.textarea.setStyle('font-weight',this.font_weight);
		this.textarea.setStyle('font-size',this.font_size);
		this.textarea.setStyle('color',this.color);
		this.textarea.setStyle('text-align',this.text_align);
		this.textarea.setStyle('overflow','hidden');
		this.textarea.setStyle('line-height',this.line_height);
		
	},
	
	get: function(){
		return this.header;
	},
	
	assignEvents: function(){
		this.header.addEvent('click',function(){
			this.header.removeEvents();
			this.resetStyles();
			var text = this.header.get('html');
			this.textarea.setProperty('value',text);
			this.header.set('html','')
			this.textarea.inject(this.header);
			this.textarea.focus();
			if(this.content_part_id == 0){
				this.textarea.select();
			}
			this.assignBlur();
		}.bind(this));
	},
	
	assignBlur: function(){
		this.textarea.addEvent('blur',function(){
			this.saving = new MessageBox({'message':'Saving, please wait...'});
			this.saving.open('elastic');
			var data = '&content_part_id=' + this.content_part_id
					  +'&content_parent_id=' + this.content_parent_id
					  +'&content_part_type=' + this.header_type
					  +'&content_language=' + this.options.content_language
					  +'&content_area_id=' + this.content_area_id
					  +'&content_order=' + this.content_order
					  +'&content_text='+encodeURIComponent(this.textarea.get('value'))
					  +'&blog=' + this.options.blog;
			var updateContent = new Request({'url':'index.cfm?action=pages.updateObrayContent','data':data,'method':'post','onComplete': function(response){
				this.response = [];
				this.contentParts = [];
				eval(response);
				for(var i=0;i<this.response.length;++i){
					var response_decoded = JSON.decode(this.response[i]);
					this.content_part_id = response_decoded.content_part_id;	
				}
				this.saving.close();
			}.bind(this)}).send();
		}.bind(this));
		
		this.textarea.addEvent('keydown',function(e){
			this.textarea.setStyle('height',this.textarea.getScrollSize().y - this.edit_offset);
			var newChar = e.key;
			if(newChar == 'backspace' && this.textarea.get('value') == ''){
				e.preventDefault();
				this.deleting = new MessageBox({'message':'Deleting, please wait...'});
				this.deleting.open('elastic');
				var updateContent = new Request({url:'index.cfm?action=pages.deleteContentPart&content_part_id='+this.content_part_id,method:'get',onComplete: function(){
						this.options.onDelete();
						this.textarea.removeEvents();
						this.header.getNext().destroy(); //removes droppable
						this.header.destroy();
						this.deleting.close();
				}.bind(this)}).send();
			}
		}.bind(this))
		
		this.textarea.addEvent('keyup',function(e){
			this.textarea.setStyle('height',this.textarea.getScrollSize().y - this.edit_offset);
			
		}.bind(this));
	}
	
	
}); // JavaScript Document

Paragraph = new Class({
	Implements: Options,
	
	options: {
		'hasChildren': false,
		'blog': false,
		'onDelete':$empty
	},
	
	initialize: function(content_part_id,content_area_id,content_parent_id,content_order,text,options){
		//data members
		this.setOptions(options);
		this.text = text;
		this.content_part_id = content_part_id;
		this.content_area_id = content_area_id;
		this.content_parent_id = content_parent_id;
		this.content_order = content_order;
		this.content_text = text;
		if(this.text == ''){this.text = 'replace this text';}
		//generate HTML
		this.paragraph = new Element('p',{'class':'oparagraph'});
		this.textarea = new Element('textarea',{'class':'otextarea'});
		this.paragraph.set('html',this.text);
		//set styles
		//assign events
		this.assignEvents();
		if(Browser.Engine.webkit){ this.edit_offset = 4; } else { this.edit_offset = 0; }
	},
	
	resetStyles: function(){
		this.width = this.paragraph.getSize().x;
		this.height = this.paragraph.getCoordinates().height;
		this.border_left = this.paragraph.getStyle('border-left');
		this.border_right = this.paragraph.getStyle('border-right');
		this.border_top = this.paragraph.getStyle('border-top');
		this.border_bottom = this.paragraph.getStyle('border-bottom');
		this.margin = this.paragraph.getStyle('margin');
		this.padding = this.paragraph.getStyle('padding');
		this.background = this.paragraph.getStyle('background');
		if(this.background == ''){this.background = 'transparent';}
		this.font_family = this.paragraph.getStyle('font-family');
		this.font_size = this.paragraph.getStyle('font-size');
		this.font_weight = this.paragraph.getStyle('font-weight');
		this.color = this.paragraph.getStyle('color');
		this.text_align = this.paragraph.getStyle('text-align');
		this.line_height = this.paragraph.getStyle('line-height');
		//create element
		this.textarea = new Element('textarea');
		//set Styles
		this.textarea.setStyle('width',this.width+5);
		this.textarea.setStyle('height',this.height - this.paragraph.getStyle('padding-top').toInt() - this.paragraph.getStyle('padding-bottom').toInt());
		this.textarea.setStyle('border-left','0px solid transparent');
		this.textarea.setStyle('border-right','0px solid transparent');
		this.textarea.setStyle('border-top','0px solid transparent');
		this.textarea.setStyle('border-bottom','0px solid transparent');
		this.textarea.setStyle('background',this.background);
		this.textarea.setStyle('font-family',this.font_family);
		this.textarea.setStyle('font-weight',this.font_weight);
		this.textarea.setStyle('font-size',this.font_size);
		this.textarea.setStyle('color',this.color);
		this.textarea.setStyle('text-align',this.text_align);
		this.textarea.setStyle('overflow','hidden');
		this.textarea.setStyle('line-height',this.line_height);
		this.textarea.setStyles({'display':'inline'});
		
	},
	
	get: function(){
		return this.paragraph;
	},
	
	assignEvents: function(){
		this.paragraph.addEvent('click',function(){
			this.paragraph.removeEvents();
			this.resetStyles();
			var text = this.paragraph.get('html');
			var regex = new RegExp("[<][bB][rR][/]*[>]");
			text_pr = '';
			while(text_pr != text){
				text_pr = text;
				text = text.replace(regex,'\n','gm');
			}
			this.textarea.setProperty('value',text);
			this.paragraph.set('html','')
			this.textarea.inject(this.paragraph);
			this.textarea.focus();
			if(this.content_part_id == 0){
				this.textarea.select();
			}
			this.assignBlur();
		}.bind(this));
	},
	
	assignBlur: function(){
		this.textarea.addEvent('blur',function(){
			this.saving = new MessageBox({'message':'Saving, please wait...'});
			this.saving.open('elastic');
			var regex = new RegExp("[\n]");
			var content_text = this.textarea.get('value');
			var content_text_pr = '';
			var data = '&content_part_id=' + this.content_part_id
					  +'&content_parent_id=' + this.content_parent_id
					  +'&content_part_type=p'
					  +'&content_language='+this.options.content_language
					  +'&content_area_id=' + this.content_area_id
					  +'&content_order=' + this.content_order
					  +'&content_text='+encodeURIComponent(content_text)
					  +'&blog=' + this.options.blog;
			var updateContent = new Request({'url':'index.cfm?action=pages.updateObrayContent','data':data,'method':'post','onComplete': function(response){
				this.response = [];
				this.contentParts = [];
				eval(response);
				for(var i=0;i<this.response.length;++i){
					var response_decoded = JSON.decode(this.response[i]);
					this.content_part_id = response_decoded.content_part_id;
					
				}
				this.textarea.dispose()
				this.paragraph.set('html',this.textarea.get('value'));
				this.assignEvents();
				this.saving.close();
			}.bind(this)}).send();
		}.bind(this));
		
		this.textarea.addEvent('keydown',function(e){
			this.textarea.setStyle('height',this.textarea.getScrollSize().y - this.edit_offset);
			var newChar = e.key;
			if(newChar == 'backspace' && this.textarea.get('value') == ''){
				e.preventDefault();
				this.deleting = new MessageBox({'message':'Deleting, please wait...'});
				this.deleting.open('elastic');
				var updateContent = new Request({'url':'index.cfm?action=pages.deleteContentPart&content_part_id='+this.content_part_id,'method':'get','onComplete': function(){
						this.options.onDelete();
						this.textarea.removeEvents();
						this.paragraph.getNext().destroy(); //removes droppable
						this.paragraph.destroy();
						this.deleting.close();
				}.bind(this)}).send();
			}
		}.bind(this))
		
		this.textarea.addEvent('keyup',function(e){
			this.textarea.setStyle('height',this.textarea.getScrollSize().y - this.edit_offset);
			
		}.bind(this));
	}
	
	
}); 

List = new Class({
	Implements: Options,
	
	options:{
		'hasChildren':false,
		'blog':false,
		'onDelete':$empty,
		'content_language':'en'
	},
	
	initialize: function(content_part_id,content_area_id,content_parent_id,content_order,options){
		//data memebers
		this.setOptions(options);
		this.content_part_id = content_part_id;
		this.content_area_id = content_area_id;
		this.content_parent_id = content_parent_id;
		this.content_order = content_order;
		
		//generate HTML
		this.list = new Element('ul',{'class':'olist'});
		this.delete_btn = new Element('div',{'class':'delete_btn'});
		this.delete_btn.set('html','X');

		if(this.content_part_id == 0){
			var data = '&content_part_id=' + this.content_part_id
					  +'&content_parent_id=' + this.content_parent_id
					  +'&content_part_type=ul'
					  +'&content_language='+this.options.content_language
					  +'&content_area_id=' + this.content_area_id
					  +'&content_order=' + this.content_order
					  +'&content_text='
					  +'&blog=' + this.options.blog;
			var updateContent = new Request({'url':'index.cfm?action=pages.updateObrayContent','data':data,'method':'post','onComplete': function(response){
				this.response = [];
				eval(response);
				this.content_part_id = JSON.decode(this.response[0]).content_part_id;
				this.startList();
			}.bind(this)}).send();
		} else {
			//THIS IS NOT WORKING!!!
			if(this.options.hasChildren == false || this.options.hasChildren == 'false'){
				this.startList();
			}
		}
		
		this.list.setStyles({'position':'relative'});
		this.delete_btn.setStyles({'position':'absolute','cursor':'pointer','right':'0px','top':'0px','width':'10px','height':'10px','border':'1px solid #c1c1c1','padding':'3px','text-align':'center','font-family':'arial','background-color':'#444444','color':'#c1c1c1'})
		this.delete_btn.inject(this.list);
		
		this.delete_btn.addEvent('click',function(){
			var delete_request = new Request({'url':'index.cfm?action=pages.deleteContentPart&content_part_id='+this.content_part_id,'onComplete':function(){
				var location = window.location.href.replace(window.location.hash,'');
				var location = location.replace('#','');
				window.location = location;
			}.bind(this)}).send();
		}.bind(this))
		
		
	},
	
	get: function(){
		return this.list;
	},
	
	startList: function(){
		this.startListItem = new ListItem(0,this.content_area_id,this.content_part_id,1,'',{'content_language':this.options.content_language});
		this.startListItem.get().inject(this.list);
	}
}); // JavaScript Document

ListItem = new Class({
	Implements: Options,
	
	options:{
		'blog': false,
		'onDelete':$empty,
		'content_language':'en'
	},
	
	initialize: function(content_part_id,content_area_id,content_parent_id,content_order,text,options){
		//data members
		this.setOptions(options)
		this.content_part_id = content_part_id;
		this.content_area_id = content_area_id;
		this.content_parent_id = content_parent_id;
		this.content_order = content_order;
		
		//genereate HTML
		this.li = new Element('li',{'class':'olistItem'});
		this.li.set('html',text);
		this.createEvents();
	},
	
	get: function(){
		return this.li;
	},
	
	startInput: function(){
		
		var width = this.li.getCoordinates().width;
		var innerText = this.li.innerHTML;
		var new_input = new Element('input',{'type':'text','value':innerText})
		this.li.set('html','');
		new_input.inject(this.li);
		new_input.setStyles({
			'width':width,
			'border':'0px',
			'font-family':this.li.getStyle('font-family'),
			'font-size':this.li.getStyle('font-size'),
			'color':this.li.getStyle('color'),
			'margin':'0px',
			'padding':'0px',
			'background-color':'transparent'
		});
		new_input.focus();
	},
	
	stopInput: function(){
		var temp = this.li.getFirst().getProperty('value');
		this.li.set('html',temp);
	},
	
	createEvents: function(){
		this.li.addEvent('click',function(){
			this.li.removeEvents();
			this.startInput();
			this.li.getFirst().addEvent('keydown',function(e){
				if(e.key == 'enter'){
					var newLi = new ListItem(0,this.content_area_id,this.content_parent_id,parseInt(this.content_order)+1,'',{'content_language':this.options.content_language});
					newLi.get().inject(this.li,'after');
					newLi.li.fireEvent('click');
				} else if(e.key == 'backspace'){
					if(this.li.getFirst().getProperty('value') == ''){
						this.deleting = new MessageBox({'message':'Deleting, please wait...'});
						this.deleting.open('elastic');
						var updateContent = new Request({url:'index.cfm?action=pages.deleteContentPart&content_part_id='+this.content_part_id,method:'get',onComplete: function(){
								this.options.onDelete();
								this.li.destroy();
								this.deleting.close();
							}.bind(this)
						}).send();
					}
				}
			}.bind(this))
			this.li.getFirst().addEvent('blur',function(){
				this.saveContent();
				this.stopInput();
				this.createEvents();
			}.bind(this));
		}.bind(this));
	},
	
	saveContent: function(){
		if(this.li.getFirst().getProperty('value') != ''){
			var data = '&content_part_id=' + this.content_part_id
					  +'&content_parent_id=' + this.content_parent_id
					  +'&content_part_type=li'
					  +'&content_language='+this.options.content_language
					  +'&content_area_id=' + this.content_area_id
					  +'&content_order=' + this.content_order
					  +'&content_text='+ encodeURIComponent(this.li.getFirst().getProperty('value'))
					  +'&blog=' + this.options.blog;
			var updateContent = new Request({'url':'index.cfm?action=pages.updateObrayContent','data':data,'method':'post','onComplete': function(response){
				this.response = [];
				eval(response);
				this.content_part_id = JSON.decode(this.response[0]).content_part_id;
				this.createEvents();
			}.bind(this)}).send();
		}
	}
	
	
}); /***********************************************
	Dbug Console: for when you get sick of alert()
************************************************/
var Debug = new Class({
	Implements: Options,
	
	options: {},
	
	initialize: function(options){
		
		this.setOptions(options);
		this.line = 1;
		
		this.debug = new Element('div',{'class':'debug-console'});
		this.debug.setStyles({'position':'absolute','top':0,'left':0,'width':996,'height':200,'overflow':'scroll','background-color':'#000000','color':'#888888','font-family':'Courier','font-size':10,'padding':15,'z-index':10000});
		this.debug.inject(document.body);
		
	},
	
	set: function(html){
		this.debug.set('html',this.line++ +': ' + html + '<br/>' + this.debug.innerHTML);
	},
	
	hide: function(){
		this.debug.setStyles({'display':'none'});
	}
})


Window = new Class({
	Implements: Options,
	
	options: {
		'window_width':100,
		'window_height':100,
		'window_canvas_width':500,
		'window_canvas_height':500,
		'window_canvas_x':0,
		'window_canvas_y':0,
		'window_canvas_zoom':100,
		'window_resizable':true,
		'enable_pan':true,
		'enable_zoom':true,
		'enable_delete':true,
		'enable_options':true,
		'resizeStep':function(){}
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.zoomDelay = 0;
		this.aspect_ratio = this.options.window_canvas_height/this.options.window_canvas_width;
		this.original_width = this.options.window_canvas_width; 			//this is our base width from which we derive the zoomed width
		this.original_height = this.options.window_canvas_height;			//this is our base height from which we derive the zoomed width
		//window-container
		this.window_container = new Element('div',{'class':'window_container'});
		this.window_container.setStyles({'position':'relative','overflow':'visible','width':this.options.window_width,'z-index':4999});
		//window
		this.window = new Element('div',{'class':'window'});
		this.window.setStyles({'background-image':'url(obray/images/place-holder-image.jpg)','margin':0,'background-position':'center','position':'relative','border':'1px solid black','width':this.options.window_width.toInt(),'height':this.options.window_height.toInt(),'overflow':'hidden','z-index':6000});
		this.window.inject(this.window_container);
		//canvas
		this.window_canvas = new Element('div',{'class':'window-canvas'});
		this.window_canvas.setStyles({'background-color':'transparent','position':'absolute','margin':0,'margin-left':0,'left':this.options.window_canvas_x,'top':this.options.window_canvas_y,'width':this.options.window_canvas_width,'height':this.options.window_canvas_height});
		this.window_canvas.inject(this.window);
		//handle
		this.window_handle = new Element('div',{'class':'window-handle'});
		this.window_handle.setStyles({'position':'absolute','bottom':-5,'right':-5,'background-color':'#ffffff','height':8,'width':8,'z-index':5000,'border':'1px solid #000000','cursor':'se-resize','opacity':1});
		if(this.options.window_resizable){this.window_handle.inject(this.window_container);}
		//zoom
		this.zoom_container = new Element('div',{'class':'zoom-container'});
		this.zoom_inner_container = new Element('div',{'class':'zoom-inner-container'});
		this.zoom_text = new Element('div',{'class':'zoom-text'});
		this.zoom_handle = new Element('div',{'class':'zoom-handle'});
		this.zoom_track = new Element('div',{'class':'zoom-track'});
		var margin_left = -147;
		
		if(Browser.Engine.trident && Browser.Engine.version == 5){margin_left = -12;}
		this.zoom_container.setStyles({'opacity':0,'position':'absolute','left':'50%','bottom':15,'margin-left':margin_left,'background-image':'url(obray/images/image/bg-zoom-container.png)','width':295,'height':31,'z-index':6001});
		this.zoom_container_handle = new Element('div',{'class':'zoom-container-handle'});
		this.zoom_inner_container.setStyles({'position':'relative','width':'100%','height':'100%','margin':'0px'});
		this.zoom_track.setStyles({'position':'absolute','top':'19px','left':'67px','width':160,'height':5,'background-image':'url(obray/images/image/bg-zoom-track.png)','background-repeat':'no-repeat','background-position':'center'});
		this.zoom_handle.setStyles({'position':'absolute','left':0,'top':-8,'width':20,'height':20,'background-image':'url(obray/images/image/bg-zoom-handle.png)','cursor':'pointer'});
		this.zoom_text.setStyles({'position':'absolute','left':'50%','top':4,'width':'150px','text-align':'center','margin-left':'-75px','font-family':'arial','font-size':'10px','color':'#ffffff'});
		this.zoom_inner_container.inject(this.zoom_container);
		this.zoom_container_handle.inject(this.zoom_inner_container);
		this.zoom_container_handle.setStyles({'background-color':'#ffffff','border':'1px solid black','position':'absolute','left':-2,'top':-2,'height':5,'width':5,'cursor':'pointer'});
		this.zoom_text.inject(this.zoom_inner_container);
		this.zoom_container.inject(this.window_container);
		this.zoom_track.inject(this.zoom_inner_container);
		this.zoom_handle.inject(this.zoom_track);
		
		this.zoom_container.makeDraggable({'handle':this.zoom_container_handle});
		
		//effect: canvas
		this.canvasFx_x = new Fx.Morph(this.window_canvas,{duration:700,transition: Fx.Transitions.Elastic.easeOut});
		this.canvasFx_y = new Fx.Morph(this.window_canvas,{duration:700,transition: Fx.Transitions.Elastic.easeOut});
		//effect: zoom
		this.zoomFx = new Fx.Morph(this.zoom_container,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
		//event: zoom
		this.window_container.addEvent('mouseenter',function(){
			$clear(this.zoomDelay);
			this.zoomDelay = this.showZoom.delay(1000,this);	
		}.bind(this))
		this.window_container.addEvent('mouseleave',function(){
			$clear(this.zoomDelay);
			this.zoomDelay = this.hideZoom.delay(1000,this);												 
		}.bind(this))
		//event: zoom
		
		//event: resizable
		if(this.options.window_resizable){
			this.window.makeResizable({
				'handle':this.window_handle,
				'onDrag': function(){
					// make sure they can't resize width larger than the canvas
					if(this.window.getCoordinates().width < this.window_canvas.getCoordinates().width+this.options.window_canvas_x){
						this.window_container.setStyles({'width':this.window.getCoordinates().width});
					} else {
						this.window.setStyles({'width':this.window_canvas.getCoordinates().width+this.options.window_canvas_x});
						this.window_container.setStyles({'width':this.window_canvas.getCoordinates().width+this.options.window_canvas_x});
					}
					// make sure they can't resize height larger than the canvas
					if(this.window.getCoordinates().height < (this.window_canvas.getCoordinates().height+this.options.window_canvas_y).toInt()){
						this.window_container.setStyles({'height':this.window.getCoordinates().height});
					} else {
						this.window.setStyles({'height':this.window_canvas.getCoordinates().height+this.options.window_canvas_y});
						this.window_container.setStyles({'height':(this.window_canvas.getCoordinates().height+this.options.window_canvas_y).toInt()});
					}
					//set the window height and width variables (very important since calculations are derived from these)
					this.options.window_width = this.window.getCoordinates().width;
					this.options.window_height = this.window.getCoordinates().height;
					this.options.resizeStep();
				}.bind(this),
				'onComplete':function(){
					
				}.bind(this)
			});
		}
		//event: pan
		if(this.options.enable_pan){
			this.window_canvas.makeDraggable({
				'handle':this.window_canvas,
				'onDrag':function(){
					this.options.window_canvas_x = this.window_canvas.getStyle('left').toInt();
					this.options.window_canvas_y = this.window_canvas.getStyle('top').toInt();
				}.bind(this),
				'onComplete':function(){
					//don't let them drag it to far to the right
					if(this.options.window_canvas_x > 0){
						this.canvasFx_x.pause();
						this.canvasFx_x.start({'left':0})
						this.options.window_canvas_x = 0;
					}
					//don't let them drag it to far to the left
					if(this.window.getCoordinates().width > this.window_canvas.getCoordinates().width+this.options.window_canvas_x){
						//this.window_canvas.setStyles({'left':this.options.window_width-this.options.window_canvas_width});
						this.canvasFx_x.pause();
						this.canvasFx_x.start({'left':this.options.window_width-this.options.window_canvas_width})
						this.options.window_canvas_x = this.options.window_width-this.options.window_canvas_width;
					}
					// if the height is "in-bounds" then set the window cavas x position
					if(this.window.getCoordinates().width < this.window_canvas.getCoordinates().width+this.options.window_canvas_x && this.options.window_canvas_x < 0){
						this.options.window_canvas_x = this.window_canvas.getStyle('left').toInt();
					}
					//don't let them drag it to far down
					if(this.options.window_canvas_y > 0){
						this.canvasFx_y.pause();
						this.canvasFx_y.start({'top':0})
						this.options.window_canvas_y = 0;
					}
					//don't let them drag it to far up
					if(this.window.getCoordinates().height > this.window_canvas.getCoordinates().height+this.options.window_canvas_y){
						//this.window_canvas.setStyles({'top':this.options.window_canvas_y});
						this.canvasFx_y.pause();
						this.canvasFx_y.start({'top':this.options.window_height-this.options.window_canvas_height})
						this.options.window_canvas_y = this.options.window_height-this.options.window_canvas_height;
					}
					// if the height is "in-bounds" then set the window cavas y position
					if(this.window.getCoordinates().height < this.window_canvas.getCoordinates().height+this.options.window_canvas_x && this.options.window_canvas_y < 0){
						this.options.window_canvas_y = this.window_canvas.getStyle('top').toInt();
					}
				}.bind(this)
			});
		}
		
			
		
	},
	
	resizeCanvas: function(width,height){
		
	},
	
	showZoom: function(){
		this.zoomFx.start({'opacity':1});
	},
	
	hideZoom: function(){
		this.zoomFx.start({'opacity':0});
	},
	
	inject: function(el,position){
		this.window_container.inject(el,position);
		this.initZoom();
	},
	
	replaces: function(el){
		this.window_container.replaces(el);
		this.initZoom();
	},
	
	initZoom: function(){
		//slider must be created after the it's elements are injected into the page.
		this.slider = new Slider(this.zoom_track,this.zoom_handle,{
			'range':[0,100],
			'steps':100,
			'onChange':function(step){
				var zoom = ((step/100)*100);
				this.zoom_text.set('html','Zoom: ' + zoom.toInt() + '%');
				var new_width = (this.original_width*(zoom/100)).toInt();
				var new_height = new_width*this.original_height/this.original_width;
				if(new_width+this.options.window_canvas_x>this.options.window_width && new_height+this.options.window_canvas_y>this.options.window_height){
					this.window_canvas.setStyles({'width':new_width,'height':new_height});
					this.options.window_canvas_width = new_width;
					this.options.window_canvas_height = new_height;
				}
			}.bind(this),
			'onComplete':function(step){
				var zoom = ((step/100)*100);
				var new_width = (this.original_width*(zoom/100)).toInt();
				var new_height = new_width*this.original_height/this.original_width;
				
				if(new_width+this.options.window_canvas_x<this.options.window_width || new_height+this.options.window_canvas_y<this.options.window_height){
					
					var current_zoom = 0;
					if(new_width-this.options.window_canvas_x-this.options.window_width<new_height-this.options.window_canvas_y-this.options.window_height){
						current_zoom = ((this.options.window_width/this.original_width) * 100).toInt();
						var new_width = this.options.window_width-this.options.window_canvas_x;
						var new_height = (new_width*this.original_height/this.original_width)
					} else {
						current_zoom = ((this.options.window_height/this.original_height) * 100).toInt();
						var new_height = this.options.window_height-this.options.window_canvas_y;
						var new_width = (new_height*this.original_width/this.original_height)
					}
					
					this.window_canvas.setStyles({'width':new_width,'height':new_height});
					this.options.window_canvas_width = new_width;
					this.options.window_canvas_height = new_height;
					this.slider.set(current_zoom)
					
				}
				
			}.bind(this)
		});
		this.slider.set(this.options.window_canvas_zoom);
	},
	
	getCanvasCoordinates: function(){
		var coordinates = {'width':this.options.window_width,'height':this.options.window_height,'x':this.options.window_canvas_x,'y':this.options.window_canvas_y,'zoom':this.options.window_canvas_width};
		return coordinates;
	},
	
	setCanvasWidth: function(width){
		//Usually this function gets called wehn we're resetting so we need to restablish our base as well as change the width
		this.options.window_canvas_width = width;
		this.original_width = width;
		this.window_canvas.setStyles({'width':width});
	},
	
	setCanvasHeight: function(height){
		//Usually this function gets called wehn we're resetting so we need to restablish our base as well as change the height
		this.options.window_canvas_height = height;
		this.original_height = height;
		this.window_canvas.setStyles({'height':height});
	}
});

OImage = new Class({
	Implements: Options,
	
	options:{
		'image_id':0,
		'content_area_id':0,
		'content_part_id':0,
		'resizable':true,
		'max_width':1024,
		'max_height':768,
		'image_width': 1024,
		'image_height': 768,
		'image_src':'',
		'image_name':'Untitled',
		'image_description':'',
		'image_description_long':'',
		'image_ext':'jpg',
		'image_x':0,
		'image_y':0,
		'image_zoom':0,
		'image_link':'',
		'image_follow':false,
		'image_thumb_x':0,
		'image_thumb_y':0,
		'content_order':0,
		'blog':false,
		'image_location':''
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.ready = false;
		this.loaded = false;
		//build container
		
		this.image_container = new Element('div',{'class':'OImage'});
		this.image_container.setStyles({'position':'relative','width':this.options.image_width,'height':this.options.image_height,'background-image':'url(obray/images/place-holder-image.jpg)','background-position':'center'});
		//start loader - show image is loading to be edited, could be really important since obray images are generally full sized and large.
		this.loader = new Element('div',{'class':'OImage-loader'});
		this.loader.setStyles({'position':'absolute','left':'50%','top':'50%','margin-top':-15,'margin-left':-60,'background-color':'#000000','opacity':.5,'width':120,'height':30});
		this.loader.inject(this.image_container);
		this.loader_animation = new Element('img',{'src':'obray/images/loaders/loader-standard.gif'});
		this.loader_animation.setStyles({'margin':7,'margin-left':17,'float':'left'});
		this.loader_animation.inject(this.loader);
		this.loader_text = new Element('div',{'class':'OImage-text'});
		this.loader_text.setStyles({'float':'left','color':'#ffffff','font-family':'arial,helvetica','font-size':'13px','padding':7,'padding-left':0});
		this.loader_text.set('html','Loading...');		
		this.loader_text.inject(this.loader);
		if(this.options.image_src != ''){
			this.asset = new Asset.images([this.options.image_src],{'failure':function(){												   
			}.bind(this),'onComplete':function(){
				if(this.ready){this.loadEditor();}
				this.ready = true;
			}.bind(this)});
			
		} else {
			this.options.image_width = this.options.max_width;
			if(this.options.max_height == 768){
				this.options.image_height = (this.options.image_width * this.options.image_height)/1024	;
			} else {
				this.options.image_height = this.options.max_height;//(this.options.image_width * this.options.image_height)/1024
			}
			
			if(this.ready){this.loadEditor();}
			this.ready = true;
			
		}
	},
	
	loadEditor: function(){
		//genreate window
		this.original_dimensions = this.getImageDimensions();
		this.original_width = this.original_dimensions.width;
		this.original_height = this.original_dimensions.height;
		this.zoom = (this.options.image_zoom/this.original_width)*100;
		this.window = new Window({
			'window_width':this.options.image_width,
			'window_height':this.options.image_height,
			'window_canvas_width':this.getImageWidth(),
			'window_canvas_height':this.getImageHeight(),
			'window_canvas_x':this.options.image_x,
			'window_canvas_y':this.options.image_y,
			'window_resizable':this.options.resizable,
			'window_canvas_zoom':this.zoom
		});
		this.window.original_height = this.original_height;
		this.window.original_width = this.original_width;
		this.window.replaces(this.image_container);
		if(this.options.image_src != ''){this.window.window.setStyles({'background-image':'none','border':0});}
		this.window.window_container.setProperty('id','OImage-'+this.options.content_part_id);
		
		
		this.window.window_container.addClass('OImage');
		
		//attach image to window canvas
		if(this.options.image_src != ''){
			this.image = new Element('img',{'src':this.options.image_src});
			this.image.setStyles({'width':'100%','height':'100%'});
			this.image.inject(this.window.window_canvas);
		} else {
			this.image = new Element('img');
			this.instructions = new Element('div',{'class':'upload-instructions'});
			this.instructions.setStyles({'width':200,'height':'auto','posi           :)    tion':'absolute','left':'50%','top':'50%','margin-left':-115,'margin-top':-65,'font-family':'arial','color':'#ffffff','font-size': 20,'background-color':'#000000','opacity':.5,'padding':15,'text-align':'center'});
			this.instructions.set('html','Mouse over the image and click on <img src="obray/images/image/edit-btn.png" alt="upload button" width="20" height="20"/> in the toolbar to upload an image.')
			this.instructions.inject(this.window.window);
			this.instructionsFx = new Fx.Morph(this.instructions,{'duration':2000,'transition':Fx.Transitions.Quint.easeOut,'onComplete':function(){this.instructions.destroy();}.bind(this)});
			this.hideInstructions.delay(5000,this)
		}
		//buttons
		this.image_save_btn = new Element('div',{'class':'OImage-save-btn'});
		this.image_save_btn_label = new Element('div',{'class':'OImage-save-btn-label'});
		this.image_save_btn_label.set('html','Save');
		this.image_save_btn_icon = new Element('div',{'class':'OImage-save-btn-icon'});
		this.image_delete_btn = new Element('div',{'class':'OImage-delete-btn'});
		this.image_edit_btn = new Element('div',{'class':'OImage-edit-btn'});
		this.image_options_btn = new Element('div',{'class':'OImage-style-btn'});
		this.image_options_btn_label = new Element('div',{'class':'OImage-option-btn-label'});
		this.image_options_btn_label.set('html','Options');
		this.image_options_btn_icon = new Element('div',{'class':'OImage-option-btn-icon'});
		this.image_save_btn.setStyles({'position':'absolute','left':'5px','top':'6px','background-image':'none','width':'59px','height':'19px','cursor':'pointer'});
		this.image_save_btn_label.setStyles({'float':'left','color':'#ffffff','font-family':'arial','font-size':'11px','padding':0,'padding-top':0,'line-height':19,'padding-left':'7px'});
		this.image_save_btn_icon.setStyles({'float':'left','height':'8px','width':'8px','background-image':'url(obray/images/image/red-dot-small.png)','margin':'6px'});
		if(this.options.image_id != 0){this.image_save_btn_icon.setStyles({'background-image':'url(obray/images/image/green-dot-small.png)'});}
		this.image_options_btn.setStyles({'position':'absolute','right':'5px','top':'6px','background-image':'none','width':'59px','height':'19px','cursor':'pointer'});
		this.image_options_btn_label.setStyles({'float':'left','color':'#ffffff','font-family':'arial','font-size':'11px','padding':0,'padding-top':0,'line-height':19,'padding-left':'5px'});
		this.image_options_btn_icon.setStyles({'float':'left','height':'10px','width':'10px','background-image':'url(obray/images/image/option-arrow-right.png)','margin-top':'4px'});
		this.image_delete_btn.setStyles({'position':'absolute','left':'-27px','top':'3px','background-image':'url(obray/images/image/delete-btn.png)','width':'25px','height':'25px','cursor':'pointer'}); 
		this.image_edit_btn.setStyles({'position':'absolute','right':'-30px','top':'3px','background-image':'url(obray/images/image/edit-btn.png)','width':'25px','height':'25px','cursor':'pointer','overflow':'hidden'});
		this.image_save_btn.inject(this.window.zoom_inner_container);
		this.image_save_btn_label.inject(this.image_save_btn);
		this.image_save_btn_icon.inject(this.image_save_btn);
		this.image_options_btn.inject(this.window.zoom_inner_container);
		this.image_options_btn_label.inject(this.image_options_btn);
		this.image_options_btn_icon.inject(this.image_options_btn);
		this.image_delete_btn.inject(this.window.zoom_inner_container);
		this.image_edit_btn.inject(this.window.zoom_inner_container);
		//upload btn
		this.image_upload_btn = new Element('div',{'class':'OImage-edit-btn'});
		this.image_upload_btn.setStyles({'position':'absolute','right':'-30px','top':'3px','background-image':'url(obray/images/image/edit-btn.png)','width':'25px','height':'25px','cursor':'pointer','overflow':'hidden'});
		this.image_upload_btn.inject(this.window.zoom_inner_container);
		//upload form
		this.image_form = new Element('form',{'action':'index.cfm?action=images.uploadImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','encoding':'multipart/form-data','enctype':'multipart/form-data','target':'upload_target','method':'post'});
		this.image_file = new Element('input',{'type':'file','name':'image_file'});
		this.image_form_image_id = new Element('input',{'type':'hidden','value':this.image_id,'name':'image_id'});
		this.image_form.setStyles({'position':'relative','top':'0px','left':'0px','background-color':'transparent','width':'100px','overflow':'hidden'});
		this.image_file.setStyles({'font-family':'arial','color':'#ffffff','opacity':0.01,'margin-left':'-175px'});
		this.image_file.inject(this.image_form);
		this.image_form_image_id.inject(this.image_form);
		this.image_form.inject(this.image_upload_btn);
		this.upload_target = $('upload_target');
		
		//options
		this.br = new Element('br',{'class':'clear'});
		this.image_options_container = new Element('div',{'class':'OImage-options-container'});
		this.image_title_label = new Element('div',{'class':'OImage-title-label'});
		this.image_title_label.set('html','<a class="OImage-title-label-a" title="imageTitle">Image Title:</a>')
		this.image_title_input = new Element('input',{'class':'OImage-title-input','type':'text','value':this.options.image_description});
		this.image_title_tip = new Tips(this.image_title_label.getFirst(),{'title':'Image Title','text':'The image title is very important for Search Engine Optimization.  It is placed in the alt property of the image and search engines use it to determine the content of the image so it is searchable.'});
		this.image_link_label = new Element('label',{'class':'OImage-link-label'});
		this.image_link_label.set('html','Image Link:');
		this.image_link_input = new Element('input',{'class':'OImage-link-input','type':'text','value':this.options.image_link});
		this.image_link_follow_chk = new Element('input',{'class':'OImage-link-follow-chk','type':'checkbox'});
		if(this.options.image_follow){
			this.image_link_follow_chk.checked = true;
			this.image_link_follow_chk.defaultChecked = true;
		} else {
			this.image_link_follow_chk.checked = false;
			this.image_link_follow_chk.defaultChecked = false;
		}
		this.image_link_follow_label = new Element('label',{'class':'OImage-link-follow-label'});
		this.image_link_follow_label.set('html','Allow search engines to follow this link (leave your site).')
		this.image_caption_label = new Element('label',{'class':'OImage-caption-label'});
		this.image_caption_label.set('html','Image Caption:');
		this.image_caption_input = new Element('textarea',{'class':'OImage-caption-input'});
		this.image_caption_input.set('html',this.options.image_description_long);
		this.image_options_container.setStyles({'position':'absolute','top':'30px','left':'-5px','width':'264px','height':'232px','background-image':'url(obray/images/image/bg-options.png)','padding':20,'opacity':0});
		this.image_title_label.setStyles({'font-family':'arial','font-size':'11px','color':'#ffffff','padding':1,'padding-left':2});
		this.image_title_input.setStyles({'width':255});
		this.image_link_label.setStyles({'font-family':'arial','font-size':'11px','color':'#ffffff','text-align':'left','padding':'0px','margin':'0px','margin-top':'10px'});
		this.image_link_input.setStyles({'width':255});
		this.image_link_follow_label.setStyles({'float':'left','font-family':'arial','font-size':'9px','color':'#ffffff','padding':'0px','margin':'0px','text-align':'left','width':240,'padding-top':3});
		this.image_link_follow_chk.setStyles({'float':'left','margin-left':'0px','padding-left':'0px'});
		this.image_caption_label.setStyles({'font-family':'arial','font-size':'11px','color':'#ffffff','padding':'1px','margin':'0px','text-align':'left','margin-top':'10px'});
		this.image_caption_input.setStyles({'width':262,'height':100});
		this.image_title_label.inject(this.image_options_container);
		this.image_title_input.inject(this.image_options_container);
		this.br.clone().inject(this.image_options_container);
		this.image_link_label.inject(this.image_options_container);
		this.image_link_input.inject(this.image_options_container);
		this.br.clone().inject(this.image_options_container);
		this.image_link_follow_chk.inject(this.image_options_container);
		this.image_link_follow_label.inject(this.image_options_container);
		this.br.clone().inject(this.image_options_container);
		this.image_caption_label.inject(this.image_options_container);
		this.image_caption_input.inject(this.image_options_container);
		this.image_options_container.inject(this.window.zoom_inner_container);
		this.fade_options = new Fx.Morph(this.image_options_container,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
		//Create Events
		
		this.image_link_follow_chk.addEvent('click',function(){
			if(this.image_follow){
				this.options.image_follow = false;
			} else {
				this.options.image_follow = true;
			}
		}.bind(this))
		
		this.image_options_btn.addEvent('click',function(){
			if(this.image_options_container.getStyle('opacity') == 0){
				this.fade_options.start({'opacity':1});
				this.image_options_btn_icon.setStyles({'background-image':'url(obray/images/image/option-arrow-down.png)'});
			} else {
				this.fade_options.start({'opacity':0});
				this.image_options_btn_icon.setStyles({'background-image':'url(obray/images/image/option-arrow-right.png)'});
			}
		}.bind(this))
		
		this.image_title_input.addEvent('change',function(){
			this.markUnsaved();
		}.bind(this));
		
		this.image_link_input.addEvent('change',function(){
			this.markUnsaved();
		}.bind(this));
		
		this.image_caption_input.addEvent('change',function(){
			this.markUnsaved();
		}.bind(this));
		
		
		//event: Upload
		this.image_file.addEvent('change',function(e){
			this.image_form.submit();
			//get upload response
			this.upload_target.addEvent('load',function(){
				//get iFrame
				var frame = window.frames['upload_target'];
				//get Response
				var response = frame.document.getElementById('response').innerHTML;
				this.imagejson = JSON.decode(response);
				this.options.image_id = this.imagejson.image.image_id;
				this.options.image_location = this.imagejson.image.image_location;
				this.options.image_name = this.imagejson.image.image_name;
				this.options.image_description = this.imagejson.image.image_description;
				this.options.image_description_long = this.imagejson.image.image_description_long;
				this.options.image_ext = this.imagejson.image.image_ext;
				this.options.image_width = this.imagejson.image.image_width;
				this.options.image_height = this.imagejson.image.image_height;
				this.options.image_width = this.imagejson.image.image_width;
				this.options.image_height = this.imagejson.image.image_height;
				this.options.image_x = 0;
				this.options.image_y = 0;
				var img = new Asset.images([this.options.image_location],{onComplete:function(){
					this.window.setCanvasWidth(this.options.image_width);
					this.window.setCanvasHeight(this.options.image_height);
					//adjust window if it's smaller than the loaded image
					if(this.options.image_width < this.window.window.getCoordinates().width){
						this.window.window.setStyles({'width':this.options.image_width});
						this.window.options.window_width = this.options.image_width;
					}
					if(this.options.image_height < this.window.window.getCoordinates().height){
						this.window.window.setStyles({'height':this.options.image_height});
						this.window.options.window_height = this.options.image_height;
					}
					this.window.window.setStyles()
					this.image.destroy();
					if(this.options.image_location == "Amazon S3"){
						this.image = new Element('img',{'src':window.obray.amazon_location+this.options.image_name+'.'+this.options.image_ext});
					} else {
						this.image = new Element('img',{'src':'assets/images/'+this.options.image_name+'.'+this.options.image_ext});
					}
					this.image.setStyles({'width':'100%','height':'100%'});
					this.image.inject(this.window.window_canvas);
					this.upload_target.removeEvents();
					//get rid of background-image and border
					this.window.window.setStyles({'background-image':'none','border':0});
				}.bind(this)});
				
			}.bind(this));
			
		}.bind(this))
		
		
		//event: save
		this.image_save_btn.addEvent('mouseenter',function(){
			this.image_save_btn.setStyles({'background-image':'url(obray/images/image/bg-control-btn.png)'});
		}.bind(this));
		this.image_save_btn.addEvent('mouseleave',function(){
			this.image_save_btn.setStyles({'background-image':'none'});
		}.bind(this));
		this.image_save_btn.addEvent('click',function(){
			this.options.image_description = this.image_title_input.getProperty('value');
			this.options.image_description_long = this.image_caption_input.getProperty('value');
			this.options.image_link = this.image_link_input.getProperty('value');
			var data = '&image_id='+this.options.image_id
					  +'&image_name='+this.options.image_name
					  +'&image_ext='+this.options.image_ext
					  +'&image_x='+this.window.getCanvasCoordinates().x
					  +'&image_y='+this.window.getCanvasCoordinates().y
					  +'&image_width='+this.window.getCanvasCoordinates().width
					  +'&image_height='+this.window.getCanvasCoordinates().height
					  +'&image_zoom='+this.window.getCanvasCoordinates().zoom
					  +'&image_description='+encodeURIComponent(this.options.image_description)
					  +'&image_location='+this.options.image_location
					  +'&image_link='+encodeURIComponent(this.options.image_link)
					  +'&image_follow='+this.options.image_follow
					  +'&image_description_long='+encodeURIComponent(this.options.image_description_long)
					  +'&thumb_size_x=' + this.options.image_thumb_x
					  +'&thumb_size_y=' + this.options.image_thumb_y;
			this.saveImage = new Request({'url':'index.cfm?action=images.saveImage&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','method':'post','data':data,'onComplete':function(response){
				eval(response);
				this.updateContentPart = new Request({'url':'index.cfm?action=pages.updateObrayContent&content_part_id='+this.options.content_part_id+'&content_area_id='+this.options.content_area_id+'&image_id='+this.options.image_id+'&content_order='+this.options.content_order+'&content_part_type=image&content_text=&blog='+false+'&content_language='+this.options.content_language+'&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','onComplete':function(){
					var location = window.location.href.replace(window.location.hash,'');
					var location = location.replace('#','');
					window.location = location;
				}.bind(this)}).send();
			}.bind(this)}).send();
		}.bind(this))
		
		//event: options
		this.image_options_btn.addEvent('mouseenter',function(){
			this.image_options_btn.setStyles({'background-image':'url(obray/images/image/bg-control-btn.png)'});												  
		}.bind(this));
		this.image_options_btn.addEvent('mouseleave',function(){
			this.image_options_btn.setStyles({'background-image':'none'});												  
		}.bind(this));
		
		this.image_delete_btn.addEvent('click',function(){
			if(this.options.image_id == 0){
				this.image_container.destroy();
			} else {
				this.deleteRequest = new Request({'url':'index.cfm?action=pages.deleteContentPart&content_part_id='+this.options.content_part_id,'onComplete':function(){
					var location = window.location.href.replace(window.location.hash,'');
					var location = location.replace('#','');
					window.location = location;
				}.bind(this)}).send();
			}
		}.bind(this));
		
	},
	
	hideInstructions: function(){
		this.instructionsFx.start({'opacity':0});
	},
	
	inject: function(el,position){
		this.image_container.inject(el,position);
		if(this.ready && this.loaded == false){
			this.loadEditor();
			this.loaded = true;
		} else if(this.loaded == true) {
		    this.window.replaces(this.image_container);
		}
		this.ready = true;
	},
	
	getImageWidth: function(){
		if(this.options.image_zoom == 0){
			return this.options.image_width;
		} else {
			return this.options.image_zoom;
		}
	},

	getImageDimensions: function(){
		if(this.options.image_src != ''){
			var temp_img = new Element('img',{'src':this.options.image_src});
			temp_img.setStyles({'position':'absolute','left':-20000,'top':-20000});
			temp_img.inject(document.body);
			var height = temp_img.getCoordinates().height;
			var width = temp_img.getCoordinates().width;
			var coordinates = {'width':width,'height':height}
		} else {
			var coordinates = {'width':0,'height':0};
		}
		return coordinates;
	},
	
	getImageHeight: function(){
		if(this.options.image_src != '' && this.options.image_zoom > 0){
			var temp_img = new Element('img',{'src':this.options.image_src});
			temp_img.setStyles({'position':'absolute','left':-20000,'top':-20000});
			temp_img.inject(document.body);
			var height = temp_img.getCoordinates().height;
			var width = temp_img.getCoordinates().width;
			new_height = (this.options.image_zoom*height)/width;
			temp_img.destroy();
			return new_height;
		} else {
			return this.options.image_height;
		}
	}
})

// JavaScript Document
/***
OImage2 = new Class({
	Implements: [Options],
	
	options: {
		'image_id':0,
		'content_area_id':0,
		'content_part_id':0,
		'resizeable':true,
		'max_width':1024,
		'max_height':768,
		'image_width': 1024,
		'image_height': 768,
		'image_src':'obray/images/place-holder-image.jpg',
		'image_name':'Untitled',
		'image_description':'',
		'image_description_long':'',
		'image_ext':'jpg',
		'image_x':0,
		'image_y':0,
		'image_zoom':0,
		'image_link':'',
		'image_follow':false,
		'image_thumb_x':0,
		'image_thumb_y':0,
		'content_order':0,
		'blog':false
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.image_id = this.options.image_id;
		this.content_area_id = this.options.content_area_id;
		this.content_part_id = this.options.content_part_id;
		this.image_name = this.options.image_name;
		this.image_description = this.options.image_description;
		this.image_description_long = this.options.image_description_long;
		this.image_location = this.options.image_src;
		this.image_ext = this.options.image_ext;
		this.image_link = this.options.image_link;
		this.image_follow = this.options.image_follow;
		this.image_thumb_x = this.options.image_thumb_x;
		this.image_thumb_y = this.options.image_thumb_y;
		this.content_order = this.options.content_order;
		this.blog = this.options.blog;
		
		//this.max_width = this.options.max_width;
		//this.max_height = this.options.max_height;
		//image dimensions
		this.image_width = this.options.image_width;
		this.image_height = this.options.image_height;
		if(this.image_id == 0){
			if(this.options.image_width > this.max_width){this.image_width=this.options.max_width;}
			this.image_height = this.getHeight();
		}
		//containing window dimensions
		this.window_width = this.image_width;
		this.window_height = this.image_height;
		//imaeg position
		this.image_x = this.options.image_x;
		this.image_y = this.options.image_y;
		
		this.upload_target = $('upload_target');
		//image HTML
		this.image_container = new Element('div',{'class':'OImage-container'});
		this.image_window = new Element('div',{'class':'OImage-window'});
		this.image_window_handle = new Element('div',{'class':'OImage-window-handle'});
		this.image = new Element('img',{'class':'OImage','src':this.options.image_src});
		this.image_container.setStyles({'position':'relative'});
		this.image_window.setStyles({'position':'relative','overflow':'hidden','border':'0px solid black','height':this.window_height,'width':this.window_width,'z-index':4999});
		this.image_window_handle.setStyles({'position':'absolute','bottom':-5,'right':-5,'background-color':'#ffffff','height':8,'width':8,'z-index':5000,'border':'1px solid #000000','cursor':'se-resize','opacity':.01});
		this.image.setStyles({'position':'absolute','z-index':99,'left':this.image_x,'top':this.image_y});
		if(this.image_id == 0){this.image.setStyles({'height':this.image_height,'width':this.options.max_width});}
		this.image_window.inject(this.image_container);
		this.image_window_handle.inject(this.image_container);
		this.image.inject(this.image_window);
		this.fade_handle = new Fx.Morph(this.image_window_handle,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
		
		//zoom
		this.image_zoom_container = new Element('div',{'class':'OImage-zoom-container'});
		this.image_zoom_inner_container = new Element('div',{'class':'OImage-zoom-inner-container'});
		this.image_zoom_text = new Element('div',{'class':'OImage-zoom-text'});
		this.image_zoom_handle = new Element('div',{'class':'OImage-zoom-handle'});
		this.image_zoom_track = new Element('div',{'class':'OImage-zoom-track'});
		this.image_zoom_container.setStyles({'opacity':'.01','position':'absolute','left':'50%','bottom':15,'margin-left':'-147px','background-image':'url(obray/images/image/bg-zoom-container.png)','width':295,'height':31,'z-index':5001});
		this.image_zoom_inner_container.setStyles({'position':'relative','width':'100%','height':'100%','margin':'0px'});
		this.image_zoom_track.setStyles({'position':'absolute','top':'19px','left':'67px','width':160,'height':5,'background-image':'url(obray/images/image/bg-zoom-track.png)','background-repeat':'no-repeat','background-position':'center'});
		this.image_zoom_handle.setStyles({'position':'absolute','left':0,'top':-8,'width':20,'height':20,'background-image':'url(obray/images/image/bg-zoom-handle.png)','cursor':'pointer'});
		this.image_zoom_text.setStyles({'position':'absolute','left':'50%','top':4,'width':'150px','text-align':'center','margin-left':'-75px','font-family':'arial','font-size':'10px','color':'#ffffff'});
		this.image_zoom_inner_container.inject(this.image_zoom_container);
		this.image_zoom_text.inject(this.image_zoom_inner_container);
		this.image_zoom_container.inject(this.image_container);
		this.image_zoom_track.inject(this.image_zoom_inner_container);
		this.image_zoom_handle.inject(this.image_zoom_track);
		this.fade = new Fx.Morph(this.image_zoom_container,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
		
		//buttons
		this.image_save_btn = new Element('div',{'class':'OImage-save-btn'});
		this.image_save_btn_label = new Element('div',{'class':'OImage-save-btn-label'});
		this.image_save_btn_label.set('html','Save');
		this.image_save_btn_icon = new Element('div',{'class':'OImage-save-btn-icon'});
		this.image_delete_btn = new Element('div',{'class':'OImage-delete-btn'});
		this.image_edit_btn = new Element('div',{'class':'OImage-edit-btn'});
		this.image_options_btn = new Element('div',{'class':'OImage-style-btn'});
		this.image_options_btn_label = new Element('div',{'class':'OImage-option-btn-label'});
		this.image_options_btn_label.set('html','Options');
		this.image_options_btn_icon = new Element('div',{'class':'OImage-option-btn-icon'});
		this.image_save_btn.setStyles({'position':'absolute','left':'5px','top':'6px','background-image':'none','width':'59px','height':'19px','cursor':'pointer'});
		this.image_save_btn_label.setStyles({'float':'left','color':'#ffffff','font-family':'arial','font-size':'11px','padding':'3px','padding-left':'7px'});
		this.image_save_btn_icon.setStyles({'float':'left','height':'8px','width':'8px','background-image':'url(obray/images/image/red-dot-small.png)','margin':'6px'});
		if(this.image_id != 0){this.image_save_btn_icon.setStyles({'background-image':'url(obray/images/image/green-dot-small.png)'});}
		this.image_options_btn.setStyles({'position':'absolute','right':'5px','top':'6px','background-image':'none','width':'59px','height':'19px','cursor':'pointer'});
		this.image_options_btn_label.setStyles({'float':'left','color':'#ffffff','font-family':'arial','font-size':'11px','padding':'3px','padding-left':'5px'});
		this.image_options_btn_icon.setStyles({'float':'left','height':'10px','width':'10px','background-image':'url(obray/images/image/option-arrow-right.png)','margin-top':'4px'});
		this.image_delete_btn.setStyles({'position':'absolute','left':'-27px','top':'3px','background-image':'url(obray/images/image/delete-btn.png)','width':'25px','height':'25px','cursor':'pointer'}); 
		this.image_edit_btn.setStyles({'position':'absolute','right':'-30px','top':'3px','background-image':'url(obray/images/image/edit-btn.png)','width':'25px','height':'25px','cursor':'pointer','overflow':'hidden'});
		this.image_save_btn.inject(this.image_zoom_inner_container);
		this.image_save_btn_label.inject(this.image_save_btn);
		this.image_save_btn_icon.inject(this.image_save_btn);
		this.image_options_btn.inject(this.image_zoom_inner_container);
		this.image_options_btn_label.inject(this.image_options_btn);
		this.image_options_btn_icon.inject(this.image_options_btn);
		this.image_delete_btn.inject(this.image_zoom_inner_container);
		this.image_edit_btn.inject(this.image_zoom_inner_container);
		
		//upload form
		this.image_form = new Element('form',{'action':'index.cfm?action=images.uploadImage','encoding':'multipart/form-data','enctype':'multipart/form-data','target':'upload_target','method':'post'});
		this.image_file = new Element('input',{'type':'file','name':'image_file'});
		this.image_form_image_id = new Element('input',{'type':'hidden','value':this.image_id,'name':'image_id'});
		this.image_form.setStyles({'position':'relative','top':'0px','left':'0px','background-color':'transparent','width':'100px','overflow':'hidden'});
		this.image_file.setStyles({'font-family':'arial','color':'#ffffff','opacity':0.01,'margin-left':'-175px'});
		this.image_file.inject(this.image_form);
		this.image_form_image_id.inject(this.image_form);
		this.image_form.inject(this.image_edit_btn);
		
		//options
		this.br = new Element('br',{'class':'clear'});
		this.image_options_container = new Element('div',{'class':'OImage-options-container'});
		this.image_title_label = new Element('div',{'class':'OImage-title-label'});
		this.image_title_label.set('html','<a class="OImage-title-label-a" title="imageTitle">Image Title:</a>')
		this.image_title_input = new Element('input',{'class':'OImage-title-input','type':'text','value':this.image_description});
		this.image_title_tip = new Tips(this.image_title_label.getFirst(),{'title':'Image Title','text':'The image title is very important for Search Engine Optimization.  It is placed in the alt property of the image and search engines use it to determine the content of the image so it is searchable.'});
		this.image_link_label = new Element('label',{'class':'OImage-link-label'});
		this.image_link_label.set('html','Image Link:');
		this.image_link_input = new Element('input',{'class':'OImage-link-input','type':'text','value':this.image_link});
		this.image_link_follow_chk = new Element('input',{'class':'OImage-link-follow-chk','type':'checkbox'});
		if(this.image_follow){
			this.image_link_follow_chk.checked = true;
			this.image_link_follow_chk.defaultChecked = true;
		} else {
			this.image_link_follow_chk.checked = false;
			this.image_link_follow_chk.defaultChecked = false;
		}
		this.image_link_follow_label = new Element('label',{'class':'OImage-link-follow-label'});
		this.image_link_follow_label.set('html','Allow search engines to follow this link (leave your site).')
		this.image_caption_label = new Element('label',{'class':'OImage-caption-label'});
		this.image_caption_label.set('html','Image Caption:');
		this.image_caption_input = new Element('textarea',{'class':'OImage-caption-input'});
		this.image_caption_input.set('html',this.image_description_long);
		this.image_options_container.setStyles({'position':'absolute','top':'30px','left':'-5px','width':'264px','height':'232px','background-image':'url(obray/images/image/bg-options.png)','padding':20,'opacity':0});
		this.image_title_label.setStyles({'font-family':'arial','font-size':'11px','color':'#ffffff','padding':1,'padding-left':2});
		this.image_title_input.setStyles({'width':255});
		this.image_link_label.setStyles({'font-family':'arial','font-size':'11px','color':'#ffffff','text-align':'left','padding':'0px','margin':'0px','margin-top':'10px'});
		this.image_link_input.setStyles({'width':255});
		this.image_link_follow_label.setStyles({'float':'left','font-family':'arial','font-size':'9px','color':'#ffffff','padding':'0px','margin':'0px','text-align':'left','width':240,'padding-top':3});
		this.image_link_follow_chk.setStyles({'float':'left','margin-left':'0px','padding-left':'0px'});
		this.image_caption_label.setStyles({'font-family':'arial','font-size':'11px','color':'#ffffff','padding':'1px','margin':'0px','text-align':'left','margin-top':'10px'});
		this.image_caption_input.setStyles({'width':262,'height':100});
		this.image_title_label.inject(this.image_options_container);
		this.image_title_input.inject(this.image_options_container);
		this.br.clone().inject(this.image_options_container);
		this.image_link_label.inject(this.image_options_container);
		this.image_link_input.inject(this.image_options_container);
		this.br.clone().inject(this.image_options_container);
		this.image_link_follow_chk.inject(this.image_options_container);
		this.image_link_follow_label.inject(this.image_options_container);
		this.br.clone().inject(this.image_options_container);
		this.image_caption_label.inject(this.image_options_container);
		this.image_caption_input.inject(this.image_options_container);
		this.image_options_container.inject(this.image_zoom_inner_container);
		this.fade_options = new Fx.Morph(this.image_options_container,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
		
		//Create Events
		
		this.image_link_follow_chk.addEvent('click',function(){
			if(this.image_follow){
				this.image_follow = false;
			} else {
				this.image_follow = true;
			}
		}.bind(this))
		
		this.image_options_btn.addEvent('click',function(){
			if(this.image_options_container.getStyle('opacity') == 0){
				this.fade_options.start({'opacity':1});
				this.image_options_btn_icon.setStyles({'background-image':'url(obray/images/image/option-arrow-down.png)'});
			} else {
				this.fade_options.start({'opacity':0});
				this.image_options_btn_icon.setStyles({'background-image':'url(obray/images/image/option-arrow-right.png)'});
			}
		}.bind(this))
		
		this.image_title_input.addEvent('change',function(){
			this.markUnsaved();
		}.bind(this));
		
		this.image_link_input.addEvent('change',function(){
			this.markUnsaved();
		}.bind(this));
		
		this.image_caption_input.addEvent('change',function(){
			this.markUnsaved();
		}.bind(this));
		
		this.setEvents();
		this.fade_delay = 0;
		this.fade_handle_delay = 0;
		this.image_container.addEvent('mouseenter',function(){
			this.image_container.setStyles({'z-index':7000});
			$clear(this.fade_delay);
			$clear(this.fade_handle_delay);
			this.fade_delay = this.fade.start.delay(500,this.fade,[{'opacity':1}]);
			this.fade_handle_delay = this.fade_handle.start.delay(500,this.fade_handle,[{'opacity':1}]);
		}.bind(this));
		
		this.image_container.addEvent('mouseleave',function(){
			this.image_container.setStyles({'z-index':5000});
			$clear(this.fade_delay);
			$clear(this.fade_handle_delay);
			this.fade_delay = this.fade.start.delay(1000,this.fade,[{'opacity':.01}]);
			this.fade_handle_delay = this.fade_handle.start.delay(1000,this.fade_handle,[{'opacity':.01}]);
			//this.image_zoom_container.setStyles.delay(2000,this.image_zoom_container,[{'display':'block','opacity':.25}]);
		}.bind(this))
		
		
		
		this.image_file.addEvent('change',function(e){
			this.markUnsaved();
			this.image_form.submit();
			
			//get upload response
			this.upload_target.addEvent('load',function(){
				
				var frame = window.frames['upload_target'];
				var response = frame.document.getElementById('response').innerHTML;
				
				eval(response);
				if(response_type == 'image'){
				this.image_id = image_id;
				this.image_location = image_location;
				this.image_name = image_name;
				this.image_description = image_description;
				this.image_ext = image_ext;
				this.options.image_width = image_width;
				this.options.image_height = image_height;
				this.image_width = image_width;
				this.image_height = image_height;
				this.image_x = 0;
				this.image_y = 0;
				if(this.image_width < this.max_width){this.max_width = this.image_width;}
					var editorImage = new Asset.images([this.image_location],{onComplete:function(){
						this.image.removeProperties('width','height');
						this.image.setProperties({'src':this.image_location,'width':this.image_width,'height':this.image_height});
						this.image.setStyles({'top':'0px','left':'0px','width':this.image_width,'height':this.image_height});
						this.slider.set(10000);
						this.setEvents();
						this.markSaved();
						this.upload_target.removeEvents();
					}.bind(this)});
				}
			}.bind(this));
			
		}.bind(this))
		
		this.image_save_btn.addEvent('mouseenter',function(){
			this.image_save_btn.setStyles({'background-image':'url(obray/images/image/bg-control-btn.png)'});
		}.bind(this));
		this.image_save_btn.addEvent('mouseleave',function(){
			this.image_save_btn.setStyles({'background-image':'none'});
		}.bind(this));
		this.image_save_btn.addEvent('click',function(){
			this.image_description = this.image_title_input.getProperty('value');
			this.image_description_long = this.image_caption_input.getProperty('value');
			this.image_link = this.image_link_input.getProperty('value');
			var data = '&image_id='+this.image_id
					  +'&image_name='+this.image_name
					  +'&image_ext='+this.image_ext
					  +'&image_x='+this.image_x
					  +'&image_y='+this.image_y
					  +'&image_width='+this.window_width
					  +'&image_height='+this.window_height
					  +'&image_zoom='+this.image_width
					  +'&image_description='+encodeURIComponent(this.image_description)
					  +'&image_location='+this.image_location
					  +'&image_link='+this.image_link
					  +'&image_follow='+this.image_follow
					  +'&image_description_long='+encodeURIComponent(this.image_description_long)
					  +'&thumb_size_x=' + this.image_thumb_x
					  +'&thumb_size_y=' + this.image_thumb_y;				  
			this.saveImage = new Request({'url':'index.cfm?action=images.saveImage','method':'post','data':data,'onComplete':function(response){
				eval(response);						
				this.updateContentPart = new Request({'url':'index.cfm?action=pages.updateObrayContent&content_part_id='+this.content_part_id+'&content_area_id='+this.content_area_id+'&image_id='+image_id+'&content_order='+this.content_order+'&content_part_type=image&content_text=&blog='+this.blog,'onComplete':function(){
					var location = window.location.href.replace(window.location.hash,'');
					var location = location.replace('#','');
					window.location = location;
				}.bind(this)}).send();
			}.bind(this)}).send();
		}.bind(this))
		
		this.image_options_btn.addEvent('mouseenter',function(){
			this.image_options_btn.setStyles({'background-image':'url(obray/images/image/bg-control-btn.png)'});												  
		}.bind(this));
		this.image_options_btn.addEvent('mouseleave',function(){
			this.image_options_btn.setStyles({'background-image':'none'});												  
		}.bind(this));
		
		
		this.image_delete_btn.addEvent('click',function(){
			if(this.image_id == 0){
				this.image_container.destroy();
			} else {
				this.deleteRequest = new Request({'url':'index.cfm?action=pages.deleteContentPart&content_part_id='+this.content_part_id,'onComplete':function(){
					var location = window.location.href.replace(window.location.hash,'');
					var location = location.replace('#','');
					window.location = location;
				}.bind(this)}).send();
			}
		}.bind(this));
		
	},
	
	setDimensions: function(){
		
		
		
	},
	
	setEvents: function(){
		//remove all previous events
		this.image_window.removeEvents();
		this.image.removeEvents();
		//set window dimensions
		if(this.window_width > this.max_width){this.window_width = this.max_width;}
		if(this.window_height > this.max_height){this.window_height = this.max_height;}
		this.image_window.setStyles({'width':this.window_width,'height':this.window_height})
		
		//Create Events
		
		//Make Resizeable
		var x_resize_limit = this.max_width;
		var y_resize_limit = this.max_height;
		if(this.image_width+this.image_x < this.max_width){x_resize_limit = this.image_width+this.image_x;}
		if(this.image_height+this.image_y < this.max_height){y_resize_limit = this.image_height+this.image_y;}
		this.image_window.makeResizable({
			'handle':this.image_window_handle,
			//'limit': {'x':[0,x_resize_limit],'y':[0,y_resize_limit]},
			'onDrag': function(){
				//drop zoom control outside of window if it's resized smaller than the zoom container
				if(this.image_window.getCoordinates().width.toInt() < this.image_zoom_container.getCoordinates().width){ this.image_zoom_container.setStyles({'bottom':'-58px'});	} else { this.image_zoom_container.setStyles({'bottom':'15px'}); }
				this.image_container.setStyles({'width':this.image_window.getCoordinates().width,'height':this.image_window.getCoordinates().height});
			}.bind(this),
			'onComplete':function(){
				this.window_width = this.image_window.getCoordinates().width;
				this.window_height = this.image_window.getCoordinates().height;
				this.setEvents();
			}.bind(this)
		});
		
		//make draggable
		var x_drag_limit_left = this.window_width - this.image_width;
		var x_drag_limit_right = 0; //this.image_width - this.window_width;
		var y_drag_limit_top = this.window_height - this.image_height;
		var y_drag_limit_bottom = 0; //this.image_height - this.window_height;
		this.image.makeDraggable({
			'handle':this.image,
			'limit': {'x':[x_drag_limit_left,x_drag_limit_right],'y':[y_drag_limit_top,y_drag_limit_bottom]},
			'onComplete':function(){
				this.markUnsaved();
				this.image_x = this.image.getCoordinates().left-this.image_window.getCoordinates().left;
				this.image_y = this.image.getCoordinates().top-this.image_window.getCoordinates().top;
				this.setEvents();
			}.bind(this)
		});
		
		
	},
	
	getHeight: function(){
		return (this.options.image_height*this.image_width)/this.options.image_width;
	},
	
	markUnsaved: function(){
		this.image_save_btn_icon.setStyles({'background-image':'url(obray/images/image/red-dot-small.png)'});
	},
	
	markSaved: function(){
		this.image_save_btn_icon.setStyles({'background-image':'url(obray/images/image/green-dot-small.png)'});
	},
	
	injectAfter: function(el){
		this.image_container.inject(el,'after');
		this.slider = new Slider(this.image_zoom_track,this.image_zoom_handle,{
			'range':[0,10000],
			'steps':10000,
			'onChange':function(step){
				
				var new_width = (step/10000)*this.options.image_width;
				this.image_width = new_width;
				this.image.setStyles({'width':new_width,'height':this.getHeight()});
				this.image_height = this.getHeight();
				this.image_zoom_text.set('html','Zoom: ' + step/100 + '%');
				if(this.window_width > this.image_width+this.image_x){
					this.window_width = this.image_width+this.image_x;
					this.image_window.setStyles({'width':this.image_width+this.image_x});
				}
				if(this.window_height > this.image_height+this.image_y){
					this.window_height = this.image_height+this.image_y;
					this.image_window.setStyles({'height':this.image_height+this.image_y});
				}
				if(this.image_window.getCoordinates().width.toInt() < 270){ this.image_zoom_container.setStyles({'bottom':'-38px'});	} else { this.image_zoom_container.setStyles({'bottom':'15px'}); }
				this.image_container.setStyles({'width':this.image_window.getCoordinates().width,'height':this.image_window.getCoordinates().height});
			}.bind(this),
			'onComplete':function(){
				this.setEvents();
			}.bind(this)
		});
		this.slider.set((this.image_width/this.options.image_width)*10000);
		this.slider.addEvent('onComplete',function(){
			this.markUnsaved();
		}.bind(this));
	},
	
	injectInside: function(el){
		this.image_container.inject(el);
		this.slider = new Slider(this.image_zoom_track,this.image_zoom_handle,{
			'range':[0,10000],
			'steps':10000,
			'onChange':function(step){
				var new_width = (step/10000)*this.options.image_width;
				this.image_width = new_width;
				this.image.setStyles({'width':new_width,'height':this.getHeight()});
				this.image_height = this.getHeight();
				this.image_zoom_text.set('html','Zoom: ' + step/100 + '%');
				if(this.window_width > this.image_width+this.image_x){
					this.window_width = this.image_width+this.image_x;
					this.image_window.setStyles({'width':this.image_width+this.image_x});
				}
				if(this.window_height > this.image_height+this.image_y){
					this.window_height = this.image_height+this.image_y;
					this.image_window.setStyles({'height':this.image_height+this.image_y});
				}
				if(this.image_window.getCoordinates().width.toInt() < 270){ this.image_zoom_container.setStyles({'bottom':'-58px'});} else { this.image_zoom_container.setStyles({'bottom':'15px'}); }
				this.image_container.setStyles({'width':this.image_window.getCoordinates().width,'height':this.image_window.getCoordinates().height});
			}.bind(this),
			'onComplete':function(){
				
				this.setEvents();
			}.bind(this)
		});
		if(this.image_id == 0){
			this.slider.set((this.image_width/this.options.image_width)*10000);
		} else {
			this.assets = new Asset.images([this.options.image_src],{onComplete:function(){
				this.old_width = this.image_width;
				this.options.image_width = this.image.getCoordinates().width;
				this.options.image_height = this.image.getCoordinates().height;
				this.slider.set((this.options.image_zoom/this.options.image_width)*10000);
				this.slider.addEvent('onComplete',function(){
					this.markUnsaved();
				}.bind(this))
			}.bind(this)});
		}
	},
	
	get: function(){
		return this.image_window;
	}
})
*****/ 


VideoEmbed = new Class({
    Implements: Options,
    
    options:{
        'position':{'x':0,'y':0},
        'embed_code':''
    },
    
    initialize: function(options){
        this.setOptions(options);
        
        // embed container
        this.embed_container = new Element('div',{'class':'ovideo-embed-container'});
        this.embed_container.setStyles({'position':'absolute','padding':8,'background-image':'url(/obray/images/oplayer/embed-popup.png)','width':216,'height':66,'top':this.options.position.y,'left':this.options.position.x,'display':'none'});
        this.embed_container.addEvent('click',function(e){ e.stopPropagation(); })
        
        // embed label
        this.embed_label = new Element('label',{'class':'ovideo-embed-label'});
        this.embed_label.setStyles({'width':200,'font-family':'arial','font-size':10,'color':'#fff','padding':5,'text-align':'left'});
        this.embed_label.set('html','COPY THIS EMBED CODE');
        
        
        // embed input
        this.embed_input = new Element('input',{'type':'text','class':'ovideo-embed-input','value':this.options.embed_code});
        this.embed_input.setStyles({'background-color':'transparent','border':0,'background-image':'url(/obray/images/oplayer/embed-input.png)','width':205,'height':22,'margin-left':4,'font-family':'Courier,Arial'});
        
        this.embed_input.addEvent('mouseup',function(){
            this.embed_input.select();
        }.bind(this))
    },
    
    open: function(){
        this.embed_container.setStyles({'display':'block'});
    },
    
    close: function(){
        this.embed_container.setStyles({'display':'none'});
    },
    
    inject: function(el){
        this.embed_container.inject(el);
        this.embed_label.inject(this.embed_container);
        this.embed_input.inject(this.embed_container);
    }
});

VideoShare = new Class({
    Implements: Options,
    
    options:{
        'video_id':0,
        'position': {'x':0,'y':0},
        'share_url':'http://www.adventcreative.com'
    },
    
    initialize: function(options){
        this.setOptions(options);
        
        // share container
        this.share_container = new Element('div',{'class':'ovideo-share-container'});
        this.share_container.setStyles({'position':'absolute','padding':8,'background-image':'url(/obray/images/oplayer/share-popup.png)','width':216,'height':170,'top':this.options.position.y,'left':this.options.position.x,'display':'none'});
        this.share_container.addEvent('click',function(e){ e.stopPropagation(); });
        
        // share label
        this.share_label = new Element('label',{'class':'ovideo-share-label'});
        this.share_label.setStyles({'width':200,'font-family':'arial','font-size':10,'color':'#fff','padding':5,'text-align':'left'});
        this.share_label.set('html','EMAIL TO A FRIEND');
        
        
        // share input
        this.share_input = new Element('input',{'class':'ovideo-share-input'});
        this.share_input.setStyles({'background-color':'transparent','border':0,'background-image':'url(/obray/images/oplayer/embed-input.png)','width':205,'height':22,'margin-left':4});
        
        
        // share message
        this.share_message = new Element('div',{'class':'ovideo-share-message'});
        this.share_message.setStyles({'text-align':'center','display':'none','font-family':'Arial,Helvetica','font-face':'bold','font-size':13,'padding-top':15,'padding-bottom':10,'padding-left':5,'font-weight':'bold'});
        this.share_message.set('html','SENT SUCCESSFULLY<br/>');
        
        
        this.send_again_btn = new Element('a');
        this.send_again_btn.setStyles({'font-family':'Arial,Helvetica','font-face':'bold','font-size':11,'color':'#d5d5d5','cursor':'pointer'});
        this.send_again_btn.set('html',' Send Another');
        
        this.send_again_btn.addEvent('click',function(){
            this.share_btn.setStyles({'display':'inline'});
            this.share_input.setStyles({'display':'inline'});
            this.share_message.setStyles({'display':'none'});
            this.share_label.setStyles({'display':'block'});
        }.bind(this));
        
        // share icons
        this.share_icons = new Element('div',{'class':'ovideo-share-icons'});
        this.share_icons.setStyles({'position':'relative','width':206,'padding':3,'border-top':'1px solid #747070','margin-top':10,'margin-left':4,'margin-right':3,'margin-bottom':3});
        
        
        // share email button
        this.share_btn = new Element('img',{'src':'/obray/images/oplayer/email-btn.png'});
        this.share_btn.setStyles({'position':'absolute','top':-34,'left':179,'width':27,'height':22});
        
        this.share_btn.addEvent('click',function(){ 
            var data = '&video_id=' + this.options.video_id
                     + '&email_address=' + this.share_input.getProperty('value');
            this.request = new Request({'url':'index.cfm?action=videos.emailVideo&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','data':data,'method':'post','onComplete':function(){
                this.share_btn.setStyles({'display':'none'});
                this.share_input.setStyles({'display':'none'});
                this.share_message.setStyles({'display':'block'});
                this.share_label.setStyles({'display':'none'});
            }.bind(this)}).send();
        }.bind(this));
        
        this.facebook_btn = new Element('img',{'src':'/obray/images/oplayer/facebook-btn.png'});
        this.facebook_btn.setStyles({'margin':4,'margin-top':10});
        
        this.facebook_btn.addEvent('click',function(){ window.open('http://www.facebook.com/share.php?u=' + encodeURIComponent(this.options.share_url),'_blank'); }.bind(this));
        
        this.twitter_btn = new Element('img',{'src':'/obray/images/oplayer/twitter-btn.png'});
        this.twitter_btn.setStyles({'margin':4,'margin-top':10});
        
        this.twitter_btn.addEvent('click',function(){ window.open('http://www.twitter.com/home?status=' + encodeURIComponent(this.options.share_url),'_blank'); }.bind(this));
        
        // this.youtube_btn = new Element('img',{'src':'/obray/images/oplayer/youtube-btn.png'});
        // this.youtube_btn.setStyles({'margin':4,'margin-top':10});
        // this.youtube_btn.inject(this.share_icons);
        
        this.myspace_btn = new Element('img',{'src':'/obray/images/oplayer/myspace-btn.png'});
        this.myspace_btn.setStyles({'margin':4,'margin-top':10});
        
        this.myspace_btn.addEvent('click',function(){ window.open('https://secure.myspace.com/index.cfm?fuseaction=login.simpleform&featureName=postToV3&dest=http%3a%2f%2fwww.myspace.com%2fModules%2fPostTo%2fPages%2fdefault.aspx%3fu%3d' + encodeURIComponent(this.options.share_url) ) }.bind(this));
        
        this.technorati_btn = new Element('img',{'src':'/obray/images/oplayer/technorati-btn.png'});
        this.technorati_btn.setStyles({'margin':4,'margin-top':10});
        
        this.technorati_btn.addEvent('click',function(){ window.open('http://technorati.com/faves?add=' + encodeURIComponent(this.options.share_url),'_blank'); }.bind(this));
        
        // this.wordpress_btn = new Element('img',{'src':'/obray/images/oplayer/wordpress-btn.png'});
        // this.wordpress_btn.setStyles({'margin':4,'margin-top':10});
        // this.wordpress_btn.inject(this.share_icons);
        
        // this.blogger_btn = new Element('img',{'src':'/obray/images/oplayer/blogger-btn.png'});
        // this.blogger_btn.setStyles({'margin':4,'margin-top':10});
        // this.blogger_btn.inject(this.share_icons);
        
        this.delicious_btn = new Element('img',{'src':'/obray/images/oplayer/delicious-btn.png'});
        this.delicious_btn.setStyles({'margin':4,'margin-top':10});
        
        this.delicious_btn.addEvent('click',function(){ window.open('http://delicious.com/save?jump=yes&url=' + encodeURIComponent(this.options.share_url),'_blank'); }.bind(this));
        
        this.digg_btn = new Element('img',{'src':'/obray/images/oplayer/digg-btn.png'});
        this.digg_btn.setStyles({'margin':4,'margin-top':10});
        
        this.digg_btn.addEvent('click',function(){ window.open('http://digg.com/submit?phase=2&url=' + encodeURIComponent(this.options.share_url),'_blank'); }.bind(this));
        
        this.stumble_btn = new Element('img',{'src':'/obray/images/oplayer/stumble-btn.png'});
        this.stumble_btn.setStyles({'margin':4,'margin-top':10});
        
        this.stumble_btn.addEvent('click',function(){ window.open('http://www.stumbleupon.com/submit?url=' + encodeURIComponent(this.options.share_url),'_blank'); }.bind(this));
    },
    
    open: function(){
        this.share_container.setStyles({'display':'block'});
    },
    
    close: function(){
        this.share_container.setStyles({'display':'none'});
    },
    
    inject: function(el){
        this.share_container.inject(el);
        this.share_label.inject(this.share_container);
        this.share_input.inject(this.share_container);
        
        this.share_message.inject(this.share_container);
        this.send_again_btn.inject(this.share_message);
        
        this.share_icons.inject(this.share_container);
        this.share_btn.inject(this.share_icons);
        this.facebook_btn.inject(this.share_icons);
        this.twitter_btn.inject(this.share_icons);
        this.myspace_btn.inject(this.share_icons);
        this.technorati_btn.inject(this.share_icons);
        this.delicious_btn.inject(this.share_icons);
        this.digg_btn.inject(this.share_icons);
        this.stumble_btn.inject(this.share_icons);
    }
});

VideoVolume = new Class({
    Implements: Options,
    
    options:{
        'position':{'x':0,'y':0},
        'onChange':$empty,
        'volume':75
    },
    
    initialize: function(options){
        this.setOptions(options);
        
        this.volume_container = new Element('div',{'class':'ovideo-volume-container'});
        this.volume_container.setStyles({'display':'none','background-image':'url(/obray/images/oplayer/volume-popup.png)','position':'absolute','left':this.options.position.x,'top':this.options.position.y,'width':28,'height':188});
        this.volume_container.addEvent('click',function(e){
            e.stopPropagation();
        }.bind(this));
        
        this.volume_track = new Element('div',{'class':'ovideo-volume-track'});
        this.volume_track.setStyles({'position':'relative','display':'block','height':154,'width':1,'border':'0px solid #000','margin-left':13,'margin-right':13,'margin-top':11});
        
        
        this.volume_handle = new Element('div',{'class':'ovideo-volume-handle'});
        this.volume_handle.setStyles({'position':'absolute','display':'block','top':0,'left':-2,'width':7,'height':7,'background-color':'#fff','cursor':'pointer'});
        
        this.volume_handle.addEvent('click',addEvent('click',function(e){
            e.stopPropagation();
        }.bind(this)));
        
        this.volume_container.addEvent('mouseleave',function(){
        	this.close();
        }.bind(this))
    },
    
    open: function(){
        this.volume_container.setStyles({'display':'block'});
        if(!this.volume_control){ 
            this.volume_control = new Slider(this.volume_track,this.volume_handle,{'mode':'vertical','steps':100,'onChange':this.options.onChange});
            this.volume_control.set(this.options.volume);
        }
    },
    
    close: function(){
        this.volume_container.setStyles({'display':'none'});
    },
    
    inject: function(el){
        this.volume_container.inject(el);
        this.volume_track.inject(this.volume_container);
        this.volume_handle.inject(this.volume_track);
        
    }
});


// JavaScript Document
PlayerControls = new Class({
    Implements: Options,
    
    options:{
        'video_id':0,
        'width':500,
        'height':282,
        'html5':false,
        'video': new Element('video'),
        'cover':'/assets/videos/video-cover-image.png',
        'enable_embed':true,
        'enable_share':true,
        'video_image_name':'',
        'video_image_ext':'',
        'video_image_location':'',
        'embed_code':'',
        'share_url':'',
        'video_autoplay':'',
        'expand_window':true,
		'enable_scrub':true,
		'enable_buffer':false
    },
    
    initialize: function(options){
        this.setOptions(options);
        
        this.play_status = 'stopped';
        this.embed_status = 'closed';
        this.share_status = 'closed';
        this.volume_status = 'closed';
        this.screen_status = 'normal';
        
        if(this.options.video_image_location == "Amazon S3"){ var image_location = window.obray.amazon_location; } else { var image_location = '/assets/images/'; }
        this.video_still = new Element('img',{'src':image_location+this.options.video_image_name+'_standard.'+this.options.video_image_ext,'class':'video-still'});
        this.video_still.setStyles({'position':'absolute','z-index':2997,'top':0,'left':0,'display':'block'});
        
        this.control_overlay = new Element('div',{'class':'ovideo-control-overlay'});
        this.control_overlay.setStyles({'background-image':'url('+this.options.cover+')','background-position':'50% 50%','position':'absolute','overflow':'hidden','top':0,'left':0,'display':'block','width':this.options.width,'height':this.options.height,'z-index':2998});
        this.control_overlay.addEvent('mouseenter',function(){ this.control_bar_fx.pause(); this.control_bar_fx.start({'bottom':0}); }.bind(this));
        this.control_overlay.addEvent('mouseleave',function(){ 
            if(this.embed_status != 'open' && this.share_status != 'open' && this.volume_status != 'open'){
                this.control_bar_fx.pause(); 
                this.control_bar_fx.start({'bottom':-this.control_bar.getCoordinates().height});
            }
        }.bind(this))
        this.control_overlay.addEvent('click',this.togglePlayStatus.bind(this))
        
        this.control_bar = new Element('div',{'class':'ovideo-control-bar','id':this.options.id});
        this.control_bar.setStyles({'position':'absolute','bottom':0,'left':0,'width':this.options.width,'height':30,'background-image':'url(/obray/images/oplayer/control-bar-bg.png)'});
        
        this.control_bar_fx = new Fx.Morph(this.control_bar,{duration:250,transition: Fx.Transitions.Quint.easeOut});
        this.control_bar.addEvent('click',function(e){ e.stopPropagation(); }.bind(this));
        
        this.play_and_pause_btn = new Element('div',{'class':'ovideo-play-and-pause-btn'});
        this.play_and_pause_btn.setStyles({'float':'left','width':30,'height':30,'background-image':'url(/obray/images/oplayer/play-btn.png)','cursor':'pointer'});
        
        this.play_and_pause_btn.addEvent('click',this.togglePlayStatus.bind(this));
        this.play_and_pause_btn.addEvent('mouseenter',function(){
            if(this.play_status == 'stopped'){
                this.play_and_pause_btn.setStyles({'background-image':'url(/obray/images/oplayer/play-btn-hover.png)'});
            } else {
                this.play_and_pause_btn.setStyles({'background-image':'url(/obray/images/oplayer/pause-btn-hover.png)'});
            }
        }.bind(this));
        this.play_and_pause_btn.addEvent('mouseleave',function(){ 
            if(this.play_status == 'stopped'){
                this.play_and_pause_btn.setStyles({'background-image':'url(/obray/images/oplayer/play-btn.png)'});
            } else {
                this.play_and_pause_btn.setStyles({'background-image':'url(/obray/images/oplayer/pause-btn.png)'});
            }
        }.bind(this));
                
        this.scrub_bar = new Element('div',{'class':'ovideo-scrub-bar'});
        var scrub_bar_width = 317;
        if(!this.options.enable_embed){scrub_bar_width = scrub_bar_width - 53;}
        if(!this.options.enable_share){scrub_bar_width = scrub_bar_width - 52;}
        
        this.scrub_bar.setStyles({'float':'left','position':'relative','width':(this.options.width-scrub_bar_width),'height':3,'background-color':'#858585','margin-top':14,'margin-bottom':12,'margin-left':3})
        
        
        this.scrub_progress = new Element('div',{'class':'ovideo-scrub-progress'});
        this.scrub_progress.setStyles({'position':'absolute','top':-1,'left':-1,'height':5,'width':0,'background-color':'#fff'});
        
        
        this.scrub_progress_handle = new Element('div',{'class':'ovideo-scrub-handle'});
        this.scrub_progress_handle.setStyles({'position':'absolute','left':-1,'top':-2,'width':7,'height':7,'cursor':'pointer','background-color':'#ffffff','margin':0,'padding':0});
        
        
        this.scrub_buffer = new Element('div',{'class':'ovideo-scrub-buffer'})
        this.scrub_buffer.setStyles({'position':'absolute','top':-1,'left':-1,'height':5,'width':0,'background-color':'#777'});
        
        
        this.timer = new Element('div',{'class':'ovideo-timer'});
        this.timer.setStyles({'float':'left','font-family':'Arial,Helvetica','color':'#fff','font-size':10,'width':75,'text-align':'center','padding':10});
        this.timer.set('html','00:00 | 00:00');
        
        
        this.embed_btn = new Element('div',{'class':'ovideo-embed-btn'});
        this.embed_btn.setStyles({'position':'relative','width':31,'float':'left','font-family':'Arial,Helvetica','color':'#fff','font-size':10,'padding':10,'letter-spacing':-1,'cursor':'pointer','border-left':'2px solid #343434'});
        this.embed_btn.set('html','EMBED');
        
        this.embed_btn.addEvent('mouseenter',function(){ this.embed_btn.setStyles({'color':'#9b9b9b','background-image':'url(/obray/images/oplayer/btn-hover.png)'}); }.bind(this));
        this.embed_btn.addEvent('mouseleave',function(){ if(this.embed_status == 'closed'){ this.embed_btn.setStyles({'color':'#fff','background-image':'none'}); } }.bind(this));
        this.embed_btn.addEvent('click',this.toggleEmbed.bind(this));
        this.embed_popup = new VideoEmbed({'position':{'y':-84,'x':-170},'embed_code':this.options.embed_code});
        
        
        this.share_btn = new Element('div',{'class':'ovideo-share-btn'});
        this.share_btn.setStyles({'position':'relative','width':30,'float':'left','font-family':'Arial,Helvetica','color':'#fff','font-size':10,'padding':10,'letter-spacing':-1,'cursor':'pointer','border-left':'2px solid #343434'});
        this.share_btn.set('html','SHARE');
        
        this.share_btn.addEvent('mouseenter',function(){ this.share_btn.setStyles({'color':'#9b9b9b','background-image':'url(/obray/images/oplayer/btn-hover.png)'}); }.bind(this));
        this.share_btn.addEvent('mouseleave',function(){  if(this.share_status == 'closed'){ this.share_btn.setStyles({'color':'#fff','background-image':'none'});} }.bind(this)); 
        this.share_btn.addEvent('click',this.toggleShare.bind(this));
        this.share_popup = new VideoShare({'position':{'x':-170,'y':-190},'share_url':this.options.share_url,'video_id':this.options.video_id});
        
        
        this.volume_btn = new Element('div',{'class':'ovideo-volumn-btn'});
        this.volume_btn.setStyles({'position':'relative','float':'left','background-image':'url(/obray/images/oplayer/volume-btn.png)','font-family':'Arial,Helvetica','color':'#fff','font-size':10,'height':10,'width':10,'padding':10,'letter-spacing':-1,'cursor':'pointer','border-left':'2px solid #343434'});
        
        this.volume_btn.addEvent('mouseenter',function(){ this.volume_btn.setStyles({'background-image':'url(/obray/images/oplayer/volume-btn-hover.png)'}); }.bind(this));
        this.volume_btn.addEvent('mouseleave',function(){ this.volume_btn.setStyles({'background-image':'url(/obray/images/oplayer/volume-btn.png)'}); }.bind(this));
        this.volume_btn.addEvent('click',this.toggleVolume.bind(this));
        this.volume_popup = new VideoVolume({'position':{'x':0,'y':-195},'onChange':function(step){
            if(!this.options.html5){ this.options.video.setVolume(100-step); } else { }
        }.bind(this)});
        
        
        if(this.options.expand_window){
            
            this.expand_btn = new Element('div',{'class':'ovideo-fullscreen-btn'})
            this.expand_btn.setStyles({'float':'left','background-image':'url(/obray/images/oplayer/expand-btn.png)','font-family':'Arial,Helvetica','color':'#fff','font-size':10,'padding':10,'height':10,'width':30,'letter-spacing':-1,'cursor':'pointer','border-left':'2px solid #343434'});
            
            this.expand_btn.addEvent('mouseenter',function(){ this.expand_btn.setStyles({'background-image':'url(/obray/images/oplayer/expand-btn-hover.png)'}); }.bind(this));
            this.expand_btn.addEvent('mouseleave',function(){ this.expand_btn.setStyles({'background-image':'url(/obray/images/oplayer/expand-btn.png)'}); }.bind(this));
            //expand window
            
            
            
        }
        
        /**********************************
        	Buffer
        **********************************/
        this.buffer = new Element('div',{'class':'ovide-player-buffer'});
        this.buffer.setStyles({'float':'left','position':'relative','height':30,'width':100,'color':'#fff','font-size':10,'padding-top':10,'font-family':'Helvetica,Arial'});
        
    },
    
    inject: function(el){
        if( this.options.video_image_name != undefined ){ this.video_still.inject(el); }
        this.control_overlay.inject(el);
        
        this.control_bar.inject(this.control_overlay);
        this.play_and_pause_btn.inject(this.control_bar);
        
		if(this.options.enable_scrub) {
	        this.scrub_bar.inject(this.control_bar);
	        this.scrub_progress.inject(this.scrub_bar);
	        this.scrub_buffer.inject(this.control_bar);
	        this.scrub_progress_handle.inject(this.scrub_bar);
		}
        this.timer.inject(this.control_bar);
        if(this.options.enable_buffer){
        	this.buffer.inject(this.control_bar);
        	//this.updateBuffer.periodical(50,this);
        }
        if(this.options.enable_embed){this.embed_btn.inject(this.control_bar);}
        this.embed_popup.inject(this.embed_btn);
        if(this.options.enable_share){this.share_btn.inject(this.control_bar);}
        this.share_popup.inject(this.share_btn);
        
        this.volume_btn.inject(this.control_bar);
        this.volume_popup.inject(this.volume_btn);
        
        if(this.options.expand_window){
        	this.expand_btn.inject(this.control_bar);
        	
        	
        	this.expand_window = new sbox({'scrollable':false,'close':function(){ 
                this.big_player.controls.pause(); 
            }.bind(this)});
            
            //create larger video player
            this.expand_btn.addEvent('click',function(){
                // calculate new height
                this.pause();
                this.nw = window.getCoordinates().width-100;
                this.nh = (this.nw * this.options.height) / this.options.width;
                this.expand_window.setOptions({'width':this.nw,'height':this.nh,'startx':this.expand_btn.getCoordinates().left,'starty':this.expand_btn.getCoordinates().top});
                this.expand_window.content.set('html','');
                this.big_player = new Player({
                    'video_width':this.nw,
                    'video_height':this.nh,
                    'video_image_id':'',
                    'video_size':0,
                    'video_length':0,
                    'video_name':this.options.video_name,
                    'video_ext':this.options.video_ext,
                    'video_autoplay':true,
                    'video_embed':false,
                    'video_share':false,
                    'cover':'/assets/videos/video-cover-image.png',
                    'embed_code':'',
                    'share_url':'',
                    'expand_window':false
                })
                
                this.big_player.inject(this.expand_window.content);
                this.expand_window.open();
            }.bind(this));
            
        }
        
        this.control_bar_fx.pause();
        this.control_bar_fx.start({'bottom':-this.control_bar.getCoordinates().height});
        this.scrub_control = new Slider(this.scrub_bar,this.scrub_progress_handle,{'mode':'horizontal','steps':1000,'onChange':this.setProgress.bind(this),'onComplete':this.scrub.bind(this)});
        //events
        if(!this.options.html5){

        }
       
        if(this.options.video_autoplay){ 
        	//this.options.video.load(this.togglePlayStatus.bind(this,new Event())) 
        }
    },
    
    play: function(){
        this.options.video.play();
        this.play_and_pause_btn.setStyles({'background-image':'url(/obray/images/oplayer/pause-btn.png)'});
        this.control_overlay.setStyles({'background-image':'url(/obray/images/oplayer/overlay-bg.png)'});

        this.video_still.setStyles({'display':'none'});
        this.play_status = 'playing';
        this.progress_timer_interval = this.updateProgress.periodical(50,this);
    },
    
    pause: function(){
        $clear(this.progress_timer_interval);
        this.options.video.pause();
        this.play_and_pause_btn.setStyles({'background-image':'url(/obray/images/oplayer/play-btn.png)'});
        this.control_overlay.setStyles({'background-image':'url('+this.options.cover+')'});
        this.play_status = 'stopped';
    },
    
    togglePlayStatus: function(e){
        e.stopPropagation();
        if(this.play_status == 'stopped'){ this.play(); } else { this.pause(); }
    },
    
    autoplay: function(){
    	    this.play_and_pause_btn.setStyles({'background-image':'url(/obray/images/oplayer/pause-btn.png)'});
            this.control_overlay.setStyles({'background-image':'url(/obray/images/oplayer/overlay-bg.png)'});
            this.video_still.setStyles({'display':'none'});
            this.play_status = 'playing';
            this.progress_timer_interval = this.updateProgress.periodical(50,this);
    },
    
    buffer: function(){
    
    },
    
    toggleEmbed: function(){
        if(this.embed_status == 'closed'){
            this.embed_popup.open();
            this.embed_status = 'open';
        } else {
            this.embed_popup.close();
            this.embed_status = 'closed';
        }
    },
    
    toggleShare: function(){
        if(this.share_status == 'closed'){
            this.share_popup.open();
            this.share_status = 'open';
        } else {
            this.share_popup.close();
            this.share_status = 'closed';
        }
    },
    
    toggleVolume: function(){
        if(this.volume_status == 'closed'){
            this.volume_popup.open();
            this.volume_status = 'open';
        } else {
            this.volume_popup.close();
            this.volume_status = 'closed';
        }
    },
	
	getStatus: function() { // Fix to counter the missing getStatus function
		this.getCurrentStatus();
	},
    
    getCurrentStatus: function(){
        if(!this.options.html5){
            var status = this.options.video.getStatus();
            var video_status = {
                'current_time':status.time,
                'duration': this.options.video.getClip().fullDuration,
                'buffer_start':status.bufferStart,
                'buffer_end':status.bufferEnd
            }
        } else {
            var video_status = {
                'current_time':this.options.video.currentTime,
                'duration': this.options.video.duration,
                'buffer_start':0,
                'buffer_end':0
            }
        }
        return video_status;
    },
    
    scrub: function(position){
        // need duration
        var status = this.getCurrentStatus();
        // convert the position into the seconds
        var seconds = position * status.duration/1000;
        // scrub to the specified time
        if(!this.options.html5){ this.options.video.seek(seconds); this.setProgress(position); } else { this.options.video.currentTime = seconds; }
    },
    
    updateProgress: function(){
        this.setProgress(false);
    },
    
    timeFormat: function(time_in_sec){
        var time_string_hr  = time_in_sec / 3600;
        var time_string_min = time_in_sec / 60;
        var time_string_sec = time_in_sec % 60;
        
        (time_string_hr.toInt()  < 10) ? time_string_hr=  ('0' + time_string_hr.toInt())  : time_string_hr=time_string_hr.toInt();
        (time_string_min.toInt() < 10) ? time_string_min= ('0' + time_string_min.toInt()) : time_string_min=time_string_min.toInt();
        (time_string_sec.toInt() < 10) ? time_string_sec= ('0' + time_string_sec.toInt()) : time_string_sec=time_string_sec.toInt();
        
        var time_string = time_string_min + ':' + time_string_sec;
        if(time_string_hr > 0){time_string_hr + ':' + time_string;}
        return time_string;
    },
    
    setProgress: function(position){
        // get current time, buffer, duration, etc...
        var status = this.getCurrentStatus();
        // if position isn't defined then set the position based on current time & duration
        if(!position){ var position = (status.current_time/status.duration*1000).toInt(); }
        // determine progres bar width
        var width = (this.scrub_bar.getCoordinates().width*(position/1000)).toInt();
        // set progress bar width
        this.scrub_progress.setStyles({'width':width+2});
        
        // set scrub handles position
        if(isNaN(position)){position=0;}
        this.scrub_control.set(position);
        // scrub the movie to the correct time
        if(this.options.html5){ this.scrub(position); }
        // get formatted times
        var time_current = this.timeFormat(status.current_time);
        var time_duration = this.timeFormat(status.duration);
        // show formatted times
        this.timer.set('html',time_current + ' | ' + time_duration);
    },
    
    updateBuffer: function(){
    	if(this.options.video.isLoaded()){
	    	var status = this.getCurrentStatus();
	    	if(this.options.enable_buffer){
				    		
	        	var buffer = status.buffer_end / status.duration * 100;
	        		this.buffer.set('html','Downloading: ' + buffer.toInt() + '%');
	        }
        }
    }
    
    
    
});


Player = new Class({
    Implements: Options,
    
    options:{
        'content_area_id':0,
		'content_part_id':0,
	    'content_order':0,
		'video_id':0,
		'video_title':'',
		'video_description':'',
		'video_width':500,
		'video_height':282,
		'video_image_id':'',
		'video_size':0,
		'video_length':0,
		'video_name':'sample',
		'video_ext':'mp4',
		'video_autoplay':false,
		'video_embed':true,
		'video_share':true,
		'cover':'/assets/videos/video-cover-image.png',
		'embed_code':'',
		'share_url':'',
		'expand_window':true,
		'background-color':'#000',
		'enable_scrub':true,
		'onFinish':$empty,
		'video_on_amazon':false,
		'amazon_path':'',
		'enable_buffer':false
		
    },
    
    initialize: function(options){
        this.setOptions(options);
        
        this.ovideo_container = new Element('div',{'class':'ovideo-container'});
        this.ovideo_container.setStyles({'position':'relative','left':0,'top':0,'height':this.options.video_height,'width':this.options.video_width});
        
		
		
    },
    
    onLoad: function(){
    	
    },
    
    isHTML5Compatible: function(){
	    var isHTML5Compatible = false;
	    var video_types = ['video/mp4'];
	    var detect = document.createElement('video');
		if (typeof detect.canPlayType === 'function') {
            if(detect.canPlayType('video/mp4') != 'no' || detect.canPlayType('video/mp4') != ''){
                isHTML5Compatible = true;
            }
        }
        return false;
	},
	
	getStatus: function() {
		// Fix	
	},
	
	inject: function(el,position){
	    this.ovideo_container.inject(el,position);
	    this.injectOther();
		if(!this.options.enable_scrub) this.controls.setOptions({'enable_scrub':false});
	    this.controls.inject(this.ovideo_container);
		this.ovideo.load();
	},
	
	injectAfter: function(el){
		this.ovideo_container.inject(el,'after');
		this.injectOther();
		this.controls.inject(this.ovideo_container);
		this.ovideo.load();
	},
	
	injectInside: function(el){
		this.ovideo_container.inject(el);
		this.injectOther();
		this.controls.inject(this.ovideo_container);
		this.ovideo.load();	
	},
	
	getPlayer: function(){
	    return this.ovideo_container;
	},
	
	setDimensions: function(width,height){
	    this.ovideo_container_fx.start({'width':width,'height':height});
	},
	
	loadLoader: function(){
		
		this.loader = new Element('div',{'class':'ovideo-loader'});
		this.loader.setStyles({'position':'absolute','color':'#fff','font-family':'Helvetica,Arial','font-size':14,'z-index':10000,'padding':15});
		this.loader.set('html','Loading player, please wait...');
		
	},
	
	injectOther: function(){
		if(this.isHTML5Compatible()){
		    this.ovideo = new Element('video',{'id':'OVideo-'+this.options.content_part_id,'autoplay':this.options.video_autoplay,'src':'assets/videos/'+this.options.video_name+'.'+this.options.video_ext,'height':this.options.video_height,'width':this.options.video_width});
            this.ovideo.setStyles({'background-color':this.options['background-color'],'height':this.video_height,'width':this.video_width});
            this.ovideo.inject(this.ovideo_container);
            this.ovideo.addEventListener('ended',function(e){
                this.controls.togglePlayStatus(e);
            }.bind(this));
		} else {
		    this.ovideo = new Element('div',{'id':'OVideo-'+this.options.content_part_id,'class':'OVideo'});
            this.ovideo.setStyles({'height':this.options.video_height,'width':this.options.video_width,'position':'absolute'});
            var path = ''
            if( this.options.video_on_amazon == true){
            	path = this.options.amazon_path;
            } else {
            	path = '/assets/videos/'+this.options.video_name+'.'+this.options.video_ext;
            }
            
            this.loadLoader();
            this.loader.inject(this.ovideo_container);
            
            if(Browser.Engine.name == 'trident'){ var cachebusting = true; } else { var cachebusting = false; }
            
            this.movie = $f(this.ovideo,{'src':'/obray/flash/flowplayer.swf','wmode':'opaque','cachebusting':cachebusting},{
                'class':'ovideo',
                'plugins': {'controls': null},
                'clip': { 
                    'url': path, 
                    'autoPlay': this.options.video_autoplay, 
                    'autoBuffering': false,
                    'scaling':'fit',
                    'bufferLength':30,
                    'onBegin':function(){
                    	this.loader.destroy();
                    	this.controls.updateBuffer.periodical(50,this.controls);
                    }.bind(this),
                    'onStart':function(){
                    	this.controls.autoplay();
                    }.bind(this),
                    'onLoad':function(e){
                        this.controls.togglePlayStatus(e);
                    }.bind(this),
                    'onLastSecond':function(){
                    	//alert('onLastSecon');
                    	this.options.onFinish.delay(250);
                    }.bind(this),
					'onFinish':function() {
						//alert('finished');
						this.options.onFinish.delay(250);
					}.bind(this)
                },
                'onLoad':this.onLoad.bind(this),
				'onFinish':function() {
				}.bind(this)
            });
            this.ovideo.inject(this.ovideo_container);
            this.ovideo = this.movie;
            
            this.ovideo_container_fx = new Fx.Morph(this.ovideo_container,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
            //this.ovideo_fx = new Fx.Morph(this.image_btn,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
		}
		
		this.controls = new PlayerControls({
		    'video_id':this.options.video_id,
		    'width':this.options.video_width,
		    'height':this.options.video_height,
		    'html5':this.isHTML5Compatible(),
		    'video':this.ovideo,
		    'video_name':this.options.video_name,
		    'video_ext':this.options.video_ext,
		    'cover':this.options.cover,
		    'enable_share':this.options.video_share,
		    'enable_embed':this.options.video_embed,
		    'video_image_name':this.options.video_image_name,
		    'video_image_ext':this.options.video_image_ext,
		    'video_image_location':this.options.video_image_location,
		    'embed_code':this.options.embed_code,
		    'share_url':this.options.share_url,
		    'video_autoplay':this.options.video_autoplay,
		    'expand_window':this.options.expand_window,
		    'enable_buffer':this.options.enable_buffer
		})
	}
	
	
	
	
});

OVideoSettings = new Class({
    Implements: Options,
    
    options: {
        'video_id':0,
        'video_width':500,
        'video_height':282,
        'video_name':'sample',
        'video_ext':'mp4',
        'video_autoplay':false,
        'video_embed':true,
        'video_share':true,
        'video_title':'',
        'video_descrption':'',
        'video_size':0,
        'onComplete':$empty,
        'video_image_name':'',
        'video_image_id':'',
        'video_image_ext':'',
        'share_url':''
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.settings = new Element('div',{'class':'ovideo-settings-container'});
        this.settings.setStyles({'padding':20});
        
        this.video_btn = new Element('input',{'type':'button','value':'Save Video'});
                
        this.settings_form = new OForm({
            'orientation':'vertical',
            'background-color':'transparent',
            'highlight-color':'#252525',
            'label-color':'#858585',
            'label-width':100,
            'input-width':250,
            'input-color':'#d5d5d5',
            'label-font-size':12,
            'input-font-size':12,
            'border':'1px solid #454545',
            'btn-background-color':'#252525',
            'btn-color':'#858585',
            'btn-font':'Arial,Helvetica',
            'url':'index.cfm?action=videos.saveVideo&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true',
            'button':this.video_btn,
            'onComplete':this.options.onComplete
        });
        
 
        
        this.settings_form.addElement(new OFFile({'label':'Upload Video','name':'file_name','file_types':{'Videos (*.mov, *.mp4, *.flv)':'*.mov; *.mp4; *.flv;'},'file_name':this.options.video_name,'file_ext':this.options.video_ext,'file_size':this.options.video_size,'onUploadSuccess':$empty}));
		
        this.settings_form.addElement(new OFText({'label':'Dimensions','name':'video_width','blur':function(){ this.settings_form.elements[3].setDimensions(this.settings_form.elements[1].getProperty('value'),this.settings_form.elements[2].getProperty('value')); }.bind(this)}));
        
        this.settings_form.elements[1].text_input.setStyles({'width':50});
        
        this.settings_form.addElement(new OFText({'label':'X','name':'video_height','blur':function(){ this.settings_form.elements[3].setDimensions(this.settings_form.elements[1].getProperty('value'),this.settings_form.elements[2].getProperty('value')); }.bind(this)}));
        
        this.settings_form.addElement(new OFImage({'label':'Video Thumb','name':'video_image_id','image_width':this.options.video_width,'image_height':this.options.video_height,'image_id':this.options.video_image_id,'image_name':this.options.video_image_name,'image_ext':this.options.video_image_ext}));
        this.settings_form.addElement(new OFText({'label':'Video Title','name':'video_title','value':this.options.video_title}));
        this.settings_form.addElement(new OFText({'label':'Video Description','name':'video_description','text-area':true,'value':this.options.video_description}));
        this.settings_form.addElement(new OFCheck({'label':'Autoplay','name':'video_autoplay','checked':this.options.video_autoplay}));
        this.settings_form.addElement(new OFCheck({'label':'Embed','name':'video_embed','checked':this.options.video_embed}));
        this.settings_form.addElement(new OFCheck({'label':'Share','name':'video_share','checked':this.options.video_share}));
        this.settings_form.addElement(new OFHidden({'value':this.options.video_id,'name':'video_id'}));
        
        
       
        
               
        
    },
    
    inject: function(el){
        this.settings.inject(el);
        this.settings_form.inject(this.settings);
        
        this.settings_form.elements[1].text_input.getParent().getNext().destroy();
        this.settings_form.elements[6].checkbox_label.getNext().destroy();
        this.settings_form.elements[6].checkbox_label.setStyles({'width':48});
        this.settings_form.elements[7].checkbox_label.getNext().destroy();
        this.settings_form.elements[7].checkbox.setStyles({'margin-left':10});
        this.settings_form.elements[7].checkbox_label.setStyles({'width':39});
        this.settings_form.elements[8].checkbox.setStyles({'margin-left':10});
        this.settings_form.elements[8].checkbox_label.setStyles({'width':39});
        this.settings_form.elements[2].text_label.setStyles({'width':6});
        this.settings_form.elements[2].text_input.setStyles({'width':50});
        
    },
    
    setDimensions: function(x,y){
        this.settings_form.elements[1].setProperty('value',x);
        this.settings_form.elements[2].setProperty('value',y);
    }
});

OVideo = new Class({
	Implements: [Options],
	
	options: {
		'content_area_id':0,
		'content_part_id':0,
	    'content_order':0,
		'video_id':0,
		'video_title':'',
		'video_description':'',
		'video_width':500,
		'video_height':282,
		'video_image_id':'',
		'video_size':0,
		'video_length':0,
		'video_name':'sample',
		'video_ext':'mp4',
		'video_image_location':'',
		'video_autoplay':false,
		'video_embed':true,
		'video_share':true,
		'share_url':''
	},
	
	initialize: function(options){
		// data members
		this.setOptions(options);
		
		// create player
		this.player = new Player({
            'content_area_id':this.options.content_area_id,
            'content_part_id':this.options.content_part_id,
		    'content_order':this.options.content_order,
            'video_id':this.options.video_id,
            'video_width':this.options.video_width,
            'video_height':this.options.video_height,
            'video_image_id':this.options.video_image,
            'video_image_name':this.options.video_image_name,
            'video_image_ext':this.options.video_image_ext,
            'video_image_location':this.options.video_image_location,
            'video_size':this.options.video_size,
            'video_length':this.options.video_length,
            'video_name':this.options.video_name,
            'video_ext':this.options.video_ext,
            'video_autoplay':this.options.video_autoplay,
            'video_embed':this.options.video_embed,
            'video_share':this.options.video_share,
            'share_url':this.options.share_url
		});
		
		window['player'+this.options.content_part_id] = this.player;
		
		this.video_delete_btn = new Element('img',{'src':'/obray/images/box/boxClose_btn.png'});
		this.video_delete_btn.setStyles({'position':'absolute','right':-15,'top':-15,'z-index':2999});
		
		this.video_delete_btn.addEvent('click',function(){
            var deletePart = new Request({'url':'index.cfm?action=pages.deleteContentPart','data':'&content_part_id='+this.options.content_part_id,'onComplete':function(){
                var location = window.location.href.replace(window.location.hash,'');
                var location = location.replace('##','');
                window.location = location;									 
            }}).send();
		}.bind(this));
		
		//this.video_edit_btn.inject(this.player.getPlayer());
		this.video_settings_btn = new Element('img',{'src':'/obray/images/btn-settings-small.png'});
		this.video_settings_btn.setStyles({'position':'absolute','right':17,'top':-6,'cursor':'pointer','z-index':2999});
		
		this.video_settings_btn.addEvent('click',function(){
            this.video_settings_box = new sbox({'width':430,'height':500});
            this.settings = new OVideoSettings({
                'content_area_id':this.options.content_area_id,
                'content_part_id':this.options.content_part_id,
                'video_id':this.options.video_id,
                'video_title':this.options.video_title,
                'video_description':this.options.video_description,
                'video_name':this.options.video_name,
                'video_ext':this.options.video_ext,
                'video_width':this.options.video_width,
                'video_height':this.options.video_height,
                'video_image_id':this.options.video_image_id,
                'video_size':this.options.video_size,
                'video_length':this.options.video_length,
                'video_image_name':this.options.video_image_name,
                'video_image_ext':this.options.video_image_ext,
                'video_autoplay':this.options.video_autoplay,
                'video_embed':this.options.video_embed,
                'video_share':this.options.video_share,
                'onComplete':function(json){
                    this.updateContentPart = new Request({'url':'index.cfm?action=pages.updateObrayContent&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true&content_part_id='+this.options.content_part_id+'&content_area_id='+this.options.content_area_id+'&video_id='+json.response.video.video_id+'&content_order='+this.options.content_order+'&content_part_type=video&content_text=&blog=false&content_language='+this.options.content_language,'onComplete':function(){
                        var location = window.location.href.replace(window.location.hash,'');
                        var location = location.replace('#','');
                        window.location = location;
                    }.bind(this)}).send();
                }.bind(this)
            });
            this.settings.settings.setStyles({'width':440});
            this.settings.setDimensions(this.options.video_width,this.options.video_height);
            var myFx = new Fx.Scroll(window).toTop();
		    this.settings.inject(this.video_settings_box.content);
            this.video_settings_box.open();
		}.bind(this))
	},
	
	handleWithFlash: function(){
	    var handle_with_flash = true;
	    var video_types = ['video/mp4'];
	    var detect = document.createElement('video');
		if (typeof detect.canPlayType === 'function') {
            if(detect.canPlayType('video/mp4') != 'no' || detect.canPlayType('video/mp4') != ''){
                handle_with_flash = false;
            }
        }
        return handle_with_flash;
	},
	
	inject: function(el,position){
	    this.player.inject(el,position);
	    this.injectOther();
	},
	
	injectAfter: function(el){
		this.player.injectAfter(el);
		this.injectOther();
	},
	
	injectInside: function(el){
		//this.player.injectInside(el);
		//this.injectOther();
	},
	
	injectOther: function(){
		this.video_delete_btn.inject(this.player.getPlayer());
		this.video_settings_btn.inject(this.player.getPlayer());
	}
	
}); /********************************************************************

	Icon class:  Creates and Icon for the Obray shelf

********************************************************************/
Icon = new Class({
	Implements: Options,
	
	options:{
		'id':0,
		'label':false
	},
	
	initialize: function(image,parent,options){
		
		//data members
		this.setOptions(options)
		this.parent = parent;
		this.image = image;
		
		//generate HTML
		this.icon_container = new Element('div',{'class':'shelf_icon'});
		this.icon = new Element('div',{'class':'shelf_icon_img'});
		this.icon_label = new Element('div',{'class':'shelf_icon_label'})
		
		//set styles
		this.icon_container.setStyles({'float':'left','position':'relative','width':'128px','height':'128px','background-image':'url(obray/images/shelf/'+this.image+')','background-repeat':'no-repeat','margin':'5px'});
		this.icon.setStyles({'position':'relative','width':'59px','height':'59px','padding-left':'10px','cursor':'pointer','margin-left':10,'margin-right':10});
		this.icon_label.setStyles({'position':'absolute','bottom':'5px','font-family':'arial','color':'#666666','padding':'5px','text-align':'center','font-size':'14px','width':'118px'});
		
		//set text
		this.icon_label.set('html',this.options.label);
		
		//construct HTML
		this.icon.inject(this.icon_container);
		this.icon_label.inject(this.icon_container);
		this.icon_container.inject(this.parent);
	}
});
/********************************************************************

	IconDrag class:  creates a draggable icon for the Obray shelf

********************************************************************/
DragIcon = new Class({
	
	Extends: Icon,
	
	Implements: Options,
	
	options: {
		
	},
	
	initialize: function(image,parent,getDroppables,type,options){
		
		//data members
		this.parent(image,parent,options);
		
		//set style
		this.icon.setStyle('cursor','move');
		this.droppables = [];
		this.getDroppables = getDroppables;
		this.mouseOverDetectors = [];
		this.droppableTransition = new Fx.Transition(Fx.Transitions.Quad);
		this.type = type;
		
		//add Events
		this.icon.addEvent('mousedown',function(e){
			this.droppables = this.getDroppables();
			$$('.obray-show-help').setStyles({'display':'none'});
			this.droppables.each(function(el,index){
				var position = index;
				this.mouseOverDetectors[position] = new Element('div',{'class':'mouse_over_detectors'});
				
				this.mouseOverDetectors[position].setStyles({'position':'absolute','left':el.getPosition().x,'top':el.getPosition().y,'height':'30px','width':el.getCoordinates().width});
				this.mouseOverDetectors[position].inject('obray');
				this.mouseOverDetectors[position].droppable = this.droppables[position];
				this.mouseOverDetectors[position].fx = new Fx.Tween(this.droppables[position], {transition: this.droppableTransition.easeOut,duration: 200});
			}.bind(this));
			this.icon_draggable = this.icon.clone();
			this.icon_draggable.setStyles({'position':'absolute','left':this.icon.getPosition().x,'top':this.icon.getPosition().y+window.getScroll().y,'cursor':'move','z-index':'2000','opacity':'.5'});
			this.icon_draggable.inject('obray');
			
			var newDrag = new Drag.Move(this.icon_draggable,{handle: this.icon_dgraggable, droppables: this.mouseOverDetectors,
				onEnter: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','0px','59px');
					detector.setStyle('height','59px');
				}.bind(this),
				onLeave: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','59px','0px');
					detector.setStyle('height','30px');
				},
				onDrop: function(el,detector){
					if(!detector == false){
						detector.fx.pause();
						detector.fx.start('height','59px','0px');
						detector.setStyle('height','30px');
						this.detector = detector;
						var save = function(response){
							eval(response);
							this.linkProductAndImage = new Request({'url':'index.cfm?action=pages.updateObrayContent&content_part_id=0&content_area_id='+this.detector.droppable.content_area_id+'&image_id='+image_id+'&content_order='+(this.detector.droppable.order+1)+'&content_part_type=image&content_text=','onComplete':function(){
								var location = window.location.href.replace(window.location.hash,'');
									var location = location.replace('#','');
									window.location = location;
							}.bind(this)}).send();
						}
						
						window.obray.pictureBox = new ImageBox({
							'position':'absolute',
							'width':800,
							'height':712,
							'image_id': 0,
							'image_ext': 'jpg',
							'description':' ',
							'window_height': 413,
							'window_width': detector.getSize().x-30,
							'window_max_width': detector.getSize.x-30,
							'window_max_height': 1000,
							'zoom_level': 0,
							'resizable': false,
							'offset_x': 0,
							'offset_y': 0,
							'onSave': save.bind(this),
							'description_long':' '
						});
						window.obray.pictureBox.open('elastic');
					}
					this.mouseOverDetectors.each(function(el){
						el.destroy();
					});
					this.icon_draggable.destroy();
				}.bind(this)
			});
			newDrag.start(e);
			
		}.bind(this));
	}
	
});
/********************************************************************

	Template Icons

********************************************************************/
ClickIcon = new Class({
	Implements: Options,
	
	options:{
		'name':false,
		'thumbnail':false,
		'type':false
	},
	
	initialize: function(page_id,options){
		
		//data members
		this.setOptions(options);
		this.page_id = page_id;
		
		//genreate HTML
		this.icon = new Element('img',{'src':this.options.thumbnail,'class':'click_icon'});
		
		//set styles
		this.icon.setStyles({'float':'left','margin':'10px','margin-left':'10px','height':70,'width':70,'background-color':'#ffffff','cursor':'pointer'});
		
		//add events
		this.icon.addEvent('click',function(){
			if(this.options.type == 'template'){
				var string = '&page_id='+this.page_id + '&template_name=' + this.options.name;
				this.updateTemplate = new Request({'url':'index.cfm?action=pages.updateObrayTemplate','method':'post','data':string,'onComplete':function(){
					window.location = 'index.cfm?page_id='+this.page_id;
				}.bind(this)}).send();	
			}
			else if (this.options.type == 'layout'){
				var string = '&page_id='+this.page_id + '&layout_name=' + this.options.name;
				this.updateTemplate = new Request({'url':'index.cfm?action=pages.updateObrayLayout','method':'post','data':string,'onComplete':function(){
					window.location = 'index.cfm?page_id='+this.page_id;
				}.bind(this)}).send();
			}				
		}.bind(this));
	},
	
	get: function(){
		return this.icon;
	}
});
/********************************************************************

	ShelfBox: Create and icon that clicks open sub menu

********************************************************************/
ShelfBox = new Class({
					 
	Implements: Options,
	
	options: {
		'width':200,
		'height':false,
		'top':false,
		'left':false
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		
		//generate HTML
		this.box = new Element('div',{'class':'shelf_box'});
		this.box_tl = new Element('div',{'class':'shelf_box_tl'});
		this.box_tr = new Element('div',{'class':'shelf_box_tr'});
		this.box_bl = new Element('div',{'class':'shelf_box_bl'});
		this.box_br = new Element('div',{'class':'shelf_box_br'});
		this.box_t  = new Element('div',{'class':'shelf_box_t'});
		this.box_r  = new Element('div',{'class':'shelf_box_r'});
		this.box_l  = new Element('div',{'class':'shelf_box_l'});
		this.box_bml= new Element('div',{'class':'shelf_box_bml'});
		this.box_mt = new Element('div',{'class':'shelf_box_mt'});
		this.box_bmr= new Element('div',{'class':'shelf_box_bmr'});
		this.box_m  = new Element('div',{'class':'shelf_box_m'});
		
		//set styles
		var tempWidth = (this.options.width/2-17);
		this.box.setStyles({'position':'fixed','top':'0px','left':'0px','z-index':'3000'});
		this.box_tl.setStyles({'float':'left','height':'13px','width':'13px','background-image':'url(obray/images/shelf/shelf_box_tl.png)'});
		this.box_t.setStyles({'float':'left','height':'13px','width':this.options.width+'px','background-image':'url(obray/images/shelf/shelf_box_t.png)'});
		this.box_tr.setStyles({'float':'left','height':'13px','width':'13px','background-image':'url(obray/images/shelf/shelf_box_tr.png)'});
		this.box_l.setStyles({'clear':'both','float':'left','padding-left':'13px','background-image':'url(obray/images/shelf/shelf_box_l.png)','background-repeat':'repeat-y'});
		this.box_m.setStyles({'background-image':'url(obray/images/shelf/shelf_box_bg.png)','width':this.options.width+'px'});
		this.box_r.setStyles({'padding-right':'13px','background-image':'url(obray/images/shelf/shelf_box_r.png)','background-repeat':'repeat-y','background-position':'right'})
		this.box_bl.setStyles({'clear':'both','float':'left','height':'13px','width':'13px','background-image':'url(obray/images/shelf/shelf_box_bl.png)'});
		this.box_bml.setStyles({'float':'left','height':'13px','width':tempWidth+'px','background-image':'url(obray/images/shelf/shelf_box_b.png)'});
		this.box_mt.setStyles({'float':'left','height':'26px','width':'34px','background-image':'url(obray/images/shelf/shelf_box_tail.png)'});
		this.box_bmr.setStyles({'float':'left','height':'13px','width':tempWidth+'px','background-image':'url(obray/images/shelf/shelf_box_b.png)'});
		this.box_br.setStyles({'float':'left','height':'13px','width':'13px','background-image':'url(obray/images/shelf/shelf_box_br.png)'});
		if(this.options.height != false){
			this.box_m.setStyles({'height':this.options.height + 'px'});
		}
		
		
		//construct HT
		this.box_tl.inject(this.box);
		this.box_t.inject(this.box);
		this.box_tr.inject(this.box);
		this.box_l.inject(this.box);
		this.box_r.inject(this.box_l);
		this.box_m.inject(this.box_r);
		this.box_bl.inject(this.box);
		this.box_bml.inject(this.box);
		this.box_mt.inject(this.box);
		this.box_bmr.inject(this.box);
		this.box_br.inject(this.box);
		
		this.box.inject('obray');
		
		this.reposition();
		
	},
	
	reposition: function(){
		if(this.options.top != false){this.box.setStyles({'position':'fixed','top':(this.options.top.toInt() - this.box_m.getSize().y.toInt()-26)+'px'});}
		if(this.options.left != false){this.box.setStyles({'position':'fixed','left':(this.options.left.toInt()-this.options.width.toInt()/2+13)+'px'});}
	},
	
	close: function(){
		this.box.destroy();	
	}
});
/********************************************************************

	FontSelector: Create and icon that clicks open sub menu

********************************************************************/
TextPreview = new Class({
	Implements: Options,
	
	options: {
		'type':'p'
	},
	
	initialize: function(parent,droppables,window2,options){
		
		//data members
		this.setOptions(options);
		this.parent = parent;
		this.getDroppables = droppables;
		this.windowObj = window2;
		
		this.mouseOverDetectors = [];
		this.droppableTransition = new Fx.Transition(Fx.Transitions.Quad);
		//generate HTML
		this.text = new Element('div',{'class':'text_preview'});
		this.text_handle = new Element('div',{'class':'text_handle'});
		this.text_box = new Element('div',{'class':'text_box'});
		this.text_container = new Element('div',{'class':'text_container'});
		this.text_end = new Element('div',{'class':'text_end'});
		this.br = new Element('br',{'class':'clear'});
		
		//set styles
		this.text.setStyles({'padding':'3px'});
		this.text_handle.setStyles({'float':'left','width':'24px','height':'37px','background-image':'url(obray/images/shelf/font_handle.png)','cursor':'move'});
		this.text_box.setStyles({'position':'relative','float':'left','width':'150px','height':'35px','background-color':'#888888','opacity':1,'padding-left':'5px','border':'1px solid white'});
		this.text_end.setStyles({'float':'left','width':'12px','height':'37px','background-image':'url(obray/images/shelf/font_end.png)'});
		this.text_container.setStyles({'position':'absolute','left':'50%','top':'50%'});
		
		//construct HTML
		this.text_handle.inject(this.text);
		this.text_box.inject(this.text);
		this.text_end.inject(this.text);
		this.br.inject(this.text);
		this.text.inject(this.parent);
		if(this.options.type == 'h1'){
			this.text_box.set('html','<h1>Header 1</h1>');
			this.text_box.getFirst().setStyles({'padding':'0px','margin':'0px'});
		} else if(this.options.type == 'h2'){
			this.text_box.set('html','<h2>Header 2</h2>');
			this.text_box.getFirst().setStyles({'padding':'0px','margin':'0px','margin-top':'8px'});
		} else if(this.options.type == 'h3'){
			this.text_box.set('html','<h3>Header 3</h3>');
			this.text_box.getFirst().setStyles({'padding':'0px','margin':'0px','margin-top':'-2px'});
		} else if(this.options.type == 'h4'){
			this.text_box.set('html','<h4>Header 4</h4>');
			this.text_box.getFirst().setStyles({'padding':'0px','margin':'0px','margin-top':'2px'});
		} else if(this.options.type == 'p'){
			this.text_box.set('html','<p>Paragraph</p>');
			this.text_box.getFirst().setStyles({'padding':'0px','margin':'0px','margin-top':'10px'});
		} else if(this.options.type == 'ul'){
			this.text_box.set('html','<ul><li>List</li></ul>');
			this.text_box.getFirst().setStyles({'padding':'0px','margin':'0px','margin-top':'10px'});
		}
		
		this.text.addEvent('mousedown',function(e){
			this.droppables = this.getDroppables();
			$$('.obray-show-help').setStyles({'display':'block'});
			
			this.droppables.each(function(el,index){
				var position = index;
				this.mouseOverDetectors[position] = new Element('div',{'class':'mouse_over_detectors'});
				this.mouseOverDetectors[position].setStyles({'border':'1px solid white','position':'absolute','left':el.getPosition().x,'top':el.getPosition().y,'height':'30px','width':el.getCoordinates().width});
				this.mouseOverDetectors[position].inject('obray');
				this.mouseOverDetectors[position].droppable = this.droppables[position];
				this.mouseOverDetectors[position].fx = new Fx.Tween(this.droppables[position], {transition: this.droppableTransition.easeOut,duration: 200});
			}.bind(this));
												
			this.text_draggable = this.text.clone();
			this.text_draggable.setStyles({'position':'absolute','left':this.text.getPosition().x+'px','top':(this.text.getPosition().y+window.getScroll().y)+'px','opacity':'.85','z-index':10000});
			this.text_draggable.inject(document.body);
			var newDrag = new Drag.Move(this.text_draggable,{handle: this.tex_handle, droppables: this.mouseOverDetectors,
				onEnter: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','0px','59px');
					detector.setStyle('height','59px');
				}.bind(this),
				onLeave: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','59px','0px');
					detector.setStyle('height','30px');
				},
				onDrop: function(el,detector){
					$$('.obray-show-help').setStyles({'display':'none'})
					if(!detector == false){
						detector.fx.pause();
						detector.fx.start('height','59px','0px');
						detector.setStyles('height','30px')
						//alert("order: "+(parseInt(detector.droppable.content_order)+1));
						//alert(detector.droppable.siblings);
						//alert(detector.droppable.siblings.length);
						var newContent = new ContentPartV2(detector.droppable,{
							'content_part_id':0,
							'content_area_id':detector.droppable.content_area_id,
							'content_part_parent_id':detector.droppable.content_parent_id,
							'content_part_type':this.options.type,
							'content_language':window.obray.options.content_language,
							'content_order':(parseInt(detector.droppable.content_order)+1),
							'content_text':'',
							'image':{'image_id':0},
							'video':{'video_id':0},
							'siblings':detector.droppable.siblings
						});
						newContent.inject('after');
						var droppable = new Droppable(newContent.el,newContent,{
							'content_area_id':detector.droppable.content_area_id,
							'content_parent_id':detector.droppable.content_parent_id,
							'content_order':(parseInt(detector.droppable.content_order)+1),
							'siblings':detector.droppable.siblings.bind(detector.droppable.siblings)
						});
						droppable.inject('after');
						window.obray.addDroppable(droppable.get());
						
						this.droppables.each(function(el,index){
							if(el.content_area_id == detector.droppable.content_area_id && el.content_order >= parseInt(detector.droppable.content_order)+1){
								++el.content_order;
							}
						}.bind(this))
						
						
					}
					this.mouseOverDetectors.each(function(el){
						el.destroy();
					});
					this.text_draggable.destroy();
				}.bind(this)
			});
			newDrag.start(e);
			this.windowObj.toggleWindow();
			
		}.bind(this));
	}
})



/********************************************************************

	FontSelector: Create and icon that clicks open sub menu

********************************************************************/
FontSelector = new Class({
	Extends: ShelfBox,
	
	Implements: Options,
	
	options: {
		
	},
	
	initialize: function(droppables,options){
		
		//data members
		this.parent(options)
		
		this.reposition();
		
	}
});

/********************************************************************

	Tempalte Icons

********************************************************************/
TemplateIcon = new Class({
	Implements: Options,
	
	options: {
		
	},
	
	initialize: function(image_src,id,page_id,options){
		
		//data memebers
		this.setOptions(options);
		this.image_src = image_src;
		this.template_id = id;
		this.page_id = page_id;
		//Genreate HTML
		this.icon = new Element('div',{'class':'template_icon'});
		this.icon_image = new Element('img',{'class':'icon_image','src':'tpl/images/thumbs/'+this.image_src+'.jpg'});
		
		//set Styles
		this.icon.setStyles({'float':'left','height':'132px','width':'130px','padding':'14px','cursor':'pointer'});
		
		//Construct HTML
		this.icon_image.inject(this.icon);
		
		this.icon.addEvent('click',function(){
			var string = '&page_id='+this.page_id + '&template_id=' + this.template_id;
			this.updateTemplate = new Request({'url':'index.cfm?action=pages.updateObrayTemplate','method':'post','data':string,'onComplete':function(response){
				window.location = 'index.cfm?action=pages.check';
			}.bind(this)}).send();					
		}.bind(this));
	},
	
	get: function(){
		return this.icon;
	}
});


ComponentIcon = new Class({
	Extends: Icon,
	
	options:{
		'label':false,
		'window':false,
		'type':'application'
	},
	
	initialize: function(img,parent,droppables,component_type,options){
		
		//data members
		this.parent(img,parent,options);
		this.getDroppables = droppables;
		this.mouseOverDetectors = [];
		this.droppableTransition = new Fx.Transition(Fx.Transitions.Quad);
		this.component_type = component_type;
		//Add Events
		//add Events
		this.icon_container.addEvent('mousedown',function(e){
			this.options.window.closeWindow();
			this.droppables = this.getDroppables();
			this.droppables.each(function(el,index){
				var position = index;
				this.mouseOverDetectors[position] = new Element('div',{'class':'mouse_over_detectors'});
				this.mouseOverDetectors[position].setStyles({'border':'0px solid black','position':'absolute','left':el.getPosition().x,'top':el.getPosition().y,'height':'30px','width':el.getCoordinates().width});
				this.mouseOverDetectors[position].inject('obray');
				this.mouseOverDetectors[position].droppable = this.droppables[position];
				this.mouseOverDetectors[position].fx = new Fx.Tween(this.droppables[position], {transition: this.droppableTransition.easeOut,duration: 200});
			}.bind(this));
			this.icon_draggable = this.icon_container.clone();
			this.icon_draggable.setStyles({'position':'absolute','left':this.icon_container.getPosition().x,'top':this.icon_container.getPosition().y+window.getScroll().y,'cursor':'move','z-index':'2000','opacity':'.5'});
			this.icon_draggable.inject('obray');
			
			var newDrag = new Drag.Move(this.icon_draggable,{handle: this.icon_dgraggable, droppables: this.mouseOverDetectors,
				onEnter: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','0px','59px');
					detector.setStyle('height','59px');
				}.bind(this),
				onLeave: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','59px','0px');
					detector.setStyle('height','30px');
				},
				onDrop: function(el,detector){
					if(!detector == false){
						var newContent = new ContentPartV2(detector.droppable,{
							'content_part_id':0,
							'content_area_id':detector.droppable.content_area_id,
							'content_part_parent_id':detector.droppable.content_parent_id,
							'content_part_type':this.component_type,
							'content_language':window.obray.options.content_language,
							'content_order':(parseInt(detector.droppable.content_order)+1),
							'content_text':'',
							'image':{'image_id':0},
							'video':{'video_id':0},
							'content_parts':[],
							'component_type':this.options.type
						});
						detector.droppable.setStyles({'height':'auto'});
						
					}
					this.mouseOverDetectors.each(function(el){
						el.destroy();
					});
					this.icon_draggable.destroy();
				}.bind(this)
			});
			newDrag.start(e);
		}.bind(this));
		
	},
	
	get: function(){
		return this.icon_container;
	}
})

Row = new Class({
	Implements: Options,
	
	options:{
		'user_firstName': '',
		'user_lastName': '',
		'user_middleName': '',
		'user_email': '',
		'user_plan': '',
		'user_active': false,
		'bg':'off'
	},
	
	initialize: function(options){
		//data members
		this.setOptions(options);
		
		//genreate HTML
		this.row = new Element('div',{'class':'row'});
		this.row_name = new Element('div',{'class':'row_name'});
		this.row_email_status = new Element('div',{'class':'row_email_status'});
		this.row_email = new Element('div',{'class':'row_email'});
		this.row_status = new Element('div',{'class':'row_status'});
		this.row_deactivate = new Element('div',{'class':'row_deactivate'});
		this.row_deactivate_btn = new Element('div',{'class':'row_deactivate_btn'});
		this.br = new Element('br',{'class':'clearboth'});
		
		//set text
		this.row_name.set('html',this.options.user_firstName + " " + this.options.user_middleName + " " + this.options.user_lastName);
		this.row_email.set('html',this.options.user_email);
		this.row_status.set('html',this.options.user_plan);
		if(this.options.user_active == false){this.row_status.set('html','Account Deactivated');}
		
		//set styles
		this.row_name.setStyles({'float':'left','font-size':'22px','font-family':'arial','width':420,'overflow':'hidden','padding':'7px','border-right':'1px solid #aaaaaa','color':'#555555'});
		this.row_email_status.setStyles({'float':'left','padding':'5px','width':235,'border-right':'1px solid #aaaaaa','color':'#555555'});
		this.row_email.setStyles({'font-family':'arial','font-size':14});
		this.row_status.setStyles({'font-family':'arial','font-size':12});
		this.row_deactivate.setStyles({'float':'left','margin':'6px','opacity':.75});
		this.row_deactivate.setStyles({'background-image':'url(obray/images/shelf/shelf_box_close_btn.png)','width':30,'height':30,'cursor':'pointer'});
		this.br.setStyles({'clear':'both'});
		if(this.options.bg == 'off'){
			this.row.setStyles({'background-color':'#eeeeee'});
		}
		
		//construct HTML
		this.row_name.inject(this.row);
		this.row_email.inject(this.row_email_status)
		this.row_status.inject(this.row_email_status);
		this.row_email_status.inject(this.row);
		this.row_deactivate.inject(this.row);
		this.row_deactivate_btn.inject(this.row_deactivate);
		this.br.clone().inject(this.row);
		
		//add events
		this.row_deactivate.addEvent('click',function(){
			this.confirm_box = new ConfirmBox({
				'message':'Are you sure you want to delete ' + this.options.user_firstName + ' ' + this.options.user_lastName + '?',
				'onConfirm':function(){
			        this.row.destroy();
			        var data = '&user_email=' + this.options.user_email;
			        var delete_request = new Request({'url':'index.cfm?action=users.deleteUserByEmail&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','data':data}).send();
			    }.bind(this)
			    });
			this.confirm_box.open('elastic');
		}.bind(this))
	},
	
	getRow: function(){
		return this.row;
	}
	
})
/********************************************************************

	User_list: Create a searchable menu of users

********************************************************************/
User_list = new Class({
	Extends: ShelfBox,
					  
	Implements: Options,
	
	Options:{
		
	},
	
	initialize: function(options){
		
		//data members
		this.parent(options);
		
		//genereate HTML
		this.user_list = new Element('div',{'class':'user_list'});
		this.user_title = new Element('div',{'class':'user_title'});
		this.user_search = new Element('div',{'class':'user_search'})
		this.user_search_input = new Element('input',{'name':'user_search','id':'user_search','class':'search_input'});
		this.br = new Element('br',{'class':'clear'});
		this.user_list_box = new Element('div',{'class':'user_list_box'});
		this.temp_row = new Row();
		this.temp_row2 = new Row();
		this.temp_row3 = new Row();
		
		//write text
		this.user_title.set('html','Users');
		this.user_search.set('html','search');
		
		//set styles
		this.user_title.setStyles({'float':'left','font-family':'Arial, Helvetica, sans-serif','font-size':'18px','color':'#ffffff','padding':'10px'});
		this.user_search.setStyles({'float':'right','padding':'10px'});
		this.user_search_input.setStyles({'background-image':'url(obray/images/search_box_bg.png)','background-color':'transparent','border':'0px','height':'15px','width':'275px','padding-left':'20px','padding-right':'5px','padding-top':'4px'});
		this.box_m.setStyles({'text-align':'left'});
		
		//construct HTML
		this.user_title.inject(this.user_list);
		this.user_search_input.inject(this.user_search);
		this.user_search.inject(this.user_list);
		this.br.inject(this.user_list);
		
		this.user_list_box.inject(this.user_list);
		this.user_list.inject(this.box_m);
		
		//insert rows
		this.temp_row.injectInside(this.user_list_box);
		this.temp_row2.injectInside(this.user_list_box);
		this.temp_row3.injectInside(this.user_list_box);
		
		this.reposition();
	}
})



ShelfWindow = new Class({
	Implements: Options,
	
	options:{
		'window_width':750
	},
	
	initialize: function(options){
		
		//set data members
		this.setOptions(options);
		this.state = 'closed';
		
		//construct HTML
		this.window = new Element('div');
		this.window_tl = new Element('div');
		this.window_t = new Element('div');
		this.window_tr = new Element('div');
		this.window_l = new Element('div');
		this.window_m = new Element('div');
		this.window_r = new Element('div');
		this.window_bl = new Element('div');
		this.window_b = new Element('div');
		this.window_br = new Element('div');
		this.window_close_btn = new Element('div');
		this.br1 = new Element('br',{'class':'clearboth clear'});
		this.br2 = new Element('br',{'class':'clearboth clear'});
		this.br3 = new Element('br',{'class':'clearboth clear'});
		
		//effects
		this.openFx = new Fx.Morph(this.window,{'duration':500,'transition':Fx.Transitions.Quint.easeOut});
		
		//set styles
		this.window.setStyles({'position':'fixed','left':'50%','bottom':99,'overflow':'hidden','height':0,'z-index':5000});
		this.window_tl.setStyles({'float':'left','background-image':'url(obray/images/shelf/shelf_box_tl.png)','height':28,'width':28});
		this.window_t.setStyles({'float':'left','background-image':'url(obray/images/shelf/shelf_box_t.png)','height':28,'width':this.options.window_width});
		this.window_tr.setStyles({'float':'left','background-image':'url(obray/images/shelf/shelf_box_tr.png)','height':28,'width':28});
		this.window_l.setStyles({'float':'left','background-image':'url(obray/images/shelf/shelf_box_l.png)','width':28});
		this.window_m.setStyles({'float':'left','background-color':'#ffffff','width':this.options.window_width});
		this.window_r.setStyles({'float':'left','background-image':'url(obray/images/shelf/shelf_box_r.png)','width':28});
		//this.window_bl.setStyles({'float':'left','background-image':'url(obray/images/shelf/shelf_box_bl.png)','height':28,'width':28});
		//this.window_b.setStyles({'float':'left','background-image':'url(obray/images/shelf/shelf_box_b.png)','height':28,'width':200});
		//this.window_br.setStyles({'float':'left','background-image':'url(obray/images/shelf/shelf_box_br.png)','height':28,'width':28});
		this.window_close_btn.setStyles({'background-image':'url(obray/images/shelf/shelf_box_close_btn.png)','width':30,'height':30,'cursor':'pointer'});
		
		//construct HTML
		this.window_tl.inject(this.window);
		this.window_t.inject(this.window);
		this.window_tr.inject(this.window);
		this.br1.inject(this.window);
		this.window_l.inject(this.window);
		this.window_m.inject(this.window);
		this.window_r.inject(this.window);
		this.br2.inject(this.window);
		//this.window_bl.inject(this.window);
		//this.window_b.inject(this.window);
		//this.window_br.inject(this.window);
		//this.br.clone().inject(this.window);
		this.window_close_btn.inject(this.window_tr);
		
		this.window.inject(document.body);
		
		//add events
		this.window_close_btn.addEvent('click',function(){
			this.closeWindow();
		}.bind(this));
		
	},
	
	openWindow: function(){
		this.openFx.pause();
		var height = this.window_m.getCoordinates().height + 28;
		var middle_height = this.window_m.getCoordinates().height;
		var width = this.options.window_width + 56;
		this.window.setStyles({'margin-left':-(width/2)});
		this.window_l.setStyles({'height':middle_height});
		this.window_r.setStyles({'height':middle_height});
		this.openFx.start({
			'height':height			  
		});
		this.state = 'opened';
	},
	
	closeWindow: function(){
		this.openFx.pause();
		this.openFx.start({
			'height':0			  
		});
		this.state = 'closed';
	},
	
	toggleWindow: function(){
		if(this.state == 'closed'){
			this.openWindow();
		} else {
			this.closeWindow();
		}
	},
	
	getWindow: function(){
		return this.window;
	}
});


ObrayIcon = new Class({
	Implements: Options,
	
	options:{
		'icon_image':false,
		'icon_rollover':false,
		'icon_label':'Icon'
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		
		//generate HTML
		this.icon = new Element('div');
		this.icon_image = new Element('div');
		this.icon_label = new Element('div');
		
		//set styles
		this.icon.setStyles({'float':'left','width':97,'height':100});
		this.icon_image.setStyles({'background-image':'url('+this.options.icon_image+')','width':97,'height':75,'cursor':'pointer'});
		this.icon_label.setStyles({'font-family':'Helvetica, Arial','color':'#ffffff','text-align':'center','margin-top':-3});
		
		//set label
		this.icon_label.set('html',this.options.icon_label);
		
		//construct HTML
		this.icon_image.inject(this.icon);
		this.icon_label.inject(this.icon);
		
		//add events
		this.icon_image.addEvent('mouseenter',function(){
			
		}.bind(this))
	},
	
	getIcon: function(){
		return this.icon;
	}
})

LogoutIcon = new Class({
	Extends: ObrayIcon,
	
	options: {
		'icon_label':''
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		
		//generate HTML
		this.icon_image.setStyles({'background-image':'url(obray/images/shelf/icon_logout.png)'});
		
		//addEvent
		this.icon_image.addEvent('click',function(){
			window.location = 'index.cfm?action=sec.logout';
		});
	}
})

SettingsIcon = new Class({
	Extends: ObrayIcon,
	
	options: {
		'icon_label':''
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		this.window = new ShelfWindow();
		
		//generate HTML
		this.icon_image.setStyles({'background-image':'url(obray/images/shelf/icon_settings.png)'});
		//load data
		this.loading = new Loader(this.box_m,{'image':'tiny','text':'Loading...','color':'#ffffff','border':true});
		this.load_data = new Request({'url':'index.cfm?action=pages.getObrayPage','data':'&page_id='+window.obray.options.page_id,'onComplete':function(response){
			eval(response);
			this.page_title_long_value = page_name_long;
			this.page_title_value = page_name;
			this.page_keywords_value = page_keywords;
			this.page_description_value = page_description;
			this.page_published_value = page_published;
			this.loading.destroy();
						
			//generate HTML
			this.settings = new Element('div',{'class':'page_settings'});
			this.page_title = new Element('div',{'class':'page_title'});
			this.page_title_label = new Element('div',{'class':'page_title_label'});
			this.page_title_input = new Element('input',{'class':'page_title_input'});
			this.page_title_long = new Element('div',{'class':'page_title_long'});
			this.page_title_long_label = new Element('div',{'class':'page_title_long_label'});
			this.page_title_long_input = new Element('input',{'class':'page_title_long_input'});
			this.page_keywords = new Element('div',{'class':'page_keywords'});
			this.page_keywords_label = new Element('div',{'class':'page_keywords_label'});
			this.page_keywords_input = new Element('textarea',{'class':'page_keywords_input'});
			this.page_description = new Element('div',{'class':'page_description'});
			this.page_description_label = new Element('div',{'class':'page_description_label'});
			this.page_description_input = new Element('textarea',{'class':'page_description_input'});
			this.page_publish = new Element('div',{'class':'page_publish'});
			this.page_publish_label = new Element('div',{'class':'page_publish_label'});
			this.page_publish_input = new Element('input',{'type':'checkbox','class':'page_publish_input'});
			this.page_save = new Element('div',{'class':'page_save'});
			this.page_save_label = new Element('div',{'class':'page_save_label'});
			this.page_save_input = new Element('input',{'type':'button','class':'page_save_input','value':'Save'});
			this.br = new Element('div',{'class':'clear'});
			
			//set text
			this.page_title_label.set('html','Menu Title:');
			this.page_title_long_label.set('html','Page Title:');
			this.page_keywords_label.set('html','Keywords:');
			this.page_description_label.set('html','Description:');
			this.page_title_input.setProperty('value',this.page_title_value);
			this.page_title_long_input.setProperty('value',this.page_title_long_value);
			this.page_keywords_input.setProperty('value',this.page_keywords_value);
			this.page_description_input.setProperty('value',this.page_description_value);
			this.page_publish_label.set('html','Publish:');
			if(this.page_published_value == true){
				this.page_publish_input.checked = true;
				this.page_publish_input.defaultChecked = true;
				this.published = true;
			} else {
				this.published = false;
			}
			
			//set styles
			this.page_title.setStyles({'padding':'3px'});
			this.page_title_long.setStyles({'padding':'3px'});
			this.page_publish.setStyles({'padding':'3px'});
			this.page_keywords.setStyles({'padding':'3px'});
			this.page_description.setStyles({'padding':'3px'});
			this.page_title_label.setStyles({'float':'left','width':'100px','font-family':'arial','color':'#666666','text-align':'right','padding':'2px','padding-right':'10px'});
			this.page_title_input.setStyles({'float':'left','width':'250px'});
			this.page_title_long_label.setStyles({'float':'left','width':'100px','font-family':'arial','color':'#666666','text-align':'right','padding':'2px','padding-right':'10px'});
			this.page_title_long_input.setStyles({'float':'left','width':'250px'});
			this.page_keywords_label.setStyles({'float':'left','width':'100px','font-family':'arial','color':'#666666','text-align':'right','padding':'2px','padding-right':'10px'});
			this.page_keywords_input.setStyles({'float':'left','width':'250px','height':'100px','padding':'2px','font-family':'arial','font-size':'13px'});
			this.page_description_label.setStyles({'float':'left','width':'100px','font-family':'arial','color':'#666666','text-align':'right','padding':'2px','padding-right':'10px'});
			this.page_description_input.setStyles({'float':'left','width':'250px','height':'100px','padding':'2px','font-family':'arial','font-size':'13px'});
			this.page_publish_label.setStyles({'float':'left','width':'100px','font-family':'arial','color':'#666666','text-align':'right','padding':'2px','padding-right':'10px'});
			this.page_publish_input.setStyles({'float':'left','width':'15px'});
			this.page_save_label.setStyles({'float':'left','width':'100px','font-family':'arial','color':'#666666','text-align':'right','padding':'2px','padding-right':'10px'});
			this.page_save_input.setStyles({'float':'right','padding':'2px','font-family':'arial','font-size':'13px','width':'100px'});
			this.settings.setStyles({'padding':'13px','opacity':'.80','width':375,'margin-left':150});
			
			//construct HTML
			this.page_title_label.inject(this.page_title);
			this.page_title_input.inject(this.page_title);
			this.br.clone().inject(this.page_title);
			this.page_title.inject(this.settings);
			
			this.page_title_long_label.inject(this.page_title_long);
			this.page_title_long_input.inject(this.page_title_long);
			this.br.clone().inject(this.page_title_long);
			this.page_title_long.inject(this.settings);
			
			this.page_keywords_label.inject(this.page_keywords);
			this.page_keywords_input.inject(this.page_keywords);
			this.br.clone().inject(this.page_keywords);
			this.page_keywords.inject(this.settings);
			
			this.page_description_label.inject(this.page_description);
			this.page_description_input.inject(this.page_description);
			this.br.clone().inject(this.page_description);
			this.page_description.inject(this.settings);
			
			this.page_publish_label.inject(this.page_publish);
			this.page_publish_input.inject(this.page_publish);
			this.br.clone().inject(this.page_publish);
			this.page_publish.inject(this.settings);
			
			this.page_save_label.inject(this.page_save);
			this.page_save_input.inject(this.page_save);
			this.br.clone().inject(this.page_save);
			this.page_save.inject(this.settings);
			
			this.settings.inject(this.window.window_m);		
		
			
			//add events
			this.page_save_input.addEvent('click',function(){
				this.page_save_input.setStyles({'display':'none'});
				this.saving = new Loader(this.page_save,{'image':'tiny','text':'Saving...','color':'#ffffff','border':true});
				this.data = '&page_name=' + encodeURIComponent(this.page_title_input.getProperty('value'))
						  + '&page_name_long=' + encodeURIComponent(this.page_title_long_input.getProperty('value'))
						  + '&page_keywords=' + encodeURIComponent(this.page_keywords_input.getProperty('value'))
						  + '&page_description=' + encodeURIComponent(this.page_description_input.getProperty('value'))
						  + '&page_published=' + this.published
						  + '&page_id='  + window.obray.options.page_id;
				this.save_settings = new Request({'url':'index.cfm?action=pages.saveSettings','data':this.data,'onComplete':function(response){
						
						this.saving.destroy();
						this.page_save_input.setStyles({'display':'block'});
				}.bind(this)}).send();
			}.bind(this));
			
			this.page_publish_input.addEvent('click',function(){
				if(this.published == true){
					this.published = false;
				} else {
					this.published = true;
				}
			}.bind(this));
			
		}.bind(this)}).send();
		
		
		
		
		//add event
		this.icon_image.addEvent('click',function(){
			this.window.toggleWindow();
		}.bind(this))
	}
	
})

SiteMapIcon = new Class({
	Extends: ObrayIcon,
	
	options: {
		
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		
		//generate HTML
		this.icon_image.setStyles({'background-image':'url(obray/images/shelf/icon_map.png)'});
		
		//add events
		this.icon_image.addEvent('click',function(){
			window.location = 'index.cfm?action=pages.map';
		}.bind(this))
		
	}
})






PeopleIcon = new Class({
	Implements: Options,				   
					   
	Extends: ObrayIcon,
	
	options: {
		
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		this.window = new ShelfWindow();
		this.rows = [];
		this.show_next = false;
		this.show_previous = false;
		this.startRow = 1;
		this.recordCount = 0;
		this.maxRows = 20;
		
		//generate HTML
		this.icon_image.setStyles({'background-image':'url(obray/images/shelf/icon_people.png)'});
		this.users = new Element('div',{'class':'users'});
		this.users_list = new Element('div',{'class':'user_list'});
		this.user_icon = new Element('img',{'src':'obray/images/shelf/icon_people_small.png','class':'users_icon'});
		this.user_title = new Element('div',{'class':'users_title'});
		this.user_search = new Element('div',{'class':'user_search'});
		this.user_search_box = new Element('input',{'type':'text','class':'search_box'});
		this.br = new Element('br',{'class':'clearBoth'});
		var value = this.user_search_box.getProperty('value');
		this.navigation = new Element('div',{'class':'navigation'});
		this.navigation_next = new Element('div',{'class':'navigation_next'});
		this.next_btn = new Element('img',{'src':'obray/images/shelf/btn_next.png','alt':'next button'})
		this.next_text = new Element('div',{'class':'next_text'});
		this.previous_btn = new Element('img',{'src':'obray/images/shelf/btn_previous.png','alt':'next button'})
		this.previous_text = new Element('div',{'class':'next_text'});
		this.navigation_previous = new Element('div',{'class':'navigation_previous'});
		
		//set text
		this.user_title.set('html','People');
		this.previous_text.set('html','Previous');
		this.next_text.set('html','Next');
		
		//set styles
		this.br.setStyles({'clear':'both'});
		this.user_icon.setStyles({'float':'left','font-family':'arial','margin':'10px','margin-right':'0px'});
		this.user_title.setStyles({'float':'left','font-family':'"Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif','font-size':'30px','font-weight':'normal','padding':5,'padding-right':20,'border-right':'1px solid #aaaaaa','color':'#6666aa'});
		this.user_search.setStyles({'float':'left','background-image':'url(obray/images/shelf/search_box.png)','width':235,'height':20,'margin':8,'padding':5,'padding-left':30,'border':0});
		this.user_search_box.setStyles({'width':220,'height':20,'border':0,'font-size':18});
		this.users_list.setStyles({'height':450,'border-top':'1px solid #aaaaaa','border-bottom':'1px solid #aaaaaa','overflow':'scroll','overflow-x':'hidden'});
		this.navigation_next.setStyles({'float':'right','font-family':'arial','font-size':'16px','padding':'5px','color':'#000000','cursor':'pointer','opacity':.5});
		this.navigation_previous.setStyles({'float':'left','font-family':'arial','font-size':'16px','padding':'5px','color':'#000000','cursor':'pointer','opacity':.5});
		this.next_text.setStyles({'float':'left','padding':'7px'});
		this.next_btn.setStyles({'float':'left'});
		this.previous_text.setStyles({'float':'left','padding':'7px'});
		this.previous_btn.setStyles({'float':'left'});
		
		//construct HMTL
		this.getUsersLike(this.startRow,this.maxRows,'')
		this.user_icon.inject(this.users);
		this.user_title.inject(this.users);
		this.user_search_box.inject(this.user_search);
		this.user_search.inject(this.users);
		this.br.clone().inject(this.users);
		this.users_list.inject(this.users);		
		this.next_text.inject(this.navigation_next);
		this.next_btn.inject(this.navigation_next);
		this.previous_btn.inject(this.navigation_previous);
		this.previous_text.inject(this.navigation_previous);
		this.navigation_previous.inject(this.navigation);
		this.navigation_next.inject(this.navigation);
		this.navigation.inject(this.users);
		this.br.clone().inject(this.navigation);	
		this.users.inject(this.window.window_m);
		
		//add event
		this.icon_image.addEvent('click',function(){
			this.window.toggleWindow();
		}.bind(this));
		
		this.navigation_next.addEvent('click',function(){
			this.startRow += this.maxRows;
			this.users_list.set('html','');
			var value = this.user_search_box.getProperty('value');
			//only get new rows if we don't already have them in the rows array
			if(this.startRow+this.maxRows > this.rows.length && this.rows.length != this.recordCount){
				this.getUsersLike(this.startRow,this.maxRows,'');
			} else {
				if(this.startRow-1+this.maxRows > this.recordCount){var endRow = this.recordCount;} else {var endRow = this.startRow-1 + this.maxRows;}
				for(var i=this.startRow-1;i<endRow;++i){this.rows[i].getRow().inject(this.users_list);}
				if(this.startRow != 1){this.navigation_previous.setStyles({'display':'block'});} else {this.navigation_previous.setStyles({'display':'none'});}
				if((this.recordCount-this.startRow ) > this.maxRows){this.navigation_next.setStyles({'display':'block'});} else {this.navigation_next.setStyles({'display':'none'});}
			}
		}.bind(this));
		
		this.navigation_previous.addEvent('click',function(){
			this.startRow -= this.maxRows;
			this.users_list.set('html','');
			for(var i=this.startRow-1;i<this.startRow-1+this.maxRows;++i){this.rows[i].getRow().inject(this.users_list);}
			if(this.startRow != 1){this.navigation_previous.setStyles({'display':'block'});} else {this.navigation_previous.setStyles({'display':'none'});}
			if((this.recordCount-this.startRow ) > this.maxRows){this.navigation_next.setStyles({'display':'block'});} else {this.navigation_next.setStyles({'display':'none'});}
		}.bind(this));
		
		this.navigation_next.addEvent('mouseenter',function(){
			this.setStyles({'opacity':1});
		});
		
		this.navigation_next.addEvent('mouseleave',function(){
			this.setStyles({'opacity':.5});
		});
		
		this.navigation_previous.addEvent('mouseenter',function(){
			this.setStyles({'opacity':1});
		});
		
		this.navigation_previous.addEvent('mouseleave',function(){
			this.setStyles({'opacity':.5});
		});
		
		this.user_search_box.addEvent('keyup',function(){
			this.rows = [];
			this.startRow = 1;
			var value = this.user_search_box.getProperty('value');
			this.getUsersLike(this.startRow,this.maxRows,value);
		}.bind(this));
	},
	
	getUsersLike: function(startRow,maxRows,string){
		this.loader = new Loader(this.users_list,{'text':'Loading People...'});
		this.users_list.set('html','');
		this.getUsers = new Request({'url':'index.cfm?action=users.getObrayUsersLike&startRow='+startRow + '&maxRows=' + maxRows + '&string='+string,'onComplete':function(response){
			eval(response);
			this.loader.destroy();
			if(startRow-1 + maxRows > recordCount){var endRow = recordCount;} else {var endRow = startRow-1 + maxRows;}
			for(var i=startRow-1;i<endRow;++i){this.rows[i].getRow().inject(this.users_list);}
			if(startRow != 1){this.navigation_previous.setStyles({'display':'block'});} else {this.navigation_previous.setStyles({'display':'none'});}
			if((recordCount-startRow ) > this.maxRows){this.navigation_next.setStyles({'display':'block'});} else {this.navigation_next.setStyles({'display':'none'});}
			this.recordCount = recordCount;
		}.bind(this)}).send();
	}
	
	
})

PicturesIcon = new Class({
	Extends: ObrayIcon,
	
	options: {
		droppables: $empty
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		this.getDroppables = this.options.droppables;
		this.mouseOverDetectors = [];
		this.droppables = '';
		this.droppableTransition = new Fx.Transition(Fx.Transitions.Quad);
		
		//generate HTML
		this.icon_image.setStyles({'background-image':'url(obray/images/shelf/icon_pictures.png)'});
	
		//add Events
		this.icon.addEvent('mousedown',function(e){
			this.droppables = this.getDroppables();
			$$('.obray-show-help').setStyles({'display':'none'});
			this.droppables.each(function(el,index){
				var position = index;
				this.mouseOverDetectors[position] = new Element('div',{'class':'mouse_over_detectors'});
				this.mouseOverDetectors[position].setStyles({'border':'1px solid white','position':'absolute','left':el.getPosition().x,'top':el.getPosition().y,'height':'30px','width':el.getCoordinates().width,'z-index':5002});
				this.mouseOverDetectors[position].inject('obray');
				this.mouseOverDetectors[position].droppable = this.droppables[position];
				this.mouseOverDetectors[position].fx = new Fx.Tween(this.droppables[position], {transition: this.droppableTransition.easeOut,duration: 200});
			}.bind(this));
			this.icon_draggable = this.icon.clone();
			this.icon_draggable.setStyles({'position':'absolute','left':this.icon.getPosition().x,'top':this.icon.getPosition().y+window.getScroll().y,'cursor':'move','z-index':'2000','opacity':'.5'});
			this.icon_draggable.inject('obray');
			
			var newDrag = new Drag.Move(this.icon_draggable,{handle: this.icon_dgraggable, droppables: this.mouseOverDetectors,
				onEnter: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','0px','59px');
					detector.setStyle('height','59px');
				}.bind(this),
				onLeave: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','59px','0px');
					detector.setStyle('height','30px');
				},
				onDrop: function(el,detector){
					if(!detector == false){
						detector.fx.pause();
						detector.fx.start('height','59px','0px');
						detector.setStyle('height','30px');
						this.detector = detector;
						
						var height = (detector.droppable.getCoordinates().width*3)/4;
						
						var newContent = new ContentPartV2(detector.droppable,{
							'content_part_id':0,
							'content_area_id':detector.droppable.content_area_id,
							'content_part_parent_id':detector.droppable.content_parent_id,
							'content_part_type':'image',
							'content_language':window.obray.options.content_language,
							'content_order':(parseInt(detector.droppable.content_order)+1),
							'content_text':'',
							'image':{'image_id':0,
							         'max_width':detector.droppable.getCoordinates().width,
							         'content_area_id':this.detector.droppable.content_area_id,
							         'content_order':(parseInt(detector.droppable.content_order)+1),
							         'image_width': detector.droppable.getCoordinates().width,
                                     'image_height': height,
                                     'image_src':'',
                                     'image_name':'Untitled',
                                     'image_description':'',
                                     'image_description_long':'',
                                     'image_ext':'jpg',
                                     'image_x':0,
                                     'image_y':0,
                                     'image_zoom':0,
                                     'image_link':'',
                                     'image_follow':false,
                                     'image_thumb_x':0,
                                     'image_thumb_y':0,
                                     'content_order':0,
                                     'blog':false
							},
							'video':{'video_id':0},
							'siblings':detector.droppable.siblings
						});
						newContent.inject('after');
						var droppable = new Droppable(newContent.el.window.window_container,newContent,{
							'content_area_id':detector.droppable.content_area_id,
							'content_parent_id':detector.droppable.content_parent_id,
							'content_order':(parseInt(detector.droppable.content_order)),
							'content_order_modifier':-1,
							'siblings':detector.droppable.siblings.bind(detector.droppable.siblings)
						});
						
						droppable.inject('after');
						window.obray.addDroppable(droppable.get());
						
					}
					this.mouseOverDetectors.each(function(el){
						el.destroy();
					});
					this.icon_draggable.destroy();
				}.bind(this)
			});
			newDrag.start(e);
			
		}.bind(this));
	}
})

VideosIcon = new Class({
	Extends: ObrayIcon,
	
	options: {
		droppables: $empty
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		this.getDroppables = this.options.droppables;
		this.mouseOverDetectors = [];
		this.droppables = '';
		this.droppableTransition = new Fx.Transition(Fx.Transitions.Quad);
		
		//generate HTML
		this.icon_image.setStyles({'background-image':'url(obray/images/shelf/icon-video.png)'});
	
		//add Events
		this.icon.addEvent('mousedown',function(e){
			this.droppables = this.getDroppables();
			$$('.obray-show-help').setStyles({'display':'none'});
			this.droppables.each(function(el,index){
				var position = index;
				this.mouseOverDetectors[position] = new Element('div',{'class':'mouse_over_detectors'});
				this.mouseOverDetectors[position].setStyles({'border':'1px solid white','position':'absolute','left':el.getPosition().x,'top':el.getPosition().y,'height':'30px','width':el.getCoordinates().width,'z-index':5002});
				this.mouseOverDetectors[position].inject('obray');
				this.mouseOverDetectors[position].droppable = this.droppables[position];
				this.mouseOverDetectors[position].fx = new Fx.Tween(this.droppables[position], {transition: this.droppableTransition.easeOut,duration: 200});
			}.bind(this));
			this.icon_draggable = this.icon.clone();
			this.icon_draggable.setStyles({'position':'absolute','left':this.icon.getPosition().x,'top':this.icon.getPosition().y+window.getScroll().y,'cursor':'move','z-index':'2000','opacity':'.5'});
			this.icon_draggable.inject('obray');
			
			var newDrag = new Drag.Move(this.icon_draggable,{handle: this.icon_dgraggable, droppables: this.mouseOverDetectors,
				onEnter: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','0px','59px');
					detector.setStyle('height','59px');
				}.bind(this),
				onLeave: function(el,detector){
					detector.fx.pause();
					detector.fx.start('height','59px','0px');
					detector.setStyle('height','30px');
				},
				onDrop: function(el,detector){
					if(!detector == false){
						detector.fx.pause();
						detector.fx.start('height','59px','0px');
						detector.setStyle('height','30px');
						this.detector = detector;
						
						/***
						video = new OVideo({
							'content_area_id':this.detector.droppable.content_area_id,
							'content_order':(parseInt(detector.droppable.content_order)+1),
							'blog':false
						});
						video.injectAfter(detector.droppable);
						***/
						
						var height = (detector.droppable.getCoordinates().width*3)/4;
						
						var newContent = new ContentPartV2(detector.droppable,{
							'content_part_id':0,
							'content_area_id':detector.droppable.content_area_id,
							'content_part_parent_id':detector.droppable.content_parent_id,
							'content_part_type':'video',
							'content_language':window.obray.options.content_language,
							'content_order':(parseInt(detector.droppable.content_order)+1),
							'content_text':'',
							'image':{'image_id':0},
							'video':{'video_id':0,
							         'video_width':500,
							         'video_height':282,
							         'video_image_id':0,
							         'video_length':0,
							         'video_size':0,
							         'video_name':'',
							         'video_ext':'',
							         'video_title':'',
							         'video_description':'',
							         'video_embed':false,
							         'video_share':false,
							         'video_autoplay':false
							},
							'siblings':detector.droppable.siblings
						});
						newContent.inject('after');
						var droppable = new Droppable(newContent.el.player.ovideo_container,newContent,{
							'content_area_id':detector.droppable.content_area_id,
							'content_parent_id':detector.droppable.content_parent_id,
							'content_order':(parseInt(detector.droppable.content_order)),
							'content_order_modifier':-1,
							'siblings':detector.droppable.siblings.bind(detector.droppable.siblings)
						});
						droppable.inject('after');
						window.obray.addDroppable(droppable.get());
					}
					this.mouseOverDetectors.each(function(el){
						el.destroy();
					});
					this.icon_draggable.destroy();
				}.bind(this)
			});
			newDrag.start(e);
			
		}.bind(this));
	},
	
	validDropArea: function(types){
		for(var i=0;i<types.length;++i){
			if(types[i] = this.type){
				return true;
			}
		}
		return false;
	}
})


TextStylesIcon = new Class({
	Extends: ObrayIcon,
	
	options: {
		'droppables':$empty
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		this.window = new ShelfWindow();
		this.droppables = this.options.droppables;
		
		//generate HTML
		this.icon_image.setStyles({'background-image':'url(obray/images/shelf/icon_textStyles.png)'});

		//generate HTML
		this.preview_block = new Element('div',{'class':'text_preview_block'});
		this.h1 = new TextPreview(this.preview_block,this.droppables,this.window,{'type':'h1'});
		this.h2 = new TextPreview(this.preview_block,this.droppables,this.window,{'type':'h2'});
		this.h3 = new TextPreview(this.preview_block,this.droppables,this.window,{'type':'h3'});
		this.h4 = new TextPreview(this.preview_block,this.droppables,this.window,{'type':'h4'});
		this.p  = new TextPreview(this.preview_block,this.droppables,this.window,{'type':'p'});
		this.ul  = new TextPreview(this.preview_block,this.droppables,this.window,{'type':'ul'});
		
		this.h3.text_box.setStyles({'padding-top':'10px','height':'25px'});
		this.h4.text_box.setStyles({'padding-top':'10px','height':'25px'});
		
		//construct HTML
		this.preview_block.inject(this.window.window_m);
		
		//add events
		this.icon_image.addEvent('click',function(){
			this.window.toggleWindow();
		}.bind(this))
		
	}
})

WidgetIcon = new Class({
	Extends: ObrayIcon,
	
	options: {
		'droppables':$empty
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		this.components = [];
		this.window = new ShelfWindow();
		this.num_obray_widgets = 0;
		this.num_application_widgets = 0;

		//generate HTML
		this.icon_image.setStyles({'background-image':'url(obray/images/shelf/icon_widgets_closed.png)'});
		this.components_container = new Element('div',{'class':'components'});
		this.br = new Element('br',{'class':'clear'});
		
		// container for application specific widgets
		this.application_widget_title = new Element('h4',{'class':'application-widget-title'});
		
		this.application_widget_title.setStyles({
			'font-family':'Arial,Helvetica',
			'font-size':14,
			'font-weight':'bold',
			'padding':0,
			'margin':0,
			'margin-top':0
		});
		this.application_widget_title.set('html','Application Widgets')
		this.application_widgets = new Element('div',{'class':'application-widgets-container'});
		this.application_hr = new Element('hr');
		this.application_hr.setStyles({'border-top':0,'border-right':0,'border-left':0,'border-top':1,'border-color':'#f5f5f5'})
		
		// container for assigned obray widgets
		this.obray_widget_title = new Element('h4',{'class':'obray-widget-title'});
		this.obray_widget_title.setStyles({'font-family':'Arial,Helvetica','font-size':14,'font-weight':'bold','padding':0,'margin':0,'margin-top':5});
		this.obray_widget_title.set('html','Obray Widgets')
		this.obray_widgets = new Element('div',{'class':'obray-widgets-container'});
		this.obray_hr = new Element('hr');
		this.obray_hr.setStyles({'border-top':0,'border-right':0,'border-left':0,'border-top':1,'border-color':'#f5f5f5'})
				
		this.window.window_m.setStyles({'height':500,'overflow-y':'scroll'});
		
		//set styles
		this.components_container.setStyles({'padding':'10px','height':'500px','overflow-x':'hidden','overflow-y':'scroll'});
		
		this.getObrayComponents = new Request({'url':'index.cfm?action=pages.getObrayComponents2&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true','method':'post','onComplete':function(response){
            var json = JSON.decode(response);
            // create draggable icon for each widget
            for(var i=0;i<json.response.components.length;++i){
                if(json.response.components[i].component_type == 'obray'){ ++this.num_obray_widgets; var container = this.obray_widgets; } else { ++this.num_application_widgets; var container = this.application_widgets; }
                this.components[this.components.length] =  new ComponentIcon(json.response.components[i].component_thumbnail,container,this.options.droppables,json.response.components[i].component_name,{'label':json.response.components[i].component_label,'type':json.response.components[i].component_type,'window':this.window});
            }
            // insert application specific widgets if there are any
            if(this.num_application_widgets != 0){
                this.br.inject(this.components_container);
                this.application_hr.clone().inject(this.window.window_m);
                this.application_widget_title.inject(this.window.window_m);
                this.application_hr.inject(this.window.window_m);
                this.application_widgets.inject(this.window.window_m);
                this.br.clone().inject(this.window.window_m);
			}
			// insert assigned obray widgets if there are any
			if(this.num_obray_widgets != 0){
                this.application_hr.clone().inject(this.window.window_m);
                this.obray_widget_title.inject(this.window.window_m);
                this.application_hr.clone().inject(this.window.window_m);
                this.obray_widgets.inject(this.window.window_m);
			}
		}.bind(this)}).send();
		
		
		/*****
		this.getComponents = new Request({'url':'index.cfm?action=pages.getObrayComponents','method':'post','onComplete':function(response){
			
		    eval(response);
		    
		}.bind(this)}).send();
		****/
		
		//add events
		this.icon_image.addEvent('click',function(){ this.window.toggleWindow(); }.bind(this))
		
	}
})

TemplatesIcon = new Class({
	Extends: ObrayIcon,
	
	options: {
		
	},
	
	initialize: function(page_id,options){
		
		//data members
		this.setOptions(options);
		this.parent(options);
		this.window = new ShelfWindow();
		this.templates = [];
		this.page_id = page_id;
		
		//generate HTML
		this.icon_image.setStyles({'background-image':'url(obray/images/shelf/icon_templates.png)'});
		this.br = new Element('br',{'class':'clear'});
		this.getTemplates = new Request({'url':'index.cfm?action=pages.getObrayTemplates&clickable=true&page_id='+page_id,'method':'post','onComplete':function(response){
			
			this.json = JSON.decode(response);
			
			for(var i = 0; i < this.json.templates.length; i++){
				this.templates[this.templates.length] = new ClickIcon(this.page_id,{'name':this.json.templates[i].template_name,'thumbnail':this.json.templates[i].template_thumbnail,'type':'template'});
			}
			
			//Construct HTML
			for(var i=0;i<this.templates.length;++i){
				this.templates[i].get().inject(this.window.window_m);
				this.br.inject(this.window.window_m);
			}
		}.bind(this)}).send();
	
		//add events
		this.icon_image.addEvent('click',function(){
			this.window.toggleWindow();
		}.bind(this))
	
	}
})

IconGroup = new Class({
	Implements: Options,
	
	options:{
		
	},
	
	initialize: function(options){
		
		//data members
		this.setOptions(options);
		
		//genreate HTML
		this.group = new Element('div');
		this.group_left = new Element('div');
		this.group_middle = new Element('div');
		this.group_right = new Element('div');
		
		//set styles
		this.group_left.setStyles({'float':'left','width':28,'height':95,'background-image':'url(obray/images/shelf/icon_group_left.png)'});
		this.group_middle.setStyles({'float':'left','height':95,'background-image':'url(obray/images/shelf/icon_group_middle.png)'});
		this.group_right.setStyles({'float':'left','width':12,'height':95,'background-image':'url(obray/images/shelf/icon_group_right.png)'});
		
		//construct HTML
		this.group_left.inject(this.group);
		this.group_middle.inject(this.group);
		this.group_right.inject(this.group);
		
	},
	
	getIconGroup: function(){
		return this.group;
	}
})

ShelfTools = new Class({
	Extends: IconGroup,
					   
	Implements: Options,
	
	options:{
		'page_id':0,
		'settings':true,
		'siteMap':true,
		'people':true,
		'templates':false
	},
	
	initialize: function(options){
		this.parent(options);
		//generate HTML
		this.settings = new SettingsIcon({'icon_label':'Settings'});
		this.siteMap = new SiteMapIcon({'icon_label':'Site Map'});
		this.people = new PeopleIcon({'icon_label':'People'});
		this.templates = new TemplatesIcon(this.options.page_id,{'icon_label':'Templates'});
		this.br = new Element('br',{'class':'clearboth'});
		
		//construct HTML
		if(this.options.settings){this.settings.getIcon().inject(this.group_middle);}
		if(this.options.siteMap){this.siteMap.getIcon().inject(this.group_middle);}
		if(this.options.people){this.people.getIcon().inject(this.group_middle);}
		if(this.options.templates){this.templates.getIcon().inject(this.group_middle);}
		this.br.clone().inject(this.group_middle);
	}
})

ShelfContent = new Class({
	Extends: IconGroup,
					   
	Implements: Options,
	
	options:{
		'droppables':$empty,
		'widgets':true
	},
	
	initialize: function(options){
		this.parent(options);
		this.setOptions(options);
		//generate HTML
		this.pictures = new PicturesIcon({'droppables':this.options.droppables,'icon_label':'Pictures'});
		this.videos = new VideosIcon({'droppables':this.options.droppables,'icon_label':'Videos'});
		this.textStyles = new TextStylesIcon({'icon_label':'Text Styles','droppables':this.options.droppables});
		this.widgets = new WidgetIcon({'icon_label':'Site Widgets','droppables':this.options.droppables});
		this.br = new Element('br',{'class':'clearboth'});
		//set styles
		this.group_left.setStyles({'background-image':'url(obray/images/shelf/icon_group_left_content.png)','margin-left':'20px'})
		//construct HTML
		this.pictures.getIcon().inject(this.group_middle);
		this.videos.getIcon().inject(this.group_middle);
		this.textStyles.getIcon().inject(this.group_middle);
		if(this.options.widgets){ this.widgets.getIcon().inject(this.group_middle); }
		this.br.clone().inject(this.group_middle);
	}
})

/********************************************************************

	Shelf class:  Creates the Obray shelf

********************************************************************/
Shelf = new Class({
	Implements: Options,
	
	options: {
		'id':0,
		'authType': false,
		'settings':true,
		'siteMap':true,
		'people':true,
		'templates':false,
		'widgets':true
	},
	
	initialize: function(options){
		//data memebers
		this.setOptions(options)
		this.dockTransition = new Fx.Transition(Fx.Transitions.Quad);
		this.droppables = [];
		this.icons = [];
		this.groups = [];
		
		//genreate HTML
		this.shelf = new Element('div');
		this.shelf_left = new Element('div');
		this.shelf_middle = new Element('div');
		this.shelf_right = new Element('div');
		this.logout = new LogoutIcon({'icon_label':'Logout'});
		this.tools = new ShelfTools({'page_id':this.options.id,'settings':this.options.settings,'siteMap':this.options.siteMap,'people':this.options.people,'templates':this.options.templates,'widgets':this.options.widgets});
		this.content = new ShelfContent({'droppables':this.getDroppables.bind(this),'widgets':this.options.widgets});
		this.br = new Element('br',{'class':'clearboth'});
		
		//set styles
		this.shelf.setStyles({'position':'fixed','left':0,'bottom':0,'z-index':5000});
		this.shelf_left.setStyles({'float':'left','height':107,'width':19,'background-image':'url(obray/images/shelf/shelf_left.png)'});
		this.shelf_middle.setStyles({'float':'left','height':96,'width':880,'background-image':'url(obray/images/shelf/shelf_middle.png)','padding-top':11});
		this.shelf_right.setStyles({'float':'left','height':107,'width':19,'background-image':'url(obray/images/shelf/shelf_right.png)'});
		
		/****
		//generate HTML
		this.shelf = new Element('div',{'id':'shelf'});
		this.shelf_left = new Element('div',{'id':'shelf_left'});
		this.shelf_middle = new Element('div',{'id':'shelf_middle'});
		this.shelf_right = new Element('div',{'id':'shelf_right'});
		this.shelf_divider = new Element('div',{'class':'shelf_divider'})
		
		//set dock styles
		this.shelf.setStyles({'position':'fixed','bottom':'0px','left':'50%','margin-left':'-200px','z-index':'2000'});
		this.shelf_left.setStyles({'position':'absolute','left':'-37px','top':'30px','background-image':'url(obray/images/shelf/shelf_left.png)','height':'50px','width':'50px'});
		this.shelf_middle.setStyles({'position':'relative','background-image':'url(obray/images/shelf/shelf_middle.png)','height':'80px','padding-left':'20px','padding-right':'20px'});
		this.shelf_right.setStyles({'position':'absolute','right':'-37px','top':'30px','background-image':'url(obray/images/shelf/shelf_right.png)','height':'50px','width':'84px'});
		//set icon styles
		
		this.shelf_divider.setStyles({'position':'relative','float':'left','width':'32px','height':'32px','background-image':'url(obray/images/shelf/shelf_divider.png)','background-repeat':'no-repeat','margin-top':'40px'});
		//construct HTML
		this.icon_logout = new clickIcon('icon_logout.png',this.shelf_middle,function(){window.location = 'index.cfm?action=sec.logout';});
		//this.icon_templates = new OpenIcon('icon_templates.png',this.shelf_middle,{'id':this.options.id});
		this.icon_settings = new OpenIcon('icon_settings.png',this.shelf_middle,{'type':'page_settings'});
		this.icon_map = new clickIcon('icon_map.png',this.shelf_middle,function(){window.location = 'index.cfm?action=pages.map';});
		this.shelf_divider.inject(this.shelf_middle);
		this.icon_photos = new DragIcon('icon_photos.png',this.shelf_middle,this.getDroppables.bind(this),'image');
		this.icon_text = new OpenIcon('icon_text.png',this.shelf_middle,{'droppables':this.getDroppables.bind(this),'type':'font_selector'});
		this.icon_components = new OpenIcon('icon_components.png',this.shelf_middle,{'droppables':this.getDroppables.bind(this),'type':'component_selector'});
		this.shelf_right.inject(this.shelf_middle);
		this.shelf_left.inject(this.shelf_middle);
		this.shelf_middle.inject(this.shelf);
		this.shelf.inject('obray');
		
		***/
		//construct HTML
		this.logout.getIcon().inject(this.shelf_middle);
		this.tools.getIconGroup().inject(this.shelf_middle);
		this.content.getIconGroup().inject(this.shelf_middle);
		this.br.clone().inject(this.shelf_middle);
		
		this.shelf_left.inject(this.shelf);
		this.shelf_middle.inject(this.shelf);
		this.shelf_right.inject(this.shelf);
		this.shelf.inject(document.body);
		
		this.adjustPosition();
		
	},
	
	addDroppable: function(droppable){
		this.droppables[this.droppables.length] = droppable;
	},
	
	getDroppables: function(){
		return $$('.droppable');
	},
	destroy: function(){
		this.shelf.destroy();
	},
	
	adjustPosition: function(){
		var width = this.shelf.getCoordinates().width;
		this.shelf.setStyles({'position':'fixed','left':'50%','bottom':0,'margin-left':-(width/2)});
	}
}); // JavaScript Document
EditMenu = new Class({
	Implements: Options,
	
	options:{
		
	},
	
	initialize: function(el,options){
		
		//data memebers
		this.setOptions(options);
		this.btns = [];
		//elements
		this.btn = new Element('div',{'class':'obray_btn'});
		this.menu = new Element('div',{'class':'editMenu'});
		//effects
		this.menu.fx = new Fx.Morph(this.menu,{'duration':400,'transition':Fx.Transitions.Bounce.easeOut});
		//set styles
		this.btn.setStyles({'position':'relative','background-image':'url(obray/images/editMenu/obray_btn.png)','height':'25px','width':'25px','opacity':'0.5','cursor':'pointer','overflow':'visible','z-index':100});
		this.menu.setStyles({'position':'absolute','width':'0px','height':'0px','left':'0px','background-color':'#999999','opacity':.85,'overflow':'hidden','z-index':5001});
		//construct HTML
		this.menu.inject(this.btn);
		
		
		this.btn.addEvent('mouseenter',function(){
			this.btn.setStyles({'background-image':'url(obray/images/editMenu/obray_btn.png)','height':'25px','width':'25px','opacity':'1.0'});
			this.menu.fx.pause();
			this.menu.fx.start({
				'width':200,
				'height':this.btns.length*30,
				'margin-left':-200
			});
		}.bind(this));
		this.btn.addEvent('mouseleave',function(){
			this.btn.setStyles({'background-image':'url(obray/images/editMenu/obray_btn.png)','height':'25px','width':'25px','opacity':'0.5'});
			this.menu.fx.pause();
			this.menu.fx.start({
				'width':0,
				'height':0,
				'margin-left':0
			});
		}.bind(this));
		if($defined(el)){
			this.addBtn('Delete',function(){
				var deletePart = new Request({'url':'index.cfm?action=pages.deleteContentPart','data':'&content_part_id=#content_part_id#','onComplete':function(){
					window.location = window.location;																																			 
				}}).send();
			});
			this.btn.setStyles({'position':'absolute','right':0,'top':0,'z-index':4999});
			this.btn.inject(el);
		}
		
	},
	
	addBtn: function(name,fn){
		
		this.btns[this.btns.length] = new Element('div',{'class':'btns'});
		this.btns[this.btns.length-1].set('html',name);
		this.btns[this.btns.length-1].setStyles({
			'position':'relative',
			'background-color':'#555555',
			'padding':'3px',
			'height':'20px',
			'margin':'1px',
			'font-family':'arial',
			'z-index':5001
		});
		this.btns[this.btns.length-1].addEvent('mouseenter',function(){
			this.setStyles({
				'background-color':'#333333'
			});
		});
		this.btns[this.btns.length-1].addEvent('mouseleave',function(){
			this.setStyles({
				'background-color':'#555555'
			});
		});
		this.btns[this.btns.length-1].addEvent('click',fn);
		this.btns[this.btns.length-1].inject(this.menu);
	},
	
	get: function(){
		return this.btn;
	}
	
	
}); /*******************************************************
	Droppables
*******************************************************/
Droppable = new Class({
	Implements: Options,
	
	options:{
		'content_area_id':0,
		'content_parent_id':0,
		'content_order':0,
		'content_part':false,
		'siblings':$empty,
		'content_order_modifier':0
	},
	
	initialize: function(parent,content_part,options){
		this.setOptions(options);
		this.parent = parent;
		this.droppable = new Element('div',{'class':'droppable'});	
		this.droppable.content_area_id = this.options.content_area_id;
		this.droppable.content_parent_id = this.options.content_parent_id;
		this.droppable.content_order = this.options.content_order;
		this.droppable.setStyles({'background-color':'#000','opacity':.5});
		this.droppable.siblings = this.options.siblings;
		this.droppable.getContentOrder = function(){ 
			if(content_part == false){
				return 0;
			}else{
				return content_part.options.content_order + this.options.content_order_modifier;
			} 
		}.bind(this);
		//this.droppable.content_part = this.options.content_part;
	},
	
	inject: function(position){
		this.droppable.inject(this.parent,position);
	},
	
	get: function(){
		return this.droppable;
	}
})
/*******************************************************
	Obray v2
*******************************************************/


var ObrayV2 = new Class({
	Implements: Options,
	
	options:{
		'page_id': 0,
		'settings':true,
		'siteMap':true,
		'people':true,
		'templates':false,
		'widgets':true,
		'content_area_object_id':0,
		'amazon_location':'',
		'content_language':'en',
		'ext_parameter':''
	},
	
	initialize: function(options){
		this.setOptions(options);
		
		this.content_areas = [];
		this.missing_areas = [];
		this.chain = new Chain();
		this.callChain = true;
		this.executing_request = false;
		this.amazon_location = this.options.amazon_location;
		/****************************************************
			OBRAY CORE: This is where the magic happens
		****************************************************/
		var data = '&page_id='+this.options.page_id
				 + '&content_language='+this.options.content_language;
		// get content data
		var time_stamp = Math.round(((new Date()).getTime()-Date.UTC(1970,0,1))/1000);
		this.request = new Request({'url':'index.cfm?action=pages.getObrayContent&content_area_object_id='+this.options.content_area_object_id+'&fusebox.password=thinkbig&fusebox.load=true&fusebox.%20parse=true&fusebox.execute=true&time='+time_stamp+'&ext_parameter='+this.options.qryStr,'data':data,'method':'get','onComplete':function(response){
		    response = JSON.decode(response);
		    
			this.toolbar = new Shelf({'id':this.options.page_id,'authType':this.authType,'settings':this.options.settings,'siteMap':this.options.siteMap,'people':this.options.people,'templates':this.options.templates,'widgets':this.options.widgets});
			for(var i=0;i<response.content_areas.length;i++){
				if($defined($(response.content_areas[i].content_area_name))){
					this.content_areas[this.content_areas.length] = new ContentAreaV2({
						'content_area_id':			response.content_areas[i].content_area_id,
						'content_area_name':		response.content_areas[i].content_area_name,
						'content_area_level':		response.content_areas[i].content_area_level,
						'content_part_types':		response.content_areas[i].content_part_types,
						'content_area_width':		response.content_areas[i].content_area_width,
						'content_area_height':		response.content_areas[i].content_area_height,
						'content_parts':			response.content_areas[i].content_parts
					})
				} else {
					// some content areas may be loaded by other content areas (therefore not appearing until that area has been loaded).  We keep track of these so we can find them later.
					this.missing_areas[this.missing_areas.length] = response.content_areas[i];
				}
			}
			this.repeatFind = this.findMissingAreas.periodical(200,this);
			
		}.bind(this)}).send();	
	},
	
	findMissingAreas: function(){
		for(var i=0;i<this.missing_areas.length;i++){
			if($defined($(this.missing_areas[i].content_area_name))){
				this.content_areas[this.content_areas.length] = new ContentAreaV2({
					'content_area_id':			this.missing_areas[i].content_area_id,
					'content_area_name':		this.missing_areas[i].content_area_name,
					'content_area_level':		this.missing_areas[i].content_area_level,
					'content_part_types':		this.missing_areas[i].content_part_types,
					'content_area_width':		this.missing_areas[i].content_area_width,
					'content_area_height':		this.missing_areas[i].content_area_height,
					'content_parts':			this.missing_areas[i].content_parts
				})
				this.missing_areas.erase(this.missing_areas[i]);
			}
		}
		if(this.missing_areas.length == 0){$clear(this.repeatFind);	}
	},
	
	addDroppable: function(droppable){
		this.toolbar.addDroppable(droppable);
	}
	
});
OWidgetBarButton = new Class({
    Implements: Options,
    
    options:{
        'button-label':'default',
        'click':$empty
    },
    
    initialize: function(options){
        this.setOptions(options);
        
        this.button = new Element('li',{'class':'owidgetbarbutton'});
        this.button.setStyles({'float':'left','background-image':'none','color':'#858585','display':'block','height':18,'font-size':14,'font-family':'Arial,helvetica','vertical-align':'middle','border-left':'1px solid #454545','border-right':'1px solid #454545','margin':0,'padding':9,'padding-top':9,'margin-top':2,'margin-bottom':2})
        this.button.set('html',this.options['button-label']);
        
        this.button.addEvent('mouseenter',function(){ this.button.setStyles({'color':'#d1d1d1','background-color':'#333333','cursor':'pointer'}); }.bind(this));
        this.button.addEvent('mouseleave',function(){ this.button.setStyles({'color':'#858585','background-color':'transparent','cursor':'pointer'}); }.bind(this));
        
        this.button.addEvent('click',this.options['click']);
    },
    
    inject: function(el,position){
        this.button.inject(el,position);
    },
    
    getCoordinates: function(){
        return this.button.getCoordinates();
    },
    
    setLabel: function(label){
    	this.button.set('html',label);
    },
    
    setStyles: function(styles){
    	this.button.setStyles(styles);
    }
});


OWidgetBar = new Class({
    Implements: Options,
    
    options:{
        'open-element': new Element('div'),
        'title-label':'default',
        'opacity':1,
        'title_div_width':315
        
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.widget_bar_buttons = [];
        
        this.open_element = this.options['open-element'];
        this.open_element.addEvent('mouseenter',function(){
            this.widget_bar.fx.pause();
            this.widget_bar.fx.start({'height':40})
        }.bind(this));
        this.open_element.addEvent('mouseleave',function(){
            this.widget_bar.fx.pause();
            this.widget_bar.fx.start({'height':0})
        }.bind(this));
        
        this.widget_bar = new Element('div',{'class':'oblog-post-bar'});
        this.widget_bar.setStyles({'position':'relative','top':0,'left':0,'width':'100%','height':0,'background-image':'url(/obray/images/widget/widget-bar.png)','opacity':this.options['opacity'],'overflow':'hidden','-webkit-border-radius':'5px 5px 5px 5px','-moz-border-radius':'5px 5px 5px 5px'})
        this.widget_bar.fx = new Fx.Morph(this.widget_bar,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
        this.widget_bar.inject(this.open_element,'top');
        
        this.widget_bar_content = new Element('div',{'class':'oblog-post-bar-content'});
        this.widget_bar_content.setStyles({'display':'block','float':'left','color':'#868686','font-size':12,'font-family':'Arial,Helvetica','padding':5,'width':this.options.title_div_width});
        //this.widget_bar_content.set('html','Blog Post Option for "'+this.options['blog-post-title']+'"');
        this.widget_bar_content.inject(this.widget_bar);
        
        // widget bar title
        this.bar_title = new Element('h2',{'class':'OBlog-bar-title'});
        this.bar_title.setStyles({'display':'block','float':'left','font-family':'Arial,Helvetica','color':'#b5b5b5','font-weight':'normal','font-size':20,'border':0,'margin':0,'padding':5});
        this.bar_title.set('html',this.options['title-label']);
        this.bar_title.inject(this.widget_bar_content);
        
        this.widget_bar_list = new Element('url',{'class':'owidgetbar-list'});
        this.widget_bar_list.setStyles({'float':'right','margin':0,'padding':0})
        this.widget_bar_list.inject(this.widget_bar);
    },
    
    getContent: function(){
        return this.widget_bar_content;
    },
    
    addButton: function(label,fn){
        this.widget_bar_buttons[this.widget_bar_buttons.length] = new OWidgetBarButton({'button-label':label,'click':fn});
        this.widget_bar_buttons[this.widget_bar_buttons.length-1].inject(this.widget_bar_list);
        return this.widget_bar_buttons[this.widget_bar_buttons.length-1];
    }
});


OWidgetMenuItem = new Class({
    Implements: Options,
    
    options:{
        'item-label':'Default',
        'click-function':$empty,
        'item-icon':''
    },
    
    initialize: function(options){
        this.setOptions(options);
        
        this.menu_item = new Element('li',{'class':'owidgetmenuitem'});
        this.menu_item.setStyles({'display':'block','font-family':'Arial,Helvetica','color':'#858585','list-style':'none','margin':0,'padding':3,'width':194,'-webkit-border-radius':'2px 2px 2px 2px','-moz-border-radius':'2px 2px 2px 2px','background-image':'none'});
        this.menu_item.set('html',this.options['item-label']);
        this.menu_item.addEvent('click',this.options['click-function']);
        this.menu_item.addEvent('mouseenter',function(){ this.menu_item.setStyles({'background-color':'#151515','color':'#ffffff'}); }.bind(this));
        this.menu_item.addEvent('mouseleave',function(){ this.menu_item.setStyles({'background-color':'#000000','color':'#858585'}); }.bind(this));
        if(this.options['item-icon'] != ''){
            this.menu_item_icon = new Element('img',{'src':this.options['item-icon']});
            this.menu_item_icon.setStyles({'margin-bottom':-4,'margin-right':2,'margin-left':-4});
            this.menu_item_icon.inject(this.menu_item,'top');
        }
        
        
    },
    
    inject: function(el,position){
        this.menu_item.inject(el,position);
    }
});


OWidgetMenu = new Class({
    Implements: Options,
    
    options:{
        'content_part_id':0,
        'onDelete':$empty
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.menu_items = [];
        
        this.widget_menu_container = new Element('div',{'class':'owidgetmenu-container'});
        this.widget_menu_container.setStyles({'position':'absolute','z-index':'6000','right':-10,'top':-10,'opacity':0,'cursor':'pointer','background-image':'url(/obray/images/btn-settings-small.png)','width':20,'height':20,'overflow':'visible'});
        this.widget_menu_container.fx = new Fx.Morph(this.widget_menu_container,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
        
        this.widget_menu_container.addEvent('mouseenter',function(){ this.widget_menu.fx.pause(); this.widget_menu.fx.start({'opacity':.75}); }.bind(this));
        this.widget_menu_container.addEvent('mouseleave',function(){ this.widget_menu.fx.pause(); this.widget_menu.fx.start({'opacity':0}); }.bind(this));
        
        this.widget_menu = new Element('div',{'class':'owidgetmenu'});
        this.widget_menu.setStyles({'position':'absolute','z-index':'1000','right':20,'top':0,'padding':5,'background-color':'#000000','opacity':0,'width':200,'height':'auto','-webkit-border-radius':'5px 5px 5px 5px','-moz-border-radius':'5px 5px 5px 5px'})
        this.widget_menu.fx = new Fx.Morph(this.widget_menu,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
        this.widget_menu.inject(this.widget_menu_container);
        
        this.widget_menu_list = new Element('ul');
        this.widget_menu_list.inject(this.widget_menu);
        
    },
    
    fade: function(toggle){
        if(toggle == "in"){
            this.widget_menu_container.fx.pause();
            this.widget_menu_container.fx.start({'opacity':1});
        } else {
            this.widget_menu_container.fx.pause();
            this.widget_menu_container.fx.start({'opacity':0});
        }
    },
    
    inject: function(el,position){
        this.widget_menu_container.inject(el,position);
    },
    
    addMenuItem: function(menu_label,fn){
        this.menu_items[this.menu_items.length] = new OWidgetMenuItem({'item-label':menu_label,'click-function':fn});
        this.menu_items[this.menu_items.length-1].inject(this.widget_menu_list);
    },
    
    enableDelete: function(label){
        this.menu_items[this.menu_items.length] = new OWidgetMenuItem({'item-label':label,'item-icon':'/obray/images/btn-small-delete.png','click-function':function(){
            this.deleteWidget();
        }.bind(this)});
        this.menu_items[this.menu_items.length-1].inject(this.widget_menu_list);
    },
    
    deleteWidget: function(){
        var deletePart = new Request({'url':'index.cfm?action=pages.deleteContentPart','data':'&content_part_id='+this.options['content_part_id'],'onComplete':function(){
            this.options.onDelete();
            var location = window.location.href.replace(window.location.hash,'');
            var location = location.replace('##','');
            window.location = location;
        }.bind(this)}).send();
    }
});


OWidget = new Class({
    Implements: Options,
    
    options:{
        'widget-container':new Element('div'),
        'content-part-id':0,
        'onDelete':$empty
    },
    
    initialize: function(options){
        this.setOptions(options);
        // assign the passed in container to the local widget object
        this.widget = this.options['widget-container'];
        // add transparent border to widget and set other styles
        this.widget.setStyles({'border':'1px solid transparent','position':'relative'});
        // show and hide border on mouse events
        this.widget.addEvent('mouseenter',function(){
            this.widget.setStyles({'border':'1px solid #d5d5d5','-webkit-border-radius':'5px 5px 5px 5px','-moz-border-radius':'5px 5px 5px 5px'});
            this.widget_menu.fade('in');
        }.bind(this));
        this.widget.addEvent('mouseleave',function(){ 
            this.widget.setStyles({'border':'1px solid transparent'});
            this.widget_menu.fade('out');
        }.bind(this));
        
        // create widget menu
        this.widget_menu = new OWidgetMenu({'content_part_id':this.options['content_part_id'],'onDelete':this.options.onDelete});
        this.widget_menu.inject(this.widget);
    },
    
    addButton: function(label,fn){
        this.widget_menu.addMenuItem(label,fn);
    },
    
    enableDelete: function(label){
        this.widget_menu.enableDelete(label);
    }
});




/*********************************************
	Mini Edit / Delete Buttons
*********************************************/
OWidgetMiniAdminButton = new Class({
    Implements: Options,
    
    options:{
        'mini-admin-button-label':'default',
		'mini-admin-button':'default-obray-btn',
        'click':$empty,
		'value':''
    },
    
    initialize: function(options){
        this.setOptions(options);
        
        this.mini_admin_button = new Element('li',{'class':'mini-admin-icon'});
        this.mini_admin_button.setStyles({'float':'left','cursor':'pointer','background-image':'none','margin':'0px 2px 0px 2px','padding':0})
        this.mini_admin_button.set('html','<img src="/obray/config/images/'+this.options['mini-admin-button']+'.png" width="23" height="23" alt="'+this.options['mini-admin-button-label']+' Item" title="'+this.options['mini-admin-button-label']+' Item"/>');
        this.mini_admin_button.addEvent('click',this.options['click'].pass(this.options.value));
    },
    
    inject: function(el,position){
        this.mini_admin_button.inject(el,position);
    },
    
    getCoordinates: function(){
        return this.mini_admin_button.getCoordinates();
    },
    
    setLabel: function(label){
    	this.mini_admin_button.set('html',btn_src);
    },
    
    setStyles: function(styles){
    	this.mini_admin_button.setStyles(styles);
    }
});


OWidgetMiniAdmin = new Class({
    Implements: Options,
    
    options:{
        'open-element': new Element('div'),
        'title-label':'default',
		'item-id':0,
        'opacity':1
    },
    
    initialize: function(options){
        this.setOptions(options);
        this.widget_mini_buttons = [];
        
        this.open_element = this.options['open-element'];
        
        this.open_element.addEvent('mouseenter',function(){
            this.widget_admin_buttons.fx.pause();
            this.widget_admin_buttons.fx.start({'opacity':1})
        }.bind(this));
        this.open_element.addEvent('mouseleave',function(){
            this.widget_admin_buttons.fx.pause();
            this.widget_admin_buttons.fx.start({'opacity':0})
        }.bind(this));
        
		//wrapper div
        this.widget_admin_buttons = new Element('div',{'class':'mini-buttons-admin'});
        this.widget_admin_buttons.setStyles({'opacity':0,'overflow':'hidden','height':23,'position':'absolute','top':0,'right':10,'z-index':5100})
        this.widget_admin_buttons.fx = new Fx.Morph(this.widget_admin_buttons,{'duration':600,'transition':Fx.Transitions.Quint.easeOut});
        this.widget_admin_buttons.inject(this.open_element,'top');
        
		this.widget_admin_buttons_list = new Element('ul',{'class':'owidgetbar-list'});
        this.widget_admin_buttons_list.setStyles({'float':'right','margin':0,'padding':0})
        this.widget_admin_buttons_list.inject(this.widget_admin_buttons);
		
    },
    
    getContent: function(){
        return this.widget_admin_buttons_content;
    },
    
    addButton: function(btn_src,btn_label,fn){
        this.widget_mini_buttons[this.widget_mini_buttons.length] = new OWidgetMiniAdminButton({'mini-admin-button':btn_src,'mini-admin-button-label':btn_label,'click':fn});
        this.widget_mini_buttons[this.widget_mini_buttons.length-1].inject(this.widget_admin_buttons_list);
        return this.widget_mini_buttons[this.widget_mini_buttons.length-1];
    }
}); 
/********************************
	Google Maps Class
	Baes on Google Maps v2
********************************/

googleMap = new Class({
	Implements: Options,
	
	options:{
		'height': 300,
		'width': 500,
		'type': 'hybrid'
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.geocoder = new GClientGeocoder();
		this.mapControl = new GMapTypeControl();		
		//generate HTML
		this.map_container = new Element('div',{'class':'map-container'});
		//set styles
		this.map_container.setStyles({'width':this.options.width,'height':this.options.height});
	},
	
	showAddress: function(address){
		this.generateMap();
		this.geocoder.getLatLng(address,function(point){
			if (!point) {
				alert(address + " not found");
			} else {
				this.map.setCenter(point, 15);
				var marker = new GMarker(point);
				this.map.addOverlay(marker);
				marker.openInfoWindowHtml(address);
			}
		}.bind(this));
	},
	
	generateMap: function(){
		this.map = new GMap2(this.map_container);
		this.map.addControl(this.mapControl);
		switch(this.options.type){
			case 'normal': this.map.setMapType(G_NORMAL_MAP);break;
			case 'satellite': this.map.setMapType(G_SATELLITE_MAP);break;
			case 'hybrid': this.map.setMapType(G_HYBRID_MAP);break;
			case 'default': this.map.setMapType(G_DEFAULT_MAP_TYPES);break;
			case 'physical': this.map.setMapType(G_PHYSICAL_MAP);break;
			default: this.map.setMapType(G_DEFAULT_MAP_TYPES);break;
		}
		
	},
	
	addControl: function(control){
		switch(control){
			case 'large3DControl': 				this.map.addControl(new GLargeMapControl3D());break;
			case 'smallControl': 				this.map.addControl(new GLargeMapControl());break;
			case 'small3DZoom':  				this.map.addControl(new GSmallZoomControl3D());break;
			case 'smallZoom':  					this.map.addControl(new GSmallZoomControl());break;
			case 'scaleControl':  				this.map.addControl(new GScaleControl());break;
			case 'typeControl':  				this.map.addControl(new GMapTypeControl());break;
			case 'HierarchicalMapTypeControl':  this.map.addControl(new GHierarchicalMapTypeControl());break;
			case 'overviewControl':  			this.map.addControl(new GOverviewMapControl());break;
			case 'navLabelControl':  			this.map.addControl(new GNavLabelControl());break;
		}
	},
	
	get: function(){
		return this.map_container;
	}
	
});
/*******************************************	OAccordion Class*******************************************/OAccordion = new Class({	Implements: Options,		options:{		'open_index':0	},		initialize: function(togglers,containers,options){		this.setOptions(options);		togglers.each(function(el,index){			containers[index].isOpen = false;			containers[index].setStyles({'height':0,'overflow':'hidden','visibility':'hidden'});			// close open containers			for(var i=0;i<containers.length;++i){ 				if(containers[i].isOpen && i != index){					containers[i].isOpen = false; 					containers[i].setStyles({'height':containers[i].getCoordinates().height});					togglers[i].fx.pause();					togglers[i].fx.start({'height':0,'overflow':'hidden','visibility':'hidden'});					togglers[i].removeClass('active');					containers[i].getFirst().getChildren('.droppable').each(function(el,index){						el.addClass('droppable-removed');						el.removeClass('droppable');					}.bind(this));				} 			}			el.fx = new Fx.Morph(containers[index],{'duration':600,'transition':Fx.Transitions.Quint.easeOut,'onComplete':function(){        		if(this.container.isOpen){        			this.container.setStyles({'height':'auto','overflow':'visible','visibility':'visible'});        		}        	}.bind(el)});        	el.setStyles({'cursor':'pointer','z-index':3000});			el.addEvent('click',function(){				el.addClass('active');				el.container = containers[index];				el.container.setStyles({'overflow':'hidden'});								// close open containers				for(var i=0;i<containers.length;++i){ 					if(containers[i].isOpen && i != index){						containers[i].isOpen = false; 						containers[i].setStyles({'height':containers[i].getCoordinates().height});						togglers[i].fx.pause();						togglers[i].fx.start({'height':0,'overflow':'hidden','visibility':'hidden'});						togglers[i].removeClass('active');						containers[i].getFirst().getChildren('.droppable').each(function(el,index){							el.addClass('droppable-removed');							el.removeClass('droppable');						}.bind(this));					} 				}								// open or close container appropriately				if(containers[index].isOpen == false){					containers[index].isOpen = true;					el.fx.pause();					el.fx.start({'height':containers[index].getScrollSize().y,'visibility':'visible'});					containers[index].getFirst().getChildren('.droppable-removed').each(function(el,index){						el.addClass('droppable');						el.removeClass('droppable-removed');					}.bind(this));				} else {					el.removeClass('active');					containers[index].isOpen = false;					containers[index].setStyles({'height':containers[index].getCoordinates().height});					el.fx.pause();					el.fx.start({'height':0,'overflow':'hidden','visibility':'hidden'});					containers[index].getFirst().getChildren('.droppable').each(function(el,index){						el.addClass('droppable-removed');						el.removeClass('droppable');					}.bind(this));				}						}.bind(this));		}.bind(this));				if(this.options.open_index != -1)			try{ togglers[this.options.open_index].fireEvent('click'); } catch(err) {  }		}});Rating2 = new Class({
    Implements: Options,
    
    options: {
        'label':'',
        'blur':$empty,
        'focus':$empty,
		'clock':$empty,
        'name':'',
        'actual_rating':'',
		'my_rating':'',
		'active':false,
		'field_id':'',
		'item_id':'',
		'id_suffix':'',
		'class_name':'rating',
		'onchange':'',
		'star_blank':'/assets/images/star_blank.png',
		'star_half':'/assets/images/star_half.png',
		'star':'/assets/images/star.png',
		'url':'',
		'actual_rating_num_text':'',
		'height':15,
		'width':175,
		'width2':70,
		'display_time':false,
		'review_time':''
    },
    
    initialize: function(options){
		
		this.setOptions(options);
        this.name = this.options.name;       
        this.text_label = new Element('label',{'class':'otext-label'});
		if(this.options.show_label == false) {
			this.text_label.addClass('Ohidden');
		}
        this.text_label.set('html',this.options.label);
		this.oh_my_stars = new Array();
		this.buildStars();
		
        this.container = new Element('div',{'class':'rating-wrapper','id':'rating-wrapper-'+this.options.field_id});
        this.container.addClass(this.options.class_name);
		if(this.options.label != ''){ this.text_label.inject(this.container); }
	    
		this.rating_element.inject(this.container);
		
		if(this.options.actual_rating_num_text != ''){
			this.rating_num_text_container = new Element('div',{'class':'rating_text_container',html:this.options.actual_rating_num_text});
			this.rating_num_text_container.inject(this.container);
		}
		
		if(this.options.display_time == true){
			this.review_time_container = new Element('div',{'class':'review_time_container',html:this.options.review_time});
			this.review_time_container.inject(this.container);
		}
   },
   buildActual: function() {
	   for(i = 1; i < 6; i++) {
			if(this.options.actual_rating >= i) {
				new Element('img',{ src:this.options.star, style:'' }).inject(this.actual_rating_element);
			} else {
				if(this.options.actual_rating >= (i - 0.75)){
					new Element('img',{ src:this.options.star_half, style:'' }).inject(this.actual_rating_element);
				} else {
					new Element('img',{ src:this.options.star_blank, style:'' }).inject(this.actual_rating_element);
				}
			}
		}
   },
    buildStars: function() {
		this.rating_element = new Element('div',{'style':'width: '+this.options.width+'px; height: '+this.options.height+'px;','class':'rating_element','id':'rating_element_'+this.options.field_id});
		this.rating_element.set('html','');
		this.actual_rating_element = new Element('div',{'style':'display: block; float: left; width: '+this.options.width2+'px; height: '+this.options.height+'px;','class':'actual_rating','id':'actual_rating_'+this.options.field_id});
		this.buildActual();
		this.actual_rating_element.inject(this.rating_element);
		this.actual_rating_num = new Element('div',{'style':'display: block; float: left; width: 60px; height: '+this.options.height+'px;','class':'actual_rating_num','id':'actual_rating_num_'+this.options.field_id,'html':this.options.actual_rating+' Stars'});
		this.actual_rating_num.inject(this.rating_element);
		
		if(this.options.active) {
			this.my_rating_element = new Element('div',{'style':'display: none; width: '+this.options.width2+'px; height: '+this.options.height+'px;','class':'my_rating','id':'my_rating_'+this.options.field_id});
			this.lowest_set = 0;
			this.lowest_set_type = 0;
			this.oh_my_stars[0] = new Element('div');
			for(i = 1; i < 6; i++) {
				if(this.options.my_rating >= i) {
					this.oh_my_stars[i] = new Element('img',{ src:this.options.star, style:'cursor: pointer;' });
					this.lowest_set = i;
					this.lowest_set_type = 1;
				}
				else {
					if(this.options.my_rating >= (i - 0.75)) {
						this.oh_my_stars[i] = new Element('img',{ src:this.options.star_half, style:'cursor: pointer;' });
						this.lowest_set = i;
						this.lowest_set_type = 2;
					}
					else { this.oh_my_stars[i] = new Element('img',{ src:this.options.star_blank, style:'cursor: pointer;' }); }
					
					this.rating_element.addEvent('mouseleave',function(){
						for(j = 5; j >= this.lowest_set; j--) {
							//alert(j);
							if(j > this.lowest_set) this.oh_my_stars[j].set({'src':this.options.star_blank});
							if(j == this.lowest_set && j != 0) {
								if(this.lowest_set_type == 2) this.oh_my_stars[j].set({'src':this.options.star_half});
								else this.oh_my_stars[j].set({'src':this.options.star});
							}
						}
					}.bind(this).pass(this));
				}
				
			}
			
			this.oh_my_stars.each(function(obj,index) {	   
				
				obj.addEvent('mouseenter',function(index){									   
					for(j = index; j > 0; j--) {
						this.oh_my_stars[j].set({'src':this.options.star});
					}
					
					for(j = (index + 1); j < 6; j++) {
						this.oh_my_stars[j].set({'src':this.options.star_blank});
					}
				}.bind(this,index));
				
				obj.addEvent('click',function(index){
					this.options.my_rating = index;
					var url = this.options.url + '&content_part_id=1&item_id='+this.options.item_id+'&field_id='+this.options.field_id+'&score='+index;
					this.request = new Request({'url':url,'method':'get'});
					this.request.removeEvents();
					this.request.setOptions({'onComplete':function(response){	
						var json = JSON.decode(response);
						if(json.response.error == 'false' || json.response.error == false){
							this.options.my_rating = json.response.my_rating;
							this.options.actual_rating = json.response.actual_rating;
							this.actual_rating_element.set('html','');
							this.actual_rating_num.set('html',this.options.actual_rating+' Stars');
							this.buildActual();
							if(this.options.active) {
								//this.my_rating_element.set('html','');
								this.my_rating_num.set('html',this.options.my_rating+' Stars');
								for(i = 1; i < 6; i++) {
									if(this.options.my_rating >= i) {
										this.oh_my_stars[i].set('src',this.options.star);
										this.lowest_set = i;
										this.lowest_set_type = 1;
									}
									else {
										if(this.options.my_rating >= (i - 0.75)) {
											this.oh_my_stars[i].set('src',this.options.star_half);
											this.lowest_set = i;
											this.lowest_set_type = 2;
										}
										else this.oh_my_stars[i].set('src',this.options.star_blank);
									}
								}	
							}
						} 
					}.bind(this)}).send();
					this.options.click();
				}.bind(this,index));
			}.bind(this));
			for(i = 1; i < 6; i++) {
				this.oh_my_stars[i].inject(this.my_rating_element);
			}
			this.my_rating_element.addEvent('mouseleave',function(){
				for(j = 5; j >= this.lowest_set; j--) {
					//alert(j);
					if(j > this.lowest_set) this.oh_my_stars[j].set({'src':this.options.star_blank});
					if(j == this.lowest_set && j != 0) {
						if(this.lowest_set_type == 2) this.oh_my_stars[j].set({'src':this.options.star_half});
						else this.oh_my_stars[j].set({'src':this.options.star});
					}
				}
			}.bind(this).pass(this));
			this.my_rating_element.inject(this.rating_element);
			
			this.my_rating_num = new Element('div',{'style':'display: none; width: 60px; height: '+this.options.height+'px;','class':'actual_rating_num','id':'actual_rating_num_'+this.options.field_id,'html':this.options.my_rating+' Stars'});
			this.my_rating_num.inject(this.rating_element);
			
			this.rating_element.addEvent('mouseenter',function(){
				this.actual_rating_element.setStyles({'display':'none'});
				this.my_rating_element.setStyles({'display':'inline-block'});
				this.actual_rating_num.setStyles({'display':'none'});
				this.my_rating_num.setStyles({'display':'inline-block'});
			}.bind(this).pass(this));
			this.rating_element.addEvent('mouseleave',function(){
				this.actual_rating_element.setStyles({'display':'inline-block'});
				this.my_rating_element.setStyles({'display':'none'});
				this.actual_rating_num.setStyles({'display':'inline-block'});
				this.my_rating_num.setStyles({'display':'none'});
			}.bind(this).pass(this));
		}
	},
    setStyles: function(style_options){
        
        //if(this.options['text-area'] && style_options['input-height'] == 'auto'){ style_options['input-height'] = (style_options['input-width'] * .50).toInt() }
		this.rating_element.setStyles({'height':style_options['input-height']});
		this.text_label.setStyles();
    },
    
	setLabelDisplay: function(label_position){
		if(label_position == 'inside'){
			this.rating_element.addEvent('focus',function(){
				this.text_label.addClass('Ohidden');
			}.bind(this));
			
			this.rating_element.addEvent('blur',function(){
				if(this.rating_element.getProperty('value') ==''){
					this.text_label.removeClass('Ohidden');
				}
			}.bind(this));
			
			this.text_label.addEvent('click',function(){
				this.text_label.addClass('Ohidden');
				this.rating_element.focus();
			}.bind(this));
		}
	},
	
	addEvent: function(type,fn){
		if(!(type == "keypress" && this.options['text-area'])){
	    	this.rating_element.addEvent(type,fn);
	    }
	},
	
	clearStars: function() {
		this.actual_rating_element.set('html','');
	},
    // get property
    getActualRating: function(){ return encodeURIComponent(this.options.actual_rating); },
    getMyRating: function(){ return encodeURIComponent(this.options.my_rating); },
    // set property
    setActualRating: function(value){ this.options.actual_rating = value; this.clearStars();this.buildActual();},
	setMyRating: function(value){ this.options.my_rating = value; },
    
    inject: function(el){
		this.container.inject(el);
    }
});
/**
 * Swiff.Uploader - Flash FileReference Control
 *
 * @version		3.0
 *
 * @license		MIT License
 *
 * @author		Harald Kirschner <http://digitarald.de>
 * @author		Valerio Proietti, <http://mad4milk.net>
 * @copyright	Authors
 */

Swiff.Uploader = new Class({

	Extends: Swiff,

	Implements: Events,

	options: {
		path: '/obray/config/Swiff.Uploader.swf',
		
		target: null,
		zIndex: 9999,
		
		height: 30,
		width: 100,
		callBacks: null,
		params: {
			wMode: 'opaque',
			menu: 'false',
			allowScriptAccess: 'always'
		},

		typeFilter: null,
		multiple: true,
		queued: true,
		verbose: false,

		url: null,
		method: null,
		data: null,
		mergeData: true,
		fieldName: null,

		fileSizeMin: 1,
		fileSizeMax: null, // Official limit is 100 MB for FileReference, but I tested up to 2Gb!
		allowDuplicates: false,
		timeLimit: (Browser.Platform.linux) ? 0 : 30,

		buttonImage: null,
		policyFile: null,
		
		fileListMax: 0,
		fileListSizeMax: 0,

		instantStart: false,
		appendCookieData: false,
		
		fileClass: null
		/*
		onLoad: $empty,
		onFail: $empty,
		onStart: $empty,
		onQueue: $empty,
		onComplete: $empty,
		onBrowse: $empty,
		onDisabledBrowse: $empty,
		onCancel: $empty,
		onSelect: $empty,
		onSelectSuccess: $empty,
		onSelectFail: $empty,
		
		onButtonEnter: $empty,
		onButtonLeave: $empty,
		onButtonDown: $empty,
		onButtonDisable: $empty,
		
		onFileStart: $empty,
		onFileStop: $empty,
		onFileRequeue: $empty,
		onFileOpen: $empty,
		onFileProgress: $empty,
		onFileComplete: $empty,
		onFileRemove: $empty,
		
		onBeforeStart: $empty,
		onBeforeStop: $empty,
		onBeforeRemove: $empty
		*/
	},

	initialize: function(options) {
		// protected events to control the class, added
		// before setting options (which adds own events)
		this.addEvent('load', this.initializeSwiff, true)
			.addEvent('select', this.processFiles, true)
			.addEvent('complete', this.update, true)
			.addEvent('fileRemove', function(file) {
				this.fileList.erase(file);
			}.bind(this), true);

		this.setOptions(options);

		// callbacks are no longer in the options, every callback
		// is fired as event, this is just compat
		if (this.options.callBacks) {
			Hash.each(this.options.callBacks, function(fn, name) {
				this.addEvent(name, fn);
			}, this);
		}

		this.options.callBacks = {
			fireCallback: this.fireCallback.bind(this)
		};

		var path = this.options.path;
		if (!path.contains('?')) path += '?noCache=' + $time(); // cache in IE

		// container options for Swiff class
		this.options.container = this.box = new Element('span', {'class': 'swiff-uploader-box'}).inject($(this.options.container) || document.body);

		// target 
		this.target = $(this.options.target);
		if (this.target) {
			var scroll = window.getScroll();
			this.box.setStyles({
				position: 'absolute',
				visibility: 'visible',
				zIndex: this.options.zIndex,
				overflow: 'hidden',
				height: 1, width: 1,
				top: scroll.y, left: scroll.x
			});
			
			// we force wMode to transparent for the overlay effect
			this.parent(path, {
				params: {
					wMode: 'transparent'
				},
				height: '100%',
				width: '100%'
			});
			
			this.target.addEvent('mouseenter', this.reposition.bind(this, []));
			
			// button interactions, relayed to to the target
			this.addEvents({
				buttonEnter: this.targetRelay.bind(this, ['mouseenter']),
				buttonLeave: this.targetRelay.bind(this, ['mouseleave']),
				buttonDown: this.targetRelay.bind(this, ['mousedown']),
				buttonDisable: this.targetRelay.bind(this, ['disable'])
			});
			
			this.reposition();
			window.addEvent('resize', this.reposition.bind(this, []));
		} else {
			this.parent(path);
		}

		this.inject(this.box);

		this.fileList = [];
		
		this.size = this.uploading = this.bytesLoaded = this.percentLoaded = 0;
		
		if (Browser.Plugins.Flash.version < 9) {
			this.fireEvent('fail', ['flash']);
		} else {
			this.verifyLoad.delay(1000, this);
		}
	},
	
	verifyLoad: function() {
		if (this.loaded) return;
		if (!this.object.parentNode) {
			this.fireEvent('fail', ['disabled']);
		} else if (this.object.style.display == 'none') {
			this.fireEvent('fail', ['hidden']);
		} else if (!this.object.offsetWidth) {
			this.fireEvent('fail', ['empty']);
		}
	},

	fireCallback: function(name, args) {
		// file* callbacks are relayed to the specific file
		if (name.substr(0, 4) == 'file') {
			// updated queue data is the second argument
			if (args.length > 1) this.update(args[1]);
			var data = args[0];
			
			var file = this.findFile(data.id);
			this.fireEvent(name, file || data, 5);
			if (file) {
				var fire = name.replace(/^file([A-Z])/, function($0, $1) {
					return $1.toLowerCase();
				});
				file.update(data).fireEvent(fire, [data], 10);
			}
		} else {
			this.fireEvent(name, args, 5);
		}
	},

	update: function(data) {
		// the data is saved right to the instance 
		$extend(this, data);
		this.fireEvent('queue', [this], 10);
		return this;
	},

	findFile: function(id) {
		for (var i = 0; i < this.fileList.length; i++) {
			if (this.fileList[i].id == id) return this.fileList[i];
		}
		return null;
	},

	initializeSwiff: function() {
		// extracted options for the swf 
		this.remote('initialize', {
			width: this.options.width,
			height: this.options.height,
			typeFilter: this.options.typeFilter,
			multiple: this.options.multiple,
			queued: this.options.queued,
			url: this.options.url,
			method: this.options.method,
			data: this.options.data,
			mergeData: this.options.mergeData,
			fieldName: this.options.fieldName,
			verbose: this.options.verbose,
			fileSizeMin: this.options.fileSizeMin,
			fileSizeMax: this.options.fileSizeMax,
			allowDuplicates: this.options.allowDuplicates,
			timeLimit: this.options.timeLimit,
			buttonImage: this.options.buttonImage,
			policyFile: this.options.policyFile
		});

		this.loaded = true;

		this.appendCookieData();
	},
	
	targetRelay: function(name) {
		if (this.target) this.target.fireEvent(name);
	},

	reposition: function(coords) {
		// update coordinates, manual or automatically
		coords = coords || (this.target && this.target.offsetHeight)
			? this.target.getCoordinates(this.box.getOffsetParent())
			: {top: window.getScrollTop(), left: 0, width: 40, height: 40}
		this.box.setStyles(coords);
		this.fireEvent('reposition', [coords, this.box, this.target]);
	},

	setOptions: function(options) {
		if (options) {
			if (options.url) options.url = Swiff.Uploader.qualifyPath(options.url);
			if (options.buttonImage) options.buttonImage = Swiff.Uploader.qualifyPath(options.buttonImage);
			this.parent(options);
			if (this.loaded) this.remote('setOptions', options);
		}
		return this;
	},

	setEnabled: function(status) {
		this.remote('setEnabled', status);
	},

	start: function() {
		this.fireEvent('beforeStart');
		this.remote('start');
	},

	stop: function() {
		this.fireEvent('beforeStop');
		this.remote('stop');
	},

	remove: function() {
		this.fireEvent('beforeRemove');
		this.remote('remove');
	},

	fileStart: function(file) {
		this.remote('fileStart', file.id);
	},

	fileStop: function(file) {
		this.remote('fileStop', file.id);
	},

	fileRemove: function(file) {
		this.remote('fileRemove', file.id);
	},

	fileRequeue: function(file) {
		this.remote('fileRequeue', file.id);
	},

	appendCookieData: function() {
		var append = this.options.appendCookieData;
		if (!append) return;
		
		var hash = {};
		document.cookie.split(/;\s*/).each(function(cookie) {
			cookie = cookie.split('=');
			if (cookie.length == 2) {
				hash[decodeURIComponent(cookie[0])] = decodeURIComponent(cookie[1]);
			}
		});

		var data = this.options.data || {};
		if ($type(append) == 'string') data[append] = hash;
		else $extend(data, hash);

		this.setOptions({data: data});
	},

	processFiles: function(successraw, failraw, queue) {
		var cls = this.options.fileClass || Swiff.Uploader.File;

		var fail = [], success = [];

		if (successraw) {
			successraw.each(function(data) {
				var ret = new cls(this, data);
				if (!ret.validate()) {
					ret.remove.delay(10, ret);
					fail.push(ret);
				} else {
					this.size += data.size;
					this.fileList.push(ret);
					success.push(ret);
					ret.render();
				}
			}, this);

			this.fireEvent('selectSuccess', [success], 10);
		}

		if (failraw || fail.length) {
			fail.extend((failraw) ? failraw.map(function(data) {
				return new cls(this, data);
			}, this) : []).each(function(file) {
				file.invalidate().render();
			});

			this.fireEvent('selectFail', [fail], 10);
		}

		this.update(queue);

		if (this.options.instantStart && success.length) this.start();
	}

});

$extend(Swiff.Uploader, {

	STATUS_QUEUED: 0,
	STATUS_RUNNING: 1,
	STATUS_ERROR: 2,
	STATUS_COMPLETE: 3,
	STATUS_STOPPED: 4,

	log: function() {
		if (window.console && console.info) console.info.apply(console, arguments);
	},

	unitLabels: {
		b: [{min: 1, unit: 'B'}, {min: 1024, unit: 'kB'}, {min: 1048576, unit: 'MB'}, {min: 1073741824, unit: 'GB'}],
		s: [{min: 1, unit: 's'}, {min: 60, unit: 'm'}, {min: 3600, unit: 'h'}, {min: 86400, unit: 'd'}]
	},

	formatUnit: function(base, type, join) {
		var labels = Swiff.Uploader.unitLabels[(type == 'bps') ? 'b' : type];
		var append = (type == 'bps') ? '/s' : '';
		var i, l = labels.length, value;

		if (base < 1) return '0 ' + labels[0].unit + append;

		if (type == 's') {
			var units = [];

			for (i = l - 1; i >= 0; i--) {
				value = Math.floor(base / labels[i].min);
				if (value) {
					units.push(value + ' ' + labels[i].unit);
					base -= value * labels[i].min;
					if (!base) break;
				}
			}

			return (join === false) ? units : units.join(join || ', ');
		}

		for (i = l - 1; i >= 0; i--) {
			value = labels[i].min;
			if (base >= value) break;
		}

		return (base / value).toFixed(1) + ' ' + labels[i].unit + append;
	}

});

Swiff.Uploader.qualifyPath = (function() {
	
	var anchor;
	
	return function(path) {
		(anchor || (anchor = new Element('a'))).href = path;
		return anchor.href;
	};

})();

Swiff.Uploader.File = new Class({

	Implements: Events,

	initialize: function(base, data) {
		this.base = base;
		this.update(data);
	},

	update: function(data) {
		return $extend(this, data);
	},

	validate: function() {
		var options = this.base.options;
		
		if (options.fileListMax && this.base.fileList.length >= options.fileListMax) {
			this.validationError = 'fileListMax';
			return false;
		}
		
		if (options.fileListSizeMax && (this.base.size + this.size) > options.fileListSizeMax) {
			this.validationError = 'fileListSizeMax';
			return false;
		}
		
		return true;
	},

	invalidate: function() {
		this.invalid = true;
		this.base.fireEvent('fileInvalid', this, 10);
		return this.fireEvent('invalid', this, 10);
	},

	render: function() {
		return this;
	},

	setOptions: function(options) {
		if (options) {
			if (options.url) options.url = Swiff.Uploader.qualifyPath(options.url);
			this.base.remote('fileSetOptions', this.id, options);
			this.options = $merge(this.options, options);
		}
		return this;
	},

	start: function() {
		this.base.fileStart(this);
		return this;
	},

	stop: function() {
		this.base.fileStop(this);
		return this;
	},

	remove: function() {
		this.base.fileRemove(this);
		return this;
	},

	requeue: function() {
		this.base.fileRequeue(this);
	} 

});


/**
 * FancyUpload - Flash meets Ajax for powerful and elegant uploads.
 * 
 * Updated to latest 3.0 API. Hopefully 100% compat!
 *
 * @version		3.0
 *
 * @license		MIT License
 *
 * @author		Harald Kirschner <http://digitarald.de>
 * @copyright	Authors
 */

var FancyUpload2 = new Class({

	Extends: Swiff.Uploader,
	
	options: {
		queued: 1,
		// compat
		limitSize: 0,
		limitFiles: 0,
		validateFile: $lambda(true)
	},

	initialize: function(status, list, options) {
		this.status = $(status);
		this.list = $(list);

		// compat
		options.fileClass = options.fileClass || FancyUpload2.File;
		options.fileSizeMax = options.limitSize || options.fileSizeMax;
		options.fileListMax = options.limitFiles || options.fileListMax;

		this.parent(options);

		this.addEvents({
			'load': this.render,
			'select': this.onSelect,
			'cancel': this.onCancel,
			'start': this.onStart,
			'queue': this.onQueue,
			'complete': this.onComplete
		});
	},

	render: function() {
		this.overallTitle = this.status.getElement('.overall-title');
		this.currentTitle = this.status.getElement('.current-title');
		this.currentText = this.status.getElement('.current-text');

		var progress = this.status.getElement('.overall-progress');
		this.overallProgress = new Fx.ProgressBar(progress, {
			text: new Element('span', {'class': 'progress-text'}).inject(progress, 'after')
		});
		progress = this.status.getElement('.current-progress')
		this.currentProgress = new Fx.ProgressBar(progress, {
			text: new Element('span', {'class': 'progress-text'}).inject(progress, 'after')
		});
				
		this.updateOverall();
	},

	onSelect: function() {
		this.status.removeClass('status-browsing');
	},

	onCancel: function() {
		this.status.removeClass('file-browsing');
	},

	onStart: function() {
		this.status.addClass('file-uploading');
		this.overallProgress.set(0);
	},

	onQueue: function() {
		this.updateOverall();
	},

	onComplete: function() {
		this.status.removeClass('file-uploading');
		if (this.size) {
			this.overallProgress.start(100);
		} else {
			this.overallProgress.set(0);
			this.currentProgress.set(0);
		}
		
	},

	updateOverall: function() {
		this.overallTitle.set('html', MooTools.lang.get('FancyUpload', 'progressOverall').substitute({
			total: Swiff.Uploader.formatUnit(this.size, 'b')
		}));
		if (!this.size) {
			this.currentTitle.set('html', MooTools.lang.get('FancyUpload', 'currentTitle'));
			this.currentText.set('html', '');
		}
	},
	
	/**
	 * compat
	 */
	upload: function() {
		this.start();
	},
	
	removeFile: function() {
		return this.remove();
	}

});

FancyUpload2.File = new Class({
	
	Extends: Swiff.Uploader.File,

	render: function() {
		if (this.invalid) {
			if (this.validationError) {
				var msg = MooTools.lang.get('FancyUpload', 'validationErrors')[this.validationError] || this.validationError;
				this.validationErrorMessage = msg.substitute({
					name: this.name,
					size: Swiff.Uploader.formatUnit(this.size, 'b'),
					fileSizeMin: Swiff.Uploader.formatUnit(this.base.options.fileSizeMin || 0, 'b'),
					fileSizeMax: Swiff.Uploader.formatUnit(this.base.options.fileSizeMax || 0, 'b'),
					fileListMax: this.base.options.fileListMax || 0,
					fileListSizeMax: Swiff.Uploader.formatUnit(this.base.options.fileListSizeMax || 0, 'b')
				});
			}
			this.remove();
			return;
		}
		
		this.addEvents({
			'start': this.onStart,
			'progress': this.onProgress,
			'complete': this.onComplete,
			'error': this.onError,
			'remove': this.onRemove
		});
		
		this.info = new Element('span', {'class': 'file-info'});
		this.element = new Element('li', {'class': 'file'}).adopt(
			new Element('span', {'class': 'file-size', 'html': Swiff.Uploader.formatUnit(this.size, 'b')}),
			new Element('a', {
				'class': 'file-remove',
				href: '#',
				html: MooTools.lang.get('FancyUpload', 'remove'),
				title: MooTools.lang.get('FancyUpload', 'removeTitle'),
				events: {
					click: function() {
						this.remove();
						return false;
					}.bind(this)
				}
			}),
			new Element('span', {'class': 'file-name', 'html': MooTools.lang.get('FancyUpload', 'fileName').substitute(this)}),
			this.info
		).inject(this.base.list);
	},
	
	validate: function() {
		return (this.parent() && this.base.options.validateFile(this));
	},
	
	onStart: function() {
		this.element.addClass('file-uploading');
		this.base.currentProgress.cancel().set(0);
		this.base.currentTitle.set('html', MooTools.lang.get('FancyUpload', 'currentFile').substitute(this));
	},

	onProgress: function() {
		this.base.overallProgress.start(this.base.percentLoaded);
		this.base.currentText.set('html', MooTools.lang.get('FancyUpload', 'currentProgress').substitute({
			rate: (this.progress.rate) ? Swiff.Uploader.formatUnit(this.progress.rate, 'bps') : '- B',
			bytesLoaded: Swiff.Uploader.formatUnit(this.progress.bytesLoaded, 'b'),
			timeRemaining: (this.progress.timeRemaining) ? Swiff.Uploader.formatUnit(this.progress.timeRemaining, 's') : '-'
		}));
		this.base.currentProgress.start(this.progress.percentLoaded);
	},
	
	onComplete: function() {
		this.element.removeClass('file-uploading');
		
		this.base.currentText.set('html', 'Upload completed');
		this.base.currentProgress.start(100);
		
		if (this.response.error) {
			var msg = MooTools.lang.get('FancyUpload', 'errors')[this.response.error] || '{error} #{code}';
			this.errorMessage = msg.substitute($extend({
				name: this.name,
				size: Swiff.Uploader.formatUnit(this.size, 'b')
			}, this.response));
			var args = [this, this.errorMessage, this.response];
			
			this.fireEvent('error', args).base.fireEvent('fileError', args);
		} else {
			this.base.fireEvent('fileSuccess', [this, this.response.text || '']);
		}
	},

	onError: function() {
		this.element.addClass('file-failed');
		var error = MooTools.lang.get('FancyUpload', 'fileError').substitute(this);
		this.info.set('html', '<strong>' + error + ':</strong> ' + this.errorMessage);
	},

	onRemove: function() {
		this.element.getElements('a').setStyle('visibility', 'hidden');
		this.element.fade('out').retrieve('tween').chain(Element.destroy.bind(Element, this.element));
	}
	
});


/**
 * FancyUpload.Attach - Flash meets Ajax for powerful and elegant uploads.
 *
 * @version     3.0 rc1
 *
 * @license     MIT License
 *
 * @author      Harald Kirschner <mail [at] digitarald [dot] de>
 * @copyright   Authors
 */

if (!window.FancyUpload3) var FancyUpload3 = {};

FancyUpload3.Attach = new Class({

    Extends: Swiff.Uploader,
    
    options: {
        queued: false,
        instantStart: true
    },

    initialize: function(list, selects, options) {
        this.list = $(list);
        this.selects = $(selects) ? $$($(selects)) : $$(selects);
                
        options.target = this.selects[0];
        options.fileClass = options.fileClass || FancyUpload3.Attach.File;
        
        this.parent(options);

        /**
         * Button state
         */
        var self = this;
        
        this.selects.addEvents({
            click: function() {
                return false;
            },
            mouseenter: function() {
                this.addClass('hover');
                self.reposition();
            },
            mouseleave: function() {
                this.removeClass('hover');
                this.blur();
            },
            mousedown: function() {
                this.focus();
            }
        });
        
        if (this.selects.length == 2) {
            this.selects[1].setStyle('display', 'none');
            this.addEvents({
                'selectSuccess': this.onSelectSuccess,
                'fileRemove': this.onFileRemove
            });
        }
    },
    
    onSelectSuccess: function() {
        if (this.fileList.length > 0) {
            this.selects[0].setStyle('display', 'none');
            this.selects[1].setStyle('display', 'inline');
            this.target = this.selects[1];
            this.reposition();
        }
    },
    
    onFileRemove: function() {
        if (this.fileList.length == 0) {
            this.selects[0].setStyle('display', 'inline');
            this.selects[1].setStyle('display', 'none');
            this.target = this.selects[0];
            this.reposition();
        }
    },
    
    start: function() {
        if (Browser.Platform.linux && window.confirm(MooTools.lang.get('FancyUpload', 'linuxWarning'))) return this;
        return this.parent();
    }
    
});

FancyUpload3.Attach.File = new Class({

    Extends: Swiff.Uploader.File,

    render: function() {
        
        if (this.invalid) {
            if (this.validationError) {
                var msg = MooTools.lang.get('FancyUpload', 'validationErrors')[this.validationError] || this.validationError;
                this.validationErrorMessage = msg.substitute({
                    name: this.name,
                    size: Swiff.Uploader.formatUnit(this.size, 'b'),
                    fileSizeMin: Swiff.Uploader.formatUnit(this.base.options.fileSizeMin || 0, 'b'),
                    fileSizeMax: Swiff.Uploader.formatUnit(this.base.options.fileSizeMax || 0, 'b'),
                    fileListMax: this.base.options.fileListMax || 0,
                    fileListSizeMax: Swiff.Uploader.formatUnit(this.base.options.fileListSizeMax || 0, 'b')
                });
            }
            this.remove();
            return;
        }
        
        this.addEvents({
            'open': this.onOpen,
            'remove': this.onRemove,
            'requeue': this.onRequeue,
            'progress': this.onProgress,
            'stop': this.onStop,
            'complete': this.onComplete,
            'error': this.onError
        });
        
        this.ui = {};
        
        this.ui.element = new Element('li', {'class': 'file', id: 'file-' + this.id});
        this.ui.title = new Element('span', {'class': 'file-title', text: this.name});
        this.ui.size = new Element('span', {'class': 'file-size', text: Swiff.Uploader.formatUnit(this.size, 'b')});
        
        this.ui.cancel = new Element('a', {'class': 'file-cancel', text: 'Cancel', href: '#'});
        this.ui.cancel.addEvent('click', function() {
            this.remove();
            return false;
        }.bind(this));
        
        this.ui.element.adopt(
            this.ui.title,
            this.ui.size,
            this.ui.cancel
        ).inject(this.base.list).highlight();
        
        var progress = new Element('img', {'class': 'file-progress', src: '/obray/config/images/progress_bar.gif'}).inject(this.ui.size, 'after');
        this.ui.progress = new Fx.ProgressBar(progress, {
            fit: true
        }).set(0);
                    
        this.base.reposition();

        return this.parent();
    },

    onOpen: function() {
        this.ui.element.addClass('file-uploading');
        if (this.ui.progress) this.ui.progress.set(0);
    },

    onRemove: function() {
        this.ui = this.ui.element.destroy();
    },

    onProgress: function() {
        if (this.ui.progress) this.ui.progress.start(this.progress.percentLoaded);
    },

    onStop: function() {
        this.remove();
    },
    
    onComplete: function() {
        this.ui.element.removeClass('file-uploading');

        if (this.response.error) {
            var msg = MooTools.lang.get('FancyUpload', 'errors')[this.response.error] || '{error} #{code}';
            this.errorMessage = msg.substitute($extend({name: this.name}, this.response));
            
            this.base.fireEvent('fileError', [this, this.response, this.errorMessage]);
            this.fireEvent('error', [this, this.response, this.errorMessage]);
            return;
        }
        
        if (this.ui.progress) this.ui.progress = this.ui.progress.cancel().element.destroy();
        this.ui.cancel = this.ui.cancel.destroy();
        
        var response = this.response.text || '';
        this.base.fireEvent('fileSuccess', [this, response]);
    },

    onError: function() {
        this.ui.element.addClass('file-failed');        
    }

});

//Avoiding MooTools.lang dependency
(function() {
    
    var phrases = {
        'fileName': '{name}',
        'cancel': 'Cancel',
        'cancelTitle': 'Click to cancel and remove this entry.',
        'validationErrors': {
            'duplicate': 'File <em>{name}</em> is already added, duplicates are not allowed.',
            'sizeLimitMin': 'File <em>{name}</em> (<em>{size}</em>) is too small, the minimal file size is {fileSizeMin}.',
            'sizeLimitMax': 'File <em>{name}</em> (<em>{size}</em>) is too big, the maximal file size is <em>{fileSizeMax}</em>.',
            'fileListMax': 'File <em>{name}</em> could not be added, amount of <em>{fileListMax} files</em> exceeded.',
            'fileListSizeMax': 'File <em>{name}</em> (<em>{size}</em>) is too big, overall filesize of <em>{fileListSizeMax}</em> exceeded.'
        },
        'errors': {
            'httpStatus': 'Server returned HTTP-Status #{code}',
            'securityError': 'Security error occured ({text})',
            'ioError': 'Error caused a send or load operation to fail ({text})'
        },
        'linuxWarning': 'Warning: Due to a misbehaviour of Adobe Flash Player on Linux,\nthe browser will probably freeze during the upload process.\nDo you want to start the upload anyway?'
    };
    
    if (MooTools.lang) {
        MooTools.lang.set('en-US', 'FancyUpload', phrases);
    } else {
        MooTools.lang = {
            get: function(from, key) {
                return phrases[key];
            }
        };
    }
    
})();


/**
 * Fx.ProgressBar
 *
 * @version		1.1
 *
 * @license		MIT License
 *
 * @author		Harald Kirschner <mail [at] digitarald [dot] de>
 * @copyright	Authors
 */

Fx.ProgressBar = new Class({

	Extends: Fx,

	options: {
		text: null,
		url: null,
		transition: Fx.Transitions.Circ.easeOut,
		fit: true,
		link: 'cancel'
	},

	initialize: function(element, options) {
		this.element = $(element);
		this.parent(options);
				
		var url = this.options.url;
		if (url) {
			this.element.setStyles({
				'background-image': 'url(' + url + ')',
				'background-repeat': 'no-repeat'
			});
		}
		
		if (this.options.fit) {
			url = url || this.element.getStyle('background-image').replace(/^url\(["']?|["']?\)$/g, '');
			if (url) {
				var fill = new Image();
				fill.onload = function() {
					this.fill = fill.width;
					fill = fill.onload = null;
					this.set(this.now || 0);
				}.bind(this);
				fill.src = url;
				if (!this.fill && fill.width) fill.onload();
			}
		} else {
			this.set(0);
		}
	},

	start: function(to, total) {
		return this.parent(this.now, (arguments.length == 1) ? to.limit(0, 100) : to / total * 100);
	},

	set: function(to) {
		this.now = to;
		var css = (this.fill)
			? (((this.fill / -2) + (to / 100) * (this.element.width || 1) || 0).round() + 'px')
			: ((100 - to) + '%');
		
		this.element.setStyle('backgroundPosition', css + ' 0px').title = Math.round(to) + '%';
		
		var text = $(this.options.text);
		if (text) text.set('text', Math.round(to) + '%');
		
		return this;
	}

});




