var $E = function $E(selector) {
	return $$(selector)[0];
};

var Overlay = new Class({
	overlay: function(elem, id) {
		var overlay = new Element('div', {'id': 'overlay', 'styles': {'opacity': '0', 'visibility': 'visible', 'height': '0', 'overflow': 'hidden'}}).inject(document.body),
			e = $(id) || new Element(elem, {'id': id}).inject(document.body);
		return e.addClass('lightbox');
	},
	showOverlay: function(close) {
		var h = window.getScroll().y,
			w = (Browser.Engine.presto) ? window.innerWidth/2: window.getScrollSize().x/2;
		$('overlay').set('tween').setStyles({
			'top': -$(window).getScroll().y,
			'height':$(window).getScrollSize().y+$(window).getScroll().y,
			'visibility': 'visible',
			'display': 'block'
		}).tween('opacity', '0.7');
		$E('.lightbox').setStyles({'display': 'block', 'visibility': 'visible'});
		$E('.lightbox').setStyles({'top': h + 100 + 'px', 'left': w - ($E('.lightbox').getScrollSize().x/2) + 'px'});
		if (close) {
			if ($type(close) === 'array') {
				close.each(function(elem) {
					elem.addEvent('click', function() {
						this.closeLightbox();
					}.bind(this));
				}, this);
			} else {
				close.addEvent('click', function() {
					this.closeLightbox();
				}.bind(this));
			}
		}
	},
	closeLightbox: function() {
		$$('.lightbox').each(function(elem) {
			elem.destroy();
		});
		$('overlay').destroy();
	}
});

var Lightbox = new Class({
	Implements: [Options, Events, Overlay],
	options: {
		// onShow: $empty,
		elems: false,
		containerId: 'lightbox',
		url: false,
		closeId: 'closeLightbox',
		closeSelector: false,
		cache: true
	},
	initialize: function(options) {
		this.setOptions(options);
		this.content = [];
		if (this.options.elems) {
			$$(this.options.elems).each(function(elem, index) {
				elem.addEvent('click', function(event) {
					var query;
					event.preventDefault();
					if (elem.href) query = getQuery(elem.href);
					this.display(index, query);
				}.bind(this));
			}, this);
		} else if (this.options.elems !== null) {
			this.display();
		}
	},
	display: function(index, query) {
		var containerId = $type(this.options.containerId) === 'array' ? this.options.containerId[index]: this.options.containerId,
			container = this.overlay('div', containerId),
			close;
		if (this.content[index]) {
			container.innerHTML = this.content[index];
			close = this.options.closeSelector ? $$(this.options.closeSelector) : $(this.options.closeId);
			this.showOverlay(close);
		} else {
			if (this.options.url) {
				this.fetchContent(container, index, this.options.cache, query);
			} else {
				if (this.options.cache) this.content[index] = container.innerHTML;
				close = this.options.closeSelector ? $$(this.options.closeSelector) : $(this.options.closeId);
				this.showOverlay(close);
			}
		}
		this.fireEvent('show', [container, this.options.elems]);
	},
	fetchContent: function(container, index, cache, query) {
		var close,
		requester = new Request({
			url: this.options.url,
			method: 'get',
			onSuccess: function(responseText) {
				container.innerHTML = responseText;
				this.content[index] = responseText;
				close = this.options.closeSelector ? $$(this.options.closeSelector) : $(this.options.closeId);
				this.showOverlay(close);
			}.bind(this)
		});
		requester.send(query);
	}
});

var parseUrl = function parseUrl(url, segment) {
	var parts,
		partNames,
		partsObject,
		parseUrl = /^(?:([A-Za-z]+):)?(?:\/{0,3})?([A-Za-z0-9\.\-]+)?(\/[\.A-Za-z_\-0-9\/]+)(?:\?([A-Za-z0-9\s=\.&@$%\*\(\)!,\:\+]+))?(?:#([A-Za-z0-9]+))?$/;
	if (parseUrl.test(url)) {
		parts = parseUrl.exec(url);
		partNames = ['url', 'protocol', 'base', 'path', 'query', 'hash'];
		partsObject = parts.associate(partNames);
		return (segment) ? partsObject[segment]: partsObject;
	} else {
		return false;
	}
};

var stripQuery = function stripQuery(url) {
	var base = url.split('?')[0];
	return base ? base: url;
};

var getQuery = function getQuery(url) {
	var query = (url.split('?')[1]) ? url.split('?')[1].split('#')[0]: false;
	return query;
};

var parseQuery = function parseQuery(url, exclude, include) {
	var query = getQuery(url) ? getQuery(url).split('&') : null,
		parts = [], splitQuery;
	if (query === null) return false;;
	for (var i = 0, l = query.length; i < l; i += 1) {
		splitQuery = query[i].split('=');
		if (exclude) {
			if (exclude.indexOf(splitQuery[0]) === -1) parts.push(query[i]);
		} else if (include) {
			if (include.indexOf(splitQuery[0]) !== -1) parts.push(query[i]);
		}
	}
	return parts.join('&');
};

var Loader = new Class({
	setLoader: function(container, options) {
		var opts = {
				loaderType: 'text', // 'image' or 'text'
				loaderText: 'loading...',
				loaderSrc: false
			},
			pos = container.getPosition(),
			w = container.getSize().x,
			loaderImg, loaderPos;
		if (options) opts = $merge(opts, options);
		if (!this.requestCount) this.requestCount = 0;
		this.requestCount += 1;
		this.loader = opts.loaderType === 'text' ? $('textLoader') : $('loader');
		
		if (!this.loader) {
			if (opts.loaderType === 'text') {
				this.loader = new Element('p', {'id': 'textLoader'}).appendText(opts.loaderText);
			} else {
				this.loader = new Element('div', {'id': 'loader'});
				loaderImg = new Element('img', {'src': opts.loaderSrc}).inject(this.loader);
			}
		}
		
		this.loader.inject(container);
		if (!opts.styles) opts.styles = {};
		if ($type(opts.styles['left']) !== 'number' && $type(opts.styles['right']) !== 'number') opts.styles['left'] = (w/2) - (this.loader.getSize().x/2) + 'px';
		opts.styles['position'] = 'absolute';
		opts.styles['display'] = 'block';
		this.loader.setStyles(opts.styles);
	},
	hideLoader: function() {
		if (this.requestCount <= 1) this.loader.setStyle('display', 'none');
		this.requestCount -= 1;
	}
});

var Login = new Class({
	Implements: [Options, Events, Chain],
	options: {
		// onFinish: $empty,
		url: null,
		required: 3,
		error: {
			'email': 'Please enter your email address.',
			'password': 'Please enter your password.',
			'incorrect': 'Sorry, you are not logged in. Your e-mail address and/or password was invalid.'
		}
	},
	initialize: function(forms, options) {
		this.setOptions(options);
		this.forms = $$(forms);
		this.forms.each(function(form, index) {
			form.addEvent('submit', function(event) {
				event.preventDefault();
				this.checkForm(form);
			}.bind(this));
		}, this);
	},
	checkForm: function(form) {
		var params = [],
			inputs = form.getElements('input');
		inputs.each(function(input) {
			if (input.get('type') !== 'submit' && input.get('type') !== 'image') {
				if ( input.value !== '') {
					params.push(input.get('name') + '=' + encodeURIComponent(input.value));
				} else {
					alert(this.options.error[input.get('name')]);
				}
			}
		}, this);
		if (params.length === this.options.required) this.sendForm(form, params);
	},
	sendForm: function(form, params) {
		var url = this.options.url;
		var requester = new Request({
			url: url,
			onComplete: function(responseText) {
				if (responseText.length === 0) {
					alert(this.options.error['incorrect']);
				} else {
					this.fireEvent('onFinish', [this.forms, this.forms.indexOf(form)]);
				}
			}.bind(this)
		});
		requester.send(params.join('&'));
	}
});
// DO NOT DELETE THIS UNTIL MATT FIXES THIS FOR THE REST OF PT
/*var Accordion = new Class({
	Implements: [Options, Events],
	options: {
		// onCollapse: $empty,
		// onExpand: $empty,
		trigger: 'click',
		direction: 'vertical',
		openedClass: 'expanded',
		closedClass: 'collapsed',
		duration: 'normal',
		allClosed: false,
		multiOpen: false,
		opacity: true,
		fixedHeight: false,
		fixedWidth: false,
		startOpen: 0
	},
	initialize: function(togglers, folds, options) {
		this.setOptions(options);
		this.togglers = $$(togglers);
		this.folds = $$(folds);
		this.open = [];
		this.params = this.options.opacity ? {'opacity': '0'}: {};
		this.dimension = this.options.direction === 'horizontal' ? 'width': 'height';
		this.params[this.dimension] = '0';
		this.folds.each(function(fold, index) {
			if (!fold.hasClass(this.options.closedClass)) this.open.push[fold];
			if (this.options.allClosed || (index !== this.options.startOpen && !this.options.multiOpen)) {
				fold.setStyles(this.params);
			}
		}, this);
		this.togglers.each(function(toggler, index) {
			toggler.addEvent(this.options.trigger, function(event) {
				event.preventDefault();
				var i = (this.togglers.length > this.folds.length) ? 0: index;
				this.display(this.folds[i]);
			}.bind(this));	
		}, this);
	},
	display: function(fold) {
		if (fold.hasClass(this.options.openedClass)) {
			this.collapse(fold);
		} else {
			this.expand(fold);
		}
	},
	collapse: function(fold) {
		this.open.splice[this.folds.indexOf(fold), 1];
		this.fireEvent('collapse', [this.togglers, this.folds, this.folds.indexOf(fold)]);
		fold.set('morph', { duration: this.options.duration, onComplete: function() {
			fold.removeClass(this.options.openedClass).addClass(this.options.closedClass);
		}.bind(this)});
		for (var fx in this.params) this.params[fx] = '0';
		fold.morph(this.params);
	},
	expand: function(fold) {
		if (!this.options.multiOpen) for (var i = 0, l = this.open.length; i < l; i += 1) this.collapse(this.open[i]);
		this.open.push(fold);
		this.fireEvent('expand', [this.togglers, this.folds, this.folds.indexOf(fold)]);
		fold.set('morph', { duration: this.options.duration });
		fold.removeClass(this.options.closedClass).addClass(this.options.openedClass);
		h = this.options.fixedHeight ? this.options.fixedHeight: fold.scrollHeight + 'px';
		w = this.options.fixedWidth ? this.options.fixedWidth: fold.offsetWidth + 'px';
		this.params[this.dimension] = this.options.direction === 'horizontal' ? w: h;
		this.params['opacity'] = '1';
		fold.morph(this.params);
	}
});*/

var Accordion = new Class({
	Implements: [Options, Events],
	options: {
		// onCollapse: $empty,
		// onExpand: $empty,
		closedClass: 'collapsed',
		direction: 'vertical',
		duration: 'normal',
		fixedHeight: false,
		fixedWidth: false,
		foldClass: 'fold',
		multiOpen: false,
		opacity: true,
		openedClass: 'expanded',
		params: false, // should be an object
		togglerClass: 'toggler'
	},
	initialize: function(container, options) {
		var closedClass = this.options.closedClass,
			params = this.options.params,
			fx, i, key, l;
		this.setOptions(options);
		this.container = $(container);
		this.togglers = $$('.' + this.options.togglerClass);
		this.folds = $$('.' + this.options.foldClass);
		
		if (!params) params = this.options.params = {};
		this.d = this.options.direction === 'horizonal' ? 'width': 'height';
		if (this.options.opacity) params.opacity = 1;
		this.collapseParams = {};
		this.collapseParams[this.d] = 0;
		for (fx in params) this.collapseParams[fx] = $type(params[fx]) === 'array'? params[fx].reverse(): 0;
		
		l = this.folds.length;
		d = this.d;
		for (i = 0; i < l; i += 1) {
			if (this.folds[i].hasClass(this.options.closedClass)) this.folds[i].setStyle(this.d, '0px');
		}
		
		this.attach();
	},
	attach: function() {
		this.container.addEvents({
			'click': function(event) {
				var elem = $(event.target);
				if (elem.hasClass(this.options.togglerClass)) {
					event.preventDefault();
					this.display(this.togglers.indexOf(elem));
				}
			}.bind(this)
		});
	},
	display: function(index) {
		var fold = this.folds[index],
			action = fold.hasClass(this.options.closedClass) ? 'expand': 'collapse';
		this[action](fold, index);
	},
	collapse: function(fold, index) {
		var opts = this.options;
		this.fireEvent('collapse', [this.togglers, this.folds, index]);
		fold.set('morph', { duration: opts.duration, onComplete: function() {
			fold.removeClass(opts.openedClass).addClass(opts.closedClass);
		}.bind(this)});
		fold.morph(this.collapseParams);
		this.fireEvent('onCollapse', [this.togglers, this.folds, index]);
	},
	expand: function(fold, index) {
		var i = 0,
			opts = this.options,
			dValue, j, l;
		
		this.fireEvent('expand', [this.togglers, this.folds, index]);
		
		fold.set('morph', { duration: opts.duration });
		fold.removeClass(opts.closedClass).addClass(opts.openedClass);
		
		if (!this.options.multiOpen) {
			l = this.folds.length;
			while (i < l) {
				if (i !== index) this.collapse(this.folds[i], i);
				i += 1;
			}
		}
		
		/*if (!this.options.multiOpen) {
			i = this.opened.length;
			while (i > 0) {
				j = this.opened.pop();
				if (j !== index) this.collapse(this.folds[j], j);
				i -= 1;
			}
		}*/
		
		// opening up or out?
		if (this.d === 'width') {
			dValue = opts.fixedWidth? opts.fixedWidth: fold.offsetWidth;
		} else {
			dValue = opts.fixedHeight? opts.fixedHeight: fold.scrollHeight;
		}
		
		opts.params[this.d] = dValue;
		
		fold.morph(opts.params);
		
		this.fireEvent('onExpand', [this.togglers, this.folds, index]);
	}
});

/*
I took this out of more.js so that we didn't have to include the entire more library on every page.
Script: Tips.js
	Class for creating nice tips that follow the mouse cursor when hovering an element.
	License:
		MIT-style license.
	Authors:
		Valerio Proietti
		Christoph Pojer
*/
var Tips = new Class({
	Implements: [Events, Options],
	options: {
		onShow: function(tip){
			tip.setStyle('visibility', 'visible');
		},
		onHide: function(tip){
			tip.setStyle('visibility', 'hidden');
		},
		title: 'title',
		text: function(el){
			return el.get('rel') || el.get('href');
		},
		showDelay: 100,
		hideDelay: 100,
		className: null,
		offset: {x: 16, y: 16},
		fixed: false
	},
	initialize: function(){
		var params = Array.link(arguments, {options: Object.type, elements: $defined});
		if (params.options && params.options.offsets) params.options.offset = params.options.offsets;
		this.setOptions(params.options);
		this.container = new Element('div', {'class': 'tip'});
		this.tip = this.getTip();
		
		if (params.elements) this.attach(params.elements);
	},
	getTip: function(){
		return new Element('div', {
			'class': this.options.className,
			styles: {
				visibility: 'hidden',
				display: 'none',
				position: 'absolute',
				top: 0,
				left: 0
			}
		}).adopt(
			new Element('div', {'class': 'tip-top'}),
			this.container,
			new Element('div', {'class': 'tip-bottom'})
		).inject(document.body);
	},
	attach: function(elements){
		var read = function(option, element){
			if (option == null) return '';
			return $type(option) == 'function' ? option(element) : element.get(option);
		};
		$$(elements).each(function(element){
			var title = read(this.options.title, element);
			element.erase('title').store('tip:native', title).retrieve('tip:title', title);
			element.retrieve('tip:text', read(this.options.text, element));
			
			var events = ['enter', 'leave'];
			if (!this.options.fixed) events.push('move');
			
			events.each(function(value){
				element.addEvent('mouse' + value, element.retrieve('tip:' + value, this['element' + value.capitalize()].bindWithEvent(this, element)));
			}, this);
		}, this);
		
		return this;
	},
	detach: function(elements){
		$$(elements).each(function(element){
			['enter', 'leave', 'move'].each(function(value){
				element.removeEvent('mouse' + value, element.retrieve('tip:' + value) || $empty);
			});
			
			element.eliminate('tip:enter').eliminate('tip:leave').eliminate('tip:move');
			
			if ($type(this.options.title) == 'string' && this.options.title == 'title'){
				var original = element.retrieve('tip:native');
				if (original) element.set('title', original);
			}
		}, this);
		
		return this;
	},
	elementEnter: function(event, element){
		$A(this.container.childNodes).each(Element.dispose);
		
		['title', 'text'].each(function(value){
			var content = element.retrieve('tip:' + value);
			if (!content) return;
			
			this[value + 'Element'] = new Element('div', {'class': 'tip-' + value}).inject(this.container);
			this.fill(this[value + 'Element'], content);
		}, this);
		
		this.timer = $clear(this.timer);
		this.timer = this.show.delay(this.options.showDelay, this, element);
		this.tip.setStyle('display', 'block');
		this.position((!this.options.fixed) ? event : {page: element.getPosition()});
	},
	elementLeave: function(event, element){
		$clear(this.timer);
		this.tip.setStyle('display', 'none');
		this.timer = this.hide.delay(this.options.hideDelay, this, element);
	},
	elementMove: function(event){
		this.position(event);
	},
	position: function(event){
		var size = window.getSize(), scroll = window.getScroll(),
			tip = {x: this.tip.offsetWidth, y: this.tip.offsetHeight},
			props = {x: 'left', y: 'top'},
			obj = {};
		
		for (var z in props){
			obj[props[z]] = event.page[z] + this.options.offset[z];
			if ((obj[props[z]] + tip[z] - scroll[z]) > size[z]) obj[props[z]] = event.page[z] - this.options.offset[z] - tip[z];
		}
		
		this.tip.setStyles(obj);
	},
	fill: function(element, contents){
		if(typeof contents == 'string') element.set('html', contents);
		else element.adopt(contents);
	},
	show: function(el){
		this.fireEvent('show', [this.tip, el]);
	},
	hide: function(el){
		this.fireEvent('hide', [this.tip, el]);
	}
});

var Search = new Class({
	Implements: [Options, Events, Loader],
	options: {
		// onSend: $empty,
		// onFinish: $empty,
		bustCache: false,
		cache: true,
		containerClass: false,
		elemClass: false,
		events: 'submit',
		loader: false,
		loaderOptions: {
			loaderSrc: false,
			loaderStyles: {'top': 0, 'right': 0},
			loaderType: 'image'
		},
		loaderParent: 'trigger', // can be 'trigger' or 'container'
		preventDefault: true,
		params: false, // should be an object
		query: 'id',
		url: null
	},
	initialize: function(elem, container, options) {
		this.setOptions(options);
		if (this.options.requestLimit) this.sent = 0;
		this.elems = this.options.elemClass? elem.getElements('.' + this.options.elemClass): elem;
		this.containers = container ? container: elem.getElements('.' + this.options.containerClass);
		this.attach(elem);
	},
	attach: function(elem) {
		var events = this.options.events;
		if ($type(events) === 'array') {
			events.each(function(e) {
				elem.addEvent(e, function(event) {
					var t = $(event.target),
						elem = t.hasClass(this.options.elemClass) ? t: elem;
					if (e === 'submit' || t.hasClass(this.options.elemClass)) this.getResults(elem, event);
				}.bind(this));
			}, this);
		} else {
			elem.addEvent(events, function(event) {
				var t = $(event.target),
					elem = t.hasClass(this.options.elemClass) ? t: elem;
				
				if (events === 'submit' || t.hasClass(this.options.elemClass)) this.getResults(elem, event);
			}.bind(this));
		}
	},
	getResults: function(elem, event) {
		var i = $type(this.elems) === 'array' ? this.elems.indexOf(elem): -1,
			container = $type(this.containers) === 'array'? this.containers[i]: this.containers,
			opts = this.options.loaderOptions,
			params = this.options.params,
			url = this.options.url,
			loader, newQuery, query, requester, results;
		
		if (this.options.preventDefault) event.preventDefault();
		
		if (event.type === 'submit') {
			query = elem.toQueryString();
		} else {
			query = elem.nodeName === 'A' ? getQuery(elem.href): this.options.query + '=' + elem.get(this.options.query);
		}
		if (params) query += '&' + params.toQueryString();
		results = container.retrieve(query);
		
		newQuery = (this.options.bustCache) ? query + '&' + new Date().getTime() : query;
		
		if (this.options.loader) loader = !opts.loaderType ? this.options.loader : this.options.loaderParent === 'container' ? container: elem;

		if (results) {
			container.innerHTML = results;
			this.fireEvent('onFinish', [this.elems, this.containers, i]);
		} else {
			requester = new Request({
				url: url,
				method: 'get',
				onRequest: function() {
					this.fireEvent('onSend', [this.elems, this.containers, i]);
					if (this.options.loader) this.setLoader(loader, opts);
				}.bind(this),
				onSuccess: function(response) {
					if (this.options.requestLimit) this.sent += 1;
					container.innerHTML = response;
					if (this.options.cache) container.store(query, response);
					this.fireEvent('onFinish', [this.elems, this.containers, i]);
					if (this.options.loader) this.hideLoader();
				}.bind(this)
			});
			requester.send(newQuery);
		}
	}
});

var Autocomplete = new Class({
	Implements: [Options, Events],
	options: {
		// onBlur: $empty,
		// onHide: $empty,
		// onInit: $empty,
		// onInput: $empty,
		// onOver: $empty,
		// onSelect: $empty,
		// onShow: $empty,
		clickSubmit: true,
		containerElem: 'ul',
		containerId: 'autocomplete',
		minLength: 1,
		resultsElem: 'li',
		resultsClass: 'highlighted',
		width: 0,
		url: null,
		zIndex: 10
	},
	initialize: function(elem, options) {
		this.setOptions(options);
		this.len = 0;
		this.elem = $(elem);
		this.form = this.elem.getParent('form');
		this.container = $(this.options.containerId) || new Element(this.options.containerElem, {'id': this.options.containerId}).inject(document.body);
		this.container.setStyle('visibility', 'hidden');
		this.fireEvent('onInit', [this.elem, this.container]);
		this.attach();
	},
	attach: function() {
		this.elem.addEvents({
			'keyup': function(event) {
				this.container.store('form', this.form);
				if ((event.code === 38 || event.code === 40) && this.len > 0) {
					if (event.code === 38) {
						this.position = this.position <= 0 ? this.len - 1 : this.position - 1;
					} else {
						this.position = this.position === this.len - 1 ? 0 : this.position + 1;
					}
					this.updatePosition();
				} else {
					if (this.elem.value.length >= this.options.minLength) {
						this.fireEvent('onInput', [this.elem, this.container]);
						this.getResults();
					}
				}
			}.bind(this),
			'blur': function(event) {
				this.fireEvent('onBlur', [this.elem, this.container]);
				this.hide();
			}.bind(this)
		});
	},
	getResults: function() {
		var url = this.options.url,
			query = this.elem.getParent('form').toQueryString(),
			results = this.container.retrieve(query);
		if (this.requester) this.requester.cancel();
		this.requester = new Request({
			method: 'get',
			url: url,
			onSuccess: function(response) {
				this.container.innerHTML = response;
				this.container.store(query, response);
				this.show();
			}.bind(this)
		});
		if (results) {
			this.container.innerHTML = results;
			this.show();
		} else {
			this.requester.send(query);
		}
	},
	hide: function() {
		this.container.setStyle('visibility', 'hidden');
		this.fireEvent('onHide', [this.elem, this.container]);
	},
	show: function() {
		var d = this.elem.getSize(),
			t = this.elem.getPosition(),
			w = this.options.width > d.x ? this.options.width: d.x,
			z = this.options.zIndex;
		this.results = this.container.getElements(this.options.resultsElem);
		this.len = this.results.length;
		if (this.len > 0) {
			this.position = -1;
			this.container.setStyles({
				'visibility': 'visible',
				'top': d.y + t.y + 'px',
				'left': t.x + 'px',
				'width': w + 'px',
				'z-index': z
			});
			this.fireEvent('onShow', [this.elem, this.container]);
		}
		if (!this.container.retrieve('hasEvents')) this.attachContainerEvents();
	},
	attachContainerEvents: function() {
		this.container.store('hasEvents', true);
		this.container.addEvents({
			'mouseover': function(event) {
				if (event.target.nodeName.toLowerCase() === this.options.resultsElem) {
					this.position = this.results.indexOf(event.target);
					this.updatePosition();
					this.fireEvent('onOver', [this.elem, this.container, event]);
				}
			}.bind(this),
			'mousedown': function(event) {
				if (event.target.nodeName.toLowerCase() === this.options.resultsElem) {
					event.preventDefault();
					this.hide();
					if (this.options.clickSubmit) this.container.retrieve('form').submit();
				}
			}.bind(this)
		});
	},
	updatePosition: function() {
		var i, cur = this.results[this.position];
		for (i = 0; i < this.len; i += 1) this.results[i].removeClass(this.options.resultsClass);
		cur.addClass(this.options.resultsClass);
		this.elem.value = cur.firstChild.nodeValue;
		this.fireEvent('onSelect', [this.elem, this.container, cur]);
	}
});

// no ajax, assumes that containers.length === tabs.length
var Tabs = new Class({
	Implements: [Options, Events],
	options: {
		// onHide: $empty,
		// onInit: $empty,
		// onShow: $empty,
		forceHTML: false,
		hideClass: 'hideTab',
		showClass: 'showTab',
		start: 0
	},
	initialize: function(tabs, containers, options) {
		this.setOptions(options);
		this.tabs = $$(tabs);
		this.containers = $$(containers);
		this.now = this.options.start;
		this.fireEvent('init', [this.tabs, this.containers]);
		if (this.options.forceHTML && !this.tabs[this.now].hasClass(this.options.showClass)) this.show(this.tabs[this.now], this.now);
		this.tabs.each(function(tab, index) {
			if (!this.options.forceHTML & tab.hasClass(this.options.showClass)) this.now = index;
			this.attach(tab, index);
		}, this);
	},
	attach: function(tab, index) {
		tab.addEvents({
			'click': function(event) {
				event.preventDefault();
				this.show(tab, index);
			}.bind(this),
			'focus': function() {
				this.show(tab, index);
			}.bind(this)
		});
	},
	hideAll: function(index) {
		var i, l = this.containers.length;
		this.fireEvent('hide', [this.tabs, this.containers, index]);
		for (i = 0; i < l; i += 1) {
			this.tabs[i].removeClass(this.options.showClass);
			this.containers[i].removeClass(this.options.showClass).addClass(this.options.hideClass);
		}
	},
	show: function(tab, index) {
		if (this.now === index) return;
		this.now = index;
		this.hideAll(index);
		this.tabs[index].addClass(this.options.showClass);
		this.containers[index].removeClass(this.options.hideClass).addClass(this.options.showClass);
		this.fireEvent('show', [this.tabs, this.containers, index]);
	}
});

var AjaxTabs = new Class({
	Extends: Tabs,
	options: {
		cache: true,
		loader: false,
		loaderOptions: {
			'type': false,
			loaderSrc: null
		},
		query: false,
		queryValue: false,
		urls: null
	},
	show: function(tab, index) {
		var container = this.containers[0],
			l = this.tabs.length, content, i;	
		
		if (this.now === index) return;
		this.fireEvent('hide', [this.tabs, this.containers, index]);
		if (this.options.cache && !this.tabs[this.now].retrieve('content')) this.tabs[this.now].store('content', container.innerHTML);
		content = tab.retrieve('content');
		if (content) {
			this.tabs[this.now].removeClass(this.options.showClass);
			tab.addClass(this.options.showClass);
			this.now = index;
			container.innerHTML = content;
			this.fireEvent('show', [this.tabs, this.containers, index]);
		} else {
			this.getContent(tab, container, index);
		}
	},
	getContent: function(tab, container, index) {
		var loader = new Loader(),
			loaderParent = this.options.loaderParent === 'container' ? container: tab,
			urls = this.options.urls,
			query, requester, url;
		
		if (urls) {
			url = $type(urls) === 'array' ? urls[index]: urls;
		} else {
			url = tab.nodeName === 'A' ? stripQuery(tab.href) : stripQuery(tab.getChildren('a')[0].href);
		}
		
		if (this.options.query) {
			query = this.options.query + '=' + tab.get(this.options.queryValue);
		} else {
			query = tab.nodeName === 'A' ? getQuery(tab.href) : getQuery(tab.getChildren('a')[0].href);
		}
		
		requester = new Request({
			method: 'get',
			url: url,
			onRequest: function() {
				var opts = this.options.loaderOptions,
					loaderParent;
				if (this.options.loader) {
					loaderParent = !opts['type'] ? this.options.loader: opts['type'] === 'container' ? container: tab;
					loader.setLoader(loaderParent, opts);
				}
			}.bind(this),
			onSuccess: function(response) {
				container.innerHTML = response;
				if (this.options.loader) loader.hideLoader();
				this.tabs[this.now].removeClass(this.options.showClass);
				tab.addClass(this.options.showClass);
				this.now = index;
				this.fireEvent('show', [this.tabs, this.containers, index]);
			}.bind(this)
		});
		
		requester.send(query);
	}
});

var AjaxPaging = new Class({
	Implements: [Options, Events, Loader],
	options: {
		// onComplete: $empty,
		// onInit: $empty,
		// onRequest: $empty,
		// onShow: $empty,
		loader: true,
		loaderContainer: null,
		loaderOptions: {
			loaderType: 'image',
			loaderSrc: '/system/img/ajax-loader.gif'
		},
		trigger: 'click',
		url: null
	},
	initialize: function(elems, container, cacheTo, options) {
		this.setOptions(options);
		this.elems = $$(elems);
		this.container = $(container);
		this.cacheTo = $(cacheTo);
		this.cache = this.cacheTo.retrieve('pagingCache', {});
		this.query = getQuery(location.href);
		this.args = [this.elems, this.container];
		this.fireEvent('init', this.args);
		this.elems.each(function(elem, index) {
			this.attach(elem, container, index);
		}, this);
	},
	attach: function(elem, container, index) {
		var trigger = this.options.trigger;
		elem.addEvent(trigger, function(event) {
			var query = trigger === 'submit' ? elem.toQueryString() : getQuery(elem.href),
				cache = this.cache[query];
			event.preventDefault();
			this.args[2] = index;
			if (cache) {
				container.innerHTML = cache;
				this.fireEvent('show', this.args);
			} else {
				this.cache[this.query] = container.innerHTML;
				this.fetchContent(elem, container, index, query);
			}
		}.bind(this));
	},
	fetchContent: function(elem, container, index, query) {
		var url = this.options.url;
		var requester = new Request({
			url: url,
			method: 'get',
			onRequest: function() {
				if (this.options.loader) {
					var loaderContainer = this.options.loaderContainer || elem;
					this.setLoader(loaderContainer, this.options.loaderOptions);
				}
				this.fireEvent('request', [this.elems, container, index, query]);
			}.bind(this),
			onSuccess: function(response) {
				this.query = query;
				container.innerHTML = response;
				if (this.options.loader) this.hideLoader();
				this.fireEvent('show', this.args);
				this.fireEvent('complete', this.args);
			}.bind(this)
		});
		requester.send(query);
	}
});
var MultipleRequestPaging = new Class({
	Extends: AjaxPaging,
	requesters: [],
	attach: function(elem, containers, index) {
		var trigger = this.options.trigger;
		elem.addEvent(trigger, function(event) {
			var query = trigger === 'submit' ? elem.toQueryString() : getQuery(elem.href),
				cache = this.cache[query],
				currentCache = this.cache[this.query];
			event.preventDefault();
			if (this.requesters.length === 0) {
				if (currentCache) {
					currentCache.length = 0;
				} else {
					currentCache = this.cache[this.query] = [];
				}
				containers.each(function(container) {
					currentCache[currentCache.length - 1] = ($type(container) === 'array') ? container[0].innerHTML : container.innerHTML;
				});
				this.query = query;
				if (cache) {
					cache.each(function(result, i) {
						if ($type(containers[i]) === 'array') {
							containers[i].each(function(container) {
								container.innerHTML = result;
							});
						} else {
							containers[i].innerHTML = result;
						}
					});
					this.fireEvent('show', this.args);
				} else {
					this.fetchContent(elem, containers, index, query);
				}
			}
		}.bind(this));
	},
	fetchContent: function(elem, containers, index, query) {
		var sending = 0;
		this.options.url.each(function(url, i) {
			this.requesters[i] = new Request({
				method: 'get',
				url: url,
				onRequest: function() {
					if (sending === 0) this.fireEvent('request', [this.elems, containers, index, query]);
					if (this.options.loader) {
						var loaderContainer = this.options.loaderContainer || elem;
						this.setLoader(loaderContainer, this.options.loaderOptions);
					}
					sending += 1;
				}.bind(this),
				onSuccess: function(response) {
					var cache;
					sending -= 1;
					if (!this.cache[query]) this.cache[query] = [];
					this.cache[query][i] = response;
					if (sending === 0) {
						containers.each(function(container, i) {
							cache = this.cache[query][i];
							if ($type(container) === 'array') {
								container.each(function(c) {
									c.innerHTML = cache;
								});
							} else {
								container.innerHTML = cache;
							}
						}, this);
						if (this.options.loader) this.hideLoader();
						this.fireEvent('show', this.args);
					}
				}.bind(this)
			});
			this.requesters[i].send(query);
		}, this);
	}
});
var Slideshow = new Class({
	Implements: [Options, Events, Chain],
	options: {
		// onInit: $empty,
		// onHide: $empty,
		// onShow: $empty,
		start: 0,
		delay: 7000,
		duration: 500,
		hideClass: 'hideSlide',
		showClass: 'showSlide',
		opacity: true,
		progressButton: false,
		progressPanel: 'panelProgress',
		previous: null,
		pause: null,
		next: null
	},
	initialize: function(slides, options) {
		var progress = $(this.options.progressPanel);
		this.setOptions(options);
		this.slides = $$(slides);
		this.index = this.options.start;
		if (this.options.opacity) {
			for (var i = 0, l = this.slides.length; i < l; i += 1) {
				if (this.options.progressButton) this.slides[i].store('button', new Element('a').inject(progress));
				if (i !== this.index) this.slides[i].setStyle('opacity', '0');
				this.slides[i].set('tween', {
					duration: this.options.duration,
					onComplete: function() {
						this.callChain();
					}.bind(this)
				});
			}
		}
		this.timer = setInterval(function() {
			this.display(true);
		}.bind(this), this.options.delay);
		this.setControls(this.options.previous, this.options.pause, this.options.next);
		this.fireEvent('onInit', [this.slides, this.index]);
	},
	display: function(effects, show, pause) {
		this.hideSlide(this.slides[this.index], effects);
		if ($type(show) === 'number') {
			this.index = show;
		} else if (show === 'previous') {
			this.index = this.index === 0 ? this.slides.length - 1: this.index - 1;
		} else {
			this.index = this.index === this.slides.length - 1 ? 0: this.index + 1;
		}
		this.showSlide(this.slides[this.index], effects);
		if (pause) clearTimeout(this.timer);
	},
	hideSlide: function(slide, effects) {
		this.chain(
			function() {
				if (effects) {
					slide.tween('opacity', '0');
				} else {
					slide.setStyle('opacity', '1');
					this.callChain();
				}
			},
			function() { slide.removeClass(this.options.showClass).addClass(this.options.hideClass); this.callChain(); },
			function() {
				this.fireEvent('onHide', [this.slides, this.index]);
				this.callChain();
			}
		);
	},
	showSlide: function(slide, effects) {
		this.chain(
			function() {
				this.fireEvent('onShow', [this.slides, this.index]);
				this.callChain();
			},
			function() { slide.removeClass(this.options.hideClass).addClass(this.options.showClass); this.callChain(); },
			function() {
				if (effects) {
					slide.tween('opacity', '1');
				} else {
					slide.setStyle('opacity', '1');
					this.callChain();
				}
			}
		);
		this.callChain();
	},
	setControls: function(prevLink, pauseLink, nextLink) {
		if (prevLink) {
			$(prevLink).addEvent('click', function(event) {
				event.preventDefault();
				this.display(false, 'previous', true);
			}.bind(this));
		}
		if (nextLink) {
			$(nextLink).addEvent('click', function(event) {
				event.preventDefault();
				this.display(false, 'next', true);
			}.bind(this));
		}
		if(pauseLink) {
			$(pauseLink).addEvent('click', function(event) { 
				event.preventDefault(); clearTimeout(this.timer);
			}.bind(this));
		}
	}
});

var Slidereel = new Class({
	Implements: [Options, Events],
	options: {
		// onChange: $empty,
		slidesSelector: 'div',
		wrapper: false,
		wrapperStyles: {},
		prevLink: false,
		nextLink: false,
		start: 0,
		duration: 500
	},
	initialize: function(container, options) {
		var scrollH = container.getScrollSize().y,
			h = container.getSize().y,
			w = container.getSize().x,
			scrollW = scrollH > h ? w * (scrollH/h): w;
		this.setOptions(options);
		this.now = this.options.start;
		this.container = container;
		this.slides = this.container.getElements(this.options.slidesSelector);
		this.wrapper = this.options.wrapper || new Element('div').wraps(this.container);
		this.wrapper.setStyles($merge(this.options.wrapperStyles, {
			width: w,
			position: 'relative',
			overflow: 'hidden'
		}));
		this.container.setStyles({
			'left': this.options.start,
			'width': scrollW,
			'overflow': 'visible'
		}).set('tween', {'duration': this.options.duration, 'onStart': function() {
			this.fireEvent('onChange', [this.wrapper, this.container, this.slides, this.now]);
		}.bind(this)});
		if (this.options.prevLink) this.setControls(this.options.prevLink, 'previous');
		if (this.options.nextLink) this.setControls(this.options.nextLink, 'next');
	},
	setControls: function(elem, action) {
		elem.addEvent('click', function(event) {
			event.preventDefault();
			this.display(action);
		}.bind(this));
	},
	display: function(action) {
		var w = this.wrapper.getSize().x,
			scrollW = this.container.getScrollSize().x;
		if (action === 'previous') {
			if (this.now === 0) {
				this.now = w - scrollW;
			} else {
				this.now = this.now + w;
			}
		} else {
			if (this.now === w - scrollW) {
				this.now = 0;
			} else {
				this.now = this.now - w;
			}
		}
		this.container.tween('left', this.now);
	}
});

var InputClear = new Class({
	Implements: [Options, Events],
	options: {
		elems: 'input[type^=text]',
		reset: true
	},
	initialize: function(options) {
		this.setOptions(options);
		$$(this.options.elems).each(function(elem) {
			if (elem.get('type') === 'password') elem.store('orig', elem.getStyle('background-image'));
			this.attach(elem);
		}, this);
	},
	attach: function(elem) {
		elem.addEvents({
			'focus': function() {
				if (elem.get('type') !== 'password') elem.store('orig', elem.get('value'));
				elem.set('value', '');
				if (elem.get('type') === 'password') elem.setStyle('background-image', 'none');
			},
			'blur': function() {
				if (elem.get('value') === '') {
					if (elem.get('type') === 'password') {
						elem.setStyle('background-image', elem.retrieve('orig'));
					} else {
						elem.set('value', elem.retrieve('orig'));
					}
				}
			}
		});
	}
});

var SaveItems = new Class({
	Implements: [Options, Overlay, Loader],
	options: {
		closeId: 'closeSavedBox',
		containerId: 'saveItemContainer',
		itemClass: 'saveItem',
		leftOffset: -12,
		lightboxId: 'saveLightbox',
		loader: true,
		loaderOptions: {
			loaderType: 'image',
			loaderSrc: '/system/img/ajax-loader.gif',
			styles: {
				'top': 5
			}
		},
		query: 'id',
		topOffset: 20,
		url: '/system/ajax/save.html'
	},
	initialize: function(elems, options) {
		this.setOptions(options);
		this.elems = $$(elems);
		if (this.elems) {
			this.elems.each(function(a, index) {
				a.addEvent('click', function(event) {
					var cur, elem = $(event.target);
					if (elem.hasClass(this.options.itemClass) || (elem.getParent() && elem.getParent().hasClass(this.options.itemClass))) {
						event.preventDefault();
						$clear(this.container.retrieve('timer'));
						if (this.now) {
							cur = $(this.now.parentNode);
							cur.setStyle('z-index', cur.retrieve('z'))
						}
						this.now = elem.hasClass(this.options.itemClass) ? elem : elem.getParent();
						this.container.store('query', this.now.href);
						this.container.store('timer', setTimeout(function() {
							this.hide();
						}.bind(this), 1500));
						this.display(this.now);
					}
				}.bind(this));
			}, this);
		}
		this.setContainer();
	},
	setContainer: function() {
		var flagged, newfolder, existing, /*calendar, */createalert, bgdiv;
		this.container = $(this.options.containerId);
		if (!this.container) {
			this.container = new Element('div', {'id': this.options.containerId, 'style': 'display: none;'}).inject(document.body);
			flagged = new Element('a', {'href': '?saveto=flagged&save=true'}).appendText('save to \'My Flagged items\'').inject(this.container);
			newfolder = new Element('a', {'href': '?saveto=newfolder'}).appendText('save to new folder').inject(this.container);
			existing = new Element('a', {'href': '?saveto=existingfolder'}).appendText('save to existing folder').inject(this.container);
			//calendar = new Element('a', {'href': '?saveto=calendar'}).appendText('add to calendar').inject(this.container);
			createalert = new Element('a', {'class': 'createAlert', 'href': '?saveto=alert&save=true'}).appendText('create an alert').inject(this.container);
			bgdiv = new Element('div').inject(this.container);
			this.container.addEvents({
				'click': function(event) {
					event.preventDefault();
					if (event.target.nodeName === 'A') {
						if ($('overlay')) {
							$E('.lightbox').destroy();
							$('overlay').destroy();
						}
						this.saveItem($(event.target));
					}
				}.bind(this),
				'mouseover': function(event) {
					var timer = this.container.retrieve('timer');
					$clear(timer);
					this.keepOpen = true;
				}.bind(this),
				'mouseout': function(event) {
					this.keepOpen = false;
					this.container.retrieve('timer', setTimeout(function() {
						this.hide();
					}.bind(this), 800));
				}.bind(this)
			});
		}
	},
	hide: function() {
		if (!this.keepOpen) {
			this.container.setStyles({
				'z-index': 0,
				'display': 'none',
				'visibility': 'hidden'
			});
		}
	},
	display: function(elem) {
		var alertLink = this.container.getElement('.createAlert'),
			par = elem.getParent(),
			t = elem.getPosition().y + this.options.topOffset + 'px',
			l = elem.getPosition().x + this.options.leftOffset + 'px';
		par.store('z', elem.parentNode.getStyle('z-index'));
		par.setStyle('z-index', 9999999);
		this.container.setStyle('z-index', 9999999);
		if (elem.href.contains('type=author') || elem.href.contains('type=keyword') || elem.href.contains('type=scripture')) {
			alertLink.setStyle('display', '');
		} else {
			alertLink.setStyle('display', 'none');
		}
		this.container.inject(document.body).setStyles({
			'left': l,
			'top': t,
			'display': 'block',
			'visibility': 'visible'
		});
	},
	saveItem: function(a) {
		var query = getQuery(a.href) + '&' + getQuery(this.container.retrieve('query'));
			resultsBox = this.overlay('div', this.options.lightboxId),
			url = this.options.url,
			requester = new Request({
				method: 'get',
				url: url,
				onRequest: function() {
					if (this.options.loader) this.setLoader(a, this.options.loaderOptions);
				}.bind(this),
				onSuccess: function(response) {
					if (this.options.loader) this.hideLoader();
					this.keepOpen = false;
					this.hide();
					resultsBox.innerHTML = response;
					this.showOverlay($(this.options.closeId));
					this.saveTo(resultsBox);
				}.bind(this)
			});
		requester.send(query + '&' + new Date().getTime());
	},
	saveTo: function(elem) {
		var lightbox = elem.nodeName === 'FORM' ? elem : elem.getElement('form');
		if (lightbox) {
			lightbox.addEvent('submit', function(event) {
				var query = lightbox.toQueryString(),
					url = this.options.url;
				event.preventDefault();
				var requester = new Request({
					url: url,
					onRequest: function() {
						if (this.options.loader) this.setLoader(elem, this.options.loaderOptions);
					}.bind(this),
					onSuccess: function(response) {
						if (this.options.loader) this.hideLoader();
						elem.innerHTML = response;
						$(this.options.closeId).addEvent('click', function(event) {
							this.closeLightbox();
						}.bind(this));
					}.bind(this)
				});
				requester.send(query);
			}.bind(this));
		}
	}
});

var charCount = function charCount(what, maxCount)
{
	var entry = what.get('value'),
		str = new String(entry),
		len = str.length,
		limitSpan = document.getElementById('limitText');
	
	len = maxCount - len;
	
	if (len < 0) {
		what.set('value', entry.slice(0, maxCount));
	} else if (len > 1) {
		limitSpan.innerHTML = "<strong>" + len + "</strong> characters remaining";
	} else {
		limitSpan.innerHTML = "<strong>" + len + "</strong> character remaining";
	}
}
var suckerfish = function suckerfish(elems) {
	if (Browser.Engine.trident4) {
		var sfEls = $$(elems);
		for (var i=0, l = sfEls.length; i < l; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
};
var externalLinks = function externalLinks(items) {
	var links = (items) ? $$(items): $$('a.external');
	links.each(function(a) {
		a.addEvent('click', function(e) {
			e.preventDefault;
			open(a.get('href'));
			return false;
		});
	});	
};
var printPage = function printPage(elems, width, height) {
	var elems = $$(elems),
		width = width || 790,
		height = height || 400;
	if (elems) {
		elems.each(function(elem) {
			elem.addEvent('click', function(event) {
				event.preventDefault();
				window.open(elem.get('href'), 'printWindow', 'width=' + width + ',height=' + height + ',toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1');
			});
		});
	}
};
var emailPage = function emailPage(elems) {
	$$(elems).each(function(elem) {
		elem.addEvent('click', function(event) {
			event.preventDefault();
			window.open(elem.get('href'), 'printWindow', 'width=625,height=400,toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1');
		});
	});	
};
var smallWindow = function smallWindow(elems, width, height) {
	$$(elems).each(function(elem) {
		elem.addEvent('click', function(event) {
			event.preventDefault();
			var w = (width) ? width: '520';
			var h = (height) ? height: '450';
			window.open($(event.target).get('href'), 'printWindow', 'width=' + w + ',height=' + h + ',toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1');
		});
	});	
};
var createOverlay = function createOverlay(elem, id) {
	var overlay = new Element('div', {'id': 'overlay', 'styles': {'opacity': '0', 'visibility': 'visible', 'height': '0', 'overflow': 'hidden'}}).inject(document.body),
		e = $(id) || new Element(elem, {'id': id}).inject(document.body);
	return e;
};
// Hover Ads
var ctiHovers = {
	init: function() {
		var h = this.getSize().y,
			that = this,
			w = this.getSize().x;
		
		this.body = document.getElementsByTagName('body')[0];
		this.closeLink = document.getElementById('closeHoverAd');
		this.hover = document.getElementById('hover');
		this.overlay = document.getElementById('overlay');
		
		this.body.appendChild(this.hover);
		this.hover.style.left = (w/2) - (this.hover.clientWidth/2) + 'px';
		this.hover.style.visibility = 'visible';

		if (this.overlay) {
			this.overlay.style.height = h + 'px';
			this.overlay.style.width = w + 'px';
		}
		
		this.timer = setTimeout(function() {
			that.closeHover();
		}, 15000);
		
		this.attach();
	},
	attach: function() {
		var that = this,
			hoverForm = this.hover.getElementsByTagName('form')[0];
		
		if (hoverForm) {
			hoverForm.onsubmit = function() {
				that.hover.style.left = '-999em';
				setTimeout(function() {
					that.closeHover();
				}, 5000);
			};
		}
		this.hover.onclick = function(event) {
			var event = event || window.event,
				elem = event.target || event.srcElement;
			if (elem.nodeName === 'A' || elem.parentNode.nodeName === 'A') {
				that.closeHover();
			}
		};
		this.hover.onmouseover = function() {
			clearTimeout(that.timer);
		};
		this.closeLink.onfocus = function() {
			clearTimeout(that.timer);
		};
		this.closeLink.onclick = function() {
			that.closeHover();
			return false;
		};
		if (this.overlay) {
			this.overlay.onclick = function() {
				that.closeHover();
			};
		}
	},
	closeHover: function() {
		this.hover.parentNode.removeChild(this.hover);
		if (this.overlay) this.overlay.parentNode.removeChild(this.overlay);
		clearTimeout(this.timer);
	},
	getSize: function() {
		var doc = (!document.compatMode || document.compatMode === 'CSS1Compat') ? document.getElementsByTagName('html')[0] : document.body,
			m = window.ActiveXObject ? 'min': 'max';
		return {x: Math[m](doc.scrollWidth, doc.offsetWidth), y: Math.max(doc.scrollHeight, doc.offsetHeight)};
	}
};
var cti = {};
window.addEvent('domready', function() {
	suckerfish($$('#globalheader li'));
	cti.inputClear = new InputClear({ elems: $$('.clearField')});
	externalLinks();
	cti.tooltips = new Tips ($$('.tooltip'), {
		className: 'tipContainer',
		text: null
	});
	if (window.showPromo) showPromo();
	if (document.getElementById('hover') && !ctiHovers.notSystem) ctiHovers.init();
});