function trace (s) {
	if (!document.getElementById('debug')) {
		var o = document.createElement('pre');
		o.id = 'debug';
		o.style.color = 'white';
		o.style.fontSize = '10pt';
		o.style.position = 'absolute';
		o.style.top = '0px';
		o.style.left = '0px';
		o.style.textAlign = 'left';
		document.getElementsByTagName('body')[0].appendChild(o);
	}
	document.getElementById('debug').innerHTML += s + '<br />';
}

document.write('<style type="text/css">');
document.write(".popuplink { visibility: hidden; }");
document.write("#bodyMedia { overflow: hidden; }");
document.write("#bodyCopyShorter { overflow: hidden; }");
document.write("#bodyCopyvac { overflow: hidden; }");
document.write("#mediaText { width: 360px; overflow: hidden; }");
document.write(".scrollBars { display: inline; }");
document.write("#mediaContainer .scrollBars { display: block; }");
document.write('</style>');


window.onresize = function () { Popup.resized() };
window.onload = init;

function init() {
	ContentScroll.init();
	PopupScroll.init();
	TypeWriter.init();

	var agent = navigator.userAgent.toLowerCase();
	if (eregi('msie', agent) && !eregi('opera', agent)) {
		var val = explode(' ', stristr(agent,'msie'));
		var browser = val[0];
		var version = val[1];
		// clean up extraneous garbage that may be in the name
		browser = browser.replace(/[^a-z,A-Z]+/g, '');
		// clean up extraneous garbage that may be in the version
		version = version.replace(/[^0-9,\.,a-z,A-Z]+/g, '');
		if (version < 7) {
			replacePngs();
		}
	}

	var as = document.getElementsByTagName('a');
	for (var i = 0; i < as.length; i++) {
		if (/\bpopuplink\b/.test(as[i].className)) {
			as[i].onclick = function () {
				var q = this.href.match(/\?(.*)/);
				var loc = this.href.substring(0, this.href.lastIndexOf('/') + 1);
				if (q) {
					//Popup.load('extra/' + q[1] + '.xml');
					Popup.load(loc + q[1] + '.xml');
				}
				return false;
			}
			as[i].style.visibility = 'visible';
		}
	}

	var overlay = document.getElementById('op');
	if (overlay) {
		var sizes = Popup.getSizes();
		overlay.style.height = sizes.page.height + 'px';
		if (/msie/gi.test(navigator.userAgent.toLowerCase())) {
			overlay.style.background = 'none';
			overlay.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\'scale\', src=\'overlay.png\')';
			overlay.style.width = sizes.page.width + 'px';
		}
	}
}

function replacePngs() {
	var imgs = document.getElementsByTagName('img');
	var pngs = new Array();
	for (var i = 0; i < imgs.length; i++) {
		if (/\.png$/i.test(imgs[i].src)) {
			var o = imgs[i];
			var p = imgs[i].parentNode;
			p.style.width = o.offsetWidth + 'px';
			p.style.height = o.offsetHeight + 'px';
			p.style.display = 'block';
			//o.style.display = 'none';
			o.style.visibility = 'hidden';
			//o.style.styleFloat = 'left';
			p.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\'crop\', src=\'' + imgs[i].src + '\')';
			if (p.nodeName == 'A') {
				p.style.cursor = 'pointer';
			}
			//trace(imgs[i].src);
		}
	}
}


TypeWriter = {
	date:	'typedate',
	news:	'typenews',
	items:	[],
	curItem: 0,
	curChar: 0,
	timing:	50,
	timer:	null,
	holdtime: 1500,
	init:	function () {
		TypeWriter.date = document.getElementById(TypeWriter.date);
		TypeWriter.news = document.getElementById(TypeWriter.news);
		if (!TypeWriter.date || !TypeWriter.news) {
			return;
		}
		/*
		TypeWriter.items = [
			{date: 'jan 07 news', news: 'Miller\'s Vanguard Invests in Masternaut GPS Software', link: 'media8'},
			{date: 'dec 06 news', news: 'Hot Business Benefits from the Field', link: 'media7'},
			{date: 'apr 06 news', news: 'FM Industry\'s Biggest Easter Egg Delivery to be Given Free to Staff of Miller\'s Vanguard', link: 'media6'}
		];
		*/
		TypeWriter.items = tickerItems;

		TypeWriter.write();
	},
	pause:	function () {
		clearTimeout(TypeWriter.timer);
	},
	play:	function () {
		TypeWriter.timer = setTimeout('TypeWriter.write()', TypeWriter.timing);
	},
	write:	function () {
		if (TypeWriter.curChar > TypeWriter.items[TypeWriter.curItem].news.length) {
			TypeWriter.curChar = 0;
			TypeWriter.curItem++;
			if (TypeWriter.curItem >= TypeWriter.items.length) {
				TypeWriter.curItem = 0;
			}
		}
		if (TypeWriter.curChar == 0) {
			document.getElementById('prefooter').onclick = function () {
				var path = '';
				if (window.location.href.indexOf('/recruitment/') != -1) {
					path += (window.location.href.indexOf('/html/') != -1) ? '../../' : '../';
				}
				//path += 'extra/' + TypeWriter.items[TypeWriter.curItem].link + '.xml';
				path += TypeWriter.items[TypeWriter.curItem].extraFolder + TypeWriter.items[TypeWriter.curItem].link + '.xml';
				//trace(path);
				Popup.load(path);
			}
			TypeWriter.date.innerHTML = TypeWriter.items[TypeWriter.curItem].date.toUpperCase();
		}
		TypeWriter.news.innerHTML = TypeWriter.items[TypeWriter.curItem].news.substr(0, TypeWriter.curChar++).toUpperCase();
		if (TypeWriter.curChar > TypeWriter.items[TypeWriter.curItem].news.length) {
			TypeWriter.timer = setTimeout('TypeWriter.write()', TypeWriter.holdtime);
		}
		else {
			TypeWriter.timer = setTimeout('TypeWriter.write()', TypeWriter.timing);
		}
	}
}

PopupScroll = {
	duration:	15,
	steps:		15,
	obj:		null,
	baseH:		0,
	smallH:		0,
	scrollers:	null,
	scrolling:	false,
	contHeight: 0,
	init:		function () {
		/*
		var divs = document.getElementsByTagName('div');
		var c1 = 'leftContent';
		for (var i = 0; i < divs.length; i++) {
			if (new RegExp('\\b' + c1 + '\\b').test(divs[i].className)) {
				ContentScroll.obj = divs[i];
				i = divs.length;
			}
		}
		if (!ContentScroll.obj) {
			return;
		}
		*/
		/*
		ContentScroll.obj = $('bodyCopyShorter');
		if (!ContentScroll.obj) {
			return;
		}
		*/

		var o = document.getElementById('popupscroller');
		if (o) {
			PopupScroll.obj = o.parentNode;
		}
		if (!PopupScroll.obj || !PopupScroll.obj.nodeName == 'DIV') {
			return;
		}

		PopupScroll.baseH = PopupScroll.obj.offsetHeight;
		//PopupScroll.smallH  = PopupScroll.baseH - 18;
		PopupScroll.smallH  = PopupScroll.baseH;
		PopupScroll.resize();
	},
	resize:		function () {
		// get the height of the content
		var h = 0;
		var d = PopupScroll.obj;
		for (i = 0; i < d.childNodes.length; i++) {
			var j = d.childNodes[i].offsetHeight;
			if (!isNaN(j)) {
				h += j;
			}
		}
		PopupScroll.contHeight = h;
	},
	up:			function () {
		if (!PopupScroll.obj || PopupScroll.scrolling) {
			return false;
		}
		var o = PopupScroll.obj;
		var current = o.scrollTop;
		var target = current - PopupScroll.smallH + 20; // give 20 pixels grace
		if (target < 0) {
			target = 0;
		} 
		PopupScroll.slide(target);
		return false;
	},
	down:		function () {
		if (!PopupScroll.obj || PopupScroll.scrolling) {
			return false;
		}
		var o = PopupScroll.obj;
		var current = o.scrollTop;
		var target = current + PopupScroll.smallH - 20; // give 20 pixels grace
		var maxScrollHeight = PopupScroll.contHeight - PopupScroll.smallH;
		if (target > maxScrollHeight) {
			target = maxScrollHeight;
		}
		PopupScroll.slide(target);
		return false;
	},
	slide:		function (target) {
		PopupScroll.scrolling = true;
		var current = PopupScroll.obj.scrollTop;
		if (target < current) {
			var increment = Math.round((target - current - PopupScroll.steps) / PopupScroll.steps);
			if (increment == 0) {
				increment = -1;
			}
			var location = current + increment;
		}
		else if (target > current) {
			var increment = Math.round((target - current) / PopupScroll.steps);
			if (increment == 0) {
				increment = 1;
			}
			var location = current + increment;
		}
		else if (target == current) {
			PopupScroll.scrolling = false;
			return;
		}
		PopupScroll.obj.scrollTop = location;
		setTimeout('PopupScroll.slide(' + target + ')', PopupScroll.duration);
	}
}


ContentScroll = {
	duration:	15,
	steps:		15,
	obj:		null,
	baseH:		0,
	smallH:		0,
	scrollers:	null,
	scrolling:	false,
	contHeight: 0,
	init:		function () {
		/*
		var divs = document.getElementsByTagName('div');
		var c1 = 'leftContent';
		for (var i = 0; i < divs.length; i++) {
			if (new RegExp('\\b' + c1 + '\\b').test(divs[i].className)) {
				ContentScroll.obj = divs[i];
				i = divs.length;
			}
		}
		if (!ContentScroll.obj) {
			return;
		}
		*/
		/*
		ContentScroll.obj = $('bodyCopyShorter');
		if (!ContentScroll.obj) {
			return;
		}
		*/

		var o = document.getElementById('scroller');
		if (o) {
			ContentScroll.obj = o.parentNode;
		}
		if (!ContentScroll.obj || !ContentScroll.obj.nodeName == 'DIV') {
			return;
		}

		ContentScroll.baseH = ContentScroll.obj.offsetHeight;
		//ContentScroll.smallH  = ContentScroll.baseH - 18;
		ContentScroll.smallH  = ContentScroll.baseH;
		ContentScroll.resize();
	},
	resize:		function () {
		// get the height of the content
		var h = 0;
		var d = ContentScroll.obj;
		for (i = 0; i < d.childNodes.length; i++) {
			var j = d.childNodes[i].offsetHeight;
			if (!isNaN(j)) {
				h += j;
			}
		}
		ContentScroll.contHeight = h;
	},
	up:			function () {
		if (ContentScroll.scrolling) {
			return false;
		}
		var o = ContentScroll.obj;
		var current = o.scrollTop;
		var target = current - ContentScroll.smallH + 20; // give 20 pixels grace
		if (target < 0) {
			target = 0;
		} 
		ContentScroll.slide(target);
		return false;
	},
	down:		function () {
		if (ContentScroll.scrolling) {
			return false;
		}
		var o = ContentScroll.obj;
		var current = o.scrollTop;
		var target = current + ContentScroll.smallH - 20; // give 20 pixels grace
		var maxScrollHeight = ContentScroll.contHeight - ContentScroll.smallH;
		if (target > maxScrollHeight) {
			target = maxScrollHeight;
		}
		ContentScroll.slide(target);
		return false;
	},
	slide:		function (target) {
		ContentScroll.scrolling = true;
		var current = ContentScroll.obj.scrollTop;
		if (target < current) {
			var increment = Math.round((target - current - ContentScroll.steps) / ContentScroll.steps);
			if (increment == 0) {
				increment = -1;
			}
			var location = current + increment;
		}
		else if (target > current) {
			var increment = Math.round((target - current) / ContentScroll.steps);
			if (increment == 0) {
				increment = 1;
			}
			var location = current + increment;
		}
		else if (target == current) {
			ContentScroll.scrolling = false;
			return;
		}
		ContentScroll.obj.scrollTop = location;
		setTimeout('ContentScroll.slide(' + target + ')', ContentScroll.duration);
	}
}

Popup = {
	overlay: 'overlay',
	outerCont: 'popouter',
	innerCont: 'popinner',
	intrans:	false,
	duration: 1.0,
	created: false,
	content:	null,
	overlayOpacity: 0.8, // percent opaque
	create:	function () {
		var overlay = document.createElement('div');
		overlay.setAttribute('id', Popup.overlay);
		overlay.onclick = function (event) {
			Popup.hide();
		}
		var outer = document.createElement('div');
		outer.setAttribute('id', Popup.outerCont);
		outer.onclick = function (event) {
			Popup.hide();
		}
		var inner = document.createElement('div');
		inner.setAttribute('id', Popup.innerCont);
		inner.onclick = function (event) {
			Popup.cancelBubble(event);
		}

		var sizes = Popup.getSizes();
		overlay.style.height = sizes.page.height + 'px';
		if (/msie/gi.test(navigator.userAgent.toLowerCase())) {
			overlay.style.width = sizes.page.width + 'px';
			/*
			overlay.style.background = 'none';
			var path = '';
			if (window.location.href.indexOf('/recruitment/') != -1) {
				path += (window.location.href.indexOf('/html/') != -1) ? '../' : '../../';
			}
			overlay.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\'scale\', src=\'' + path  +'images/overlay.png\')';
			overlay.style.width = sizes.page.width + 'px';
			*/
		}

		outer.appendChild(inner);

		overlay.style.display = 'none';
		outer.style.display = 'none';
		document.getElementsByTagName('body')[0].appendChild(overlay);
		document.getElementsByTagName('body')[0].appendChild(outer);

		Popup.overlay = document.getElementById(Popup.overlay);
		Popup.outerCont = document.getElementById(Popup.outerCont);
		Popup.innerCont = document.getElementById(Popup.innerCont);

		Popup.created = true;
	},
	show:	function (oXML) {
		if (!Popup.created) {
			Popup.create();
		}
		var str = oXML.responseText;
		var path = '';
		if (window.location.href.indexOf('/recruitment/') != -1) {
			path += (window.location.href.indexOf('/html/') != -1) ? '../../' : '../';
			str = str.replace(/images\//, path + 'images/');
		}
		Popup.innerCont.innerHTML = str;

		if (document.getElementById('popclose')) {
			var a = document.createElement('a');
			a.href = '#';
			a.onclick = function () {
				Popup.hide();
				return false;
			}
			document.getElementById('popclose').appendChild(a);
		}

		if ($('FLVvid')) {
			$('FLVvid').style.display = 'none';
		}

		//Popup.overlay.style.visibility = 'hidden';
		Popup.outerCont.style.visibility = 'hidden';
		Popup.overlay.style.display = 'block';
		Popup.outerCont.style.display = 'block';
		PopupScroll.init();

		Popup.intrans = true;
		TypeWriter.pause();
		var e1 = new Effect.Appear(Popup.overlay, {from: 0.0, to: Popup.overlayOpacity, duration: Popup.duration});
		//var e2 = new Effect.AppearGrow(Popup.innerCont, {duration: Popup.duration});
		var e2 = new Effect.AppearGrow(($('flvContainer') || $('mediaContainer')), {duration: Popup.duration});
		Popup.startTrans();
	},
	hide:		function () {
		/*
		Popup.overlay.style.display = 'none';
		Popup.outerCont.style.display = 'none';
		*/
		if (Popup.intrans) {
			return;
		}

		if ($('FLVvid')) {
			$('FLVvid').style.display = 'none';
		}

		var e1 = new Effect.Fade(Popup.overlay, {from: Popup.overlayOpacity, to: 0.0, duration: Popup.duration});
		var e2 = new Effect.FadeShrink(($('flvContainer') || $('mediaContainer')),{duration: Popup.duration});
		setTimeout('Popup.delContent()', Popup.duration * 1000);
		Popup.startTrans();
		TypeWriter.play();
		return false;
	},
	delContent:	function () {
		Popup.innerCont.innerHTML = '';
	},
	stopTrans:	function () {
		Popup.intrans = false;

		if ($('FLVvid')) {
			$('FLVvid').style.display = 'block';
		}
	},
	startTrans: function () {
		Popup.intrans = true;
		setTimeout('Popup.stopTrans()', Popup.duration * 1000);
	},
	load:	function (href) {
	    var con = Popup.xhcon();
	    if (!con) {
			return;
		}
		con.connect(href, 'GET', Math.random(), Popup.show);
	},
	resized:	function () {
		if (Popup.created && /msie/gi.test(navigator.userAgent.toLowerCase())) {
			var sizes = Popup.getSizes();
			overlay.style.height = sizes.page.height + 'px';
			overlay.style.width = sizes.page.width + 'px';
		}
	},
	getSizes: function () {
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		}
		else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		}
		else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		}
		else {
			pageWidth = xScroll;
		}
	
	
		return { page: {width: pageWidth, height: pageHeight}, window: {width: windowWidth, height: windowHeight }};
	},
	getDimensions: function(element) {
		if (!element) {
			return false;
		}
		if (element.style.display != 'none') {
			return {width: element.offsetWidth, height: element.offsetHeight};
		}

		// All *Width and *Height properties give 0 on elements with display none,
		// so enable the element temporarily
		var els = element.style;
		var originalVisibility = els.visibility;
		var originalPosition = els.position;
		els.visibility = 'hidden';
		els.position = 'absolute';
		els.display = '';
		var originalWidth = element.clientWidth;
		var originalHeight = element.clientHeight;
		els.display = 'none';
		els.position = originalPosition;
		els.visibility = originalVisibility;
		return {width: originalWidth, height: originalHeight};
	},
	cloneNode:	function (oldNode, deep) {
		deep = (deep) ? true : false;
		// a replacement to the normal dom clone node
		// this will copy xml nodes to html nodes
		// which can then be inserted into the document
		// scope in all browsers
		// See for for the bug http://www.quirksmode.org/blog/archives/2005/12/xmlhttp_notes_c.html
		var newNode = null;
		if (oldNode.nodeType == '3') {
			// textnode
			newNode = $t(oldNode.nodeValue);
		}
		else if (oldNode.nodeType == '1') {
			// element node
			newNode = document.createElement(oldNode.nodeName);
			if (deep) {
				for (var i = 0; i < oldNode.childNodes.length; i++) {
					newNode.appendChild(Jargon.cloneNode(oldNode.childNodes[i], true));
				}
			}
		}
		return newNode;
	},
	cancelBubble:	function (eObj) {
		if (!eObj) var eObj = window.event;
		if (!eObj) return;
		eObj.cancelBubble = true;
		if (eObj.stopPropagation) {
			eObj.stopPropagation();
		}
	},
	xhcon:		function () {
		var xmlhttp, bComplete = false;
		try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) { try { xmlhttp = new XMLHttpRequest(); }
		catch (e) { xmlhttp = false; }}}
		if (!xmlhttp) {
			return null;
		}
		this.connect = function(sURL, sMethod, sVars, fnDone) {
			if (!xmlhttp) {
				return false;
			}
			bComplete = false;
			sMethod = sMethod.toUpperCase();
	
			try {
				if (sMethod == "GET") {
					xmlhttp.open(sMethod, sURL+"?"+sVars, true);
					sVars = "";
				}
				else {
					xmlhttp.open(sMethod, sURL, true);
					xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
					xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				}
				xmlhttp.onreadystatechange = function() {
					if (xmlhttp.readyState == 4 && !bComplete) {
						bComplete = true;
						fnDone(xmlhttp);
					}
				};
				xmlhttp.send(sVars);
			}
			catch(z) { return false; }
			return true;
		};
		return this;
	}
}

/*
Popup = {
	overlayId:	'op',
	show:		function (imgUrl) {
		if (!Popup.created) {
			Popup.create();
		}
		document.getElementById(Popup.imgId).onload = Popup.loaded;
		document.getElementById(Popup.imgId).src = imgUrl;
	},
	loaded:		function () {
		// set the popup to the middle
		var sizes = Popup.getSizes();
		var dims = Popup.getDimensions(document.getElementById(Popup.popupId));
		var x = parseInt((sizes.page.width - dims.width) / 2);
		var y = ((window.scrollY) ? window.scrollY : document.body.scrollTop) + Popup.topPos;
		document.getElementById(Popup.popupId).style.left = x + 'px';
		document.getElementById(Popup.popupId).style.top = y + 'px';

		document.getElementById(Popup.overlayId).style.display = 'block';
		document.getElementById(Popup.popupId).style.display = 'block';
	},
	hide:		function () {
		document.getElementById(Popup.overlayId).style.display = 'none';
		document.getElementById(Popup.popupId).style.display = 'none';
		return false;
	},
	create:		function () {
		var sizes = Popup.getSizes();
		overlay.style.height = sizes.page.height + 'px';
		if (/msie/gi.test(navigator.userAgent.toLowerCase())) {
			overlay.style.background = 'none';
			var path = (window.location.href.indexOf('/html/') == -1) ? '' : '../';
			overlay.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\'scale\', src=\'' + path  +'images/popup/overlay.png\')';
			overlay.style.width = sizes.page.width + 'px';
		}

		
		document.getElementsByTagName('body')[0].appendChild(overlay);
		document.getElementsByTagName('body')[0].appendChild(popup);
		Popup.created = true;
	},
	cancelBubble:	function (eObj) {
		if (!eObj) var eObj = window.event;
		if (!eObj) return;
		eObj.cancelBubble = true;
		if (eObj.stopPropagation) {
			eObj.stopPropagation();
		}
	},
	getSizes: function () {
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		}
		else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		}
		else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		}
		else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		}
		else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		}
		else {
			pageWidth = xScroll;
		}
	
	
		return { page: {width: pageWidth, height: pageHeight}, window: {width: windowWidth, height: windowHeight }};
	},
	getDimensions: function(element) {
		if (!element) {
			return false;
		}
		if (element.style.display != 'none') {
			trace(element.style.display);
			return {width: element.offsetWidth, height: element.offsetHeight};
		}

		// All *Width and *Height properties give 0 on elements with display none,
		// so enable the element temporarily
		var els = element.style;
		var originalVisibility = els.visibility;
		var originalPosition = els.position;
		els.visibility = 'hidden';
		els.position = 'absolute';
		els.display = '';
		var originalWidth = element.clientWidth;
		var originalHeight = element.clientHeight;
		els.display = 'none';
		els.position = originalPosition;
		els.visibility = originalVisibility;
		return {width: originalWidth, height: originalHeight};
	}
}
*/


/*
function $(element) {
	if (typeof element == 'string' && element.length > 0) {
		element = document.getElementById(element);
	}
	return element;
}
*/
function eregi(pattern, string) {
    var reg = new RegExp(pattern, ['gi']);
    return reg.test(string);
}
function stristr(haystack, needle) {
    var reg = new RegExp(needle, ['gi']);
    var pos = haystack.search(reg);
    if (pos == -2) {
        return false;
    }
    return haystack.substring(pos,haystack.length);
}
function explode(separator, str) {
    var reg = new RegExp(separator, ['gi']);
    return str.split(reg);
}


/************************************************
*                                               *
*            Date object                        *
*                                               *
************************************************/

// format is used in a similar way to http://uk.php.net/date
// restricted chars must be escaped with a '\', however in javascript
// when writing the string the '\' itself must be escaped
// E.g. var str = new Date().format('\\Year: Y');  -> Year: 2005
//      var str = new Date().format('\Year: Y');   -> 2005ear: 2005
// note only the 1 '\' in the second example
Date.prototype.format = function (str) {
  this.procProps();
  var pos = 0;
  var buff = '';
  var esc = false;
  while (pos < str.length) {
    var c = str.charAt(pos);
    if (c == '\\' && !esc) {
      esc = true;
    }
    else if (this.isReservedChar(c) && !esc) {
      buff += eval('this.' + c);
    }
    else {
      buff += c;
      esc = false;
    }
    pos++;
  }
  return buff;
}
Date.prototype.isReservedChar = function (c) {
  for (var i = 0; i < this.reservedChars.length; i++) {
    if (this.reservedChars[i] == c) {
      return true;
    }
  }
  return false;
}
Date.prototype.strPad = function (strIn, padLength) {
  var strPad = '0';
  var strIn = new String(strIn);
  var j = strIn.length;
  for (var i = j; i < padLength; i++) {
    strIn = strPad + strIn;
  }
  return strIn;
}
Date.prototype.procProps = function () {
  // see http://uk.php.net/date for a list of the properties
  // D - A textual representation of a day, three letters (Sun through Sat)
  // l (lowercase 'L') - A full textual representation of the day of the week (Sunday through Saturday)
  // d - Day of the month, 2 digits with leading zeros (01 to 31)
  // j - Day of the month without leading zeros (1 to 31)
  // F - A full textual representation of a month, such as January or March (January through December)
  // m - Numeric representation of a month, with leading zeros (01 through 12)
  // M - A short textual representation of a month, three letters (	Jan through Dec)
  // Y - A full numeric representation of a year, 4 digits (Examples: 1999 or 2003)
  // y - A two digit representation of a year (Examples: 99 or 03)
  // H - 24-hour format of an hour with leading zeros (00 through 23)
  // i - Minutes with leading zeros (00 to 59)
  // s - Seconds, with leading zeros (00 through 59)
  // S - English ordinal suffix for the day of the month, 2 characters (st, nd, rd & th)
  this.reservedChars = ['D', 'l', 'd', 'j', 'F', 'm', 'M', 'Y', 'y', 'a', 'A', 'h', 'H', 'i', 's', 'S'];
  if (isNaN(this.getDate()) || isNaN(this.getMonth()) || isNaN(this.getFullYear())) { 
    this.setFullYear(1900, 0, 1);
  }
  var shortDays = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
  var longDays = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
  var monthNames = new Array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
  var shortMonthNames = new Array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
  this.D = shortDays[this.getDay()];
  this.l = longDays[this.getDay()];
  this.d = this.strPad(this.getDate(), 2);
  this.j = this.getDate();
  this.F = monthNames[this.getMonth()];
  this.m = this.strPad(this.getMonth() + 1, 2);
  this.M = shortMonthNames[this.getMonth()];
  this.Y = this.getFullYear();
  this.y = (this.getYear() > 100) ? this.strPad(this.getYear() - 100, 2) : this.strPad(this.getYear(), 2);
  this.a = (this.getHours() >= 12) ? 'pm' : 'am';
  this.A = (this.getHours() >= 12) ? 'PM' : 'AM';
  this.i = this.strPad(this.getMinutes(), 2);
  this.h = (this.getHours() > 12) ? (this.getHours() - 12) : this.getHours();
  this.H = this.strPad(this.getHours(), 2);
  this.s = this.strPad(this.getSeconds(), 2);
  switch (this.getDate()) {
    case 1:
      this.S = 'st';
      break;
    case 2:
      this.S = 'nd';
      break;
    case 3:
      this.S = 'rd';
      break;
    case 21:
      this.S = 'st';
      break;
    case 22:
      this.S = 'nd';
      break;
    case 23:
      this.S = 'rd';
      break;
    case 31:
      this.S = 'st';
      break;
    default:
      this.S = 'th';
      break;
  }
}




Effect.AppearGrow = function(element) {
	element = $(element);
	element.style.display = 'block';
	element.style.visibility = 'hidden';

	var options = Object.extend({
		direction: 'center',
		moveTransition: Effect.Transitions.sinoidal,
		scaleTransition: Effect.Transitions.sinoidal,
		opacityTransition: Effect.Transitions.full
	}, arguments[1] || {});

	var dims = element.getDimensions();

	var oldStyle = {
		top: element.style.top,
		left: element.style.left,
		height: dims.height + 'px',
		width: dims.width + 'px',
		//height: element.style.height,
		//width: element.style.width,
		opacity: element.getInlineOpacity() };

	//var dims = element.getDimensions();
	var initialMoveX = dims.width / 2;
	var initialMoveY = dims.height / 2;
	var moveX = -dims.width / 2;
	var moveY = -dims.height / 2;

	var appearOptions = Object.extend({
		sync: true,
		from: 0.0,
		to: 1.0,
		// force Safari to render floated elements properly
		afterFinishInternal: function(effect) {
			effect.element.forceRerendering();
		},
		beforeSetup: function(effect) {
			effect.element.setOpacity(effect.options.from);
			effect.element.show();
		}
	}, arguments[1] || {});

	return new Effect.Move(element, {
		x: initialMoveX,
		y: initialMoveY,
		duration: 0.01, 
		beforeSetup: function(effect) {
			effect.element.hide();
			effect.element.makeClipping();
			effect.element.makePositioned();
			effect.element.setOpacity(0.0);
		},
		afterFinishInternal: function(effect) {
			new Effect.Parallel(
				[
					new Effect.Opacity(element, appearOptions),
					//new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }),
					new Effect.Move(effect.element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }),
					new Effect.Scale(effect.element, 100, {
						scaleMode: { originalHeight: dims.height, originalWidth: dims.width }, 
						sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true})
				], Object.extend({
						 beforeSetup: function(effect) {
							effect.effects[0].element.setStyle({height: '0px', width: '0px'});
							effect.effects[0].element.show();
							element.style.display = 'block';
							element.style.visibility = 'visible';
						 },
						 afterFinishInternal: function(effect) {
							effect.effects[0].element.undoClipping();
							effect.effects[0].element.undoPositioned();
							effect.effects[0].element.setStyle(oldStyle);
						 }
					 }, options)
			)
		}
	});
}



Effect.FadeShrink = function(element) {
	element = $(element);
	var options = Object.extend({
		direction: 'center',
		moveTransition: Effect.Transitions.sinoidal,
		scaleTransition: Effect.Transitions.sinoidal,
		opacityTransition: Effect.Transitions.none
	}, arguments[1] || {});
	var oldStyle = {
	top: element.style.top,
	left: element.style.left,
	height: element.style.height,
	width: element.style.width,
	opacity: element.getInlineOpacity() };

	var dims = element.getDimensions();
	var moveX = dims.width / 2;
	var moveY = dims.height / 2;

	var fadeOptions = Object.extend({
		sync: true,
		from: 1.0,
		to: 0.0,
		// force Safari to render floated elements properly
		afterFinishInternal: function(effect) {
			effect.element.forceRerendering();
		},
		beforeSetup: function(effect) {
			effect.element.setOpacity(effect.options.from);
			effect.element.show();
		}
	}, arguments[1] || {});

	return new Effect.Parallel(
		[
			new Effect.Opacity(element, fadeOptions),
			//new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }),
			new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}),
			new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition })
		], Object.extend({						
				beforeStartInternal: function(effect) {
					effect.effects[0].element.makePositioned();
					effect.effects[0].element.makeClipping();
				},
				afterFinishInternal: function(effect) {
					effect.effects[0].element.hide();
					effect.effects[0].element.undoClipping();
					effect.effects[0].element.undoPositioned();
					effect.effects[0].element.setStyle(oldStyle);
				}
			 }, options)
	);
}
