function launchLB(htmlStr, picture_id, images_server, root_server, showClose,additional_params){

   htmlStr = (typeof(htmlStr) != 'undefined' ? htmlStr : '');

	hideSelectBoxes();
	hideFlash();
	
	var arrayPageSize = getPageSize();
		
	//create wrapper
	var wrap = document.createElement('div');
	wrap.id = 'lb_overlay';
	wrap.setAttribute('id','lb_overlay');	
	mainwrapper = document.getElementById('wrapper');
	document.body.insertBefore(wrap,mainwrapper);
	wrap.style.width = arrayPageSize[0]+"px";
	wrap.style.height = arrayPageSize[1]+"px";
		
	//create div to hold everything
	var lbwrapper = document.createElement('div');
	lbwrapper.setAttribute('id','lb_wrapper');
	wrap.appendChild(lbwrapper);
	
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 10);
	currentWidth = 825;
	lbwrapper.style.width = currentWidth + "px";
	lbwrapper.style.top=lightboxTop+"px";
		
	//create close button
	if(showClose!=false){
		var closebtn = document.createElement('div');
		closebtn.setAttribute('id','lb_close');
		closebtn.innerHTML = "<a href='javascript:void(0)' onclick='closeLB();'>Close</a>";
		lbwrapper.appendChild(closebtn);
	}

		//create HTML area if required
      if(htmlStr != ""){
		   var htmlArea = document.createElement('div');
   		htmlArea.setAttribute('id','lb_conf');
         htmlArea.innerHTML = htmlStr;
   		lbwrapper.appendChild(htmlArea);
      }
		
		//create flash object for swf viewer if required
      if(picture_id != ""){
			window.onresize = resizePicViewer;
			window.onscroll =  resizePicViewer;
			resizePicViewer();
			var lbviewer = document.createElement('div');
			lbviewer.setAttribute('id','lb_flashcontent');
			lbwrapper.appendChild(lbviewer);
			lbviewer.innerHTML = "<div id=\"no_flash\"><span>Notice: </span>You either have JavaScript turned off or an old version of Macromedia's Flash Player. <a href=\"http://www.macromedia.com/go/getflashplayer/\">Get the latest Flash player.</a></div>";
			var so = new SWFObject(images_server+"/flash/picture_viewer.swf?default_picture_id="+picture_id+"&root_server="+root_server+"&pictures="+pictures+additional_params, "lb", "825", "483", "9", "#000000");
			so.useExpressInstall(images_server+'/flash/expressinstall.swf');
			so.addParam("quality", "BEST");	
			so.addParam("allowScriptAccess", "always");
			so.write("lb_flashcontent");
      }
		
}

function resizePicViewer(){
		var arrayPageScroll = getPageScroll();
		var arrayPageSize = getPageSize();
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3]-483) / 2)-50;
		document.getElementById('lb_overlay').style.height = arrayPageSize[1]+"px";
		document.getElementById('lb_wrapper').style.top=lightboxTop+"px";
}

function resizeVidViewer(){
		var arrayPageScroll = getPageScroll();
		var arrayPageSize = getPageSize();
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3]-currentHeight) / 2)-50;
		document.getElementById('lb_overlay').style.height = arrayPageSize[1]+"px";
		document.getElementById('lb_video_wrapper').style.top=lightboxTop+"px";
}

currentHeight=0;

function launchVideoLB(video_id, images_server, root_server, showClose){

	hideSelectBoxes();
	hideFlash();
	
	var arrayPageSize = getPageSize();
		
	//create wrapper
	var wrap = document.createElement('div');
	wrap.id = 'lb_overlay';
	wrap.setAttribute('id','lb_overlay');	
	mainwrapper = document.getElementById('wrapper');
	document.body.insertBefore(wrap,mainwrapper);
	wrap.style.width = arrayPageSize[0]+"px";
	wrap.style.height = arrayPageSize[1]+"px";
		
	//create div to hold everything
	var lbwrapper = document.createElement('div');
	lbwrapper.setAttribute('id','lb_video_wrapper');
	wrap.appendChild(lbwrapper);
	
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 13);
	lbwrapper.style.top=lightboxTop+"px";
	currentWidth = 700;
	lbwrapper.style.width = currentWidth + "px";
	//keep height at 4:3 aspect
	currentHeight = (currentWidth/(4/3));
	lbwrapper.style.height = currentHeight+"px";
		
	//create close button
	if(showClose!=false){
		var closebtn = document.createElement('div');
		closebtn.setAttribute('id','lb_close');
		closebtn.innerHTML = "<a href='javascript:void(0)' onclick='closeLB();'>Close</a>";
		lbwrapper.appendChild(closebtn);
	}
		
		//create flash object for swf viewer
      if(video_id != ""){
			window.onresize = resizeVidViewer;
			window.onscroll =  resizeVidViewer;
			resizeVidViewer();
			var lbviewer = document.createElement('div');
			lbviewer.setAttribute('id','lb_video_flashcontent');
			lbwrapper.appendChild(lbviewer);
			lbviewer.innerHTML = "<div id=\"no_flash\"><span>Notice: </span>You either have JavaScript turned off or an old version of Macromedia's Flash Player. <a href=\"http://www.macromedia.com/go/getflashplayer/\">Get the latest Flash player.</a></div>";
			var so = new SWFObject(images_server+"/flash/rwplayer.swf?video_id="+video_id+"&site="+root_server, "lb", "100%", "100%", "9", "#000000");
			so.addParam("allowFullscreen", "true");
			so.addParam("allowScriptAccess", "always");
			so.useExpressInstall(images_server+'/flash/expressinstall.swf');
			so.addVariable("lightbox", "true");
			so.write("lb_video_flashcontent");
      }
		
}

function closeLB(){

	var wrap = document.getElementById('lb_overlay');
	window.onresize = null;
	window.onscroll =  null;
	document.body.removeChild(wrap);
	showFlash();
	showSelectBoxes();
	
}


function showSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

function showFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "visible";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideFlash(){
	var flashObjects = document.getElementsByTagName("object");
	for (i = 0; i < flashObjects.length; i++) {
		flashObjects[i].style.visibility = "hidden";
	}

	var flashEmbeds = document.getElementsByTagName("embed");
	for (i = 0; i < flashEmbeds.length; i++) {
		flashEmbeds[i].style.visibility = "hidden";
	}

}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(windowWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

function launchLBFlipbook(){
	
	self.moveTo(0,0);
	self.resizeTo(screen.availWidth,screen.availHeight);

	hideSelectBoxes();
	hideFlash();
	
	var arrayPageSize = getPageSize();
		
	//create wrapper
	var wrap = document.createElement('div');
	wrap.id = 'lb_overlay';
	wrap.setAttribute('id','lb_overlay');	
	mainwrapper = document.getElementById('wrapper');
	document.body.insertBefore(wrap,mainwrapper);
	wrap.style.width = arrayPageSize[0]+"px";
	wrap.style.height = arrayPageSize[1]+"px";
		
	//create div to hold everything
	var lbwrapper = document.createElement('div');
	lbwrapper.setAttribute('id','lb_flipbook_wrapper');
	document.body.insertBefore(lbwrapper,mainwrapper);
	
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1];
	currentWidth = arrayPageSize[0] - 50;
	currentHeight  = arrayPageSize[3] - 50;
	lbwrapper.style.width = currentWidth + "px";
	lbwrapper.style.height = currentHeight + "px";
	lbwrapper.style.left = (arrayPageSize[0] - currentWidth)/2 + "px";
	lbwrapper.style.top = lightboxTop+"px";
		
	//create close button
	var closebtn = document.createElement('div');
	closebtn.setAttribute('id','lb_close');
	closebtn.innerHTML = "<a href='javascript:void(0)' onclick='closeFlipBook();'>Close</a>";
	lbwrapper.appendChild(closebtn);
	
	//create HTML area if required
	var htmlArea = document.createElement('div');
   htmlArea.setAttribute('id','lb_conf');
	htmlArea.style.width  = currentWidth + "px";
	htmlArea.style.height  = currentHeight + "px";
   htmlArea.innerHTML = '<div id="fbContainer"><a class="altlink" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"><div id="altmsg">Download Adobe Flash Player.</div></a></div><div id="fbFooter"></div></div>';
   lbwrapper.appendChild(htmlArea);
	
	window.onresize = resizeFlipbook;
	window.onscroll =  resizeFlipbook;
		
}

function resizeFlipbook(){
		var arrayPageScroll = getPageScroll();
		var arrayPageSize = getPageSize();
		var lightboxTop = arrayPageScroll[1];
		var currentWidth = arrayPageSize[0] - 50;
		var currentHeight  = arrayPageSize[3] - 50;
		document.getElementById('lb_overlay').style.width = arrayPageSize[0]+"px";
		document.getElementById('lb_overlay').style.height = arrayPageSize[1]+"px";
		document.getElementById('lb_flipbook_wrapper').style.width = currentWidth + "px";
		document.getElementById('lb_flipbook_wrapper').style.height= currentHeight + "px";
		document.getElementById('lb_flipbook_wrapper').style.top=lightboxTop+"px";
		document.getElementById('lb_flipbook_wrapper').style.left=(arrayPageSize[0] - currentWidth)/2 + "px";
		document.getElementById('lb_conf').style.width = currentWidth + "px";
		document.getElementById('lb_conf').style.height= currentHeight + "px";
}

function closeFlipBook(){

	var wrap = document.getElementById('lb_overlay');
	var wrap2 = document.getElementById('lb_flipbook_wrapper');
	window.onresize = null;
	window.onscroll =  null;
	document.body.removeChild(wrap);
	document.body.removeChild(wrap2);
	showFlash();
	showSelectBoxes();
	
}