Date.prototype.getCivHours = function() {
	if (this.getHours() > 12) { return this.getHours() - 12; }
	else if (this.getHours() == 0) { return 12; }
	else { return this.getHours(); }
}
Date.prototype.getLocalTime = function() { return this.getTime() - this.getTimezoneOffset()*60000; }
Date.prototype.setLocalTime = function(time) { return this.setTime(time + this.getTimezoneOffset()*60000); }
Date.prototype.getMinDeg = function() { return this.getMinutes()*6+this.getSeconds()/10; }
Date.prototype.getHrDeg = function() { return this.getHours()*30+this.getMinutes()/2; }
Date.prototype.getFullDate = function() {
	if (this.getDate() < 10) { return "0"+this.getDate(); }
	else { return this.getDate().toString(); }
}
Date.prototype.getFullMonth = function() {
	var m = this.getMonth() + 1;
	if (m < 10) { return "0"+m; } else { return m.toString(); }
}
Date.prototype.getFullMinutes = function() {
	var m = this.getMinutes();
	if (m < 10) { return "0"+m; } else { return m.toString(); }
}


CNLT = {
	IE: document.all ? true : false,
};

CNLT.scrollBar = function(element, orientation) {
	this.sizerID;
	this.startEvent;
	this.scrollID;
	this.o = orientation;
	this.box = element;
	this.contentbox = $$('#'+this.box.id+' .scrollContentBox')[0];
	this.content = $$('#'+this.box.id+' .scrollContentBox .scrollContent')[0];
	this.track = document.createElement('div');
	this.track.addClassName('scrollTrack'+this.o);
	this.handle = document.createElement('div');
	this.handle.addClassName('scrollHandle'+this.o);
	
	this.handletop = document.createElement('div');
	this.handleimage = document.createElement('div');
	this.handlebottom = document.createElement('div');
	this.handlecover = document.createElement('div');
	this.handletop.addClassName('scrollHandleTop');
	this.handleimage.addClassName('scrollHandleVImage');
	this.handlebottom.addClassName('scrollHandleBottom');
	this.handlecover.addClassName('scrollHandleVCover');
	this.handle.appendChild(this.handletop);
	this.handle.appendChild(this.handleimage);
	this.handle.appendChild(this.handlebottom);
	this.handle.appendChild(this.handlecover);
	
	this.tracktop = document.createElement('div');
	this.trackimage = document.createElement('div');
	this.trackbottom = document.createElement('div');
	this.trackcover = document.createElement('div');
	this.tracktop.addClassName('scrollTrackTop');
	this.trackimage.addClassName('scrollTrackVImage');
	this.trackbottom.addClassName('scrollTrackBottom');
	this.trackcover.addClassName('scrollTrackVCover');
	this.track.appendChild(this.tracktop);
	this.track.appendChild(this.trackimage);
	this.track.appendChild(this.trackbottom);
	this.track.appendChild(this.trackcover);
	if (this.o == "V") {
		this.up = document.createElement('div');
		this.up.addClassName('scrollUp');
		this.down = document.createElement('div');
		this.down.addClassName('scrollDown');
		this.track.appendChild(this.up);
		this.track.appendChild(this.down);
	}
	else if (this.o == "H") {
		this.left = document.createElement('div');
		this.left.addClassName('scrollLeft');
		this.right = document.createElement('div');
		this.right.addClassName('scrollRight');
		this.track.appendChild(this.left);
		this.track.appendChild(this.right);
	}
	this.box.appendChild(this.track);
	this.track.appendChild(this.handle);
	
	this.mouseStart = 0;
	this.scrollStart = 0;
	this.isScrolling = false;
	this.tracki = 0;
	
	this.setScrollSize = function() {
		if (this.o == "V") {
			this.hh = Math.pow(this.box.offsetHeight,2) / this.content.offsetHeight;
			this.handle.style.height = this.hh - 28 + "px";
			this.maxScroll = Math.round(this.box.offsetHeight - this.hh);
			this.ratio = (this.box.offsetHeight - 38) / this.content.offsetHeight;
		}
		else if (this.o == "H") {
			this.hw = Math.pow(this.box.offsetWidth,2) / this.content.offsetWidth;
			this.handle.style.width = this.hh+"px";
			this.maxScroll = Math.round(this.box.offsetWidth - this.hw);
			this.ratio = (this.box.offsetWidth - 38) / this.content.offsetWidth;
		}
	}
	this.setScrollSize();
	
	this.start = function(e) {
		this.setScrollSize();
		this.startEvent = e;
		this.scrollStart = this.handle.offsetTop;
		this.isScrolling = true;
		document.observe('selectstart', function() { return false; });
		document.body.addClassName('scrollSelectOff');
		if (e.target == this.handlecover) {
			this.mouseStart = this.o == "V" ? e.pageY : e.pageX;
			document.observe('mousemove', this.doIt.bind(this));
			this.trackcover.stopObserving('mousedown', this.start.bind(this));
		}
		else if (e.target == this.trackcover) {
			this.mouseStart = this.o == "V" ? e.offsetY || e.layerY : e.offsetX || e.layerX;
			clearInterval(this.scrollID);
			this.scrollID = setInterval( function() { this.doIt("t"); }.bind(this), 33);
		}
		else if (e.target == this.up) {
			clearInterval(this.scrollID);
			this.scrollID = setInterval( function() { this.doIt("n"); }.bind(this), 33);
		}
		else if (e.target == this.down) {
			clearInterval(this.scrollID);
			this.scrollID = setInterval( function() { this.doIt("p"); }.bind(this), 33);
		}
		else if (e.type == "mousewheel") {
			this.mouseStart = e.wheelDelta;
			this.doIt("s");
			e.stop();
		}
		else if (e.type == "DOMMouseScroll") {
			this.mouseStart = e.detail * -40;
			this.doIt("s");
			e.stop();
		}
	}
	this.doIt = function(e) {
		this.doItEvent = e;
		var d = 0;
		if (e.type == "mousemove") { d = this.scrollStart + e.pageY - this.mouseStart; }
		else if (e == "t") {
			this.tracki++;
			if (this.mouseStart > this.handle.offsetTop) { d = this.mouseStart - this.handle.offsetHeight; }
			else { d = this.mouseStart; }
		}
		else if (e == "s") { d = this.scrollStart - this.mouseStart / 10; }
		else if (e == "p") { this.scrollStart+=2; d = this.scrollStart; }
		else if (e == "n") { this.scrollStart-=2; d = this.scrollStart; }
		//$('comedynBio').innerHTML = d + " : " + this.maxScroll;
		if (d < 0) { d = 0; }
		if (d > this.maxScroll) { d = this.maxScroll; }
		if (this.isScrolling) {
			this.handle.style.top = d + "px";
			this.content.style.top = -d / this.ratio + "px";
		}
	}
	this.stop = function(e) {
		clearInterval(this.scrollID);
		this.isScrolling = false;
		document.stopObserving('mousemove', this.doIt.bind(this));
		this.trackcover.observe('mousedown', this.start.bind(this));
		document.stopObserving('selectstart', function() { return false; });
		document.body.removeClassName('scrollSelectOff');
	}		
	
	this.handlecover.observe('mousedown', this.start.bind(this));
	this.trackcover.observe('mousedown', this.start.bind(this));
	this.content.observe('mousewheel', this.start.bind(this));
	this.content.observe('DOMMouseScroll', this.start.bind(this));
	document.observe('mouseup', this.stop.bind(this));
	
	if (this.o == "V") {
		this.up.observe('mousedown', this.start.bind(this));
		this.down.observe('mousedown', this.start.bind(this));
		this.up.observe('mouseup', this.stop.bind(this));
		this.down.observe('mouseup', this.stop.bind(this));
	}
}

function JSCal(et) {
	element = et.element;
	
	this.dayNames = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
	this.monthNames = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	this.dates = {};
	this.now = new Date();
	this.FullNow = function(b) {
		if (b) {
			var fn = new Date(b);
			return this.dayNames[fn.getDay()]+", "+this.monthNames[fn.getMonth()]+" "+fn.getDate()+", "+fn.getFullYear();
		}
		else {
			return this.dayNames[this.now.getDay()]+", "+this.monthNames[this.now.getMonth()]+" "+this.now.getDate()+", "+this.now.getFullYear();
		}
	}
	this.then = new Date(this.now.getLocalTime());
	this.selected = et.time || new Date(this.now.getTime());
	this.select = function(event) {
		this.selected.setFullYear(this.dates[event.target.getAttribute('data-date')].date.getFullYear());
		this.selected.setMonth(this.dates[event.target.getAttribute('data-date')].date.getMonth());
		this.selected.setDate(this.dates[event.target.getAttribute('data-date')].date.getDate());
		this.html.fire('jscal:select');
		for (x in this.dates) { this.dates[x].div.removeClassName('jsCalS'); }
		event.target.addClassName('jsCalS');
	}
	this.next = function() {
		if (this.nm == 1) { this.ym++; }
		this.draw({month:this.nm,year:this.ym});
	}
	this.prev = function() {
		if (this.pm == 12) { this.ym--; }
		this.draw({month:this.pm,year:this.ym});
	}
	this.html = document.createElement('div');
	this.html.addClassName('jsCalBox');
	element.appendChild(this.html);
	this.draw = function(a) {
		this.html.innerHTML = "";
		var o = new Date();
		o.setDate(1);
		var q = this.then.getMonth();
		var r = this.then.getFullYear();
		if (a.month) { a.month--; this.then.setMonth(a.month); }
		if (a.year) { this.then.setFullYear(a.year); }
		o.setYear(this.then.getFullYear());
		var d = 1;
		var e, k, m, n, p, t, u;
	
		m = document.createElement('div');
		m.addClassName('jsCalMRow');
		m.innerText = this.then.toString().substring(3,7)+" "+this.then.getFullYear();
		this.html.appendChild(m);
	
		o.setMonth(this.then.getMonth() + 1);
		n = document.createElement('div');
		n.addClassName('jsCalN');
		n.innerText = o.toString().substring(3,7)+" >";
		n.observe('click', this.next.bind(this));
		this.nm = o.getMonth() + 1;
		this.html.appendChild(n);
	
		o.setMonth(this.then.getMonth() - 1);
		if (this.then.getMonth() == 11) { o.setYear(this.then.getFullYear()); }
		p = document.createElement('div');
		p.addClassName('jsCalP');
		p.innerText = "< "+o.toString().substring(3,7);
		p.observe('click', this.prev.bind(this));
		this.pm = o.getMonth() + 1;
		this.html.appendChild(p);
		
		this.ym = this.then.getFullYear();
	
		k = document.createElement('div');
		k.addClassName('jsCalDNRow');
		this.html.appendChild(k);
	
		u = new Date();
		u.setDate(u.getDate() - u.getDay() - 1);
		for (i = 0; i < 7; i++) {
			u.setDate(u.getDate() + 1);
			e = document.createElement('div');
			e.addClassName('jsCalDNCell');
			e.innerText = u.toString().substring(0,3);
			k.appendChild(e);
		}
	
		this.then.setDate(d);
		var c = this.then.getMonth();
		var g = this.then.getDay();
		var h = 0;
		var l = false;
		while (this.then.getMonth() == c || h < 7) {
			if (h > 6) { h = 0; }
			if (h == 0) {
				k = document.createElement('div');
				k.addClassName('jsCalRow');
				this.html.appendChild(k);
			}
			if (this.then.getDate() == 1 && g > 0 || l) {
				e = document.createElement('div');
				e.addClassName('jsCalCellBlank');
				e.innerHTML = "<br/>";
				k.appendChild(e);
				g--;
			}
			else {
				t = this.then.getFullMonth()+this.then.getFullDate()+this.then.getFullYear();
				this.dates[t] = {
					date: new Date(this.then.getTime()),
					div: document.createElement('div')
				};
				this.dates[t].div.addClassName('jsCalCell');
				if (d == this.now.getDate() && q == this.now.getMonth() && r == this.now.getFullYear())
				{ this.dates[t].div.addClassName('jsCalT'); }
				this.dates[t].div.setAttribute('data-date', t);
				this.dates[t].div.id = "jscal"+t;
				this.dates[t].div.innerText = d;
				this.dates[t].div.observe('click', this.select.bind(this));
				k.appendChild(this.dates[t].div);
				d++;
				this.then.setDate(d);
				if (this.then.getDate() != d) { l = true; }
			}
			h++;
		}
	}.bind(this);
	this.draw({});
}

function jsClock(et) {
	element = et.element;
	this.time = et.time || new Date();
	
	this.html = document.createElement('div');
	this.html.addClassName('jsClockBox');
	element.appendChild(this.html);
	
	var a, b, c, d, f, g, k;
	this.isMoving = false;
	this.minQuad = Math.ceil((this.time.getMinutes()+0.01)/15);
	this.hrQuad = Math.ceil((this.time.getHours()+0.01)/3*Math.ceil((this.time.getHours()+0.01)/12));
	this.lastminQuad = this.minQuad;
	this.lasthrQuad = this.hrQuad;
	this.snapMin = Math.round(this.time.getLocalTime()/1000/300)*300000;
	
	this.handGrab = function(e) {
		this.minuteHand.style.webkitTransitionProperty = 'none';
		this.hourHand.style.webkitTransitionProperty = 'none';
		this.testBox = document.createElement('div');
		this.testBox.style.position = "absolute";
		document.body.appendChild(this.testBox);
		
		k = this.time.getMinDeg();
		if (e.target == this.hourHand) { k = this.time.getHrDeg(); }
		
		h = Math.round((e.target.offsetHeight - e.offsetY + 10)*Math.sin(k*deg2radians));
		j = Math.round((e.target.offsetHeight - e.offsetY + 10)*Math.cos(k*deg2radians));
	
		this.center = {
			x: e.pageX - h,
			y: e.pageY + j
		};
		this.grabbedHand = e.target;
		this.isMoving = true;
		document.observe('selectstart', function() { return false; });
		document.body.addClassName('scrollSelectOff');
		document.observe('mousemove', this.moveHands.bind(this));
		document.observe('mouseup', this.letgo.bind(this));
	}
	
	this.scrollHands = function(e) {
		this.minuteHand.style.webkitTransitionProperty = 'none';
		this.hourHand.style.webkitTransitionProperty = 'none';
		f = e.wheelDelta/Math.abs(e.wheelDelta)*-45*this.minQuad;
		f = Math.abs(f + Math.abs(f)/this.minQuad) + 45*(this.minQuad - 1);
		if (e.wheelDelta > 0 && this.time.getMinutes() == 15*(this.minQuad - 1)) { f -= 90; }
		if (f == 360) { f = 0; }
		this.isMoving = true;
		this.grabbedHand = this.minuteHand;
		this.moveHands(f);
		this.isMoving = false; 
		e.stop();
	}
	this.html.observe('mousewheel', this.scrollHands.bind(this));
	
	this.moveHands = function(e) {
		if (this.isMoving) {
			if (e.pageY) {
				y = this.center.y - e.pageY;
				x = e.pageX - this.center.x;
				d = x/y;
				f = Math.atan(d)/deg2radians;
				if (y < 0) { f += 180; }
			}
			else if (typeof e == 'number') { f = e;}
			if (f < 0) { f += 360; }
			
			if (this.grabbedHand == this.minuteHand) {
				this.minQuad = Math.ceil((f+0.01)/90);
				f += Math.floor(this.time.getLocalTime()/1000/60/60)*360;
				if (this.lastminQuad == 4 && this.minQuad == 1) { f += 360; }
				else if (this.lastminQuad == 1 && this.minQuad == 4) { f-= 360; }
				this.time.setLocalTime(f*10000);
				this.lastminQuad = this.minQuad;
				this.lasthrQuad = Math.ceil((this.time.getHours()+0.01)/3*Math.ceil((this.time.getHours()+0.01)/12));
			}
			else if (this.grabbedHand == this.hourHand) {
				this.hrQuad = Math.ceil((f+0.01)/90);
				f += Math.floor(this.time.getLocalTime()/1000/60/60/12)*360;
				if (this.lasthrQuad == 4 && this.hrQuad == 1) { f += 360; }
				else if (this.lasthrQuad == 1 && this.hrQuad == 4) { f-= 360; }
				this.time.setLocalTime(f*120000);
				this.lasthrQuad = this.hrQuad;
				this.lastminQuad = Math.ceil((this.time.getMinutes()+0.01)/15);
			}
			this.snapMin = Math.round(this.time.getLocalTime()/1000/300)*300000;
			this.minuteHand.style.webkitTransform = 'rotate('+this.time.getMinDeg()+'deg)';
			this.hourHand.style.webkitTransform = 'rotate('+this.time.getHrDeg()+'deg)';
			this.moveEvent = e;
			this.M.innerText = this.time.getHours() >= 12 ? "PM" : "AM";
			this.html.fire('jsclock:sendtime');
		}
		else { document.stopObserving('mousemove', this.moveHands.bind(this)); }
	}
	
	this.letgo = function(e) {
		document.stopObserving('mousemove', this.moveHands.bind(this));
		document.stopObserving('mouseup', this.letgo.bind(this));
		this.isMoving = false;
		this.time.setLocalTime(this.snapMin);
		this.minuteHand.style.webkitTransitionProperty = '-webkit-transform';
		this.hourHand.style.webkitTransitionProperty = '-webkit-transform';
		this.minuteHand.style.webkitTransform = 'rotate('+this.time.getMinDeg()+'deg)';
		this.hourHand.style.webkitTransform = 'rotate('+this.time.getHrDeg()+'deg)';
		this.M.innerText = this.time.getHours() >= 12 ? "PM" : "AM";
		this.html.fire('jsclock:sendtime');
	}
	
	this.M = document.createElement('div');
	this.M.addClassName('jsClockM');
	this.html.appendChild(this.M);
	this.M.innerText = this.time.getHours() >= 12 ? "PM" : "AM";
	
	for (i = 1; i < 13; i++) {
		a = document.createElement('div');
		a.addClassName('jsClockHour');
		this.html.appendChild(a);
		a.innerText = i;
		b = 30 * i * deg2radians;
		c = Math.round(a.offsetWidth / 2);
		a.style.left = Math.round(Math.sin(b) * 75) - c + 98 - a.offsetWidth/2 + "px";
		c = Math.round(a.offsetHeight / 2);
		a.style.top = Math.round(Math.cos(b) * -75) - c + 92 - a.offsetHeight/2 + "px";
	}
	
	this.close = document.createElement('div');
	this.close.addClassName('jsClockClose');
	this.html.appendChild(this.close);
	this.close.innerText = 'X';
	this.close.observe('click', function() { this.html.hide(); }.bind(this));
	
	this.hourHand = document.createElement('div');
	this.hourHand.addClassName('jsClockHourHand');
	this.html.appendChild(this.hourHand);
	this.hourHand.observe('mousedown', this.handGrab.bind(this));
	
	this.minuteHand = document.createElement('div');
	this.minuteHand.addClassName('jsClockMinuteHand');
	this.html.appendChild(this.minuteHand);
	this.minuteHand.observe('mousedown', this.handGrab.bind(this));
	
	this.hourHand.style.webkitTransform = 'rotate('+(this.time.getHours()*30+this.time.getMinutes()/2)+'deg)';
	this.minuteHand.style.webkitTransform = 'rotate('+(this.time.getMinutes()*6+this.time.getSeconds()/10)+'deg)';
	
}
	

function inputWidth(input) {
	if (!$('iWTB')) {
		this.testBox = document.createElement('span');
		this.testBox.id = 'iWTB';
		this.testBox.style.position = 'absolute';
		this.testBox.style.top = '-999px';
		document.body.appendChild(this.testBox);
	}
	this.testBox.style.fontFamily = input.getStyle('font-family');
	this.testBox.style.fontSize = input.getStyle('font-size');
	this.testBox.innerText = input.value;
	
	return this.testBox.offsetWidth + 5;
}

