////////////////////////////////////////////////////////////////////////////////////////
//  In-Browser Windows
//  Generic IBW creation, handling, removing
//  2/1/06 DW
//  8/16/06 Removed from gvars.js
//  9/11/06 Ready for release - move, resize, close
//  STANDALONE VERSION - includes browser check and element functions

// Browser checks here

// Will be true for Netscape and Firefox
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_nav  = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
					&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
					&& (agt.indexOf('webtv') == -1));
var is_nav6up = (is_nav && (is_major >= 5)); // True for Firefox
var is_ie = (agt.indexOf("msie") != -1);

var ibwCloseUpImg = new Image();
ibwCloseUpImg.src = "images/WindowCloseX_up.gif";
var ibwCloseDownImg = new Image();
ibwCloseDownImg.src = "images/WindowCloseX_down.gif";

var dragapproved=false;
var resizeapproved=false;
var ibw_el;
var ibw_x;
var ibw_y;
var ibwLeft;
var ibwTop;
var ibwWidth;
var ibwHeight;
var ibwMainID;

var ibw_uid = 1;  // increment for unique id numbers
var ibw_highz = 100;  // highest z-index
var ibwOver = new Array();  // tracks which windows are over which DTS elements
var ibwURL = new Array(); // array of ibw id's that contain IFRAMES (URLs)  #=[script sequence #, ibw.id]

function ibw_move(nav_event)
{
	if (dragapproved)
	{
		var tempx=is_nav6up? ibwLeft+nav_event.clientX-ibw_x: ibwLeft+event.clientX-ibw_x;
		// bounding: keep inside browser window
		if(tempx < 0) 
		{
			tempx = 0;
		}
/* 		if(tempx > 280)  // Should we allow user to drag window partially off browser?
		{
			tempx = 280;
		}
*/
 		ibw_el.style.left = tempx;
		
		var tempy=is_nav6up? ibwTop+nav_event.clientY-ibw_y : ibwTop+event.clientY-ibw_y;
		if(tempy < 0)
		{
			tempy = 0;
		}
/* 		if(tempy > 5) // Should we allow user to drag window partially off browser?
		{
			tempy = 5;
		}
*/
 		ibw_el.style.top = tempy;
		
					// Check to see if we need to hide or unhide media player or flash content
				
		//find ibw
		var _i = 0;
		for(; _i < ibwOver.length; _i++)
		{
			if(ibwOver[_i])
			{
				if(ibwOver[_i][0] == ibw_el.id)
				{
					ibwOver[_i] = [ibw_el.id,false,false,false]; // id, videoOver, contentOver, qualityOver
					break;
				}
			}
		}
		if(_i == ibwOver.length) // didn't find it
		{
			//register ibw
			_i = ibwOver.push([ibw_el.id,false,false,false]) - 1; // id, videoOver, contentOver, qualityOver
		}
		
		// Check to see if we need to hide media player or content content
		
/* 		//  THIS IS THE AREA WHERE BOUNDING CHECKS WITH INCOMPATIBLE LAYERS ARE MADE - ie: forms, video, flash
		if( videoOn && overlappingLayerCheck(ibw_el.id, "media_player") == true)
		{
			ibwOver[_i][1] = true;  // over video
		}
		if( useSlides && overlappingLayerCheck(ibw_el.id, "content_area") == true)
		{
			ibwOver[_i][2] = true;  // over content
		}	
		if(overlappingLayerCheck(ibw_el.id, "bandwidth") == true)
		{
			ibwOver[_i][3] = true;  // over bandwidth drop down
		}		
		if( useTOC && overlappingLayerCheck(ibw_el.id, "tocSelector") == true)
		{
			ibwOver[_i][4] = true;  // over TOC
		}	
		updateOverHidden();
*/
			
		return false;
	}
}

function ibw_resize(nav_event)
{
	var tempW = ibwWidth;
	var tempH = ibwHeight;
	var tempLeft = ibwLeft;
	var tempTop = ibwTop;
	if (resizeapproved)
	{
		if(resizeapproved == "SE")
		{
			tempW=is_nav6up? ibwWidth+nav_event.clientX-ibw_x: ibwWidth+event.clientX-ibw_x;
			// bounding: keep inside browser window
			if(tempW > (document.body.clientWidth - ibwLeft) - 5)  
			{
				tempW = (document.body.clientWidth - ibwLeft) - 5;
			}
			if(tempW < 200) 
			{
				tempW = 200;
			}
	
			
			tempH=is_nav6up? ibwHeight+nav_event.clientY-ibw_y : ibwHeight+event.clientY-ibw_y;
			if(tempH > (document.body.clientHeight - ibwTop) - 5) 
			{
				tempH = (document.body.clientHeight - ibwTop) - 5;
			}
			if(tempH < 100)
			{
				tempH = 100;
			}
		}
		else if(resizeapproved == "S")
		{
			tempH=is_nav6up? ibwHeight+nav_event.clientY-ibw_y : ibwHeight+event.clientY-ibw_y;
			if(tempH > (document.body.clientHeight - ibwTop) - 5) 
			{
				tempH = (document.body.clientHeight - ibwTop) - 5;
			}
			if(tempH < 100)
			{
				tempH = 100;
			}
		}
		else if(resizeapproved == "SW")
		{
			tempLeft=is_nav6up? ibwLeft+nav_event.clientX-ibw_x: ibwLeft+event.clientX-ibw_x;

			tempW=is_nav6up? ibwWidth-nav_event.clientX+ibw_x: ibwWidth-event.clientX+ibw_x;
			if(tempW < 200) 
			{
				tempLeft = tempLeft + (tempW - 200);
				tempW = 200;
			}

			tempH=is_nav6up? ibwHeight+nav_event.clientY-ibw_y : ibwHeight+event.clientY-ibw_y;
			if(tempH > (document.body.clientHeight - ibwTop) - 5) 
			{
				tempH = (document.body.clientHeight - ibwTop) - 5;
			}
			if(tempH < 100)
			{
				tempH = 100;
			}
		}
		else if(resizeapproved == "W")
		{
			tempLeft=is_nav6up? ibwLeft+nav_event.clientX-ibw_x: ibwLeft+event.clientX-ibw_x;

			tempW=is_nav6up? ibwWidth-nav_event.clientX+ibw_x: ibwWidth-event.clientX+ibw_x;
			if(tempW < 200) 
			{
				tempLeft = tempLeft + (tempW - 200);
				tempW = 200;
			}
		}
		else if(resizeapproved == "NW")
		{
			tempLeft=is_nav6up? ibwLeft+nav_event.clientX-ibw_x: ibwLeft+event.clientX-ibw_x;

			tempTop=is_nav6up? tempTop+nav_event.clientY-ibw_y: tempTop+event.clientY-ibw_y;

			tempW=is_nav6up? ibwWidth-nav_event.clientX+ibw_x: ibwWidth-event.clientX+ibw_x;
			if(tempW < 200) 
			{
				tempLeft = tempLeft + (tempW - 200);
				tempW = 200;
			}
			tempH=is_nav6up? ibwHeight-nav_event.clientY+ibw_y : ibwHeight-event.clientY+ibw_y;
			if(tempH < 100)
			{
				tempTop = tempTop + (tempH - 100);
				tempH = 100;
			}
		}
		else if(resizeapproved == "N")
		{
			tempTop=is_nav6up? tempTop+nav_event.clientY-ibw_y: tempTop+event.clientY-ibw_y;
			tempH=is_nav6up? ibwHeight-nav_event.clientY+ibw_y : ibwHeight-event.clientY+ibw_y;
			if(tempH < 100)
			{
				tempTop = tempTop + (tempH - 100);
				tempH = 100;
			}
		}
		else if(resizeapproved == "NE")
		{
			tempTop=is_nav6up? tempTop+nav_event.clientY-ibw_y: tempTop+event.clientY-ibw_y;

			tempW=is_nav6up? ibwWidth+nav_event.clientX-ibw_x: ibwWidth+event.clientX-ibw_x;
			// bounding: keep inside browser window
			if(tempW > (document.body.clientWidth - ibwLeft) - 5)  
			{
				tempW = (document.body.clientWidth - ibwLeft) - 5;
			}
			if(tempW < 200) 
			{
				tempW = 200;
			}

			tempH=is_nav6up? ibwHeight-nav_event.clientY+ibw_y : ibwHeight-event.clientY+ibw_y;
			if(tempH < 100)
			{
				tempTop = tempTop + (tempH - 100);
				tempH = 100;
			}
		}
		else if(resizeapproved == "E")
		{
			tempW=is_nav6up? ibwWidth+nav_event.clientX-ibw_x: ibwWidth+event.clientX-ibw_x;
			// bounding: keep inside browser window
			if(tempW > (document.body.clientWidth - ibwLeft) - 5)  
			{
				tempW = (document.body.clientWidth - ibwLeft) - 5;
			}
			if(tempW < 200) 
			{
				tempW = 200;
			}
		}
					
	//		window.status = tempH;	
			// Update position of IBW
			ibw_el.style.left = tempLeft;
			ibw_el.style.top = tempTop;

			// Update IBW and sub parts with new width/height
			ibw_el.style.width = tempW + "px";
			ibw_el.style.height = tempH + "px";
	
			var tempEl = null;
			// "ibwWindow" + ibwMainID
			tempEl = getElement("ibwWindow" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.width=is_ie? tempW:tempW-10 + "px";
				tempEl.style.height=is_ie? tempH:tempH-10 + "px";
			}
			// "ibwTitle" + ibwMainID
			tempEl = getElement("ibwTitle" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.width=(tempW - (is_ie?10:12)) + "px";
			}
			// "ibwCloseButton" + ibwMainID
			tempEl = getElement("ibwCloseButton" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.left=(tempW - 23) + "px";
			}
			// "ibwFrame" + ibwMainID
			tempEl = getElement("ibwFrame" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.width=(tempW - 10) + "px";
				tempEl.style.height=(tempH - 28) + "px";
			}
			// "ibwContent" + ibwMainID
			tempEl = getElement("ibwContent" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.width=(tempW - 10) + "px";
				tempEl.style.height=(tempH - 28) + "px";
			}
			// Resize bars
			// ibwResizeNNW and ibwResizeWNW do not need to be changed
			tempEl = getElement("ibwResizeN" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.width=(tempW - 50) + "px";
			}
			tempEl = getElement("ibwResizeNNE" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.left=(tempW - 25) + "px";
			}
			tempEl = getElement("ibwResizeENE" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.left=(tempW - 5) + "px";
			}
			tempEl = getElement("ibwResizeE" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.left=(tempW - 5) + "px";
				tempEl.style.height=(tempH - 50) + "px";
			}
			tempEl = getElement("ibwResizeESE" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.left=(tempW - 5) + "px";
				tempEl.style.top=(tempH - 25) + "px";
			}
			tempEl = getElement("ibwResizeSSE" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.left=(tempW - 25) + "px";
				tempEl.style.top=(tempH - 5) + "px";
			}
			tempEl = getElement("ibwResizeS" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.top=(tempH - 5) + "px";
				tempEl.style.width=(tempW - 50) + "px";
			}
			tempEl = getElement("ibwResizeSSW" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.top=(tempH - 5) + "px";
			}
			tempEl = getElement("ibwResizeWSW" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.top=(tempH - 25) + "px";
			}
			tempEl = getElement("ibwResizeW" + ibwMainID);
			if(tempEl)
			{
				tempEl.style.height=(tempH - 50) + "px";
			}
			
	
			// Check to see if we need to hide or unhide media player or flash content
					
			//find ibw
			var _i = 0;
			for(; _i < ibwOver.length; _i++)
			{
				if(ibwOver[_i])
				{
					if(ibwOver[_i][0] == ibw_el.id)
					{
						ibwOver[_i] = [ibw_el.id,false,false,false]; // id, videoOver, contentOver, qualityOver
						break;
					}
				}
			}
			if(_i == ibwOver.length) // didn't find it
			{
				//register ibw
				_i = ibwOver.push([ibw_el.id,false,false,false]) - 1; // id, videoOver, contentOver, qualityOver
			}
			
			// Check to see if we need to hide media player or content content
			
/* 		//  THIS IS THE AREA WHERE BOUNDING CHECKS WITH INCOMPATIBLE LAYERS ARE MADE - ie: forms, video, flash
			if( videoOn && overlappingLayerCheck(ibw_el.id, "media_player") == true)
			{
				ibwOver[_i][1] = true;  // over video
			}
			if( useSlides && overlappingLayerCheck(ibw_el.id, "content_area") == true)
			{
				ibwOver[_i][2] = true;  // over content
			}	
			if(overlappingLayerCheck(ibw_el.id, "bandwidth") == true)
			{
				ibwOver[_i][3] = true;  // over bandwidth drop down
			}		
			if( useTOC && overlappingLayerCheck(ibw_el.id, "tocSelector") == true)
			{
				ibwOver[_i][4] = true;  // over TOC
			}	
			updateOverHidden();
*/	
			
		return false;
	}
}


function drags(nav_event)
{
	if (!is_ie&&!is_nav6up)
	{
		return;
	}
	var firedobj=is_nav6up? nav_event.target : event.srcElement;
	var topelement=is_nav6up? "HTML" : "BODY";
	
	while (firedobj.tagName!=topelement && firedobj.className!="WindowDrag" && firedobj.className.indexOf("WindowResize") < 0 && firedobj.className!="Window") 
	{
		firedobj=is_nav6up? firedobj.parentNode : firedobj.parentElement;
	}
	
	if (firedobj.className=="WindowDrag")
	{
		dragapproved=true;
		ibw_el=is_nav6up? firedobj.parentNode : firedobj.parentElement; // go to top element of window group
		// For dragging
		ibwLeft=parseInt(ibw_el.style.left+0);
		ibwTop=parseInt(ibw_el.style.top+0);
		ibwMainID=ibw_el.id.substr(3); // get unique number

		// Initial position of mouse
		ibw_x=is_nav6up? nav_event.clientX: event.clientX;
		ibw_y=is_nav6up? nav_event.clientY: event.clientY;
		document.onmousemove=ibw_move;
		
		// bring drag object to front
		if(parseInt(ibw_el.style.zIndex) < ibw_highz)
		{
			ibw_highz++;
			ibw_el.style.zIndex = ibw_highz;
		}
		
		// make IFRAME invisible
		// "ibw" + ibw_uid
		// Use ibwURL to affect other IFRAME IBW's. Dragging target should be invisible, others opaque
		
		for(var _if=0; _if < ibwURL.length; _if++)
		{
			if(ibwURL[_if][1] == ibw_el.id)  // matches drag target
			{
				var iframe_el=getElement("ibwFrame" + ibwMainID);
				if (iframe_el)
				{
					iframe_el.style.visibility = "hidden";
				}
			}
			else  // all other iframes
			{
				var base_el=getElement(ibwURL[_if][1]);
				if(base_el)
				{
					base_el.style.background = "#FFFFFF";

					var temp_uid=ibwURL[_if][1].substr(3);
					var iframe_el=getElement("ibwFrame" + temp_uid);
					if (iframe_el)
					{
						iframe_el.style.visibility = "hidden";
					}

				}
			}
		}
		return false;
	}
	else if(firedobj.className.indexOf("WindowResize") == 0)
	{
		ibw_el=is_nav6up? firedobj.parentNode : firedobj.parentElement; // go to top element of window group
		resizeapproved=firedobj.className.substr(12);

		//ibw_el=firedobj;
		ibwLeft=parseInt(ibw_el.style.left);
		ibwTop=parseInt(ibw_el.style.top);
		// For resizing
		ibwWidth=parseInt(ibw_el.style.width);
		ibwHeight=parseInt(ibw_el.style.height);
		ibwMainID=ibw_el.id.substr(3); // get unique number
		// Initial mouse position
		ibw_x=is_nav6up? nav_event.clientX: event.clientX;
		ibw_y=is_nav6up? nav_event.clientY: event.clientY;
		document.onmousemove=ibw_resize;
			
		// bring drag object to front

		if(parseInt(ibw_el.style.zIndex) < ibw_highz)
		{
			ibw_highz++;
			ibw_el.style.zIndex = ibw_highz;
		}
			
		// make IFRAME invisible
		// "ibw" + ibw_uid
		// Use ibwURL to affect other IFRAME IBW's. Dragging target should be invisible, others opaque
		
		for(var _if=0; _if < ibwURL.length; _if++)
		{
			if(ibwURL[_if][1] == ibw_el.id)  // matches drag target
			{
				var iframe_el=getElement("ibwFrame" + ibwMainID);
				if (iframe_el)
				{
					iframe_el.style.visibility = "hidden";
				}
			}
			else  // all other iframes
			{
				var base_el=getElement(ibwURL[_if][1]);
				if(base_el)
				{
					base_el.style.background = "#FFFFFF";

					var temp_uid=ibwURL[_if][1].substr(3);
					var iframe_el=getElement("ibwFrame" + temp_uid);
					if (iframe_el)
					{
						iframe_el.style.visibility = "hidden";
					}

				}
			}
		}
		return false;

	}	
	else if(firedobj.className=="Window")
	{
		// bring drag object to front
		if(parseInt(firedobj.style.zIndex) < ibw_highz)
		{
			ibw_highz++;
			firedobj.style.zIndex = ibw_highz;
		}
	}	
}

function doneDrag()
{
	if(ibw_el)
	{
		// Make IFRAME visible again
		for(var _if=0; _if < ibwURL.length; _if++)
		{
			if(ibwURL[_if][1] == ibw_el.id)  // matches drag target
			{
				var temp_uid=ibw_el.id.substr(3);
				var iframe_el=getElement("ibwFrame" + temp_uid);
				if (iframe_el)
				{
					iframe_el.style.visibility = "visible";
				}
			}
			else  // all other iframes
			{
				var base_el=getElement(ibwURL[_if][1]);
				if(base_el)
				{
					base_el.style.background = "transparent";

					var temp_uid=ibwURL[_if][1].substr(3);
					var iframe_el=getElement("ibwFrame" + temp_uid);
					if (iframe_el)
					{
						iframe_el.style.visibility = "visible";
					}

				}
			}
		}
		ibw_el = null;	
	}

	dragapproved=false;
	resizeapproved=false;
	
	document.onmousemove=null; // remove handler for mouse move
}

document.onmousedown=drags;
document.onmouseup=doneDrag;
//document.onmouseout=doneDrag;

//  createWindow  - takes object with filled properties:
/*
 displayMode ("Normal", "Minimized", "Maximized")  // Only Normal works in this version
 width (pixels)
 height (pixels)
 left (pixels)
 top (pixels)
 contentType ("div", "url")
 contentBackground (background css style)
 content (html content or url)
 title (window title)
 titleTextColor (color)
 titleBackground (background css style)
 titleAlign ("left", "center", "right")
*/

function createWindow(createObj)
{
	//doneDrag();  // remove any window or resizing on another window, to avoid errors when new window is created.

	// Set defaults for missing properties
	
	if(!createObj.displayMode) { createObj.displayMode = "Normal" } // Normal, Minimized, Maximized

	if(!createObj.width) { createObj.width = 480; } 
	if(!createObj.height) { createObj.height = 360; }
	if(!createObj.left) { createObj.left = 100  + Math.round(Math.random() * 40); }   // Randomized to avoid windows exactly overlapping on creation
	if(!createObj.top) { createObj.top = 60  + Math.round(Math.random() * 40); } 
	
	if(!createObj.contentType) { createObj.contentType = "html"; } //  html or url
	if(!createObj.contentBackground) 
	{ 
		if(createObj.contentType == "url")
		{
			createObj.contentBackground = "#FFFFFF"; 
		}
		else
		{
			createObj.contentBackground = "#E8E8E8"; 
		}
	}
	if(!createObj.content) 
	{
		if(createObj.contentType == "url")
		{
			 createObj.content = "about:blank"; 
		}
		else
		{
			 createObj.content = "&nbsp;"; 
		}
	}
	
	if(!createObj.title) 
	{ 
		if(createObj.contentType == "url")
		{
			createObj.title = "Webpage"; 
		}
		else
		{
			createObj.title = "Window"; 
		}
	}
	if(!createObj.titleTextColor) { createObj.titleTextColor = "#FFFFFF"; }
	if(!createObj.titleBackground) { createObj.titleBackground = "#0A246A"; } // Default windows dark blue title color
	if(!createObj.titleAlign) { createObj.titleAlign = "left"; }

	// Create base container for window

	var newWin = document.createElement("div");
	newWin.id = "ibw" + ibw_uid;
	// Most compatible method to set style on new node (IE won't accept single "style" input.  NS6/FF will.)
	newWin.style.position = "absolute";
	newWin.style.left = createObj.left + "px";
	newWin.style.top = createObj.top + "px";
	newWin.style.width = createObj.width + "px";
	newWin.style.height = createObj.height + "px";
	newWin.style.background = "transparent";// createObj.contentBackground;
	newWin.style.overflow = "hidden";
	ibw_highz++;  // increase z-buffer (layer height)
	newWin.style.zIndex = ibw_highz;
	newWin.className = "Window";

//	newWin.style.border = "3px ridge";
	var newWinHTML = "";
	if(createObj.displayMode == "Normal")
	{
		// add bordered frame
		newWinHTML += "<div id=\"ibwWindow" + ibw_uid + "\" style=\"width:" + ((is_ie)? createObj.width:createObj.width - 10) + "; height:" + ((is_ie)? createObj.height:createObj.height - 10) + "; border:5px ridge #FFFFFF; position:absolute; top:0px; left:0px; background:transparent;\"></div>\n";
		// inside bordered frame
		// draw Title bar
		newWinHTML += "<div id=\"ibwTitle" + ibw_uid + "\"   class='WindowDrag' style=\"position:absolute; top:5; left:5; width:" + (createObj.width - (is_ie?10:12)) + "px; height:" + (is_ie?18:16) + "px; padding:2px 0px 0px 2px; overflow:hidden; background:" + createObj.titleBackground + "; cursor:move; color:" + createObj.titleTextColor + "; font-family: Verdana; font-size: 12px; font-weight: bold; \" align=\""+createObj.titleAlign+"\">" + createObj.title + "</div>";
		// add close button
		newWinHTML += "<div id='ibwCloseButton" + ibw_uid + "' style='position:absolute; top:7px; left:" + (createObj.width - 23) + "px;'><img src='" + ibwCloseUpImg.src + "' style='cursor:pointer;' onClick='removeWindow(\"ibw" + ibw_uid + "\");' onMousedown='this.src=ibwCloseDownImg.src;' onMouseout='this.src=ibwCloseUpImg.src;'></div>";
		// add content area		
		if(createObj.contentType == "url")
		{
			newWinHTML += "<iframe id=\"ibwFrame" + ibw_uid + "\" style=\"position:absolute; left:5px; top:23px; border:none; width:" + (createObj.width - 10) + "px; height:" + (createObj.height - 28) + "px; overflow:auto; background:" + createObj.contentBackground + ";\" src=\"" + createObj.content + "\"></iframe>\n";
		}
		else  // (is_ie?24:18)
		{
			newWinHTML += "<div id=\"ibwContent" + ibw_uid + "\" style=\"position:absolute; left:5px; top:23px; width:" + (createObj.width - 10) + "px; height:" + (createObj.height - 28) + "px; overflow:auto; background:" + createObj.contentBackground + ";  color:#000000;\">" + createObj.content + "</div>\n";	
		}

		// begin adding resize areas - 12 in all!
		// top bar
		newWinHTML += "<div id=\"ibwResizeNNW" + ibw_uid + "\" class=\"WindowResizeNW\" style=\"position:absolute; left:0px; top:0px; width:25px; height:5px; background:transparent; cursor:nw-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"25\" height=\"5\"></div>";
		newWinHTML += "<div id=\"ibwResizeN" + ibw_uid + "\" class=\"WindowResizeN\" style=\"position:absolute; left:25px; top:0px; width:" + (createObj.width - 50) + "px; height:5px; background:transparent; cursor:n-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"" + (createObj.width - 50) + "\" height=\"5\"></div>";
		newWinHTML += "<div id=\"ibwResizeNNE" + ibw_uid + "\" class=\"WindowResizeNE\" style=\"position:absolute; left:" + (createObj.width - 25) + "px; top:0px; width:25px; height:5px; background:transparent; cursor:ne-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"25\" height=\"5\"></div>";
		// left side bar
		newWinHTML += "<div id=\"ibwResizeWNW" + ibw_uid + "\" class=\"WindowResizeNW\" style=\"position:absolute; left:0px; top:0px; width:5px; height:25px; background:transparent; cursor:nw-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"5\" height=\"25\"></div>";
		newWinHTML += "<div id=\"ibwResizeW" + ibw_uid + "\" class=\"WindowResizeW\" style=\"position:absolute; left:0px; top:25px; width:5px; height:" + (createObj.height - 50) + "px; background:transparent; cursor:w-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"5\" height=\"" + (createObj.height - 50) + "\"></div>";
		newWinHTML += "<div id=\"ibwResizeWSW" + ibw_uid + "\" class=\"WindowResizeSW\" style=\"position:absolute; left:0px; top:" + (createObj.height - 25) + "px; width:5px; height:25px; background:transparent; cursor:sw-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"5\" height=\"25\"></div>";
		// bottom bar
		newWinHTML += "<div id=\"ibwResizeSSW" + ibw_uid + "\" class=\"WindowResizeSW\" style=\"position:absolute; left:0px; top:" + (createObj.height - 5) + "px; width:25px; height:5px; background:transparent; cursor:sw-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"25\" height=\"5\"></div>";
		newWinHTML += "<div id=\"ibwResizeS" + ibw_uid + "\" class=\"WindowResizeS\" style=\"position:absolute; left:25px; top:" + (createObj.height - 5) + "px; width:" + (createObj.width - 50) + "px; height:5px; background:transparent; cursor:s-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"" + (createObj.width - 50) + "\" height=\"5\"></div>";
		newWinHTML += "<div id=\"ibwResizeSSE" + ibw_uid + "\" class=\"WindowResizeSE\" style=\"position:absolute; left:" + (createObj.width - 25) + "px; top:" + (createObj.height - 5) + "px; width:25px; height:5px; background:transparent; cursor:se-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"25\" height=\"5\"></div>";
		// right side bar
		newWinHTML += "<div id=\"ibwResizeENE" + ibw_uid + "\" class=\"WindowResizeNE\" style=\"position:absolute; left:" + (createObj.width - 5) + "px; top:0px; width:5px; height:25px; background:transparent; cursor:ne-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"5\" height=\"25\"></div>";
		newWinHTML += "<div id=\"ibwResizeE" + ibw_uid + "\" class=\"WindowResizeE\" style=\"position:absolute; left:" + (createObj.width - 5) + "px; top:25px; width:5px; height:" + (createObj.height - 50) + "px; background:transparent; cursor:e-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"5\" height=\"" + (createObj.height - 50) + "\"></div>";
		newWinHTML += "<div id=\"ibwResizeESE" + ibw_uid + "\" class=\"WindowResizeSE\" style=\"position:absolute; left:" + (createObj.width - 5) + "px; top:" + (createObj.height - 25) + "px; width:5px; height:25px; background:transparent; cursor:se-resize; overflow:hidden;\"><img src=\"images/player/pixel.gif\" width=\"5\" height=\"25\"></div>";
	}
	newWin.innerHTML = newWinHTML;
	
	document.body.appendChild(newWin);

	//register ibw
	var _io = ibwOver.push([newWin.id,false,false,false]) - 1; // id, videoOver, contentOver, qualityOver

	// Check to see if we need to hide media player or flash content
	
/* 		//  THIS IS THE AREA WHERE BOUNDING CHECKS WITH INCOMPATIBLE LAYERS ARE MADE - ie: forms, video, flash
	if( videoOn && overlappingLayerCheck(newWin.id, "media_player") == true)
	{
		ibwOver[_io][1] = true;  // over video
	}
	if( useSlides && overlappingLayerCheck(newWin.id, "content_area") == true)
	{
		ibwOver[_io][2] = true;  // over content
	}	
	if(overlappingLayerCheck(newWin.id, "bandwidth") == true)
	{
		ibwOver[_io][3] = true;  // over bandwidth drop down
	}		
	if( useTOC && overlappingLayerCheck(newWin.id, "tocSelector") == true)
	{
		ibwOver[_io][4] = true;  // over TOC
	}	
	updateOverHidden();
*/
	
	// Tracks which windows contain IFRAMES that need to be hidden during moves or drags.
	if(createObj.contentType = "url")
	{
		ibwURL.push([ibw_uid, newWin.id]);
	}

	ibw_uid++;

	// bring drag object to front - if an object is being dragged or resized
	if(ibw_el)
	{
		if(parseInt(ibw_el.style.zIndex) < ibw_highz)
		{
			ibw_highz++;
			ibw_el.style.zIndex = ibw_highz;
		}
	}

	return newWin.id;  // returns id of new ibw
}

// Determine which layers need to be hidden behind IBW.
// LEFT IN AS EXAMPLE OF HIDING OR SHOWING INCOMPATIBLE LAYERS ie: forms, video, flash

function updateOverHidden()
{
	var hideVideo = false;
	var hideFlash = false;
	var hideQuality = false;
	var hideTOC = false;
	
	for ( var _i = 0; _i < ibwOver.length; _i++)
	{
		if(ibwOver[_i])
		{
			if(ibwOver[_i][1] == true) 
			{
				hideVideo = true;
			}
			if(ibwOver[_i][2] == true)  // generic content.. set appropriate flags as needed
			{
				hideFlash = true;
			}
			if(ibwOver[_i][3] == true) 
			{
				hideQuality = true;
			}
			if(ibwOver[_i][4] == true) 
			{
				hideTOC = true;
			}
		}
		
	}

	if( videoOn )
	{
		var mp = getElement("media_player");
		if(hideVideo)
		{
			mp.style.visibility = "hidden";
//					window.document.MediaPlayer1.uiMode = "invisible"; // only works correctly with IE; layer hiding works for IE/Mozilla
			changeMediaPlayerVisibility = false;
		}
		else
		{
			changeMediaPlayerVisibility = true;
			// Check to see if video should be turned back on.
			mp.style.visibility = "visible";
		}
	}
//	var ca = getElement("content_area");
	if( useSlides && contentWindowDefinedAs == "flash") 
	{
		if( hideFlash)
		{
			if(currentFlashLayer)
			{
				currentFlashLayer.style.visibility = "hidden";
			}
		}
		else
		{
			if(currentFlashLayer)
			{
				currentFlashLayer.style.visibility = "visible";
			}
		}
	}		
	else
	{
//		ca.style.visibility = "visible";
	}
	var qual = getElement("bandwidth");
	if(qual)
	{
		if(hideQuality)
		{
			qual.style.visibility = "hidden";
		}
		else
		{
			qual.style.visibility = "visible";
		}
	}
	if(useTOC)
	{
		var elTOC = getElement("tocSelector");
		if(elTOC && hideTOC)
		{
			elTOC.style.visibility = "hidden";
		}
		else
		{
			elTOC.style.visibility = "visible";
		}
	}
}

function removeWindow(wid)
{
	var wel = getElement(wid);

	if(wel)
	{
		// bring ibw_highz down to current highest z-index
		ibw_highz = 100;
		for(var _i = 0; _i < ibwOver.length; _i++)
		{
			if(ibwOver[_i])
			{
				var tempel = getElement(ibwOver[_i][0]);
				if(tempel)
				{
					var _z = parseInt(tempel.style.zIndex);
					if( _z > ibw_highz)
					{
						ibw_highz = _z;
					}
				}
			}
		}
		document.body.removeChild(wel);
	}
	
	// Remove array reference to IBW
	for ( var _i = 0; _i < ibwOver.length; _i++)
	{
		if(ibwOver[_i])
		{
			if(ibwOver[_i][0] == wid)
			{
				ibwOver.splice(_i,1); // delete out of array
			}
		}
	}	
	
	for ( var _i = 0; _i < ibwURL.length; _i++)
	{
		if(ibwURL[_i])
		{
			if(ibwURL[_i][1] == wid)
			{
				ibwURL.splice(_i,1); // delete out of array
				break;
			}
		}
	}	
	
	// Unhide to use layer hide function
	//updateOverHidden();  // Now that IBW is gone, see if anything needs to be made visible again.
		
}



// END In Browser Windows (aka Embedded Windows)
//
//////////////////////////////////////////////////////////////////////////////////

// Check bounding boxes of two layers to see if they overlap

function overlappingLayerCheck(layer1, layer2)
{
	var id1 = getElement(layer1);
	var id2 = getElement(layer2);
	
	if(!id1 || !id2) // can't find one or more layers
	{
		return false; 
	}

	var st1 = getCurrStyle(id1);
	var st2 = getCurrStyle(id2);

	var x1 = parseInt(st1.left);
	var xx1 = x1 + id1.clientWidth;
	
	var x2 = parseInt(st2.left);
	var xx2 = x2 + id2.clientWidth;
	
	var y1 = parseInt(st1.top);
	var yy1 = y1 + id1.clientHeight;
	
	var y2 = parseInt(st2.top);
	var yy2 = y2 + id2.clientHeight;



	// bound check
	if(x1 <= xx2 && xx1 >= x2) 
	{
		if(y1 <= yy2 && yy1 >= y2)
		{
			// Overlapping
			return true;
		}
	}
	
	
	return false; // all else fails..
}

// returns style object (includes all inherited styles)

function getCurrStyle(el)
{
//	var el = getElement(id);
	if (window.getComputedStyle) // Mozilla, DOM compliant
	{
		var st = window.getComputedStyle(el,null);
	}
	else if (el.currentStyle)  // IE 
	{
		var st = el.currentStyle;
	}
	return st;
}

// Returns element object based on given id

function getElement(id)
{
	// Compatible with Netscape 6+, Firefox 1.0+, IE 6+
	if (document.getElementById)
	{
		return document.getElementById(id);
	}
	// Compatible with IE 4+
	else if (document.all)
	{
		return document.all[id];
	}
	else
	{
		return false;
	}
}

// Open function added by ML

function openURL(theUrl, WinTitle, xWindowSize, yWindowSize, Top, Left, WinTitleBackground, WinTitleTextColor, WinTitleAlign)
{
    var newWinObj = new Object();

	newWinObj.contentType = "url"
	newWinObj.content = theUrl;
	
	newWinObj.title           = WinTitle;
	newWinObj.titleAlign      = WinTitleAlign;
    newWinObj.titleBackground = WinTitleBackground;
    newWinObj.titleTextColor  = WinTitleTextColor
	newWinObj.top             = Top;
	newWinObj.left            = Left;
	newWinObj.width           = xWindowSize;
	newWinObj.height          = yWindowSize;
	
	createWindow(newWinObj);

}