var MWJ_ldD = []; // XML IMPORT

function ajax_marquee(xmlfile, marqueeId){
	this.xmlfile = xmlfile; //Variable pointing to the local marquee xml file (txt)
	this.xmlfile += ( ( this.xmlfile.indexOf('?') + 1 ) ? '&' : '?' ) + ( new Date() ).getTime(); //prevent cache
	this.marqueeid=marqueeId ;//ID of marquee to display information
	this.getXMLfile();
}

ajax_marquee.prototype.initialize=function(){ 
	this.contentmarquee=document.getElementById(this.marqueeid);
	if (this.xmlData != null && this.xmlData.getElementsByTagName("marqueeitem").length==0){ //if no messages were found
		this.contentdiv.innerHTML="<b>Error</b> fetching marquee file!";
		return;
	}
	var instanceOfMarquee=this;
	if (window.attachEvent) //Clean up loose references in IE
	    window.attachEvent("onunload", function(){instanceOfMarquee.contentdiv=instanceOfMarquee.ajaxobj=null});

	//Cycle through XML object and store each message inside array
    var marqueeHtml = "";
    var newWindowAttribute = "";
	if (this.xmlData != null)
	{
		for (var i=0; i<this.xmlData.getElementsByTagName("marqueeitem").length; i++){			
			if(i > 0 ){
			    marqueeHtml += "...";
			}
			marqueeHtml += this.xmlData.getElementsByTagName("header")[i].firstChild.nodeValue+"...";
			
			if (this.xmlData.getElementsByTagName("newwindow")[i].firstChild.nodeValue == "True")
			  newWindowAttribute = "target='_blank'";
			    	  
			var theUrl = this.xmlData.getElementsByTagName("link")[i].firstChild.nodeValue;
			if(theUrl == "http://")
			{
			    marqueeHtml += this.xmlData.getElementsByTagName("content")[i].firstChild.nodeValue;			    
			}
			else
			{
			    marqueeHtml += "<a href='"+theUrl+"' "+newWindowAttribute+">";
			    marqueeHtml += this.xmlData.getElementsByTagName("content")[i].firstChild.nodeValue;
			    marqueeHtml += "</a>";
			}
			newWindowAttribute = "";
		}
	}
	this.contentmarquee.innerHTML=marqueeHtml;
}

ajax_marquee.prototype.getXMLfile=function(){
	//note: in XML importing event handlers, 'this' refers to window
	if( window.XMLHttpRequest ) {
		//alternate XMLHTTP request - Gecko, Safari 1.2+ and Opera 7.6+
		MWJ_ldD[MWJ_ldD.length] = new XMLHttpRequest();
		MWJ_ldD[MWJ_ldD.length-1].onreadystatechange = new Function( 'if( MWJ_ldD['+(MWJ_ldD.length-1)+'].readyState == 4 && MWJ_ldD['+(MWJ_ldD.length-1)+'].status < 300 ) {marqueePromos.xmlData = MWJ_ldD['+(MWJ_ldD.length-1)+'].responseXML;  marqueePromos.initialize(); }' );
		MWJ_ldD[MWJ_ldD.length-1].open("GET", this.xmlfile, true);
		MWJ_ldD[MWJ_ldD.length-1].send(null);
		return true;
	}

	if( !navigator.__ice_version && window.ActiveXObject ) {
		//the Microsoft way - IE 5+/Win (ICE produces errors and fails to use try-catch correctly)
		try { //IE Mac has the property window.ActiveXObject but produces errors if you try and use it
			try { var tho = new ActiveXObject( 'Microsoft.XMLDOM' ); //newer
			} catch(e) { var tho = new ActiveXObject( 'Msxml2.XMLHTTP' ); } //older
			MWJ_ldD[MWJ_ldD.length] = tho;
			MWJ_ldD[MWJ_ldD.length-1].onreadystatechange = new Function( 'if( MWJ_ldD['+(MWJ_ldD.length-1)+'].readyState == 4 ) { marqueePromos.xmlData = MWJ_ldD['+(MWJ_ldD.length-1)+']; marqueePromos.initialize(); }' );
			MWJ_ldD[MWJ_ldD.length-1].load(this.xmlfile);
			return true;
		} catch(e) {}
	}
	if( document.createElement && document.childNodes ) {
		return false;
	}
	return false;
}