function getXMLParser() {
    if (document.implementation &&
            document.implementation.createDocument) {
        return document.implementation.createDocument("","",null);
    } else if (window.ActiveXObject) {
        //return new ActiveXObject("Microsoft.XMLDOM");
    } else {
        return null;
    }
}

function getXMLHTTPRequest() {
    var xmlHttp;
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHttp");
	} catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
		} catch(e2) {
		}
	}

	if(xmlHttp == undefined && (typeof XMLHttpRequest != 'undefined')) {
		xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp;
}

function getPosition(e){
	var left = 0;
	var top  = 0;
	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
		e = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;
	return {x:left, y:top};
}

/**
*	Constructor for the class.
*
*	@constructor
*/
function NavigatorFlyer(mmItem, siblingsId) {
	this.id = mmItem.id;
	this.flyerDIV = null;
	this.item = mmItem;
	this.allItems = null;
	this.isOver = false;
	this.heightItem = 23;
	this.siblingsId = siblingsId;
	
	this._writeContainer();
}

NavigatorFlyer.prototype.show = function() {
		if (this.flyerDIV!=null) {
			this.isOver = true;
			this.flyerDIV.style.display = '';
            this.flyerDIV.style.visibility = 'visible';
		}
	}

NavigatorFlyer.prototype.showAfterUpdateItems = function() {
		if (this.flyerDIV!=null) {
			this.loadAllItems();
		}
	}

NavigatorFlyer.prototype.hide = function() {
		//alert(this.isOver);
		if (this.flyerDIV!=null && this.isOver==false) {
			this.flyerDIV.style.display = '';
            this.flyerDIV.style.visibility = 'hidden';
		}
	}

NavigatorFlyer.prototype._draw = function(nodes) {
	var content = "";
	var count = 1;
	if (nodes!=null) {
		content += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";	
		content += "<tr><td><div class=\"navigatorFlyerLight\" height=\"3\"><img src=\"#\" height=1></div></td></tr>";
		content += "<tr><td>";
		content += "<div class=\"navigatorMmPathLink\">" + this.item.innerHTML + "</div>";
		content += "</td></tr>";
		content += "<tr><td align=\"right\"><br>";
		content += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"85%\">";

		//count = 0;
		for( var x = 0; x < nodes.length; x++ ) {
			if(nodes[x].attributes && nodes[x].nodeName=="item") {
				content += "<tr><td class=\"navigatorTabSubItems\"><nobr><a href=\""+nodes[x].attributes[2].nodeValue+"\">"+nodes[x].attributes[1].nodeValue+"</a></nobr></td></tr>";
				count++;
			}
		}
		
		content += "</table>";
		content += "</td></tr></table>";
	}
	if (this.flyerDIV!=null) {
		this.flyerDIV.style.height = (this.item.offsetHeight + 10 + this.heightItem * count)+"px";
		this.flyerDIV.innerHTML = content;
	}
	this.show();
}

NavigatorFlyer.prototype._writeContainer = function() {
		if (this.flyerDIV==null) {
			this.flyerDIV = document.createElement('div');
			this.flyerDIV.oncontextmenu = function() {return false};
			this.flyerDIV.onselectstart = function() {return false};
			this.flyerDIV.onmouseout = function() {
				var coverClass = nMMItems[this.id];
				if (coverClass!=null) {
					coverClass.isOver = false;
					coverClass.hide();
				}
				return true;
			};
			this.flyerDIV.onmouseover = function() {
				var coverClass = nMMItems[this.id];
				if (coverClass!=null) {
					coverClass.isOver = true;
					coverClass.show();
				}
				return true;
			};
			this.flyerDIV.id = this.id;
			this.flyerDIV.className = "navigatorFlyer";
			this.flyerDIV.style.display    = '';
			this.flyerDIV.style.visibility = 'hidden';
			var pos = getPosition(this.item);
			this.flyerDIV.style.top = (pos.y-4)+"px";
			this.flyerDIV.style.left = (pos.x-1)+"px";
			this.flyerDIV.style.width = (this.item.offsetWidth+60)+"px";
			this.flyerDIV.style.height = (this.item.offsetHeight + 10 + this.heightItem * 1)+"px";
			document.getElementsByTagName("body")[0].appendChild(this.flyerDIV);
		}
	}

NavigatorFlyer.prototype._request = undefined;

NavigatorFlyer.prototype.loadAllItems = function() {
	this._request = getXMLHTTPRequest();

	//set the var so we can scope the callback
	var _this = this;

	//callback will be an anonymous function that calls back into our class
	//this allows the call back in which we handle the response (_onData())
	// to have the correct scope.
	var url = "/index/sibling/?sid="+this.siblingsId;
	//var url = "http://vh2/index/sibling/?sid="+this.siblingsId;
	this._request.onreadystatechange = function(){_this._onData()};
	this._request.open("GET", url, true);
	this._request.send(null);
}

NavigatorFlyer.prototype._onData = function() {
	if(this._request.readyState == 4) {
		if(this._request.status == "200") {
			var nodes = this._request.responseXML.getElementsByTagName("menu");
			//setMessage(message.childNodes[0].nodeValue);
			/*for( var x = 0; x < theParagraph.attributes.length; x++ ) {
				if( theParagraph.attributes[x].nodeName.toLowerCase() == 'title' ) {
					window.alert( 'The value of the \'title\' attribute is: ' +
						theParagraph.attributes[x].nodeValue );
				}
			}*/
			//childNodes
			for( var x = 0; x < nodes.length; x++ ) {
				//if(nodes[x].attributes[0].nodeValue=="mainmenu") {
					this._draw(nodes[x].childNodes);
				//}
			}
		}
		//clean up
		delete this._request;
	}
}


var nFlyerTimerId;
var nCurrentMMLink = 0;
var nMMItems = new Array();

function nShowFlyer() {
	if (nCurrentMMLink!=null && nMMItems[nCurrentMMLink.id]) {
		nMMItems[nCurrentMMLink.id].showAfterUpdateItems();
	}
}

function nHideFlyer() {
	if (nCurrentMMLink!=null && nMMItems[nCurrentMMLink.id]) {
		nMMItems[nCurrentMMLink.id].hide();
	}
}

function nOnMouseOverAction(mmItem, siblingsId) {
	clearTimeout(nFlyerTimerId);
	nCurrentMMLink = mmItem;
	if (nMMItems[mmItem.id]==null) {
		nMMItems[mmItem.id] = new NavigatorFlyer(mmItem, siblingsId);
	}
	
	nFlyerTimerId = setTimeout("nShowFlyer();", 600);
}

function nOnMouseOutAction(mmItem) {
	clearTimeout(nFlyerTimerId);
	nHideFlyer();
	nCurrentMMLink = null;
}
