var fadeTime = 25;
var counter = 0;
var hideCounter = 50;
var menuCounter = 0;

var showing = false;
var unfading = false;

var rssShowingId = "none";
var rssHidingId = "none";
var rssShowing = false;
var rssHiding = false;
var currentShowing;

var opacityProp = (document.all) ? "filter" : "opacity";
var showInterval;
var hideInterval;
var menuInterval;
var _cvs_version = '$Id: ajaxManager.js,v 1.2 2005/12/28 14:45:32 ckeswani Exp $';

function init() {
	var theMenu = document.getElementById("rssMenu");
	theMenu.onmouseover = showSubMenu;
}

function showSubMenu() {
	if (showing == false) {
		showing = true;
		counter = 0;
		menuInterval = setInterval('unfadeMenu("rssSubMenu")',fadeTime); 
	}
}

function unfadeMenu(id) {
	if (menuCounter < 50) {
		menuCounter++;
		document.getElementById(id).style[opacityProp] = 
			(document.all) ? "alpha(opacity=" + (menuCounter) *2 + ")" : (menuCounter)*.02; 
		if(document.getElementById(id).style.visibility == "hidden" ||
			document.getElementById(id).style.visibility == "") {
			document.getElementById(id).style.visibility = "visible";
		}
	} else {
		clearInterval(menuInterval);
		menuCounter = 0;
	}
}

function unfade(id) {
	if (counter < 50) {
		counter++;
		document.getElementById(id).style[opacityProp] = 
			(document.all) ? "alpha(opacity=" + (counter) *2 + ")" : (counter)*.02; 
		if(document.getElementById(id).style.visibility == "hidden" ||
			document.getElementById(id).style.visibility == "") {
			document.getElementById(id).style.visibility = "visible";
			debug("setting ", id, " to visible");
		}
	} else {
			clearInterval(showInterval);
			document.getElementById(id).style.zIndex = 1;
			rssShowing = false;
			counter = 0;
	}
}

function fade(id) {
	if (hideCounter > 1) {
		--hideCounter;
		document.getElementById(id).style[opacityProp] = 
			(document.all) ? "alpha(opacity=" + (hideCounter) * 2 + ")" : (hideCounter)*.02; 

		//document.getElementById(id).style.opacity = (hideCounter)*.02; 
	} else {
		clearInterval(hideInterval);
		rssHiding = false;
		hideCounter = 50;	
		document.getElementById(id).style.zIndex = 10;
		document.getElementById(id).style.visibility = "hidden";
	}
}

function showRss(command, interval) {
	if (rssShowing && rssHiding) {
		return false;
	}
	rssShowing = true;
	showInterval = setInterval(command, interval);
	return true;
}

function hideRss(command, interval) {
	if (rssShowing && rssHiding) {
		return false;
	}
	rssHiding = true;
	hideInterval = setInterval(command, interval);
	return true;
}
function debug() {
    var debugField = document.getElementById('debugContent');
	if(debugField) {
	    var args = debug.arguments;
    	var text;
    	var p = document.createElement("p");
    	for (var i = 0; i < args.length; i++) {
			text = document.createTextNode(args[i] + "");
			p.appendChild(text);
		}
    	debugField.appendChild(p);
	}
}

function getHttp() {
	var x;
	if (document.getElementById) {
	    x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	}
	return x;
}

function parseXml(http,id) {
	if (http.readyState == 4 && http.status == 200) {
		if (rssShowingId == "none") {
			rssShowingId = id + "1";
			rssHidingId = id + "2";
			id = id + "1";
			currentShowing = id;
			var theDiv = document.getElementById(id);
			theDiv.innerHTML = http.responseText;
			showRss("unfade('" + id + "')",fadeTime);
		} else {
			var theDiv = document.getElementById(rssHidingId);
			theDiv.innerHTML = http.responseText;
			if (showRss("unfade('"+rssHidingId + "')", fadeTime) &&	
				hideRss("fade('"+rssShowingId + "')", fadeTime)) {
				var tmp = rssHidingId;
				rssHidingId = rssShowingId;
				rssShowingId = tmp;
			}
		}
	}
}


function ajaxManager() {
var args = ajaxManager.arguments;
switch (args[0])
    {
    case "load_page":
	var x = getHttp();
	if (x)	    {
	    x.onreadystatechange = function()
		{
		    if (x.readyState == 4 && x.status == 200)
		    {
			el = document.getElementById(args[2]);
			el.innerHTML = x.responseXML;
		    }
		}
	    x.open("GET", args[1], true);
	    x.send(null);
	}
	break;
	case "load_rss":
	var x = getHttp();
	if (x) {
			x.onreadystatechange = function() 
			{
				parseXml(x,args[2]);
			}
		    x.open("GET", args[1], true);
		    x.send(null);
	}
	break;
    case "start_up":
	var startPage = 'basic.xml'
	ajaxManager('load_page', startPage, 'ckContent');
	break;
    }
}

