var n = 0;
var ie = 0;
var activeMenu = 0;

if (document.layers) n = 1;
if (document.all) ie = 1;

var layerRef = (n) ? "document" : "document.all";
var styleRef = (n) ? "" : ".style";

function imgmenuOn(imgName) {
	if ((n) || (ie)) document[imgName].src = eval(imgName + "On.src");
}

function imgmenuOff(imgName) {
	if ((n) || (ie)) document[imgName].src = eval(imgName + "Off.src");
}

function activateMenu(menuLayer,verticalPosition) {

	if (((n) || (ie)) && (activeMenu != menuLayer)) {
		if (activeMenu) hideMenu("menu" + activeMenu);
		menuID = "menu" + menuLayer;
		activeMenu = menuLayer;

		if (n) {
			document[menuID].left = 116;
			document[menuID].top = verticalPosition;
		}

		if (ie) {
			document.all[menuID].style.pixelLeft = 116;
			document.all[menuID].style.pixelTop = verticalPosition;
		}		

		showMenu(menuID)
   	}

	if (ie) window.event.cancelBubble = true;
}

function showMenu(layerID) {
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.visibility = "visible"');
	document["img" + layerID].src = eval("img" + layerID + "On.src");
}

function hideMenu(layerID) {
	eval(layerRef + '["' + layerID + '"]' + styleRef + '.visibility = "hidden"');
	document["img" + layerID].src = eval("img" + layerID + "Off.src");
}

function killMenu(e) {

	if (activeMenu) {
		menuID = "menu" + activeMenu;

		if (n) {
			menuX1 = document[menuID].left;
            menuX2 = menuX1 + document[menuID].clip.right;
			menuY1 = document[menuID].top;
			menuY2 = menuY1 + document[menuID].clip.bottom;
					
			if ((e.pageX > menuX2 || e.pageY < menuY1 || e.pageY > menuY2)
				|| (e.pageX < menuX1 && e.pageY > menuY1 + 33)) {
				hideMenu(menuID);
				activeMenu = 0;
			}
		}

		if (ie) {
			hideMenu(menuID);
			activeMenu = 0;
		}
	}  
}

function init() {
	if (n) {
		document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = killMenu;
	}

	if (ie) {
		document.onmouseover = killMenu;
	}
}

function getCookie(name) {
	if ((n) || (ie)) {
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
	
		if (begin == -1) { 
			begin = dc.indexOf(prefix);
			if (begin != 0) return null;
		}
		
		else {
			begin += 2;
		}
		
		var end = dc.indexOf(";", begin);
		if (end == -1) end = dc.length;
		return unescape(dc.substring(begin + prefix.length, end));
	}
}		

function setCookie(name,value) {
	if ((n) || (ie)) {
		var curCookie = name + "=" + escape(value);
		document.cookie = curCookie;	
	}
}

if ((n) || (ie)) {
	var ftcSite = "http://www.fundthecure.org";
	var ftcURL = "/support/ftconline.html";
	var ftcString = "On-line Donations";
	var iabURL = "/support/online.html";
	var iabString = "On-line Donations";

	var ftcSnailURL = "/support/ftcoffline.html";
	var ftcSnailString = "Off-line Donations";
	var iabSnailURL = "/support/offline.html";
	var iabSnailString = "Off-line Donations";
	
	if (getCookie("ref") == "ftc") {
		donateURL = ftcURL;
		donateString = ftcString;
		donateSnailURL = ftcSnailURL;
		donateSnailString = ftcSnailString;
	}
	
	else if (getCookie("ref") == "iab") {
		donateURL = iabURL;
		donateString = iabString;
		donateSnailURL = iabSnailURL;
		donateSnailString = iabSnailString;
	}
	
	else {
		var referrer = document.referrer
		if ((referrer.search("fundthecure") != -1) || (referrer.search("gay.com") != -1)) {
			setCookie("ref","ftc");
			donateURL = ftcURL;
			donateString = ftcString;
			donateSnailURL = ftcSnailURL;
			donateSnailString = ftcSnailString;
		}
		
		else {
			setCookie("ref","iab");
			donateURL = iabURL;
			donateString = iabString;
			donateSnailURL = iabSnailURL;
			donateSnailString = iabSnailString;
		}
	}
}
