//\//////////////////////////////////////////////////////////////////////////////////
//\  overLIB 3.50  --  This notice must remain untouched at all times.
//\  Copyright Erik Bosrup 1998-2001. All rights reserved.
//\
//\  By Erik Bosrup (erik@bosrup.com).  Last modified 2001-08-28.
//\  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 regarding 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.
//\//////////////////////////////////////////////////////////////////////////////////
//\mini

var INARRAY		=	1;
var CAPARRAY		=	2;
var NOCLOSE		=	5;
var CAPTION		=	6;
var LEFT		=	7;
var RIGHT		=	8;
var CENTER		=	9;
var WIDTH		=	17;
var BORDER		=	18;
var STATUS		=	19;
var AUTOSTATUS		=	20;
var AUTOSTATUSCAP	=	21;
var HEIGHT		=	22;
var CLOSETEXT		=	23;
var FIXX		=	26;
var FIXY		=	27;
var CSSOFF		=	51;
var CSSSTYLE		=	52;

// Main background color (the large area)
var ol_fgcolor = "#CCCCFF";

// Border color and color of caption
var ol_bgcolor = "#333399";

// Text color
var ol_textcolor = "#000000";

// Color of the caption text
var ol_capcolor = "#FFFFFF";

// Color of "Close" when using Sticky
// Usually a semi-bright color
var ol_closecolor = "#9999FF";

// Font face for the main text
var ol_textfont = "Verdana,Arial,Helvetica";

// Font face for the caption
var ol_captionfont = "Verdana,Arial,Helvetica";

// Font face for the close text
var ol_closefont = "Verdana,Arial,Helvetica";

// Width of the popups in pixels
// 100-300 pixels is typical
var ol_width = "200";

// How many pixels to the right/left of the cursor to show the popup
// Values between 3 and 12 are best
var ol_offsetx = 10;

// How many pixels to the below the cursor to show the popup
// Values between 3 and 12 are best
if (typeof ol_offsety == 'undefined') { var ol_offsety = 10;}

// Default text for popups
// Should you forget to pass something to overLIB this will be displayed.
if (typeof ol_text == 'undefined') { var ol_text = "Default Text"; }

// Text for the closing sticky popups.
// Normal is "Close".
if (typeof ol_close == 'undefined') { var ol_close = "Close"; }

// Default status bar text when a popup is invoked.
if (typeof ol_status == 'undefined') { var ol_status = ""; }

// If the status bar automatically should load either text or caption.
// 0=nothing, 1=text, 2=caption
if (typeof ol_autostatus == 'undefined') { var ol_autostatus = 0; }

// Default frame. We default to current frame if there is no frame defined.
if (typeof ol_frame == 'undefined') { var ol_frame = self; }

// Array with texts.
if (typeof ol_texts == 'undefined') { var ol_texts = new Array("Text 0", "Text 1"); }

// Array with captions.
if (typeof ol_caps == 'undefined') { var ol_caps = new Array("Caption 0", "Caption 1"); }


// Runtime variables init. Used for runtime only, don't change, not for config!
var o3_text = "";
var o3_close = "Close";
var o3_offsetx = 2;
var o3_offsety = 2;
var o3_fgcolor = "";
var o3_bgcolor = "";
var o3_textcolor = "";
var o3_capcolor = "";
var o3_closecolor = "";
var o3_width = 100;
var o3_status = "";
var o3_autostatus = 0;
var o3_textfont = "Verdana,Arial,Helvetica";
var o3_captionfont = "Verdana,Arial,Helvetica";
var o3_closefont = "Verdana,Arial,Helvetica";
var o3_textsize = "1";
var o3_captionsize = "1";
var o3_closesize = "1";
var o3_frame = self;
var o3_allowmove = 0;

// Display state variables
var o3_x = 0;
var o3_y = 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;

// Microsoft Stupidity Check(tm).
if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		ie5 = true;
	}
	if (ns6) {
		ns6 = false;
	}
}


// Capture events, alt. diffuses the overlib function.
if ( (ns4) || (ie4) || (ns6)) {
	document.onmousemove = mouseMove
	if (ns4) document.captureEvents(Event.MOUSEMOVE)
} else {
	overlib = no_overlib;
	nd = no_overlib;
	ver3fix = true;
}


// Fake function for 3.0 users.
function no_overlib() {
	return ver3fix;
}

// overlib(arg0, ..., argN)
// Loads parameters into global runtime variables.
function overlib() {
	// Load defaults to runtime.
	o3_text = ol_text;
	o3_close = ol_close;
	o3_offsetx = ol_offsetx;
	o3_offsety = ol_offsety;
	o3_fgcolor = ol_fgcolor;
	o3_bgcolor = ol_bgcolor;
	o3_textcolor = ol_textcolor;
	o3_capcolor = ol_capcolor;
	o3_closecolor = ol_closecolor;
	o3_width = ol_width;
	o3_status = ol_status;
	o3_autostatus = ol_autostatus;
	o3_textfont = ol_textfont;
	o3_captionfont = ol_captionfont;
	o3_closefont = ol_closefont;
	o3_textsize = 1;
	o3_captionsize = 1;
	o3_closesize = "1";

	// Special for frame support, over must be reset...
	if ( (ns4) || (ie4) || (ns6) ) {
		o3_frame = ol_frame;
		if (ns4) over = o3_frame.document.overDiv
		if (ie4) over = o3_frame.overDiv.style
		if (ns6) over = o3_frame.document.getElementById("overDiv");
	}

	// What the next argument is expected to be.
	var parsemode = -1;
	var ar = arguments;

	for (i = 0; i < ar.length; i++) {

		if (parsemode < 0) {
			// Arg is maintext, unless INARRAY
			if (ar[i] == INARRAY) {
				o3_text = ol_texts[ar[++i]];
			} else {
				o3_text = ar[i];
			}

			parsemode = 0;
		} else {
			// Note: NS4 doesn't like switch cases with vars.
			if (ar[i] == INARRAY) { o3_text = ol_texts[ar[++i]]; continue; }
			if (ar[i] == NOCLOSE) { o3_close = ""; continue; }
			if (ar[i] == WIDTH) { o3_width = ar[++i]; continue; }
			if (ar[i] == STATUS) { o3_status = ar[++i]; continue; }
			if (ar[i] == AUTOSTATUS) { o3_autostatus = 1; continue; }
			if (ar[i] == AUTOSTATUSCAP) { o3_autostatus = 2; continue; }
			if (ar[i] == CLOSETEXT) { o3_close = ar[++i]; continue; }
		}
	}

	return overlib350();
}

// Clears popups if appropriate
function nd() {
	if ( (ns4) || (ie4) || (ns6) ) {
		o3_allowmove = 0;
		if (over != null) hideObject(over);
	}
	return true;
}

// This function decides what it is we want to display and how we want it done.
function overlib350() {

	// Make layer content
	var layerhtml;

	// They want a popup box.

	// Prepare popup colors
	o3_fgcolor = "BGCOLOR=\""+o3_fgcolor+"\"";
	o3_bgcolor = "BGCOLOR=\""+o3_bgcolor+"\"";

	layerhtml = "<TABLE WIDTH="+o3_width+" BORDER=0 CELLPADDING=1 CELLSPACING=0 "+o3_bgcolor+"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 "+o3_fgcolor+"><TR><TD VALIGN=TOP><FONT FACE=\""+o3_textfont+"\" COLOR=\""+o3_textcolor+"\" SIZE=\""+o3_textsize+"\">"+o3_text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>";

	// Write layer
	layerWrite(layerhtml);

	// 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);
	return true;
}

// Displays the popup
function disp(statustext) {
	if ( (ns4) || (ie4) || (ns6) ) {
		if (o3_allowmove == 0) 	{
			placeLayer();
			showObject(over);
			o3_allowmove = 1;
		}
	}

	if (statustext != "") {
		self.status = statustext;
	}
}

// Decides where we want the popup.
function placeLayer() {
	var placeX, placeY;

	winoffset = (ie4) ? o3_frame.document.body.scrollLeft : o3_frame.pageXOffset;
	if (ie4) iwidth = o3_frame.document.body.clientWidth;
	if (ns4) iwidth = o3_frame.innerWidth; // was screwed in mozilla, fixed now?
	if (ns6) iwidth = o3_frame.outerWidth;

	// From mouse
	placeX = o3_x+o3_offsetx;
	if ( (eval(placeX) + eval(o3_width)) > (winoffset + iwidth) ) {
		placeX = iwidth + winoffset - o3_width;
		if (placeX < 0) placeX = 0;
	}

	// VERTICAL PLACEMENT
	scrolloffset = (ie4) ? o3_frame.document.body.scrollTop : o3_frame.pageYOffset;
	placeY = o3_y + o3_offsety;

	// Actually move the object.
	repositionTo(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();
	}
}

// Makes sure target frame has overLIB
function compatibleframe(frameid) {        
	if (ns4) {
		if (typeof frameid.document.overDiv =='undefined') return false;
	} else if (ie4) {
		if (typeof frameid.document.all["overDiv"] =='undefined') return false;
	} else if (ns6) {
		if (frameid.document.getElementById('overDiv') == null) return false;
	}

	return true;
}

// Writes to a layer
function layerWrite(txt) {
	txt += "\n";

        if (ns4) {
                var lyr = o3_frame.document.overDiv.document

                lyr.write(txt)
                lyr.close()
        } else if (ie4) {
		o3_frame.document.all["overDiv"].innerHTML = txt
	} else if (ns6) {
		range = o3_frame.document.createRange();
		range.setStartBefore(over);
		domfrag = range.createContextualFragment(txt);
		while (over.hasChildNodes()) {
			over.removeChild(over.lastChild);
		}
		over.appendChild(domfrag);
	}
}

// Make an object visible
function showObject(obj) {
        if (ns4) obj.visibility = "show";
        else if (ie4) obj.visibility = "visible";
	else if (ns6) obj.style.visibility = "visible";
}

// Hides an object
function hideObject(obj) {
        if (ns4) obj.visibility = "hide";
        else if (ie4) obj.visibility = "hidden";
	else if (ns6) obj.style.visibility = "hidden";
        self.status = "";
}

// Move a layer
function repositionTo(obj,xL,yL) {
	if ( (ns4) || (ie4) ) {
	        obj.left = xL;
	        obj.top = yL;
	} else if (ns6) {
		obj.style.left = xL + "px";
		obj.style.top = yL+ "px";
	}
}

