//\/////
//\  overLIB 4.00 - You may not remove or change this notice.
//\  Copyright Erik Bosrup 1998-2004. All rights reserved.
//\
//\  Contributors are listed on the homepage.
//\  This file might be old, always check for the latest version at:
//\  http://www.bosrup.com/web/overlib/
//\
//\  Please read the license agreement (available through the link above)
//\  before using overLIB. Direct any licensing questions to erik@bosrup.com.
//\
//\  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.
//   $Revision: 1.68.2.1 $                $Date: 2004/03/23 16:29:38 $
//\/////
//\mini

//\/////
//   Modified to popup existing DIV sections, and trimmed away the plugin
//   framework as well as the rendering code.  Reduced code to half its
//   original size.  Finally removed the onload check because we only have
//   one module, and the onload event is having conflicts with other page
//   load events
//
//   Brian Leung                          Date: 2004/08/11
//\/////

////////
// PRE-INIT: Ignore these lines, configuration is below.
////////
var pmStart = 10000000; var pmUpper = 10001000; var pmCount = pmStart+1;  var pms = new Array();
var olHideForm=0;  // parameter for hiding SELECT and ActiveX elements in IE5.5+ 
registerCommands('div,donothing,sticky,noclose,left,right,center,offsetx,offsety,width,status,height,snapx,snapy,fixx,fixy,relx,rely,above,below,timeout,delay,hauto,vauto,followmouse,mouseoff');

////////
// DEFAULT CONFIGURATION: Settings you want everywhere are set here. All of this can also be changed on your html page or through an overLIB call.
////////
if (typeof ol_div == 'undefined') var ol_div="";
if (typeof ol_width=='undefined') var ol_width="200";
if (typeof ol_offsetx=='undefined') var ol_offsetx=10;
if (typeof ol_offsety=='undefined') var ol_offsety=10;
if (typeof ol_sticky=='undefined') var ol_sticky=0;
if (typeof ol_close=='undefined') var ol_close="Close";
if (typeof ol_hpos=='undefined') var ol_hpos=RIGHT;
if (typeof ol_status=='undefined') var ol_status="";
if (typeof ol_height=='undefined') var ol_height=-1;
if (typeof ol_snapx=='undefined') var ol_snapx=0;
if (typeof ol_snapy=='undefined') var ol_snapy=0;
if (typeof ol_fixx=='undefined') var ol_fixx=-1;
if (typeof ol_fixy=='undefined') var ol_fixy=-1;
if (typeof ol_relx=='undefined') var ol_relx=null;
if (typeof ol_rely=='undefined') var ol_rely=null;
if (typeof ol_vpos=='undefined') var ol_vpos=BELOW;
if (typeof ol_aboveheight=='undefined') var ol_aboveheight=0;
if (typeof ol_frame=='undefined') var ol_frame=self;
if (typeof ol_timeout=='undefined') var ol_timeout=0;
if (typeof ol_delay=='undefined') var ol_delay=0;
if (typeof ol_hauto=='undefined') var ol_hauto=0;
if (typeof ol_vauto=='undefined') var ol_vauto=0;
if (typeof ol_followmouse=='undefined') var ol_followmouse=0;
if (typeof ol_mouseoff=='undefined') var ol_mouseoff=0;

////////
// INIT
////////
// Runtime variables init. Don't change for config!
var o3_div="";
var o3_sticky=0;
var o3_close="Close";
var o3_hpos=RIGHT;
var o3_offsetx=2;
var o3_offsety=2;
var o3_width=100;
var o3_status="";
var o3_height=-1;
var o3_snapx=0;
var o3_snapy=0;
var o3_fixx=-1;
var o3_fixy=-1;
var o3_relx=null;
var o3_rely=null;
var o3_vpos=BELOW;
var o3_aboveheight=0;
var o3_frame=self;
var o3_timeout=0;
var o3_timerid=0;
var o3_allowmove=0;
var o3_delay=0;
var o3_delayid=0;
var o3_hauto=0;
var o3_vauto=0;
var o3_followmouse=1;
var o3_mouseoff=0;

// Display state variables
var o3_x = 0;
var o3_y = 0;
var o3_showingsticky = 0;
var o3_removecounter = 0;

// Our layer
var over = null;
var olIframe = null;
var hoveringSwitch = false;
var olHideDelay;

// Decide browser version
var olMac = (navigator.userAgent.indexOf("Mac") != -1);
var olOp = (navigator.userAgent.toLowerCase().indexOf('opera') > -1 && document.createTextNode);  // Opera 7
var olNs4 = (navigator.appName=='Netscape' && parseInt(navigator.appVersion) == 4);
var olNs6 = (document.getElementById) ? true : false;
var olKq = (olNs6 && /konqueror/i.test(navigator.userAgent));
var olIe4 = (document.all) ? true : false;
var olIe5 = false; 
var olIe55 = false; // Added additional variable to identify IE5.5+
var docRoot = 'document.body';

// Resize fix for NS4.x to keep track of layer
if (olNs4) {
	var oW = window.innerWidth;
	var oH = window.innerHeight;
	window.onresize = function() { if (oW != window.innerWidth || oH != window.innerHeight) location.reload(); }
}

// Microsoft Stupidity Check(tm).
if (olIe4) {
	var agent = navigator.userAgent;
	if (/MSIE/.test(agent)) {
		var versNum = parseFloat(agent.match(/MSIE (\d\.\d+)\.*/i)[1]);
		if (versNum >= 5){
			olIe5=true;
			olIe55=(versNum>=5.5&&!olOp) ? true : false;
			if (olNs6) olNs6=false;
		}
	}
	if (olNs6) olIe4 = false;
}

// Check for compatability mode.
if (document.compatMode && document.compatMode == 'CSS1Compat') {
	docRoot= ((olIe4 && !olOp) ? 'document.documentElement' : docRoot);
}

// Capture events, alt. diffuses the overlib function.
var olCheckMouseCapture = true;
if ((olNs4 || olNs6 || olIe4)) {
	olMouseCapture();
} else {
	overlib = no_overlib;
	nd = no_overlib;
	ver3fix = true;
}

////////
// PUBLIC FUNCTIONS
////////

// overlib(arg0,...,argN)
// Loads parameters into global runtime variables.
function overlib() {
	if (olCheckMouseCapture) olMouseCapture();
	if (over) cClick();

	// Load defaults to runtime.
  olHideDelay=0;
	o3_div=ol_div;
	o3_sticky=ol_sticky;
	o3_close=ol_close;
	o3_hpos=ol_hpos;
	o3_offsetx=ol_offsetx;
	o3_offsety=ol_offsety;
	o3_width=ol_width;
	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_relx=ol_relx;
	o3_rely=ol_rely;
	o3_vpos=ol_vpos;
	o3_aboveheight=ol_aboveheight;
	o3_timeout=ol_timeout;
	o3_delay=ol_delay;
	o3_hauto=ol_hauto;
	o3_vauto=ol_vauto;
	o3_followmouse=ol_followmouse;
	o3_mouseoff=ol_mouseoff;
	
	// Special for frame support, over must be reset...
	o3_frame = ol_frame;

	parseTokens('o3_', overlib.arguments);
	
	if (olNs4) { over = o3_frame.document.layers[o3_div]; } 
	else if (document.all) { over = o3_frame.document.all[o3_div]; } 
	else if (document.getElementById) { over = o3_frame.document.getElementById(o3_div); }

    if (olIframe == null && olIe4)
    {
        olIframe = document.createElement("<iframe scrolling='no' frameborder='0' style='position:absolute;top:0px;left:0px;height:1px;width:1px;visibility:hidden;z-index:100'></iframe>");
        document.body.appendChild(olIframe);
    }

    if (over != null)
    {
        over.parentNode.removeChild(over);
        document.forms[0].appendChild(over);
                
	    if (o3_delay == 0) {
		    return olMain();
 	    } else {
		    o3_delayid = setTimeout("olMain()", o3_delay);
		    return false;
	    }
	}
}

// Clears popups if appropriate
function nd(time) {
	hideDelay(time);  // delay popup close if time specified
		
	if (o3_removecounter >= 1) { o3_showingsticky = 0 };
	
	if (o3_showingsticky == 0) {
		o3_allowmove = 0;
		if (over != null && o3_timerid == 0) hideObject(over);
	} else {
		o3_removecounter++;
	}
	
	return true;
}

// The Close onMouseOver function for stickies
function cClick() {
	hideObject(over);
	o3_showingsticky = 0;
	return false;
}

// Method for setting page specific defaults.
function overlib_pagedefaults() {
	parseTokens('ol_', overlib_pagedefaults.arguments);
}

////////
// OVERLIB MAIN FUNCTION
////////

// This function decides what it is we want to display and how we want it done.
function olMain() {
	var styleType;

	// We want it to stick!
	if (o3_sticky) {
		if (o3_timerid > 0) {
			clearTimeout(o3_timerid);
			o3_timerid = 0;
		}
		o3_showingsticky = 1;
		o3_removecounter = 0;
	}

	// Created a separate routine to generate the popup to make it easier
	// to implement a plugin capability
	if (!createPopup()) return false;

	// When placing the layer the first time, even stickies may be moved.
	o3_allowmove = 0;

	// Initiate a timer for timeout
	if (o3_timeout > 0) {          
		if (o3_timerid > 0) clearTimeout(o3_timerid);
		o3_timerid = setTimeout("cClick()", o3_timeout);
	}
	
	// Show layer
	disp(o3_status);
	
	if (o3_status != '') { return true; } else { return; }
}

////////
// HANDLING FUNCTIONS
////////
var olShowId=-1;

// Displays the popup
function disp(statustext) {	
	if (o3_allowmove == 0) {
		placeLayer();
		(olNs6&&olShowId<0) ? olShowId=showObject(over) : showObject(over);
		o3_allowmove = (o3_sticky || o3_followmouse==0) ? 0 : 1;
	}
	if (statustext != "") self.status = statustext;
}

// Creates the actual popup structure
function createPopup(){
	var theObj=(olNs4 ? over : over.style);
	theObj.width = '';
	theObj.height = '';
	if (theObj.overflow) theObj.overflow = 'visible';
	
	if (!(olNs4 || olOp)) {
		if (olNs6) {
			repositionTo(over, -(over.offsetLeft+over.offsetWidth), (olIe4) ? eval('o3_frame.'+docRoot+'.scrollTop') : o3_frame.pageYOffset);
		}
	}
	
	// set o3_width for placeLayer() routine always
	o3_width=(olNs4 ? over.clip.width : over.offsetWidth);
	return true;
}

// Decides where we want the popup.
function placeLayer() {
	var placeX, placeY, widthFix = 0;
	
	// HORIZONTAL PLACEMENT, re-arranged to work in Safari
	if (o3_frame.innerWidth) widthFix=18; 
	iwidth = windowWidth();

	// Horizontal scroll offset
	winoffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollLeft') : o3_frame.pageXOffset;
	
	placeX = horizontalPlacement(iwidth,winoffset,widthFix);

	// VERTICAL PLACEMENT, re-arranged to work in Safari
	if (o3_frame.innerHeight) {
		iheight=o3_frame.innerHeight;
	} else if (eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientHeight=='number'")&&eval('o3_frame.'+docRoot+'.clientHeight')) { 
		iheight=eval('o3_frame.'+docRoot+'.clientHeight');
	}			

	// Vertical scroll offset
	scrolloffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollTop') : o3_frame.pageYOffset;
	placeY = verticalPlacement(iheight,scrolloffset);

	// Actually move the object.
	repositionTo(over, placeX, placeY);
}

// Moves the layer
function olMouseMove(e) {
	var e = (e) ? e : event;

	if (e.pageX) {
		o3_x = e.pageX;
		o3_y = e.pageY;
	} else if (e.clientX) {
		o3_x = eval('e.clientX+o3_frame.'+docRoot+'.scrollLeft');
		o3_y = eval('e.clientY+o3_frame.'+docRoot+'.scrollTop');
	}
	
	if (o3_allowmove == 1) placeLayer();

	// MouseOut handler
	if (hoveringSwitch && !olNs4 && cursorOff()) {
		(olHideDelay ? hideDelay(olHideDelay) : cClick());
		hoveringSwitch = !hoveringSwitch;
	}
}

// When showing a sticky popup, allow closing the popup by clicking outside it
function olMouseClick()
{
    if ((o3_removecounter >= 1) && o3_showingsticky && cursorOff()) cClick();
}

// Fake function for 3.0 users.
function no_overlib() { return ver3fix; }

// Capture the mouse and chain other scripts.
function olMouseCapture() {
	var capExtent = (!olIe4 && window.onmousemove) ? window : document;
	var oldOnmousemove = capExtent.onmousemove ? capExtent.onmousemove : new Function;
	capExtent.onmousemove = function (e)
	{
		olMouseMove(e)
		oldOnmousemove(e);
	}
    var oldOnclick = capExtent.onclick? capExtent.onclick : new Function;
	capExtent.onclick = function()
	{
	    olMouseClick()
	    oldOnclick();
	}
	if (olNs4) capExtent.captureEvents(Event.MOUSEMOVE | Event.CLICK);
	olCheckMouseCapture = false;
}

////////
// PARSING FUNCTIONS
////////

// Does the actual command parsing.
function parseTokens(pf, ar) {
	var par = (pf != 'ol_');

	for (i = 0; i < ar.length; i++) {
		// Note: NS4 doesn't like switch cases with vars.
		if (ar[i] >= pmCount || ar[i]==DONOTHING) { continue; }
		if (ar[i]==DIV) { eval(pf+"div='"+ar[++i]+"'"); continue; }
		if (ar[i]==STICKY) { if (pf!='ol_') eval(pf+'sticky=1'); continue; }
		if (ar[i]==NOCLOSE) { if (pf!='ol_') opt_NOCLOSE(); continue; }
		if (ar[i]==CENTER || ar[i]==LEFT || ar[i]==RIGHT) { eval(pf+'hpos='+ar[i]); continue; }
		if (ar[i]==OFFSETX) { eval(pf+'offsetx='+ar[++i]); continue; }
		if (ar[i]==OFFSETY) { eval(pf+'offsety='+ar[++i]); continue; }
		if (ar[i]==WIDTH) { eval(pf+'width='+ar[++i]); continue; }
		if (ar[i]==STATUS) { eval(pf+"status='"+escSglQuote(ar[++i])+"'"); continue; }
		if (ar[i]==HEIGHT) { eval(pf+'height='+pf+'aboveheight='+ar[++i]); continue; } // Same param again.
		if (ar[i]==SNAPX) { eval(pf+'snapx='+ar[++i]); continue; }
		if (ar[i]==SNAPY) { eval(pf+'snapy='+ar[++i]); continue; }
		if (ar[i]==FIXX) { eval(pf+'fixx='+ar[++i]); continue; }
		if (ar[i]==FIXY) { eval(pf+'fixy='+ar[++i]); continue; }
		if (ar[i]==RELX) { eval(pf+'relx='+ar[++i]); continue; }
		if (ar[i]==RELY) { eval(pf+'rely='+ar[++i]); continue; }
		if (ar[i]==BELOW || ar[i]==ABOVE) { eval(pf+'vpos='+ar[i]); continue; }
		if (ar[i]==TIMEOUT) { eval(pf+'timeout='+ar[++i]); continue; }
		if (ar[i]==DELAY) { eval(pf+'delay='+ar[++i]); continue; }
		if (ar[i]==HAUTO) { eval(pf+'hauto=('+pf+'hauto == 0) ? 1 : 0'); continue; }
		if (ar[i]==VAUTO) { eval(pf+'vauto=('+pf+'vauto == 0) ? 1 : 0'); continue; }
		if (ar[i]==FOLLOWMOUSE) { eval(pf +'followmouse=('+pf+'followmouse == 1) ? 0 : 1'); continue; }
		if (ar[i]==MOUSEOFF) { eval(pf +'mouseoff=('+pf+'mouseoff==0) ? 1 : 0'); v=ar[i+1]; if (pf != 'ol_' && eval(pf+'mouseoff') && typeof v == 'number' && (v < pmStart || v > pmUpper)) olHideDelay=ar[++i]; continue; }
	}
	
	if (pf == 'o3_') {
		o3_width = 0;
	}
	if ((pf == 'o3_') && o3_sticky) {
		if (!o3_close && (o3_frame != ol_frame)) o3_close = ol_close;
		if (o3_mouseoff && (o3_frame == ol_frame)) opt_NOCLOSE(' ');
	}
}

////////
// LAYER FUNCTIONS
////////

// Make an object visible
function showObject(obj) {
	var theObj=(olNs4 ? obj : obj.style);
	theObj.visibility = 'visible';
	
	if (olIframe != null)
	{
	    olIframe.style.top = obj.style.top;
	    olIframe.style.left = obj.style.left;
	    olIframe.style.width = obj.offsetWidth;
	    olIframe.style.height = obj.offsetHeight;
	    olIframe.style.zIndex = obj.style.zIndex - 1;
	    olIframe.style.visibility = 'visible';
	}
}

// Hides an object
function hideObject(obj) {
	var theObj=(olNs4 ? obj : obj.style);
	if (olNs6 && olShowId>0) { clearTimeout(olShowId); olShowId=0; }
	theObj.visibility = 'hidden';
	theObj.width = '10px';
	theObj.height = '10px';
	if (theObj.overflow) theObj.overflow = 'hidden';

	if (o3_timerid > 0) clearTimeout(o3_timerid);
	if (o3_delayid > 0) clearTimeout(o3_delayid);

	o3_timerid = 0;
	o3_delayid = 0;
	self.status = "";

	if (obj.onmouseout || obj.onmouseover) {
		if (olNs4) obj.releaseEvents(Event.MOUSEOUT || Event.MOUSEOVER || Event.CLICK);
		obj.onmouseout = obj.onmouseover = null;
	}
	
	if (olIframe != null)
	{
	    olIframe.style.visibility = 'hidden';
	    olIframe.style.top = '0px';
	    olIframe.style.left = '0px';
	    olIframe.style.width = '1px';
	    olIframe.style.height = '1px';
	}
}

// Move a layer
function repositionTo(obj, xL, yL) {
	var theObj=(olNs4 ? obj : obj.style);
	theObj.left = xL + (!olNs4 ? 'px' : 0);
	theObj.top = yL + (!olNs4 ? 'px' : 0);
}

// Check position of cursor relative to overDiv DIVision; mouseOut function
function cursorOff() {
	var left = parseInt(over.style.left);
	var top = parseInt(over.style.top);
	var right = left + (over.offsetWidth >= parseInt(o3_width) ? over.offsetWidth : parseInt(o3_width));
	var bottom = top + (over.offsetHeight >= o3_aboveheight ? over.offsetHeight : o3_aboveheight);

	return (o3_x < left || o3_x > right || o3_y < top || o3_y > bottom);
}

////////
// COMMAND FUNCTIONS
////////

// Handle hovering
function opt_NOCLOSE(unused) {
	if (!unused) o3_close = "";

	if (olNs4) {
		over.captureEvents(Event.MOUSEOUT || Event.MOUSEOVER);
		over.onmouseover = function () { if (o3_timerid > 0) { clearTimeout(o3_timerid); o3_timerid = 0; } }
		over.onmouseout = function (e) { if (olHideDelay) hideDelay(olHideDelay); else cClick(e); }
	} else {
		over.onmouseover = function () {hoveringSwitch = true; if (o3_timerid > 0) { clearTimeout(o3_timerid); o3_timerid =0; } }
	}

	return 0;
}

// Escape embedded single quotes in text strings
function escSglQuote(str) {
    return str.toString().replace(/'/g,"\\'");
}

// function will delay close by time milliseconds
function hideDelay(time) {
	if (time&&!o3_delay) {
		if (o3_timerid > 0) clearTimeout(o3_timerid);

		o3_timerid=setTimeout("cClick()",(o3_timeout=time));
	}
}

// Was originally in the placeLayer() routine; separated out for future ease
function horizontalPlacement(browserWidth, horizontalScrollAmount, widthFix) {
	var placeX, iwidth=browserWidth, winoffset=horizontalScrollAmount;
	var parsedWidth = parseInt(o3_width);

	if (o3_fixx > -1 || o3_relx != null) {
		// Fixed position
		placeX=(o3_relx != null ? ( o3_relx < 0 ? winoffset +o3_relx+ iwidth - parsedWidth - widthFix : winoffset+o3_relx) : o3_fixx);
	} else {  
		// If HAUTO, decide what to use.
		if (o3_hauto == 1) {
			if ((o3_x - winoffset) > (iwidth / 2)) {
				o3_hpos = LEFT;
			} else {
				o3_hpos = RIGHT;
			}
		}  		

		// From mouse
		if (o3_hpos == CENTER) { // Center
			placeX = o3_x+o3_offsetx-(parsedWidth/2);

			if (placeX < winoffset) placeX = winoffset;
		}

		if (o3_hpos == RIGHT) { // Right
			placeX = o3_x+o3_offsetx;

			if ((placeX+parsedWidth) > (winoffset+iwidth - widthFix)) {
				placeX = iwidth+winoffset - parsedWidth - widthFix;
				if (placeX < 0) placeX = 0;
			}
		}
		if (o3_hpos == LEFT) { // Left
			placeX = o3_x-o3_offsetx-parsedWidth;
			if (placeX < winoffset) placeX = winoffset;
		}  	

		// 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);
			}

			if (placeX < winoffset) placeX = winoffset;
		}
	}	

	return placeX;
}

// was originally in the placeLayer() routine; separated out for future ease
function verticalPlacement(browserHeight,verticalScrollAmount) {
	var placeY, iheight=browserHeight, scrolloffset=verticalScrollAmount;
	var parsedHeight=(o3_aboveheight ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight));

	if (o3_fixy > -1 || o3_rely != null) {
		// Fixed position
		placeY=(o3_rely != null ? (o3_rely < 0 ? scrolloffset+o3_rely+iheight - parsedHeight : scrolloffset+o3_rely) : o3_fixy);
	} else {
		// If VAUTO, decide what to use.
		if (o3_vauto == 1) {
			if ((o3_y - scrolloffset) > (iheight / 2) && o3_vpos == BELOW && (o3_y + parsedHeight + o3_offsety - (scrolloffset + iheight) > 0)) {
				o3_vpos = ABOVE;
			} else if (o3_vpos == ABOVE && (o3_y - (parsedHeight + o3_offsety) - scrolloffset < 0)) {
				o3_vpos = BELOW;
			}
		}

		// From mouse
		if (o3_vpos == ABOVE) {
			if (o3_aboveheight == 0) o3_aboveheight = parsedHeight; 

			placeY = o3_y - (o3_aboveheight+o3_offsety);
			if (placeY < scrolloffset) placeY = scrolloffset;
		} 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);
			} 			

			if (placeY < scrolloffset) placeY = scrolloffset;
		}
	}

	return placeY;
}

// get Browser window width
function windowWidth() {
	var w;
	if (o3_frame.innerWidth) w=o3_frame.innerWidth;
	else if (eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientWidth=='number'")&&eval('o3_frame.'+docRoot+'.clientWidth')) 
		w=eval('o3_frame.'+docRoot+'.clientWidth');
	return w;			
}

// Registers commands and creates constants.
function registerCommands(cmdStr) {
	if (typeof cmdStr!='string') return;

	var pM = cmdStr.split(',');
	pms = pms.concat(pM);

	for (var i = 0; i< pM.length; i++) {
		eval(pM[i].toUpperCase()+'='+pmCount++);
	}
}
