var o3_frame = self;
var o3_sticky = 0;

// Display state variables
var o3_x = 0;
var o3_y = 0;
var o3_allowmove = 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;

// Microsoft Stupidity Check(tm).
if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		if(document.compatMode && document.compatMode == 'CSS1Compat') docRoot = 'document.documentElement';
		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;
}


// Loads parameters into global runtime variables.
function overlib(cadre) {
	
	// Load defaults to runtime.

	// Special for frame support, over must be reset...
	if ( (ns4) || (ie4) || (ns6) ) {
		if (over) cClick();
		o3_frame = self;
		if (ns4) over = o3_frame.document.overDiv
		if (ie4) over = o3_frame[cadre].style
		if (ns6) over = o3_frame.document.getElementById(cadre);
	}
	
	// What the next argument is expected to be.
	var parsemode = -1;

	for (i = 0; i < arguments.length; i++) {
		
		o3_text = arguments[i];
		parsemode = 0;
	}
	
	return overlib310(cadre);
}



// Clears popups if appropriate
function nd() {
	if ( o3_removecounter >= 1 ) { o3_showingsticky = 0 };
	if ( (ns4) || (ie4) || (ns6) ) {
		if ( o3_showingsticky == 0 ) {
			o3_allowmove = 0;
			if (over != null) hideObject(over);
		} else {
			o3_removecounter++;
		}
	}
	
	return true;
}


////////////////////////////////////////////////////////////////////////////////////
// OVERLIB 3.10 FUNCTION
////////////////////////////////////////////////////////////////////////////////////


// This function decides what it is we want to display and how we want it done.
function overlib310() {

	// Make layer content
	//var layerhtml;
	
	
	//layerhtml = ol_content_simple(o3_text);
	
	// We want it to stick!
	if (o3_sticky) {
		o3_showingsticky = 1;
		o3_removecounter = 0;
	}
	
	// Write layer
	//layerWrite(layerhtml);
	
	// Prepare status bar
	o3_status = o3_text;

	// When placing the layer the first time, even stickies may be moved.
	o3_allowmove = 0;

	// Show layer
	disp(o3_status);

	// Stickies should stay where they are.	
	if (o3_sticky) {
		o3_allowmove = 0;
		return false;
	} else {
		return true;
	}
}

////////////////////////////////////////////////////////////////////////////////////
// LAYER GENERATION FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////

// Makes simple table without caption
function ol_content_simple(text) {
	txt = "<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=0><TR><TD bgcolor=#999999><TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=0><TR><TD VALIGN=TOP bgcolor=#FFFFFF><FONT FACE=\"Verdana, Arial, Helvetica, sans-serif\" COLOR=\"#999999\" SIZE=\"1\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>"
	return txt;
}

////////////////////////////////////////////////////////////////////////////////////
// LAYER FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////


/* 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 (obj != null) {
	if (ns4) obj.visibility = "hide";
	else if (ie4) obj.visibility = "hidden";
	else if (ns6) obj.style.visibility = "hidden";

	self.status = "";
   }
}

// Move a layer
function moveTo(obj,xL,yL) {
	if ( (ns4) || (ie4) ) {
		obj.left = (ie4 ? xL + 'px' : xL);
		obj.top = (ie4 ? yL + 'px' : yL);
	} else if (ns6) {
		obj.style.left = xL + "px";
		obj.style.top = yL+ "px";
	}
}


////////////////////////////////////////////////////////////////////////////////////
// HANDLING FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////


// 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;
	
	// HORIZONTAL PLACEMENT
	placeX = o3_x + 12;
	placeY = o3_y - 2;

	// 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) {
		placeLayer();
	}
}

// The Close onMouseOver function for stickies
function cClick() {
	hideObject(over);
	o3_showingsticky=0;
}
