var d = document;
var w = window;

var agent= navigator.userAgent.toLowerCase();
var mac = (agent.indexOf("mac")>-1)
var ie5 = (agent.indexOf("msie 5")>-1);

/*
if(ie5 && mac==true)
{
	document.write('<link rel="stylesheet" type="text/css" href="../css/screen_macie5.css" media="screen" />');
}
*/



var fcolor = "#FCFCE7";
var backcolor1 = "#ff9900";
var backcolor2 = "#3CA112";
var textcolor = "#000000";
var capcolor1a = "#A66400";
var capcolor1b = "#000000";
var capcolor2a = "#B5F19C";
var capcolor2b = "#ffffff";
var capcolor = "#000099";
var backcolor = "#ff9900";
var closecolor = "#EEDCB9";
var width = "200";
var border = "2";
var offsetx = 10;
var offsety = 0;

var x = 0;
var y = 0;
var snow = 0;
var sw = 0;
var cnt = 0;
var dir = 1;
var tr = 1;

var ns4, ie4, ie5, ns6, over;

function initTooltip(){
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false
	ns6 = (!document.all && document.getElementById)? true:false
	
	// Microsoft Stupidity Check.
	if (ie4) {
		if (navigator.userAgent.indexOf('MSIE 5')>0 || navigator.userAgent.indexOf('MSIE 6')>0) {
			ie5 = true;
		} else {
			ie5 = false; }
	} else {
		ie5 = false;
	}

	if (ns4) over = document.overDiv
	if (ie4) over = overDiv.style
	if (ns6) over = document.getElementById('overDiv').style
	document.onmousemove = mouseMove
	if (ns4) document.captureEvents(Event.MOUSEMOVE)

}


// Simple popup right
function drs(text) {
dts(1,text);
}

// Caption popup right
function drc(text, address, title, rented) {
	if (rented == 1)
	{
		dtc_1(1,text,address,title);
	}else{
		dtc_2(1,text,address,title);
	}

}

// Sticky caption right
function src(text,title) {
stc(1,text,title);
}

// Simple popup left
function dls(text) {
dts(0,text);
}

// Caption popup left
function dlc(text, title) {
dtc(0,text,title);
}

// Sticky caption left
function slc(text,title) {
stc(0,text,title);
}

// Simple popup center
function dcs(text) {
dts(2,text);
}

// Caption popup center
function dcc(text, title) {
dtc(2,text,title);
}

// Sticky caption center
function scc(text,title) {
stc(2,text,title);
}

// Clears popups if appropriate
function nd() {
	if ( cnt >= 1 ) { sw = 0 };
	if ( sw == 0 ) {
		snow = 0;
		hideObject(over);
	} else {
		cnt++;
	}
}

// Simple popup
function dts(d,text) {
	txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><FONT FACE=\"Arial,Helvetica\" COLOR=\""+textcolor+"\" SIZE=\"-2\">"+text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>"
	layerWrite(txt);
	dir = d;
	disp();
}

// Caption popup
function dtc_1(d,text,address,title) {
	txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor1+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><SPAN ID=\"PTT\"><B><FONT COLOR=\""+capcolor1a+"\">"+address+"</FONT>&nbsp;<FONT COLOR=\""+capcolor1b+"\">"+title+"</FONT></B></SPAN></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><SPAN ID=\"PST\"><FONT COLOR=\""+textcolor+"\">"+text+"</FONT><SPAN></TD></TR></TABLE></TD></TR></TABLE>"
	layerWrite(txt);
	dir = d;
	disp();
}
function dtc_2(d,text,address,title) {
	txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor2+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><SPAN ID=\"PTT\"><B><FONT COLOR=\""+capcolor2a+"\">"+address+"</FONT>&nbsp;<FONT COLOR=\""+capcolor2b+"\">"+title+"</FONT></B></SPAN></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><SPAN ID=\"PST\"><FONT COLOR=\""+textcolor+"\">"+text+"</FONT><SPAN></TD></TR></TABLE></TD></TR></TABLE>"
	layerWrite(txt);
	dir = d;
	disp();
}

// Sticky
function stc(d,text, title) {
	sw = 1;
	cnt = 0;
	txt = "<TABLE WIDTH="+width+" BORDER=0 CELLPADDING="+border+" CELLSPACING=0 BGCOLOR=\""+backcolor+"\"><TR><TD><TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD><SPAN ID=\"PTT\"><B><FONT COLOR=\""+capcolor+"\">"+title+"</FONT></B></SPAN></TD><TD ALIGN=RIGHT><A HREF=\"/\" onMouseOver=\"cClick();\" ID=\"PCL\"><FONT COLOR=\""+closecolor+"\">Close</FONT></A></TD></TR></TABLE><TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0 BGCOLOR=\""+fcolor+"\"><TR><TD><SPAN ID=\"PST\"><FONT COLOR=\""+textcolor+"\">"+text+"</FONT><SPAN></TD></TR></TABLE></TD></TR></TABLE>"
	layerWrite(txt);
	dir = d;
	disp();
	snow = 0;
}

// Common calls
function disp() {
	if (snow == 0) 	{
		if (dir == 2) { // Center
			moveTo(over,x+offsetx-(width/2),y+offsety);
		}
		if (dir == 1) { // Right
			moveTo(over,x+offsetx,y+offsety);
		}
		if (dir == 0) { // Left
			moveTo(over,x-offsetx-width,y+offsety);
		}
		showObject(over);
		snow = 1;
	}
}

// Moves the layer
function mouseMove(e) {
	if (ns4) {x=e.pageX; y=e.pageY;}
	if (ie4) {x=event.x; y=event.y;}
	if (ie5) {x=event.x+document.body.scrollLeft; y=event.y+document.body.scrollTop;}
	if (ns6) {x=e.pageX+10; y=e.pageY;}
	if (snow) {
		if (dir == 2) { // Center
			moveTo(over,x+offsetx-(width/2),y+offsety);
		}
		if (dir == 1) { // Right
			moveTo(over,x+offsetx,y+offsety);
		}
		if (dir == 0) { // Left
			moveTo(over,x-offsetx-width,y+offsety);
		}
	}
}

function cClick() {
	hideObject(over);
	sw=0;
}

function layerWrite(txt) {
    if (ns4) {
        var lyr = document.overDiv.document
        lyr.write(txt)
        lyr.close()
    }
    else if (ie4) {
		document.all["overDiv"].innerHTML = txt
	}
	else if (ns6) {
		document.getElementById("overDiv").innerHTML = txt
	}
}

function showObject(obj) {
    if (ns4) obj.visibility = "show"
    else if (ie4) obj.visibility = "visible"
	else if (ns6) obj.visibility = "visible";       
}

function hideObject(obj) {
    if (ns4) obj.visibility = "hide"
    else if (ie4) obj.visibility = "hidden"
	else if (ns6) obj.visibility = "hidden";    
}

function moveTo(obj,xL,yL) {
    obj.left = xL
    obj.top = yL
}
