<!--
// constants used to determine lightbox settings
// minimum width of viewable div area
var lb_min_width = 820;//760;
// minimum height of viewable div area
var lb_min_height = 600;//540;
// amount of padding around thread box
var lb_padding = 5;
// lightbox html id
var lb_html_id = 'lightbox_stage';
// duration of fade interval
var fadeUpdateInterval = setInterval(fadeUpdate, 20);
var elementsToFade = new Array();
// duration to wait before container starts
var fadeEmbedInterval;
// object id that contains the children nodes
var lb_parent_node = null;
// disable lighbox when close detected
var lb_close_window = false;
// property for actual VoiceThread
//var lb_thread_width = 570;
//var lb_thread_height = 400;
var lb_thread_width = 800;//700;
var lb_thread_height = 600;//500;
// detect for IE (we like it no more than you do)
var _isIE = (navigator.appName == "Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera") < 0) ? true : false;


// construct lightbox 
// expects thread id and reference object
function lightBox(id, obj_id, doc_text, embed_type, width, height) {
	obj = lb_getElement(obj_id);
	if (!obj) {
		return(false);
  }
	// default to using VT embed code
	if (embed_type == 'mov') embed_type = 'quicktime';
	else if (embed_type == 'img') embed_type = 'image';
	else embed_type = 'flash';
	// setup default width for no voicethread content
	if (width == null) {
		width = lb_thread_width;
		height = lb_thread_height;
	}
	// make sure lightbox is not already on stage
	if (lb_getElement(lb_html_id) != null)
		return (false);
	// calculate and construct lightbox for display
	lb_stage = constructStage(doc_text);
	if (!lb_stage)
		return(false);
	// now create the thread
	lb_thread = constructThread(id, embed_type, width, height);
	if (!lb_thread)
		return(false);
	lb_thread.style.display = 'none';
	// attach the thread to the stage
	lb_stage.appendChild(lb_thread);
	// attach the stage to the current object
	obj.appendChild(lb_stage);
	// fade in the element
	fadeElement(lb_stage, 0);
	// set the object of the lightbox
	lb_parent_node = obj;
}

// calculate and create dom properties for lightbox
function constructStage(doc_text) {
	// determine the clients current width & height
	client_width = parent.document.body.clientWidth;
	client_height = parent.document.body.clientHeight;
	// if properties are less than minimum values then use min values
	if (client_width < lb_min_width) client_width = lb_min_width;
	if (client_height < lb_min_height) client_height = lb_min_height;
	// calculate the middle of screen on x-axis
	client_center_x = parseFloat(client_width/2);
	// caulculate the middle of the screen on y-axis
	client_center_y = parseFloat(client_height/2);
	// calculate the x-axis offset for div position
	client_pos_x_coord = parseInt(client_center_x - (lb_min_width/2));
	// calculate the y-axis offset for div position
	client_pos_y_coord = ((client_height - lb_min_height)/2);
	// adjust the y-axis in case it is too close to the margin
  if (client_pos_y_coord < lb_padding) client_pos_y_coord = lb_padding;
	// create the stage div to display content
	lb_stage = parent.document.createElement('div');
	// attach the stage id to this element
	lb_stage.setAttribute('id',lb_html_id);
	// do not process if element not created
	if (lb_stage == null)
		return(false);
	// set the style properties for the div
	lb_stage.style.width = lb_min_width;
	lb_stage.style.height = lb_min_height;
	// center the lightbox in the middle of the screen
	lb_stage.style.left = client_pos_x_coord;
	lb_stage.style.top = client_pos_y_coord;
	lb_stage.style.zIndex = '1000';
	// create a div for the close button
	close_code = '<div id="lightbox_embed" >'+
		'<a href="#" onClick="closeLB();" onmouseover="updateImgLB();" '+
		'onmouseout="updateImgLB();">'+
		'<img src="/image/lb_close_off.gif" title="Click to close." '+
		'id="lightbox_close_button" /></a></div>'+
		'<p>'+doc_text+'</p>';
	lb_stage.innerHTML = close_code;
	// return the new object
	return(lb_stage);
}

// construct the embed code for the thread
function constructThread(id, embed_type, width, height) {
	// create a div container for the thread box
	lb_thread_div = parent.document.createElement('div');
	if (!lb_thread_div)
		return(false);
	lb_thread_div.setAttribute('id','lb_embed_code');
	lb_thread_div.style.textAlign = 'center';	
	lb_thread_ob = parent.document.createElement('object');
	// make sure object created
	if (!lb_thread_ob)
		return(false);
	// have appropriate plugin
	// embed code for voicethread embed
	plugin = new Array();
	failLoad = false;
	// create an area to test plugin
	// detect if plugin exists
	hasPlugin = detectPlugin(embed_type);
	
	if (!hasPlugin) {
		vt_embed_code = 'You do not have the '+embed_type+' plug-in installed or you have JavaScript disabled. '+
		'Please correct this error and try again.';
	}
	else if (embed_type == 'quicktime') {
		vt_embed_code = '<embed src="'+id+'" '+
		'type="video/quicktime" autoplay="true"'+
		'width="'+width+'" height="'+height+'" cache="true" style="background:transparent"><\/embed>';	
	}
	else if (embed_type == 'image') {
		vt_embed_code = '<img src="'+id+'" style="width:'+width+'px; height: '+height+'px;" />';	
	}
	else if (embed_type == 'flash') {
		vt_embed_code = '<embed src="/book.swf?b='+id+'&autoplay=1" '+
		'type="application/x-shockwave-flash" wmode="transparent" '+
		'width="'+width+'" height="'+height+'"><\/embed>';
	}
	else
		vt_embed_code = 'We could not load the content. We apologize for the inconvenience.';
		'width="'+width+'" height="'+height+'"><\/embed>';
										
	// setup properties for embedded thread
	
	lb_thread_div.innerHTML = vt_embed_code;
	// return the thread
	return(lb_thread_div);
}

// update the lightbox image
function updateImgLB() {
	// make sure that image reference exists
	lb_img = lb_getElement('lightbox_close_button');
	if (!lb_img)
		return(false);
	// update the image to correct state
	if (lb_img.getAttribute('src').indexOf('lb_close_off.gif') != -1)
		lb_img.setAttribute('src','/image/lb_close_on.gif');
	else
		lb_img.setAttribute('src','/image/lb_close_off.gif');
}

// close the lightbox
function closeLB() {
	lb_close_window = true;
	// attempt to load default anchor node in case parent_node is overwritten
	lb_default_node = lb_getElement('lbDiv');
	if ((!lb_parent_node) && (!lb_default_node))
		return(false);
	else if ((!lb_parent_node) && (lb_default_node))
		lb_parent_node = lb_default_node;
	else
		lb_parent_node = lb_parent_node;
	//lb_parent_node.removeChild(lb_getElement(lb_html_id));
	content_node = lb_getElement(lb_html_id);
	// recursively remove all of the children elements
	removeChildrenRecursive(lb_getElement(lb_html_id));
	// now remove the lightbox element
	lb_parent_node.removeChild(lb_getElement(lb_html_id));
}

// detects if plugin is installed on system
function detectPlugin(ref) {
	ieTest = mozTest = null;
	if (ref == 'quicktime') {
		ieTest = 'QuickTimeCheckObject.QuickTimeCheck.1';
		mozTest = 'QuickTime';
	} else if (ref == 'flash') {
		ieTest = 'ShockwaveFlash.ShockwaveFlash.1';
		mozTest = 'Shockwave Flash';
	} else if (ref == 'image') {
		return(true);
	}
	
	if (_isIE) {
		return(true);
	}
	else if (navigator.plugins) {
		for (i=0; i < navigator.plugins.length; i++ ) {
			if (navigator.plugins[i].name.toLowerCase().indexOf(ref) >= 0)
				return(true);
		}
		return(false);
	}
	return(false);
}

// return a reference to an object
function lb_getElement(elm) {
	return(parent.document.getElementById(elm));
}

function showEmbedElement() {
	// first get the element in question
	embed_code = lb_getElement('lb_embed_code');
	if (!embed_code)
		return(false);
	embed_code.style.display = 'block';
}

function fadeUpdate() {
  var opacity;
  var newElements = new Array();
  for (var i = 0; i < elementsToFade.length; i++) {
    opacity = getOpacity(elementsToFade[i]);
    opacity = Math.max(0, opacity + 5);
    setOpacity(elementsToFade[i], opacity);
    elementsToFade[i].style.visibility = (opacity > 0) ? "visible" : "hidden";
    if (opacity < 100) newElements.push(elementsToFade[i]);
    else showEmbedElement();
  }
  elementsToFade = newElements;
}

function setOpacity(element, opacity) {
  element.style.opacity = (opacity / 100);
  element.style.filter = "alpha(opacity="+opacity+")";
}
function getOpacity(element) {
  var opacity = 100;
  if (element.style.opacity) {
    opacity = Math.round(parseFloat(element.style.opacity) * 100);
  }
  else if (element.style.filter) {
    var opacityFilter = element.style.filter.match(/opacity=\d+/ig);
    if (opacityFilter.length > 0)
      opacity = parseInt(opacityFilter[0].match(/\d+/));
  }
  return(opacity);
}

function fadeElement(element, initialOpacity) {
  if (! element) return;
  // set an initial opacity for the element if specified
  if (initialOpacity != undefined) setOpacity(element, initialOpacity);
  // add the element to the list of fading elements if it isn't already there
  for (var i = 0; i < elementsToFade.length; i++) {
    if (elementsToFade[i] == element) return;
  }
  elementsToFade.push(element);
}

function removeChildrenRecursive(node) {
	if (!node)
		return(false);
	while(node.hasChildNodes()) {
		removeChildrenRecursive(node.firstChild);
		node.removeChild(node.firstChild);
	}
}
-->