//  ***********************
//  AJAX RSS FEED
//  ***********************
//  Author: Richard Lehmann
//  Company: SonyBMG  
//  =======================
//  Date: 20th October 2006
//  =======================
//  © 2006 SonyBMG
//  =======================
var agent = navigator.userAgent.toLowerCase(); 
var isMac = (agent.indexOf("mac") != -1) ? true : false;
var isMSIE = (navigator.appVersion.indexOf("MSIE")!=-1) ? true : false;
//
RSS=function(url,el, amount){
	var myConn = new XHConn();
	if (!myConn){
		document.getElementById(el).innerHTML ="Your browser does not support this content.";
		return false;
	}
	// reference itself
	var self=this;
	this.el=el;
	this.amount=amount
	this.onLoad=function(xhttp){
		self.xhttp=xhttp;
		self.populate();
	}
	// append unique timestamp to kill cache
	var d=new Date();
	myConn.connect(url, "GET", "cacheKiller="+d.getTime(), this.onLoad);
	
}
//
RSS.prototype.getChildNodeByName=function(node,name){
	for(var n=node.firstChild;n;n=n.nextSibling){
		if(n.nodeName==name){
			return n
			break;
		}
	}
}
//
RSS.prototype.getChildValueByName=function(node,name){
	for(var n=node.firstChild;n;n=n.nextSibling){
		if(n.nodeName==name){
			if(n.firstChild!=undefined){
				var ret = n.childNodes.length > 1 ? n.childNodes[1].nodeValue : n.childNodes[0].nodeValue;
				return ret
				break;
			}
		}
	}
}
//
RSS.prototype.wrapTag= function(tag, text, prefix , suffix) {
	var i = text.indexOf('<'+tag);
	if (i != -1) {
		var temp = [];
		var ret = text;
		//
		loop = 1;
		while(loop) {
			var i = ret.indexOf('<'+tag);
			if (i != -1) {
				var s1 = ret.substring(0,i) + prefix;
				var s2 = ret.substring(i,ret.length);
				var i = s2.indexOf('/>');
				var s3 = s2.substring(0,i+2) + suffix;
				var s4 = s2.substring(i+2,s2.length);
				temp.push(s1);
				temp.push(s3);
				ret = s4;
			} else {
				temp.push(ret);
				loop = 0;
			}
		}
		//
		ret=""
		for (var i=0; i < temp.length; i++) {
			ret += temp[i];
		}
		//
		return ret;
	} else {
		return text;
	}
}
//
RSS.prototype.populate = function() {
	with(this){
		var i=0;
		var xmldoc = xhttp.responseXML;
		var root_node = xmldoc.getElementsByTagName('channel').item(0);
		var baselink=getChildValueByName(root_node, 'link');
		var html = '';
		var nodelist=root_node.firstChild.childNodes
		for (var n = root_node.firstChild; n; n=n.nextSibling) {
			// item node
			if(n.nodeName=='item'){;
				if(i<amount || amount ==undefined ){
					// pull description node value		
					var title=getChildValueByName(n, 'title')
					if(title!=undefined){
						html +="<div class='newsTitle'>"+title+"</div>";
					}
					html +="<div class='newsDescription'>"+getChildValueByName(n, 'description')+"</div>";
				}else{
					break
				}
				i++
			}
		}
		el= document.getElementById(el);
		el.innerHTML = html+'';
	}
};