var fx_config = new Array();
fx_config['images'] = new Array();
fx_config['images']['constraint'] = new Array;
fx_config['images']['zoom'] = new Array;
fx_config['fade'] = new Array;

/* config area */
fx_config['images']['constraint']['mini'] 		= 100;
fx_config['images']['constraint']['thumb'] 		= 175;
fx_config['images']['constraint']['fullsize'] 		= 390;
fx_config['images']['constraint']['zoom'] 		= 800;
fx_config['images']['constraint']['constrainBy'] 	= 'w';		// width (w) or height (h)

fx_config['images']['zoom']['step']			= 7;		// number pixels to jump with each expand/contract
fx_config['images']['zoom']['speed']			= 1;		// delay in milliseconds between jumps
fx_config['images']['zoom']['runout']			= 1000;		// maximum number of iterations to expand
fx_config['images']['zoom']['tween']			= 10;		// positive number tweens out

fx_config['fade']['step']			= .3;			// % to fade in / out with each jump
fx_config['fade']['speed']			= 100;			// delay in milliseconds between jumps
/* end config area */

var defaultSpeed = 20;


function fade_in(obj, time) {
	time = time ? time : .5;
	if(obj.tween)	obj.tween.stop();
	obj.tween = new Tween(obj, 'alpha', '', 0, 1, time);
	obj.tween.start();
	return obj.tween;
}
function fade_out(obj, time) {
	time = time ? time : .5;
	if(obj.tween)	obj.tween.stop();
	obj.tween = new Tween(obj, 'alpha', '', 1, 0, time);
	obj.tween.start();
	return obj.tween;
}
/* thumb functions */
function getImage(uri, variation) {
	var ext = uri.substring(uri.lastIndexOf('.')+1);		// get extension
	var base = uri.substring(0, uri.length-ext.length-1);		// get remainder of string
	if(base.lastIndexOf('.') > uri.lastIndexOf('/')) 		// contains another variaiton
		base = base.substring(0, base.lastIndexOf('.'));	// strip from start to last '.'

	return	base + '.' + variation + '.' + ext;
}

function changeVideo(v, src, w, h) {
	var flash = false;
	var base;
	if((typeof src) == 'string') {
		base = src.substring(0, (src.lastIndexOf('.')>0?src.lastIndexOf('.'):src.length))+'.';
		var src = { ogg:base+'ogv', mp4:base+'mp4', mov:base+'mov', flv:base+'flv' };
	} else if(src['mp4']) {
		base = src.substring(0, (src['mp4'].lastIndexOf('.')>0?src['mp4'].lastIndexOf('.'):src['mp4'].length))+'.';
	}

	var at = v.currentTime;

	if(v.canPlayType && v.canPlayType('video/ogg') && src['ogg']) {
		v.src = src['ogg'];
	} else if(v.canPlayType && v.canPlayType('video/mp4') && src['mp4']) {
		v.src = src['mp4'];
	} else {
		flash = true;
	}

	//flash=true;
	if(!flash) {
		//v.autoplay = false;
		v.load();
		v.play();
		if(!w) w=v.offsetWidth;
		//v.poster=base+'.'+w+'.jpg';
		v.poster='/i/ui/overlays/poster.jpg'
		//v.currentTime = at;
	} else {
		if(!w)	w = v.offsetWidth;
		if(!h)	h = v.offsetHeight;
		 v.innerHTML = generateEmbedCode('flv',src['flv'],w,h, true, true);
	}
	_gaq.push(['_trackEvent', 'Videos', 'Play', src['mp4']]);
}
function createVideo(src, w, h, controls, autoplay, preload, startAt) {
	if(controls==undefined)	controls = true;
	if(autoplay==undefined)	autoplay = true;
	if(preload==undefined)	preload = true;
	if(startAt==undefined)	startAt = 0;
	if(!w && !h) {
	 	w = 640;
		h = 360;
	}

	var base;
	if((typeof src) == 'string') {
		base = src.substring(0, (src.lastIndexOf('.')>0?src.lastIndexOf('.'):src.length))+'.';
		var src = { mov:base+'mov', ogg:base+'ogv', mp4:base+'mp4', flv:base+'flv' };
	} else if(src['mp4']) {
		base = src.substring(0, (src['mp4'].lastIndexOf('.')>0?src['mp4'].lastIndexOf('.'):src['mp4'].length))+'.';
	}

	v = document.createElement('video');
	v.width = w;
	v.height = h;
	v.controls = controls;
	v.autoplay = autoplay;
	v.autoplay = true;
	v.preload = preload;

	var flash = false;
	if(v.canPlayType && src['ogg'] && v.canPlayType('video/ogg')) {
		var srcObj = addChild(v, 'source');		// mozilla
		srcObj.type = "video/ogg";
		srcObj.src = src['ogg'];
	} else if(v.canPlayType && src['mp4'] && v.canPlayType('video/mp4')) {
		var srcObj = addChild(v, 'source');		// webkit video
		srcObj.type = "video/mp4";
		srcObj.src = src['mp4'];
		//v.src = src['mp4'];
	} else if(v.canPlayType && src['webm'] && v.canPlayType('video/webm')) {
		var srcObj = addChild(v, 'src');
		srcObj.type = "video/webm";
		srcObj.src = src['webm'];
	} else {
		flash = true;
	}

	//flash = true;
	if(!flash) {
		//if(startAt) v.startTime = startAt;
		//v.poster=base+'.'+w+'.jpg';
		v.poster='/i/ui/overlays/poster.jpg';
		///if(autoplay)	v.play();
	} else {
		 var v = document.createElement('div');
		 v.innerHTML = generateEmbedCode('flv',src['flv'],w,h, autoplay, true);
	}
	//_trackEvent('video-'+srcObj['mp4'], 'play', 'page', document['title']);
	_gaq.push(['_trackEvent', 'Videos', 'Play', src['mp4']]);
	return v;
}
function fullscreenVideo(src, w,h, controls, autoplay, preload, startAt) {
	if(controls==undefined)	controls = true;
	if(autoplay==undefined)	autoplay = true;
	if(preload==undefined)	preload = true;
	if(startAt==undefined)	startAt = 0;
	if(!w && !h) {
	 	w = 640;
		h = 360;
	}

	var fullDimensions = getMaxDimensions(w, h);

	var v = createVideo(src, fullDimensions[0], fullDimensions[1], controls, autoplay, preload, startAt);

	lightbox(v, fullDimensions[0], 'obj', '', fullDimensions[1]);
	//if(startAt) v.currentTime = startAt;
}
function fullscreenImage(obj, type) {
	var fullDimensions = getMaxDimensions(obj.offsetWidth, obj.offsetHeight);

	var fullObj = false;
	fullObj = document.createElement('img');
	fullObj.src = getImage(obj.src, fullDimensions[0]);
	lightbox(fullObj, fullDimensions[0], 'obj', 'loading', fullDimensions[1]);
}
function getMaxDimensions(w,h) {
	var winW = getWinWidth() - 20;
	var winH = getWinHeight() - _lightboxTopOffset - 30;

	var ratio = winW / w;
	var newW = winW;
	var newH = Math.floor(ratio * h);
	if(newH > winH) {
		var ratio = winH / h;
		newH = winH;
		newW = Math.floor(ratio * w);
	}
	return Array( newW, newH );
}

/* functionality */
var _lightboxObj = new Array();
var _lightboxTopOffset = 90;
var _lightboxLoadedImages = new Array();
function lightboxCloseCurrent() {	
	if(window['slideshow']) 	window['slideshow'].resume();

	_lightboxObj.pop().closeButton.onclick();
	clearEventHandler(window, 'keyup', lightboxCloseCurrent);
}
function lightbox(src, width, type, className, height) {
	if(window['slideshow']) 	window['slideshow'].pause();

	var topMargin = (_lightboxTopOffset - getScrollHeight() > 0) ? _lightboxTopOffset - getScrollHeight() : _lightboxTopOffset;
	if(className==undefined)	className = '';
	if(_lightboxObj.length && !src) {
		_lightboxObj.pop().closeButton.onclick();
		return;
	}
	if(!src)	return;
	var lbIndex = _lightboxObj.length;

	if(type==undefined)	type = 'img';
	var scrollTop = getScrollHeight();
	var scrollLeft = isNaN(window.pageXOffset) ? document.body.scrollLeft : window.pageXOffset;
	var closeButtonLeftOffset = 2;

	/* lightbox container */
	_lightboxObj[lbIndex] = document.createElement('div');
	_lightboxObj[lbIndex].id = 'lightbox|'+lbIndex;
	//_lightboxObj[lbIndex].className = className+(isIE?'':' transparent ')+' lightboxMaster'+' '+type;
	_lightboxObj[lbIndex].className = className+' lightboxMaster'+' '+type;
	_lightboxObj[lbIndex].style.position = 'absolute';
	_lightboxObj[lbIndex].style.top = getScrollHeight()+'px'; 
	addEventHandler(window, 'scroll', function() { if(_lightboxObj[lbIndex]) _lightboxObj[lbIndex].style.top=getScrollHeight()+'px'; } );
	_lightboxObj[lbIndex].style.left = '0px';
	_lightboxObj[lbIndex].style.width='100%';
	_lightboxObj[lbIndex].style.zIndex='9';

	_lightboxObj[lbIndex].style.height=getFullWinHeight()+'px';
	document.body.appendChild(_lightboxObj[lbIndex]);

	/* create background */
	var bg = document.createElement('div');
	bg.style.position = 'absolute';
	bg.style.marginTop = getScrollHeight()*-1+'px';
	bg.style.left = '0px';
	bg.style.width='100%';

	bg.style.height=getFullWinHeight()+'px';
	bg.className = 'lightboxBG';
	_lightboxObj[lbIndex].style.height = getWinHeight()+'px';

	if(type!='url') bg.onclick = function() { this.closeButton.onclick(); };
	_lightboxObj[lbIndex].bg = bg;
	_lightboxObj[lbIndex].appendChild(bg);

	/* setup img width */
	if(type=='img') {
		var imgProps = new Array();
		if(width && height) {
			imgProps['w'] = width;
			imgProps['h'] = height;
		} else {
			_lightboxObj[lbIndex].className = _lightboxObj[lbIndex].className +' blackbox';
			var imgXML = load('/boss/getImageInfo.php?src='+src);
			if(parseXML(imgXML, Array('response','w'))) {
				imgProps['w'] = parseXML(imgXML, Array('response','w'));		// size is appropriate
				imgProps['h'] = parseXML(imgXML, Array('response','h'));
				if(imgProps['h'] > (getWinHeight()*.8)) {				// size needs to be adjusted
					var h = imgProps['h'];
					imgProps['h'] = getWinHeight()*.8;				// recalc height
					imgProps['w'] = imgProps['h']/h * imgProps['w'];		// recalc width
				}
			} else {
				imgProps['w'] = 450;
			}
		}
	}


	/* create container */
	var lbContainer = document.createElement('div');					// create container
	lbContainer.className = 'lightboxContainer';
	lbContainer.style.padding = '0px';
	lbContainer.style.position = 'absolute';
	if(width) lbContainer.style.width = width+'px';

	_lightboxObj[lbIndex].container = lbContainer;
	_lightboxObj[lbIndex].appendChild(lbContainer);
	
	/* setup html */
	if(type=='img') {
		var lbBody = document.createElement('img');
		lbBody.src = src;
		if(_lightboxLoadedImages.toString().indexOf(src)>=0) {	// already loaded (ie)
			lbBody.style.visibility = 'visible';
			var fade = new Tween(lbBody, 'alpha', false, 0, 1, .5);
			fade.start();
		} else {
			lbBody.style.visibility = 'hidden';
		}
		lbBody.style.width = imgProps['w']+'px';
		lbBody.style.height = (imgProps['h']!=undefined) ? imgProps['h']+'px' : 'auto';
		lbBody.lb = _lightboxObj[lbIndex];
		lbBody.className = 'lightboxBody';
		lbBody.style.background = 'transparent';
		lbContainer.style.overflow = 'hidden';
		lbBody.onload = function() { 								// onload modify sizing
			if(lbBody.offsetHeight > (getWinHeight()*.8)) {					// adjust if larger than 70% of screen
				lbBody.style.width = 'auto';
				lbBody.style.height = Math.round(getWinHeight()*.8)+'px';
			}
			var fade = new Tween(this, 'alpha', false, 0, 1, .5);
			fade.start();
			this.lb.container.style.visibility='visible'; 
			lbBody.style.visibility = 'visible';
			this.lb.container.style.left = (parseInt(getWinWidth()/2)-this.width/2)+'px'; 
			this.lb.container.style.top = (getWinHeight()/2-(this.height?this.height:lbContainer.offsetHeight)/2)+'px';
			_lightboxObj[lbIndex].style.top = scrollTop+'px'; 
			_lightboxObj[lbIndex].closeButton.style.top = Top(lbContainer)-getScrollHeight()+'px';
			this.lb.container.style.width = this.width+'px';
			this.lb.container.style.height = this.height+'px';
			_lightboxLoadedImages[_lightboxLoadedImages.length] = this.src;
		};
		lbContainer.appendChild(lbBody);
	} else if(type == 'obj') {									// load from an html node obj
		bg.onclick = function() { ; };
		var lbBody = document.createElement('div');
		lbBody.appendChild(src);
		src.style.margin='0px';
		lbBody.className = 'lightboxBody obj';
		lbContainer.appendChild(lbBody);
		lbContainer.style.width = lbBody.offsetWidth+'px';

		var clrDiv = document.createElement('div');
		clrDiv.style.clear='both';
		lbContainer.appendChild(clrDiv);
	} else {											// load from a url
		var html = load(src);
		var lbBody = document.createElement('div');
		lbBody.innerHTML = html;
		lbBody.className = 'lightboxBody';
		if(width) lbBody.style.width = width+'px';
		lbContainer.appendChild(lbBody);
		lbContainer.style.height = (height!=undefined ? height : lbBody.offsetHeight)+'px';
		lbBody.style.height = (height!=undefined ? height : lbBody.offsetHeight)+'px';
		if(topMargin+Top(lbContainer)-getScrollHeight()+lbContainer.offsetHeight > getWinHeight()) {
			lbBody.style.height = Math.floor(getWinHeight()-topMargin-5)+'px';		// adjust if larger than 70% of screen
			lbContainer.style.height = lbBody.style.height;
		}
	}

	if(topMargin+Top(lbContainer)-getScrollHeight()+lbContainer.offsetHeight > getWinHeight()) {
		var newHeight = getWinHeight()-topMargin-20;
		if(newHeight < parseInt(lbContainer.offsetHeight))
			lbContainer.style.height = newHeight+'px';
		height = parseInt(lbContainer.style.height);
		lbContainer.style.top = topMargin+'px';
	}
	if(type=='img')
		lbContainer.style.top = Math.ceil(getWinHeight()/2-(lbContainer.offsetHeight/2)+topMargin)+'px';
	else	lbContainer.style.top = Math.ceil(getWinHeight()/3-(lbContainer.offsetHeight/2))+topMargin+'px';
	lbContainer.style.left = (parseInt(getWinWidth()/2)-(width?width:lbContainer.offsetWidth)/2)+'px';

	/* create close button */
	_lightboxObj[lbIndex].closeButton = document.createElement('div');
	_lightboxObj[lbIndex].closeButton.innerHTML = '<img src="/i/ui/closeX.png" />';
	_lightboxObj[lbIndex].closeButton.className = 'lightboxButton';
	_lightboxObj[lbIndex].appendChild(_lightboxObj[lbIndex].closeButton);
	_lightboxObj[lbIndex].closeButton.style.top = Top(lbContainer)-getScrollHeight()+'px';
	_lightboxObj[lbIndex].closeButton.style.left = Left(lbContainer)+lbContainer.offsetWidth-_lightboxObj[lbIndex].closeButton.offsetWidth-closeButtonLeftOffset+'px';
	_lightboxObj[lbIndex].closeButton.onclick=function() { 
		if(this.parentNode && (this.parentNode!=undefined) && this.parentNode.parentNode) {
			/**/
			var t = new Tween(this.parentNode, 'alpha', false, 1, 0, .5, true);
			t.onstop = function() { 
				remove(_lightboxObj[lbIndex]);
				this.obj.parentNode.removeChild(this.obj);
			}
			/**/
			//this.parentNode.parentNode.removeChild(this.parentNode);
		}
		_lightboxObj.splice(lbIndex);						// remove from array
	};

	bg.closeButton = _lightboxObj[lbIndex].closeButton;

	if(!isIE) {
		bg.style.opacity = 0;
		lbContainer.style.opacity = 0;
		_lightboxObj[lbIndex].closeButton.style.opacity = 0;
		var tw = new Tween(bg, 'alpha', '', .4, 1, .3, true, 30);
		tw.onchange = function(pos) {
			if(pos>.8) {
				var tw = new Tween(lbContainer, 'alpha', '', 0, 1, .3, true, 30);
				tw.onstop = function() { 
						var tw = new Tween(_lightboxObj[lbIndex].closeButton, 'alpha', '', 0, 1, .3, true, 20);
						this.onchange = function(){ ; };
				}
			}
		}
	}

	addEventHandler(window, 'keyup', function(e){ var e=e?e:window.event; if(e.keyCode==13) lightboxCloseCurrent;} );
	return _lightboxObj[lbIndex];
}
function center(obj, to, horiz, vert) {
	if(!to)			to = obj.parentNode;
	if(horiz==undefined)	horiz=true;
	if(vert==undefined)	vert=true;
	if(!obj.offsetWidth) 	obj.style.display='block';
	if(horiz) {
		obj.style.marginLeft = '0px';
		obj.style.marginLeft = ((to.offsetWidth-obj.offsetWidth)/2)+'px';
	}
	if(vert) {
		obj.style.marginTop = '0px';
		obj.style.marginTop = ((to.offsetHeight-obj.offsetHeight)/2)+'px';
	}
}

/* Formatting functions */
_dropshadows = Array();
_dropshadowLeft = 18;
_dropshadowRight = 24;
_dropshadowTop = 17;
_dropshadowBottom = 25;
function setupDrop(targ, noTop) {
	if(noTop==undefined)	noTop = false;
	if(_dropshadows[targ.id])	remove(_dropshadows[targ.id]);
	if(!targ.id)	targ.id = 'anonymous|'+(unique_counter++);
	_dropshadows[targ.id] = document.createElement('div');
	_dropshadows[targ.id].className = 'dropshadow drop';
	_dropshadows[targ.id].id="_dropshadow";

	if(noTop)	_dropshadows[targ.id].className = 'drop dropshadow noTop';

	w = (targ.offsetWidth + _dropshadowLeft+_dropshadowRight)/2;
	h = Math.floor((targ.offsetHeight + (noTop?0:_dropshadowTop)+_dropshadowBottom)/2)-1;

	targ.parentNode.insertBefore(_dropshadows[targ.id], targ);

	_dropshadows[targ.id].innerHTML = 
		!noTop ? '<table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td id="TL"></td><td id="TR"></td></tr><tr><td id="BL"></td><td id="BR"></td></tr></tbody></table>' 
		       : '<table cellpadding="0" cellspacing="0" border="0"><tbody><tr><td id="BL"></td><td id="BR"></td></tr></tbody></table>' ;

	if(!noTop) _dropshadows[targ.id].style.marginTop = '-'+_dropshadowTop+'px';

	_dropshadows[targ.id].style.width = (targ.offsetWidth + _dropshadowLeft+_dropshadowRight)+'px';		// dimensions
	var h = targ.offsetHeight + (noTop?0:_dropshadowTop)+_dropshadowBottom;
	_dropshadows[targ.id].style.height = h+'px';
	_dropshadows[targ.id].style.left = (Left(targ)-_dropshadowLeft)+'px';					// position
	_dropshadows[targ.id].style.top = (Top(targ)-getScrollHeight())+'px';

	return _dropshadows[targ.id];
}

var _dropdownHolder = false;
var _dropdownAnchor = false;
function showMask(targ, className, loading) {
	var mask = targ.mask;
	if(!mask || !mask.parentNode) {
		mask = document.createElement('div');
		document.body.appendChild(mask);
		mask.className = 'mask'+((className!=undefined)?className:'');
	}
	targ.mask = mask;
	resizeMask(targ);
	mask.targ = targ;

	if(loading) {
		mask.className = 'mask load';
		var marg = (mask.offsetHeight + Top(mask) > getWinHeight()) ? (getWinHeight()-Top(mask))/2 : mask.offsetHeight / 2;
		mask.innerHTML = '<div align="center" style="margin-top:'+(marg-25)+'px;"><img src="/i/ui/loading.gif" /></div>';
	}

	fade_in(mask, .8);
	return mask;
}
function resizeMask(targ) {
	targ.mask.style.width = targ.offsetWidth+'px';
	targ.mask.style.height = targ.offsetHeight+'px';
	targ.mask.style.display = 'block';
	targ.mask.style.top = Top(targ)+'px';
	targ.mask.style.left = Left(targ)+'px';
}
function hideMask(targ) {
	if(targ.mask && targ.mask.parentNode) 
		fade_out(targ.mask, true);
}


var _loading = false;
function setLoad(dv, isLoading) {
	if(_loading) {
		_loading.parentNode.removeChild(_loading);	// remove old
		_loading=false;
	} else {
		_loading = document.createElement('div');
		_loading.className = 'loadMask';
		_loading.style.left = Left(dv)+'px';
		_loading.style.top = Top(dv)+'px';
		_loading.style.width = dv.offsetWidth+'px';
		_loading.style.height = dv.offsetHeight+'px';
		_loading.style.zIndex = 99;
		document.body.appendChild(_loading);
	}
}

function fit(obj, padding, rent) {
	if(padding==undefined)	padding = 0;
	obj.style.position='absolute';
	rent = (rent==undefined) ? obj.parentNode : rent;

	obj.style.display = 'none';
	var rentWidth = rent.offsetWidth-padding*2;
	var rentHeight = rent.offsetHeight-padding*2;
	obj.style.display = '';
	var objWidth = obj.offsetWidth;
	var objHeight = obj.offsetHeight;

	var proportion =  rentWidth / objWidth;
	var proposedHeight = proportion * objHeight;

	if(proposedHeight > rentHeight) {				// too tall, constrain by height
		proportion = rentHeight / objHeight;
	}

	obj.style.width = Math.floor(objWidth * proportion)+'px';	// set width
	obj.style.height = Math.floor(objHeight * proportion)+'px';	// set height
	obj.style.maxWidth = Math.floor(objWidth * proportion)+'px';	// set width
	obj.style.maxHeight = Math.floor(objHeight * proportion)+'px';	// set height
	obj.style.position='relative';
}

function imageProperties(src) {	
	src = replace(replace(src,'&','%26'),' ','%20');
	var xml = load('/boss/getImageInfo.php?src='+src); 
	var ary = new Array();
	ary['w'] = parseXML(xml,Array('response','w'));
	ary['h'] = parseXML(xml,Array('response','h'));
	return ary;
}
function generateEmbedCode(type,src,w,h, autostart, transparent) {
	var code = '';
	var rand = Math.random(0,100000);
	src = ''+src;
	autostart = (!autostart || (autostart==undefined)) ? 0 : 1;
	transparent = (!transparent || (transparent==undefined)) ? 0 : 1;
	if(w==undefined) w='320';
	if(h==undefined) h='260';
	w = Math.round(w);
	h = Math.round(h);
	switch(type) {
		case 'img':
			code = '<img onclick="lightbox(this.src);" src="'+src+'" />';
			break;
		case 'flv':
			code = ''+
				'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+w+'" height="'+h+'" id="videoPlayer" align="middle">'+
				'<param name="allowScriptAccess" value="sameDomain" />'+
				'<param name="allowFullScreen" value="true" />'+
				'<param name="wmode" value="transparent" />'+
				'<param name="movie" wmode="transparent" value="/i/ui/swf/videoPlayer.swf?autostart=1&vSrc='+src+'" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" />	<embed src="/i/ui/swf/videoPlayer.swf?autostart=1&vSrc='+src+'" quality="high" bgcolor="#000000" width="'+w+'" height="'+h+'" name="videoPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
				'</object>';
			break;
	}
	return code;
}
function setOverlay(targ, type) {
	var overlay = document.createElement('div');
	targ.parentNode.appendChild(overlay);
	overlay.style.position='absolute';
	//overlay.style.marginLeft = (targ.offsetWidth*-1)+'px';
	overlay.style.marginTop = (targ.offsetHeight*-1)+'px';
	overlay.style.width = targ.offsetWidth+'px';
	overlay.style.height = targ.offsetHeight+'px';
	overlay.className = 'overlay '+type;
	overlay.onclick = function() { targ.onclick(); }
}
/* end video generator functions */

var currentContentItem = false;
function setTabSet(active, contentItem) {
	switchInlineTab(active);		// switch tab
	switchInlineTab(contentItem);		// switch content area

	currentContentItem = contentItem;

	if(currentContentItem.className && (currentContentItem.className.indexOf('active')!=-1)) {	// current tab
		var player = getElementByNodeName('OBJECT', currentContentItem);
		player.innerHTML = player.innerHTML;
	}
	fade_in(contentItem);			// fade it in
}
function setTabSetToMaxHeight(holder) {
	var maxH = 0;
	for(var x in holder.childNodes)	{
		if(holder.childNodes[x].offsetHeight > maxH) {
			maxH = holder.childNodes[x].offsetHeight;
		}
	}
	if(maxH) holder.style.height =  maxH+'px';
}
function switchInlineTab(active) {
	var holder = active.parentNode;
	for(var x in holder.childNodes)	{
		holder.childNodes[x].className = holder.childNodes[x].className ? holder.childNodes[x].className.replace(/active/g,'') : '';
	}
	active.className = active.className + ' active';
	holder.active = active;
}
/* end misc functions */

/* glossary functions */
var definitionDV = false;
function def(obj, specificTo, overrideTerm, overrideWidth) {
	obj = (obj!=undefined)	? obj : false; 
	var term = overrideTerm ? overrideTerm : obj.innerHTML;
	var html = load('/boss/definition.php?s='+term+'&cat='+specificTo);
	if(!obj.onmouseout)	obj.onmouseout=function(){ def(); };

	return showMore(obj, html, overrideWidth);
}
var moreDV = false;
function showMore(anchorTo, html, overrideWidth) {
	if(moreDV) {
		moreDV.parentNode.removeChild(moreDV);
		moreDV = false;
	}
	if(anchorTo) {
		moreDV = document.createElement('div');
		moreDV.innerHTML = html;
		moreDV.className = 'more';
		if(overrideWidth) moreDV.style.width = overrideWidth+'px';
		moreDV.style.left='0px';
		document.body.appendChild(moreDV);

		if((Top(anchorTo)-moreDV.offsetHeight) > getScrollY()) {	// too big to put above
			moreDV.style.top=Top(anchorTo)-moreDV.offsetHeight+'px';
		} else {							// put below object
			moreDV.style.top=Top(anchorTo)+anchorTo.offsetHeight+'px';
		}

		var x = Left(anchorTo);
		if(x+moreDV.offsetWidth > getWinWidth())	x = getWinWidth()-moreDV.offsetWidth-10;
		moreDV.style.left=x+'px';
		fade_in(moreDV);
	}
}
/**/
function share(network, link, label) {
	if(!link) {
		var loc = window.location;
	}
	if(!label)	label = document.title;
	var url = '';
	switch(network) {
		case 'facebook':
			url = 'http://www.facebook.com/sharer.php?t='+encodeURIComponent(label.replace(/-/g,'%20'))+'&u='+encodeURIComponent(link);//+string_generator(5);
			break;
		case 'twitter':
			url = 'http://twitter.com/home?status='+label+' '+encodeURIComponent(link);
			break;
		case 'delicious':
			url = 'http://delicious.com/save?v=5&amp;noui&amp;jump=close&url='+link+'&title='+label.replace(/-/g,' ');
			break;
		case 'myspace':
			url = 'http://www.myspace.com/Modules/PostTo/Pages/?u='+link+'&c='+encodeURIComponent(label.replace(/-/g, ' '));
			break;
		case 'stumbleupon':
			url = 'http://www.stumbleupon.com/submit?url='+encodeURIComponent(link)+'&title='+label;
			break;
	}
	window.open(url, network, 'toolbar=no,width=550,height=550');
        _gaq.push(['_trackEvent', document.title, 'Share - '+network, label]);
}

function checkRequired(frm) {
	var good2go = true;
	for(var x in frm) {
		if(frm[x] && frm[x].name && frm[x].className) {
			if((frm[x].className.indexOf('required')!=-1) && (frm[x].value.replace(/^\s+|\s+$/g, '') =='')) {
				frm[x].className = frm[x].className+' warning';
				good2go=false;
			} else	frm[x].className = frm[x].className.replace('warning','');
		}
	}
	return good2go;
}

function getErrorStr(xml) {
	var errStr = '';
	while(err = parseXML(xml, Array('error'))) {
		errStr += err+"\n";
		xml = EatXML(xml, Array('error'));
	}
	return errStr;
}



