var fx_config = new Array();
fx_config['images'] = new Array();
fx_config['images']['constraint'] = new Array;
fx_config['images']['zoom'] = 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
/* end config area */

var defaultSpeed = 20;

/* transitions */
function slideIn(obj, to, speed) {
	if(!obj.style.top) 	obj.style.top = obj.offsetHeight*-1+getScrollHeight();
	if(to==undefined)	to = 0;
	if(speed==undefined)	speed = defaultSpeed;

	obj.style.display='block';
	obj.style.visiblity='visible';
	obj.style.top = (parseFloat(obj.style.top)+speed)+'px';
	if(parseInt(obj.style.top) <= to+getScrollHeight()) {
		setTimeout('slideIn($("'+obj.id+'"),'+to+','+speed+');', 50);
	} else {
		obj.style.top = to+getScrollHeight()+'px';
	}
} 
function slideOut(obj, speed) {
	if(!obj.style.top) obj.style.top = 0;
	if(speed==undefined)	speed = defaultSpeed;
	obj.style.display='block';
	obj.style.visiblity='visible';
	obj.style.top = (parseFloat(obj.style.top)-speed)+'px';
	if(parseInt(obj.style.top) > obj.offsetHeight*-1) {
		setTimeout('slideOut($("'+obj.id+'"));', 50);
	} else	obj.style.top = obj.offsetHeight*-1;
}

var curGrowObj = false;
function grow(obj, to, speed) {
	if(obj) curGrowObj = obj;
	if(!obj.style.height) obj.style.height = obj.offsetHeight;
	if(speed==undefined)	speed = defaultSpeed*1.5;
	obj.style.height = (parseFloat(obj.style.height)+speed)+'px';
	if(parseInt(obj.style.height) < to) {
		setTimeout('grow(curGrowObj, '+to+', '+(speed*.9)+');', 50);
	} else	{
		obj.style.height = to+'px';
	}
} 
function shrink(obj, to, speed, removeObj) {
	if(to==undefined)	to = 0;
	if(removeObj==undefined)	removeObj = 0;
	if(!obj.id)		obj.id = 'shrnk|'+Math.round(Math.random()*10000000000);
	if(!obj.style.height) 	obj.style.height = obj.offsetHeight+'px';

	if(speed==undefined)	speed = defaultSpeed;
	obj.style.overflow='hidden';
	obj.style.visiblity='visible';
	obj.style.height = (parseFloat(obj.style.height)-speed)+'px';
	if(parseInt(obj.style.height) > (speed+to)) { 
		setTimeout('shrink($("'+obj.id+'"),'+to+','+speed+','+removeObj+');', 50);
	} else {
		obj.style.height = to+'px';
		if(removeObj)	remove(obj);
	}
}

var unique_counter = 0;
var _currentlyFading = new Array();
function fade_in(obj, to) {
	if(!obj || !obj.style)	return;
	if(!obj.id) obj.id = 'anonymous|'+(unique_counter++);

	if(to==undefined) 	to = 1;

	if(!obj.style.opacity) {
		obj.style.opacity=0;
		obj.style.filter='alpha(opacity=0)';
	}
	obj.style.opacity = parseFloat(obj.style.opacity)+.3;
	obj.style.filter='alpha(opacity='+(parseFloat(obj.style.opacity)*100)+')';
	if(obj.style.opacity >= to) {
		obj.style.filter='alpha(opacity='+(to*100)+')';
		obj.style.opacity=to;
		_currentlyFading[obj.id] = false;
	} else {
		_currentlyFading[obj.id] = true;
		setTimeout('fade_in($("'+obj.id+'"),'+to+');', 100);
	}
} 
function fade_out(obj, removeAfter) {
	if(removeAfter==undefined)	removeAfter = 0;
	if(obj == null)	{
		remove(obj);
		return;
	}

	if(!obj.style.opacity || (obj.style.opacity==undefined)) {
		obj.style.opacity=1;
		obj.style.filter='alpha(opacity=100)';
	}
	if(!obj.id) obj.id = 'anonymous|'+(unique_counter++);
	obj.style.opacity = parseFloat(obj.style.opacity)-.3;
	obj.style.filter='alpha(opacity='+(parseFloat(obj.style.opacity)*100)+')';
	if(obj.style.opacity <= 0) {
		if(removeAfter) {
			remove(obj);
			obj = false;
		}
		return;
	} else {
		setTimeout('fade_out($("'+obj.id+'"),'+(removeAfter?1:0)+');', 50);
	}
}

var _screen;
function screen(out, opacity) {
	if(_screen || out)	remove(_screen);
	if(out)	return;
	_screen = document.createElement('div');
	_screen.id = 'screen';
	_screen.style.position = 'absolute';
	_screen.style.top = getScrollHeight()+'px';
	_screen.style.height = getFullWinHeight()+'px';
	window.onscroll = function() { 
		var scrollTop = getScrollHeight();
		_screen.style.top = scrollTop+'px'; 
	};
	_screen.style.left = '0px';
	_screen.style.width='100%';

	document.body.appendChild(_screen);
	fade_in(_screen, (opacity==undefined)?.5:opacity);
}

/* functionality */
var _lightboxObj = false;
var _lightboxTopOffset = 125;
var _lightboxLoadedImages = new Array();
function lightbox(src, width, type, className, height) {
	var topMargin = (_lightboxTopOffset - getScrollHeight() > 0) ? _lightboxTopOffset - getScrollHeight() : 50;
	if(className==undefined)	className = '';
	if(_lightboxObj) {
		_lightboxObj.closeButton.onclick();
       		if(src==undefined)	return;
	}
	if(type==undefined)	type = 'img';
	//var scrollTop = isNaN(window.pageYOffset) ? document.body.scrollTop : window.pageYOffset;
	var scrollTop = getScrollHeight();
	var scrollLeft = isNaN(window.pageXOffset) ? document.body.scrollLeft : window.pageXOffset;
	var closeButtonLeftOffset = 2;

	/* lightbox container */
	_lightboxObj = document.createElement('div');
	_lightboxObj.id = 'lightbox';
	_lightboxObj.className = className;
	_lightboxObj.style.position = 'absolute';
	_lightboxObj.style.top = getScrollHeight()+'px'; 
	_lightboxObj.style.left = '0px';
	_lightboxObj.style.width='100%';
	_lightboxObj.style.zIndex='9';

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

	/* create background */
	var bg = document.createElement('div');
	bg.style.position = 'absolute';
	bg.style.top = '0px';
	window.onscroll = function() { 
		var scrollTop = getScrollHeight();
		if(_lightboxObj)	_lightboxObj.style.top = scrollTop+'px'; 
	};
	bg.style.left = '0px';
	bg.style.width='100%';

	bg.style.height='100%';
	bg.className = 'lightboxBG';
	bg.onclick = function() { this.closeButton.onclick(); };
	_lightboxObj.bg = bg;
	_lightboxObj.appendChild(bg);

	/* setup img width */
	if(type=='img') {
		var imgProps = new Array();
		if(width && height) {
			imgProps['w'] = width;
			imgProps['h'] = height;
		} else {
			_lightboxObj.className = _lightboxObj.className +' lackbox';
			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';
	lbContainer.style.left = (parseInt(getWinWidth()/2)-lbContainer.offsetWidth/2)+'px';	// center
	lbContainer.style.height = (height && (height!=undefined)) ? (height+'px') : 'auto';

	_lightboxObj.container = lbContainer;
	_lightboxObj.appendChild(lbContainer);
	
	_lightboxObj.style.opacity = .4;
	_lightboxObj.style.filter='alpha(opacity=40)';

	/* 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';
			fade_in(lbBody);
		} else {
			lbBody.style.visibility = 'hidden';
		}
		lbBody.style.width = imgProps['w']+'px';
		lbBody.style.height = (imgProps['h']!=undefined) ? imgProps['h']+'px' : 'auto';
		lbBody.lb = _lightboxObj;
		lbBody.className = 'lightboxBody img';
		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';
			}
			fade_in(this);
			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.style.top = scrollTop+'px'; 
			if(_lightboxObj.closeButton) {
				_lightboxObj.closeButton.style.top = (getWinHeight()/2-(lbContainer.offsetHeight)/2)+1+'px';
				//_lightboxObj.closeButton.style.left = Left(this.lb.container)+this.lb.container.offsetWidth-_lightboxObj.closeButton.offsetWidth-1+'px';
			}
			this.lb.container.style.width = this.width+'px';
			this.lb.container.style.height = this.height+'px';
			_lightboxObj.drop = setupDrop(this.lb.container);
			_lightboxLoadedImages[_lightboxLoadedImages.length] = this.src;
		};
		lbContainer.appendChild(lbBody);
	} else if(type == 'obj') {									// load from an html node obj
		var lbBody = document.createElement('div');
		lbBody.appendChild(src);
		src.style.margin='0px';
		lbBody.className = 'lightboxBody obj';
		lbContainer.appendChild(lbBody);
		lbContainer.style.height = ((height&&(height!=undefined)) ? height : lbBody.offsetHeight)+'px';
		lbContainer.style.width = lbBody.offsetWidth+'px';

		var clrDiv = document.createElement('div');
		clrDiv.style.clear='both';
		lbContainer.appendChild(clrDiv);
		if(lbBody.offsetHeight > ((getWinHeight()-topMargin)*.97)) {				// adjust if larger than 97% of screen
			lbBody.style.height = Math.round((getWinHeight()-topMargin)*.97)+'px';
			lbContainer.style.height = Math.round((getWinHeight()-topMargin)*.97)+'px';	
		}
	} else if(type == 'iframe') {									// load into iframe
		var lbBody = document.createElement('iframe');
		lbBody.src = src;
		lbBody.className = 'lightboxBody';
		lbBody.style.width = (width-0)+'px';
		lbContainer.appendChild(lbBody);
		lbBody.style.height = (height!=undefined ? height : Math.round(getWinHeight()*.83)-topMargin)+'px';
		lbBody.style.width= '100%';
		lbBody.frameBorder=0;
		if(topMargin+Top(lbContainer)+lbContainer.offsetHeight > getWinHeight()) {
			lbBody.style.height = Math.floor(getWinHeight()-topMargin-5)+'px';		// adjust if larger than 70% of screen
		}
		lbContainer.style.height = lbBody.offsetHeight+3+'px';
		lbContainer.style.overflowY='hidden';
	} else {											// load from a url
		var html = load(src);
		var lbBody = document.createElement('div');
		lbBody.innerHTML = html;
		lbBody.className = 'lightboxBody';
		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;
		}
	}
	lbContainer.style.top = Math.ceil((getWinHeight()-topMargin)/2-(lbContainer.offsetHeight/2)+topMargin)+'px';

	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';
	}
	lbContainer.style.left = (parseInt(getWinWidth()/2)-(width?width:lbContainer.offsetWidth)/2)+'px';

	/* create close button */
	_lightboxObj.closeButton = document.createElement('div');
	_lightboxObj.closeButton.innerHTML = '<p>close</p> &times;';
	_lightboxObj.closeButton.className = 'lightboxButton';
	_lightboxObj.appendChild(_lightboxObj.closeButton);
	//_lightboxObj.closeButton.style.top = ((getWinHeight()-topMargin)/2-(lbContainer.offsetHeight?lbContainer.offsetHeight:height)/2)-20+topMargin+'px';
	_lightboxObj.closeButton.style.top = Top(lbContainer)-getScrollHeight()+'px';
	_lightboxObj.closeButton.style.left = Left(lbContainer)+lbContainer.offsetWidth-_lightboxObj.closeButton.offsetWidth-closeButtonLeftOffset-10+'px';
	_lightboxObj.closeButton.onclick=function() { 
		if(this.parentNode && (this.parentNode!=undefined) && this.parentNode.parentNode) 
			this.parentNode.parentNode.removeChild(this.parentNode); _lightboxObj=false; 
		// re-enable scroll
		if(!isIE || (getIEVersion()>6)) {
			//document.body.scroll = "yes";
			//document.body.style.overflow='auto'
		}
	};
	if(type=='img') _lightboxObj.closeButton.style.visible = 'hidden';

	bg.closeButton = _lightboxObj.closeButton;

	fade_in(lbContainer);
	fade_in(_lightboxObj);

	if(type!='img') {
		_lightboxObj.drop = setupDrop(lbContainer);
		_lightboxObj.drop.style.top = lbContainer.style.top;
	}

	// disable scroll
	if(!isIE || (getIEVersion()>6)) {
		//document.body.scroll = "no";
		//document.body.style.overflow='hidden'
	}
}

function showMsg(msg, stayOpen) {
	var dv = document.createElement('div');
	dv.innerHTML = msg;
	dv.className = 'msg';
	lightbox(dv, 400, 'obj');
	if(stayOpen && (stayOpen!=undefined))
		setTimeout('if(_lightboxObj)	fade_out(_lightboxObj, true)', 1500);
}

_dropshadow = false;
_dropshadowLeft = 18;
_dropshadowRight = 24;
_dropshadowTop = 17;
_dropshadowBottom = 25;
function setupDrop(targ, noTop) {
	if(noTop==undefined)	noTop = false;
	if(_dropshadow || _dropshadow==undefined)	remove(_dropshadow);
	_dropshadow = document.createElement('div');
	_dropshadow.id="_dropshadow";

	if(noTop)	_dropshadow.className = 'noTop';

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

	targ.parentNode.insertBefore(_dropshadow, targ);

	//table.innerHTML = (!noTop)  ? '<tr><td id="TL"></td><td id="TR"></td></tr><tr><td id="BL"></td><td id="BR"></td></tr>' : '<tr><td id="BL"></td><td id="BR"></td></tr>';
	_dropshadow.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) _dropshadow.style.marginTop = '-'+_dropshadowTop+'px';
	//targ.parentNode.insertBefore(_dropshadow, targ);

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

	return _dropshadow;
}

var _dropdownHolder = false;
var _dropdownAnchor = false;
function showDropdown(anchor, options) {
	if(!anchor || (anchor==undefined)) {								// just remove
		fade_out(_dropdownHolder,true);
		//if(_dropshadow) fade_out(_dropshadow,true);
		if(_dropshadow) remove(_dropshadow);
		return;
	}
	if(_dropdownHolder)
		remove(_dropdownHolder);								// remove any open drops

	_dropdownAnchor = anchor;
	_dropdownHolder = document.createElement('div');
	_dropdownHolder.className = 'dropdown';
	for(var x in options) {
		var opt = document.createElement('li');
		_dropdownHolder.appendChild(opt);
		opt.innerHTML = x;
		opt.alt = options[x];
		opt.onclick = function() { showDropdown(); eval(this.alt); };
	}
	_dropdownHolder.style.left = Left(anchor)+'px';
	_dropdownHolder.style.top = Top(anchor)+anchor.offsetHeight+'px';
	document.body.appendChild(_dropdownHolder);

	anchor.onmouseout = function() { setTimeout('if(!isOver(_dropdownHolder) && !isOver(_dropdownHolder)) showDropdown();',100); }
	_dropdownHolder.onmouseout = anchor.onmouseout;

	setupDrop(_dropdownHolder, true);
	_dropshadow.style.top = Top(_dropdownHolder)+'px';
}


var _loading;
function setLoad(dv, isLoading) {
	if(_loading) {
		_loading.parentNode.removeChild(_loading);	// remove old
		_loading=false;
	}
	if(isLoading) {
		_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 showLoad(dv) {	return setLoad(dv); }			// alias for setLoad function

/* misc */
function setCSS(fileTitle, selector, prop, val) {
	var rulesVar = document.styleSheets[0].cssRules ? 'cssRules' : 'rules';
	var file = false;
	var styleSheets = document.styleSheets;
	var x,y,z;
	for(file in styleSheets) {
		if(styleSheets[file].title==fileTitle) {	// found file
			var rules = styleSheets[file][rulesVar];
			for(x in rules) {
				if(rules[x].selectorText == selector) {
					rules[x].style[prop] = val;
					return;
				}
			}
		}
	}
}
function loadCSS(file) {
	var headID = document.getElementsByTagName("head")[0];         
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = '/css/'+file;
	cssNode.media = 'screen';
	headID.appendChild(cssNode);
	return cssNode;
}

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 = objWidth / rentWidth;
	var proportion =  rentWidth / objWidth;
	var proposedHeight = proportion * objHeight;

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

	//alert(Math.floor(objWidth * proportion)+' , '+Math.floor(objHeight * proportion));
	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';
}

var _curThumb = false;
var _curClick = false;
function setType(obj,thumb, type,table,link,mediaArea,addlClass) {
	/** /
	var overlayHolder = document.createElement('div');
	if(thumb) {
		var overlay = document.createElement('div');

		overlay.className = 'overlay '+type.toLowerCase()+(addlClass? ' '+addlClass:'');	// class for overlay
		overlay.style.width = obj.offsetWidth+'px';						// dimension
		overlay.style.height = obj.offsetHeight+'px';
		overlay.style.height = obj.parentNode.offsetHeight+'px';
		overlay.style.marginLeft = Left(obj)-Left(obj.parentNode)+'px';
		//overlay.style.position = 'absolute';
	}
	/**/
	// setup click actions
	switch(type.toLowerCase()) {
		case 'flv':
		case 'video':
			obj.onclick = function() {
				var w = mediaArea.offsetWidth;
				var h = mediaArea.offsetHeight;

				while(mediaArea.firstChild)	remove(mediaArea.firstChild);	// remove old content
				var caption = document.createElement('span');
				caption.innerHTML = '<h2>'+((thumb.alt!=undefined) ? unescape(thumb.alt):'')+'</h2>'+((thumb.title!=undefined) ? unescape(thumb.title):'');
				var media = document.createElement('div');
				mediaArea.appendChild(caption);
				media.innerHTML = generateEmbedCode('flv',link, w,h-caption.offsetHeight,1,true);
				mediaArea.insertBefore(media, caption);
				mediaArea.onclick=function() { ; };

				_curThumb = thumb.src;
			};
			break;
		case 'img':
		case 'image':
			obj.onclick = function() {      
				lightbox((link ? link : thumb.src).replace('.t.','.').replace('.m.','.').replace('.jpg','.z.jpg'));     
			};
			break;
		case 'audio':
			obj.onclick = function() {	
				var media = document.createElement('div');
				media.innerHTML = generateEmbedCode('swf','/images/swf/audioPlayer.single.swf?autoplay=1&i='+obj.id, 250, 150, true,true);
				lightbox(media, 300, 'obj');
			};
			break;
		case 'article':
			obj.onclick = function() {	
				if(_curThumb) {
					if(mediaArea.fistChild) 
						mediaArea.firstChild.innerHTML = '<img style="width:'+mediaArea.firstChild.offsetWidth+'px"src="'+_curThumb.replace('.t.', '.'+mediaArea.offsetWidth+'.')+'" />';
					else if(mediaArea && mediaArea.innerHTML)
						mediaArea.innerHTML = '<img style="width:'+mediaArea.firstChild.offsetWidth+'px" src="'+_curThumb.replace('.t.', '.'+mediaArea.offsetWidth+'.')+'" />';
				}
				show(obj.id, table);	

				_curThumb = thumb.src;
			};
			break;
		case 'event':
			obj.onclick = function() {
				showEventDetails(obj.id);
			}
			break;
	}
	/** /
	thumb.overlay = overlay;			// set overlay to be accessed later
	overlay.onclick = obj.onclick;			// transfer click
	/**/
	//thumb.parentNode.insertBefore(overlay, obj);	// insert overlay
}

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;
}

var popinContainer=false;
function Popin(obj, width) {
	if(popinContainer && popinContainer!=undefined)	{
		popinContainer.parentNode.removeChild(popinContainer);
		popinContainer = false;
	}

	var scrollTop = isNaN(window.pageYOffset) ? document.body.scrollTop : window.pageYOffset;
	var scrollLeft = isNaN(window.pageXOffset) ? document.body.scrollLeft : window.pageXOffset;

	if(!obj)	return;
	popinContainer = document.createElement('div');
	document.body.appendChild(popinContainer);

	/* create background */
	var popinBG = document.createElement('div');
	popinBG.className = 'lightboxBG';
	popinBG.style.position = 'absolute';
	popinBG.style.top = scrollTop+'px';
	popinBG.style.left = '0px';
	popinBG.style.width='100%';
	popinBG.style.height=getFullWinHeight()+'px';
	popinContainer.appendChild(popinBG);
	popinBG.onclick = function() {	popinContainer.parentNode.removeChild(popinContainer); popinContainer=false; };

	/* create popin container */
	var popin = document.createElement('div');
	popin.className='lightbox blackbox';
	popin.appendChild(obj);
	popin.style.position = 'absolute';
	popinContainer.appendChild(popin);
	popinContainer.pop=popin;

	popin.className = 'popinContainer';
	if(width && (width!=undefined)) popin.style.width = width+'px';
	popin.style.left = (parseInt(getWinWidth()/2)-popin.offsetWidth/2)+'px';
	popin.style.top = (scrollTop+145)+'px';

	return popinContainer;
}


function expandImage(targ,w,h,center, otherStep, speed, running) {
	if(speed == undefined)	speed = fx_config['images']['zoom']['step'];
	if(running == undefined)running = 0;
	if(center == undefined)	center = false;
	if(!targ) return;
	if(fx_config['images']['zoom']['tween']) {
		if(fx_config['images']['constraint']['constrainBy'] == 'w')
			speed = (targ.offsetWidth<fx_config['images']['zoom']['tween'] && speed>2) ? speed/.4 : speed;
		else	speed = (targ.offsetHeight<fx_config['images']['zoom']['tween'] && speed>2) ? speed/.4 : speed;
	}
	if((fx_config['images']['constraint']['constrainBy'] == 'w') && (targ.offsetWidth+speed > w)
	    ||(fx_config['images']['constraint']['constrainBy'] == 'h') && (targ.offsetHeight+speed > h)
	    ||((running++) > fx_config['images']['zoom']['runout'])) {
		targ.style.offsetWidth = w;
		targ.style.offsetHeight = h;
	} else {
		if(fx_config['images']['constraint']['constrainBy'] == 'w') {
			if(!otherStep || otherStep == undefined) {
				var ratio = targ.offsetWidth / targ.offsetHeight;
				otherStep = speed/ratio;
			}
			targ.style.width  = targ.offsetWidth+speed+'px';
			targ.style.height  = targ.offsetHeight+otherStep+'px';
		} else {
			targ.style.height = targ.offsetHeight+speed+'px';
		}
		setTimeout('expandImage($(\''+targ.id+'\'), '+w+','+h+', '+center+','+otherStep+','+speed+','+running+');', fx_config['images']['zoom']['speed']);
	}
}
function generateEmbedCode(type,src,w,h, autostart, transparent) {
	var code = '';
	var rand = Math.random(0,100000);
	//src = 'http://girls.boss32.com'+src;
	src = ''+src;
	autostart = (!autostart || (autostart==undefined)) ? 0 : 1;
	transparent = (!transparent || (transparent==undefined)) ? 0 : 1;
	if(w==undefined) w='425';
	if(h==undefined) h='240';
	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 class="flv" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" width="'+w+'" height="'+h+'" id="videoViewer" align="middle">'+
				'<param name="allowScriptAccess" value="sameDomain" />'+
				'<param name="vSrc"="'+src+'" />'+
				'<param name="FlashVars" value="vSrc='+src+'" />'+
				'<param name="allowFullScreen" value="true" />'+
				'<param name="movie" value="/images/swf/videoPlayer.swf?autostart='+autostart+'&vSrc='+src+'&transparent='+transparent+'&'+rand+'" /><param name="quality" value="high" /><embed src="/images/swf/videoPlayer.swf?autostart='+autostart+'&vSrc='+src+'" &transparent='+transparent+'&'+rand+'" FlashVars="autostart='+autostart+'&vSrc='+src+'" allowFullScreen="true" quality="high" mode="transparent" width="'+w+'" height="'+h+'" name="videoViewer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
			'</object>';
			break;
		case 'swf':
			var paramStr = '';
			if(src.indexOf('?')) {
				var paramAry = src.substring(src.indexOf('?')+1).split('&');
				for(var x in paramAry) {
					var tmp = paramAry[x].split('=');
					paramStr += '<param name="'+tmp[0]+'" value="'+escape(tmp[1])+'">';
				}
			}
			code = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" width="'+w+'" height="'+h+'" id="videoViewer" align="middle">'+
				'<param name="allowScriptAccess" value="sameDomain" />'+
				paramStr+
				'<param name="wmode" value="transparent" />'+
				'<param name="allowFullScreen" value="true" />'+
				'<param name="movie" value="'+src+'" /><param name="quality" value="high" /><embed src="'+src+'" allowFullScreen="true" quality="high" wmode="transparent" width="'+w+'" height="'+h+'" name="videoViewer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
			'</object>';
			break;
	}
	return code;
}

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','') : '';
	active.className = active.className + ' active';
}
function highlightColumn(tbody, num, highClass) {
	if(highClass==undefined)	highClass='high';
	removeBlankChildren(tbody);
	for(var rowIndex=0; rowIndex<tbody.childNodes.length; rowIndex++) {
		var row = tbody.childNodes[rowIndex];
		removeBlankChildren(row);
		for(var colIndex=0; colIndex<row.childNodes.length; colIndex++) {
			if(row.childNodes[colIndex].className)
				row.childNodes[colIndex].className = row.childNodes[colIndex].className.replace(highClass,'')+' '+((colIndex==num)?highClass:'');
			else	row.childNodes[colIndex].className = (colIndex==num)?highClass:'';
		}
	}
}
function removeColumn(tbody, num) {
	removeBlankChildren(tbody);
	for(var rowIndex=0; rowIndex<tbody.childNodes.length; rowIndex++) {
		var row = tbody.childNodes[rowIndex];
		removeBlankChildren(row);
		row.removeChild(row.childNodes[num-1]);
	}
}
/* 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);
	}
}
/**/

/* map functions */
if(window.GIcon) {
	var iconSize = new GSize(12,20);

	var defaultIcon = new GIcon(G_DEFAULT_ICON);
	defaultIcon.iconSize = iconSize;

	var onlineIcon = new GIcon(defaultIcon, 'http://beartopia.com/images/ui/marker_online.png');
	onlineIcon.iconSize=iconSize;

	var offlineIcon = new GIcon(defaultIcon, 'http://beartopia.com/images/ui/marker_offline.png');
	var iconSize = new GSize(20,34);
	offlineIcon.iconSize=iconSize;
}

function plotAddress(map_obj, address, html, status, mapType, panning, point) {
	if (GBrowserIsCompatible()) {
		if(!map_obj.canvas)	map_obj.canvas = new GMap2(map_obj);

		geocoder = new GClientGeocoder();
		if(mapType==undefined) mapType=G_NORMAL_MAP;
		if(!point || point==undefined) {
			address = replace(replace(replace(unescape(address).toLowerCase(),'<br>',', '),'<br />',', '),' <br/>',', ');
			var bounds = geocoder.getLatLng(address,function(point) { 
					if(point) {
							//map_obj.canvas.setZoom(13);
							map_obj.canvas.addControl(new GSmallMapControl());
							plotPoint(map_obj.canvas, point,address,html, status,false,panning);
							//map_obj.canvas.setMapType(mapType);
						}
					} );
						map_obj.canvas.addControl(new GSmallMapControl());
						plotPoint(map_obj.canvas, point,address,html, status,false,panning);
		} else {
			map_obj.canvas.addControl(new GSmallMapControl());
			plotPoint(map_obj.canvas, point,address,html, status,false,panning);
		}
	}
	//return 
}
var lastPoint = false;
function plotAddresses(map_obj, ary, x, geocoder, holderTag,  latLong, recurse) {
	if(!map_obj.canvas)	map_obj.canvas = new GMap2(map_obj);
	if(geocoder==undefined) geocoder = new GClientGeocoder();
	var map = map_obj.canvas;

	var holder = false;
	if(!recurse && (holderTag != undefined)) {
		holder = mapMarkerHolders[holderTag];

		// clear old results
		var k;
		if(holder)for(k in holder) {
			map_obj.canvas.clearOverlays(holder[k]);
		}
		mapMarkerHolders[holderTag] = new Array();
		mapMarkerHTML[holderTag] = new Array();
		usedMarkers = new Array();
	}
	
	if(!x || x==undefined)	x = 0;
	if(!ary[x]) {
		return;
	}
	var tmp = ary[x].split('|');
	var address = tmp[0];
	var status = tmp[1];
	var html = tmp[2];
	var markerID = tmp[3];

	if(!markerID)	markerID = x;
	if((latLong!=undefined) && (latLong!=undefined)) {
		var latLongAry = address.split(',');
		if(latLongAry[0]*1 && latLongAry[1]*1) {
			var point = new GLatLng(latLongAry[0],latLongAry[1]);
			plotPoint(map_obj.canvas, point,markerID,html, status, holderTag);
			//map_obj.canvas.addControl(new GSmallMapControl());
			lastPoint = point;
		}
		if(ary[x++]) plotAddresses(map_obj, ary,x, geocoder, holderTag, latLong, true);
	}
}

function clearMap(map_obj) {
	var x,k;
	usedMarkers = Array();
	for(x in mapMarkers) 
		map_obj.canvas.clearOverlays(mapMarkerHolders[x]);
}
var usedMarkers = new Array();
var usedMarkersHTML = new Array();
var mapMarkerHolders = new Array();
var mapMarkerHTML = new Array();
var mapMarkers = new Array();
function plotPoint(map, point,id, html, status, holderTag, panning) {
	if(point) {
		/**/
		while(usedMarkers[point]) { 	// marker already placd in this spot
			var tmp = point;
			point = new GLatLng(parseFloat(point.y)+.0007, parseFloat(point.x)+.0007);
		}
		/**/
		usedMarkers[point] = true;
		mapMarkers[id] = new GMarker(point,(status==1) ? onlineIcon : offlineIcon);
		if(holderTag) {
			mapMarkerHolders[holderTag][id] = mapMarkers[id];
			mapMarkerHTML[holderTag][id] = html;
			//mapMarkerHolders[holderTag][mapMarkerHolders[holderTag].length] = mapMarkers[id];
		}
		mapMarkers[id].html = html;

		if(!map.isLoaded()) {
			map.setCenter(point, 7);
		} else if(panning) {
			map.panTo(point);
		}
		map.addOverlay(mapMarkers[id]);
		if(html) GEvent.addListener(mapMarkers[id], "click", function(){  this.openInfoWindow(this.html, {pixelOffset:new GSize(2,5), maxWidth: 100});}  );
	}
}
/* end map functions */

/* video generator functions */
var maxVideoW = 960;
var videoRatio = 320/240;
var videoRatio = 475/350;
//var videoRatio = 320/180;
function setupVideoPlayer(initialSrc, holderObj, autostart, w, h, rent, keywords) {
	if(!autostart || (autostart==undefined))	autostart = true;
	if(!w || (w==undefined) || !h || (h==undefined)) {	// set to max width
		if(!w || (w==undefined)) 
			w = (getWinWidth() > maxVideoW) ? maxVideoW : getWinWidth();
		h = w / videoRatio;
		if(h > getWinHeight()*.8) {	// greater than win height, set to max height
			h = getWinHeight()*.8;
			w = h * videoRatio;
		}
	}

	var mainDV = document.createElement('div');
	mainDV.style.overflow='hidden';
	mainDV.style.height=h+'px';
	mainDV.innerHTML = generateEmbedCode('flv', initialSrc, w, h, autostart);

	var previewsDV = document.createElement('div');
	previewsDV.className = 'videoPreviewHolder lightboxVideoPreviews';
	mainDV.appendChild(previewsDV);
	previewsDV.innerHTML = holderObj.innerHTML.replace('more videos...','');

	lightbox(mainDV, w+40, 'obj', 'blackbox', h+50);
}
/* end video generator functions */

/* setup preview over video / images */
function initPreview(icon, type) {
	switch(type) {
		case 'video':
			/*
			icon.preview = document.createElement('div');
			icon.preview.className = 'previewOverlay';
			icon.preview.style.top = Top(icon)+'px';
			icon.preview.style.left = Left(icon)+'px';
			icon.preview.style.width = icon.offsetWidth+'px';	// leave room for border
			icon.preview.style.height = icon.offsetHeight+'px';
			icon.preview.icon = icon;

			if(!icon.onclick) icon.onclick = function() { document.location.href=this.parentNode.href;	};
			icon.preview.onclick = function() { this.icon.onclick(); 	};
			icon.preview.onmouseout = function() { this.icon.onmouseout(); 	};
			icon.onmouseover = function() { this.preview.onmouseover(); 	};
			icon.onmouseout = function() { this.preview.onmouseout(); 	};
			icon.preview.onmouseover = function() { this.className = this.className.replace('over','')+' over';		
								this.style.top = Top(this.icon)+'px';
								this.style.left = Left(this.icon)+'px';
								this.style.height = this.icon.offsetHeight+'px';
								this.style.width = this.icon.offsetWidth+'px';
			};
			icon.preview.onmouseout = function() { this.className = this.className.replace('over','');			};
			document.body.appendChild(icon.preview);
			//debug(icon.preview);
			*/
			break;
		case 'image':
			break;
	}
}
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;
}
