//\//////////////////////////////////////////////////////////////////////////////////
//\  overLIB 3.30  --  This notice must remain untouched at all times.
//\  Copyright Erik Bosrup 1998-2000. All rights reserved.
//\
//\  By Erik Bosrup (erik@bosrup.com).  Last modified 2000-11-15.
//\  Portions by Dan Steinman (dansteinman.com). Additions by other people are
//\  listed on the overLIB homepage.
//\
//\  Get the latest version at http://www.bosrup.com/web/overlib/
//\
//\  This script is published under an open source license. Please read the license
//\  agreement online at: http://www.bosrup.com/web/overlib/license.html
//\  If you have questions regard the license please contact erik@bosrup.com.
//\
//\  This script library was originally created for personal use. By request it has
//\  later been made public. This is free software. Do not sell this as your own
//\  work, or remove this copyright notice. For full details on copying or changing
//\  this script please read the license agreement at the link above.
//\
//\  Please give credit on sites that use overLIB and submit changes of the script
//\  so other people can use them as well. This script is free to use, don't abuse.
//\//////////////////////////////////////////////////////////////////////////////////


var INARRAY		=	1;
var CAPARRAY		=	2;
var STICKY		=	3;
var NOCLOSE		=	5;
var LEFT		=	7;
var RIGHT		=	8;
var CENTER		=	9;
var OFFSETX		=	10;
var OFFSETY		=	11;
var WIDTH		=	17;
var STATUS		=	19;
var AUTOSTATUS		=	20;
var AUTOSTATUSCAP	=	21;
var HEIGHT		=	22;
var CLOSETEXT		=	23;
var SNAPX		=	24;
var SNAPY		=	25;
var FIXX		=	26;
var FIXY		=	27;
var FULLHTML		=	34;
var ABOVE		=	35;
var BELOW		=	36;
var FRAME		=	44;
var TIMEOUT		=	45;
var FUNCTION		=	46;
var DELAY		=	47;
var HAUTO		=	48;
var VAUTO		=	49;
var stay = "0";
var ol_hpos = LEFT;
var ol_status = "";
var ol_autostatus = 0;
var ol_height = -1;
var ol_snapx = 0;
var ol_snapy = 0;
var ol_fixx = -1;
var ol_fixy = -1;
var ol_padxl = 1;
var ol_padxr = 1;
var ol_padyt = 1;
var ol_padyb = 1;
var ol_fullhtml = 0;
var ol_vpos = BELOW;
var ol_aboveheight = 0;
var ol_frame = self;
var ol_timeout = 0;
var ol_function = Function();
var ol_delay = 0;
var ol_hauto = 0;
var ol_vauto = 0;
var ol_offsetx = 10;

var ol_texts = new Array("Array Text 0", "Array Text 1");
var ol_caps = new Array("Array Caption 0", "Array Caption 1");

var o3_sticky = 0;
var o3_hpos = RIGHT;
var o3_offsetx = 2;
var o3_offsety = 2;
var o3_status = "";
var o3_autostatus = 0;
var o3_snapx = 0;
var o3_snapy = 0;
var o3_fixx = -1;
var o3_fixy = -1;
var o3_padxl = 0;
var o3_padxr = 0;
var o3_padyt = 0;
var o3_padyb = 0;
var o3_fullhtml = 0;
var o3_vpos = BELOW;
var o3_aboveheight = 0;
var o3_capicon = "";
var o3_frame = self;
var o3_timeout = 2100;
var o3_timerid = 0;
var o3_allowmove = 0;
var o3_function = Function();
var o3_delay = 0;
var o3_delayid = 0;
var o3_hauto = 0;
var o3_vauto = 0;    
var o3_width = 0;

// Display state variables
var o3_x = 0;
var o3_y = 0;
var o3_allow = 0;
var o3_showingsticky = 0;
var o3_removecounter = 0;

// Our layer
var over = null;

// Decide browser version
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;
var g_cY;
var g_pY;

// Microsoft Stupidity Check(tm).
if (ie4) {
	if (navigator.userAgent.indexOf('MSIE 5')>0) {
		ie5 = true;
	}
	if (ns6) {
		ns6 = false;
	}
}

// Capture events, alt. diffuses the overlib function.
if ( (ns4) || (ie4) || (ns6)) {
	document.onmousemove = mouseMove;
	document.onmousedown = mouseDown;
	if (ns4) document.captureEvents(Event.MOUSEMOVE);
	if (ns6) document.captureEvents(Event.MOUSEDOWN);
} else {
	overlib = no_overlib;
	nd = no_overlib;
	ver3fix = true;
}


// Fake function for 3.0 users.
function no_overlib() {
	return ver3fix;
}

function stayHere() {
	stay = 1;
}

function leaveHere() {
	stay = 0;
	// Initiate a timer for timeout        
	if (o3_timerid > 0) clearTimeout(o3_timerid);
	o3_timerid = setTimeout("cClick()", 1200);
}

function cClick() {     
	if (over != null && stay==0) { 
		hideObject(over);
	}
}


// overlib(arg0, ..., argN)
// Loads parameters into global runtime variables.
function overlib() {

nd();
var content = arguments[0];
	o3_sticky = 0;
	o3_hpos = ol_hpos;
	o3_offsetx = ol_offsetx;
	o3_offsety = 10;
	o3_status = ol_status;
	o3_height = ol_height;
	o3_snapx = ol_snapx;
	o3_snapy = ol_snapy;
	o3_fixx = ol_fixx;
	o3_fixy = ol_fixy;
	o3_fullhtml = ol_fullhtml;
	o3_vpos = ol_vpos;
	o3_aboveheight = ol_aboveheight;
	o3_timeout = ol_timeout;
	o3_function = ol_function;
	o3_delay = ol_delay;
	o3_hauto = ol_hauto;
	o3_vauto = ol_vauto;

	// Special for frame support, over must be reset...
	if ( (ns4) || (ie4) || (ns6) ) {
		o3_frame = ol_frame;
		if (ns4) over = o3_frame.document[content];
		if (ie4) over = o3_frame.document.all[content]; //alert(over.innerHTML);}
		if (ns6) over = o3_frame.document.getElementById(content);
	}

	return overlib330(); 
}

// Clears popups if appropriate
function nd() { 
	if ( o3_removecounter >= 1 ) { o3_showingsticky = 0 };
	if ( (ns4) || (ie4) || (ns6) ) {
			if (over != null) hideObject(over);
	}
	
	return true;
}


// This function decides what it is we want to display and how we want it done.
function overlib330() {
	var layerhtml;
    o3_showingsticky = 1;
	o3_removecounter = 0;
	
	// Prepare status bar
	if (o3_autostatus > 0) {
		o3_status = o3_text;
		if (o3_autostatus > 1) {
			o3_status = o3_cap;
		}
	}

	// When placing the layer the first time, even stickies may be moved.
	o3_allowmove = 0;

	// Show layer
	disp(o3_status);
	o3_allowmove = 0;
	return false;
}

// Displays the popup
function disp(statustext) { 
	//alert("ns6 = " + ns6);	
	
	if ( (ns4) || (ie4) || (ns6) ) {
		if (o3_allowmove == 0) 	{
			placeLayer(); 
		//alert("Before call to showObject in disp");	 		
			showObject(over); 
			o3_allowmove = 1;
		}
	}

	if (statustext != "") {
		self.status = statustext;
	}
}

// Decides where we want the popup.
function placeLayer() { 
	var placeX, placeY;
	
	// HORIZONTAL PLACEMENT
	if (o3_fixx > -1) {
		// Fixed position
		placeX = o3_fixx;
	} else {
		// If HAUTO, decide what to use.
		if (o3_hauto == 1) {
			if (ie4) iwidth = o3_frame.document.body.clientWidth;
			if (ns4) iwidth = o3_frame.innerWidth;
			if (ns6) iwidth = o3_frame.outerWidth;

			iwidth = (eval(iwidth)) / 2;
			if (o3_x > iwidth) {
				o3_hpos = LEFT;
			} else {
				o3_hpos = RIGHT;
			}
		}
		
		// From mouse
		if (o3_hpos == CENTER) { // Center
			placeX = o3_x+o3_offsetx-(o3_width/2);
		}
		if (o3_hpos == RIGHT) { // Right
			placeX = o3_x+o3_offsetx;
		}
		if (o3_hpos == LEFT) { // Left
			placeX = o3_x-o3_offsetx-o3_width;
		}
	
		// Snapping!
		if (o3_snapx > 1) {
			var snapping = placeX % o3_snapx;
			if (o3_hpos == LEFT) {
				placeX = placeX - (o3_snapx + snapping);
			} else {
				// CENTER and RIGHT
				placeX = placeX + (o3_snapx - snapping);
			}
		}
	}	
	
	// VERTICAL PLACEMENT
	if (o3_fixy > -1) {
		// Fixed position
		placeY = o3_fixy;
	} else {
		// If VAUTO, decide what to use.
		if (o3_vauto == 1) {
			if (ie4) iheight = o3_frame.document.body.clientHeight;
			if (ns4) iheight = o3_frame.innerHeight;
			if (ns6) iheight = o3_frame.outerHeight;

			iheight = (eval(iheight)) / 2;
			if (o3_y > iheight) {
				o3_vpos = ABOVE;
			} else {
				o3_vpos = BELOW;
			}
		}

		// From mouse
		if (o3_aboveheight > 0 && o3_vpos == ABOVE) {
			placeY = o3_y - (o3_aboveheight + o3_offsety);
		} else {
			// BELOW
			placeY = o3_y + o3_offsety;
		}

		// Snapping!
		if (o3_snapy > 1) {
			var snapping = placeY % o3_snapy;
			
			if (o3_aboveheight > 0 && o3_vpos == ABOVE) {
				placeY = placeY - (o3_snapy + snapping);
			} else {
				placeY = placeY + (o3_snapy - snapping);
			}
		}
	}

	// Actually move the object.	
	moveTo(over, placeX, placeY);           
}


// Moves the layer
function mouseMove(e) {
	if ( (ns4) || (ns6) ) {o3_x=e.pageX; o3_y=e.pageY;}
	if (ie4) {o3_x=event.x; o3_y=event.y;}
	if (ie5) {o3_x=event.x+o3_frame.document.body.scrollLeft; o3_y=event.y+o3_frame.document.body.scrollTop;}
	
	if (o3_allowmove == 1) {
		placeLayer();
	}
}

function mouseDown(e)
{	
	// Capture the buttondown event for ns6
	// and determine the coordinates
	if (ns6)
	{
		g_cY = e.clientY;
		g_pY = e.pageY;
	}

}
// Make an object visible
function showObject(obj) {  

	if (ns4) {obj.visibility = "show";}
        else if (ie4) obj.className = "ToolTipShow"
	else if (ns6) obj.className = "ToolTipShow";
		
	// Determine the pop up height
	var popupHeight = obj.offsetHeight;	

	if (ie4) 
	{
		obj.style.left = event.clientX-90+document.body.scrollLeft;
	
		var screenHeight = document.body.clientHeight;
	
		if ((screenHeight  - event.clientY) < popupHeight)
		{
			obj.style.top = event.clientY - popupHeight - 10 + document.body.scrollTop;
		}
		else
		{
		 	obj.style.top = event.clientY + 5 + document.body.scrollTop;
		}
	}


	if (ns4) iheight = o3_frame.innerHeight;
	
	if (ns6) 
	{
		
		var screenHeight = o3_frame.innerHeight;
	
		if ((screenHeight - g_cY) < popupHeight)
		{
			obj.style.top = g_pY - 10 - popupHeight;
				
		}
		else
		{
			obj.style.top = g_pY + 5;
		}
	}


}

// Hides an object
function hideObject(obj) { 
        if (ns4) obj.visibility = "hidden"
        else if (ie4) obj.className = "ToolTip"
	else if (ns6) obj.className = "ToolTip"
        
	if (o3_timerid > 0) clearTimeout(o3_timerid);
	if (o3_delayid > 0) clearTimeout(o3_delayid);
	o3_timerid = 0;
	o3_delayid = 0;
    self.status = "";
}
          
          
// Move a layer
function moveTo(obj,xL,yL) {
//SS:-March 15, 2001 Added to bring the layer into the screen visibility completely

	if (ns4) {
		iwidth = o3_frame.innerWidth;
		if ((xL + obj.clip.width) > iwidth) {
			xL = iwidth - obj.clip.width;
		}
		iheight = o3_frame.outerHeight;
		if ((yL + obj.clip.height) > iheight) {
			yL = iheight - obj.clip.height;
		}
	}
//SS:-March 15, 2001 End
	if ( (ns4) || (ie4) ) { 
	        obj.left = xL;  
	        obj.top = yL;
	} else if (ns6) {
		//obj.style.left = xL;
		//obj.style.top = yL;
	}		
}

var done = "no";
function HighlightMe(ObjElement)
{
 
 if (navigator.appVersion.indexOf("Mac") < 0) 
 {
    ObjElement.className = "MenuAreaOn";
    if (ObjElement.children[0] != null) 
 	ObjElement.children[0].className = "MenuLabelOn";
 }
 
} 
 
function DimMe(ObjElement)
{
 if (navigator.appVersion.indexOf("Mac") < 0) 
 {
    ObjElement.className = "MenuAreaOff";
    if (ObjElement.children[0] != null) 
 	ObjElement.children[0].className = "MenuLabelOff";
 }
}
 
function moveComponent(ObjElement)
{
 if (done != "yes")
  doMoveComponent(ObjElement.children[0]);
 done = "no"; 
 
}
 
function NNHighlightMe(ObjElement)
{
 if (document.layers)
  ObjElement.className = "MenuAreaOn";
} 
 
function NNDimMe(ObjElement)
{
 if (document.layers)
  ObjElement.className = "MenuAreaOff";
}
 
var doneContent = "no";
function changeContent(ObjElement)
{
 
 if (doneContent != "yes")
  tearoffWithScroll(ObjElement.children[0].href,'maineditor',600,500,0,0);
 doneContent = "no";
}
 
var doneComponent = "no";
function changeComponentProperties(ObjElement)
{
 if (doneComponent != "yes")
  tearoffWithScroll(ObjElement.children[0].href,'maineditor',600,500,0,0);
 doneComponent = "no";
 
}
 
var doneDelete = "no";
function deleteComponent(ObjElement)
{
 if (doneDelete != "yes"){
   doDeleteComponent(ObjElement.children[0]);
 } 
 doneDelete = "no"; 
 
}

var processing = false;
function doDeleteComponent(objLink)
{
	if (processing) return;
	if (confirm("Are you sure you want to delete this content module and everything it contains?")) {
		processing = true;
		document.body.style.cursor = "wait";
		window.status = "Processing component deletion, please wait ......";
		document.location = objLink.href;
	}
}	

function doMoveComponent(objLink)
{
	if (processing) return;
	processing = true;
	document.body.style.cursor = "wait";
	window.status = "Processing component movement, please wait ......";
	document.location = objLink.href;
}