/*
|	Feed reader 
|
|	Read JSON streing from parsed XML
|	Requires: core.js,connection.js,json.js
*/

		//Feedreader function
		{hp.feedread=function(){
			return {
				rss:function(vTitle,oT,nCount,vURL,vClass,vTitleClass,bFull,vStyle,vInternalLink,vStrapLine){
					var oR=hp.http.conn(),oT=hp.utils.get(oT);
					hp.http.loading(oT);
					oR.open("get","/get/feeds/?f="+vURL,true);
					oR.onreadystatechange=function() {
						if(oR.readyState==4){
							if (oR.status==200) {
								var oResponse=JSON.parse(oR.responseText),vState=oResponse.news.state;
								if(vState==='pass'){
									var oItems=oResponse.news.items,nLength=oItems.length,nOuputLength=nLength;
									if (bFull!==true) {
										(nLength>nCount)?nLength=nCount:null;
										vTitlePhrase=vTitle+' ('+nCount+' of '+nOuputLength+')';
										vImage = '<div class="right"><a href="'+vURL+'" target="_blank"><img src="/images/feed.gif" /></a></div>';
										vRSSLink='';
									} else {
										vTitlePhrase=vTitle+' - Viewing all';
										vImage = '';
										vRSSLink='<div class="list_options greybg gainlayout"><div style="margin-right: 5px;" class="left"><img src="/images/feed_big.gif"/></div><div class="padded5 left"><h4 class="light"><a target="_blank" href="'+vURL+'">View RSS feed of this page</a></h4></div><div class="clear"></div></div>';
									};
									if(vStrapLine){
										vStrapLine=',';
									} else {
										vStrapLine = '';
									}
									
									vListBody='<div class="'+vClass+'">';
									if(nLength>0){
										vListBody+='<ul>';
										vListBody+=vStrapLine;
										for(var i=0;i<nLength;i++){
											vDate = oItems[i].pubDate;
											vDescription = (bFull===true)?'<p>'+oItems[i].description.trim()+'</p>':'';
											vLink = oItems[i].link;
											vTarget = (vInternalLink=='')?' target="_blank"':'';
											vListBody+='<a href="'+vLink+'"'+vTarget+' class="listlink" target="_blank"><strong>'+oItems[i].title.trim()+'</strong> </a>'+vDescription+'<hr style="border: 1px solid #cccccc;" /></li>';
										};
										if(vInternalLink!==''){
											vListBody+='<li style="text-align: right;"><a href="'+vInternalLink+'">&raquo; More '+vTitle+'</a></li>';
										}
										vListBody+='</ul>';
									} else {
										vListBody+='<ul><li class="grey" style="padding: 5px;"><em>No news stories found!</em></li></ul>';
									};
									oT.innerHTML=vListBody;
									
									//get id for hilight
									if (bFull==true) {
										vHL=location.href,vHL=vHL.split("#");
										if(vHL[1]){
											oT=hp.utils.get('oListItem'+vHL[1]);
											
											window.scrollTo(0,oT.offsetTop);
											oT.className='highlighted gainlayout';
										}
									}
								} else {
									oT.innerHTML='<div class="title">'+vTitle+'</div><div class="'+vClass+'"><ul><li style="padding: 5px;">Sorry, '+vTitle+' feed currently unavailable</li></ul></div>';
								}
							} else {
								oT.innerHTML='<div class="title">'+vTitle+'</div><div class="'+vClass+'"><ul><li style="padding: 5px;">Sorry, '+vTitle+' feed currently unavailable</li></ul></div>'
							}
						}
					}
					oR.send(null);
				}
			}
					
		}()};
		{hp.homefeedread=function(){
					return {
						rss:function(vTitle,oT,nCount,vURL,vClass,vTitleClass,bFull,vStyle,vInternalLink,vStrapLine){
							var oR=hp.http.conn(),oT=hp.utils.get(oT);
							//hp.http.loading(oT);
							oR.open("get","/get/feeds/?f="+vURL,true);
							oR.onreadystatechange=function() {
								if(oR.readyState==4){
									if (oR.status==200) {
									var oResponse=JSON.parse(oR.responseText),vState=oResponse.news.state;
										if(vState==='pass'){
											var oItems=oResponse.news.items,nLength=oItems.length,nOuputLength=nLength;
											if (bFull!==true) {
												(nLength>nCount)?nLength=nCount:null;
												vTitlePhrase=vTitle+' ('+nCount+' of '+nOuputLength+')';
												vImage = '<div class="right"><a href="'+vURL+'" target="_blank"><img src="/images/feed.gif" /></a></div>';
												vRSSLink='';
											} else {
												vTitlePhrase=vTitle+' - Viewing all';
												vImage = '';
												vRSSLink='<div class="list_options greybg gainlayout"><div style="margin-right: 5px;" class="left"><img src="/images/feed_big.gif"/></div><div class="padded5 left"><h4 class="light"><a target="_blank" href="'+vURL+'">View RSS feed of this page</a></h4></div><div class="clear"></div></div>';
											};
											if(vStrapLine){
												vStrapLine=',';
											} else {
												vStrapLine = '';
											}
											
											vListBody='<div class="'+vClass+'">';
											if(nLength>0){
												vListBody+='<ul>';
												vListBody+=vStrapLine;
												for(var i=0;i<nLength;i++){
													vDate = oItems[i].pubDate;
													vDescription = (bFull===true)?'<p>'+oItems[i].description.trim()+'</p>':'';
													vLink = oItems[i].link;
													vTarget = (vInternalLink=='')?' target="_blank"':'';
													vListBody+='<div class="promo_content_title"><a href="'+vLink+'"'+vTarget+' class="rssnewslink" target="_blank">'+oItems[i].title.trim()+'</a></div><div class="promo_content_title_date">'+vDate+'</i></div></li>';
												};
												if(vInternalLink!==''){
													vListBody+='<li style="text-align: right;"><a href="'+vInternalLink+'">&raquo; More '+vTitle+'</a></li>';
												}
												vListBody+='</ul>';
											} else {
												vListBody+='<ul><li class="grey" style="padding: 5px;"><em>No news stories found!</em></li></ul>';
											};
											oT.innerHTML=vListBody;
											
											//get id for hilight
											if (bFull==true) {
												vHL=location.href,vHL=vHL.split("#");
												if(vHL[1]){
													oT=hp.utils.get('oListItem'+vHL[1]);
													
													window.scrollTo(0,oT.offsetTop);
													oT.className='highlighted gainlayout';
												}
											}
										} else {
											oT.innerHTML='<div class="title">'+vTitle+'</div><div class="'+vClass+'"><ul><li style="padding: 5px;">Sorry, '+vTitle+' feed currently unavailable</li></ul></div>';
										}
									} else {
										oT.innerHTML='<div class="title">'+vTitle+'</div><div class="'+vClass+'"><ul><li style="padding: 5px;">Sorry, '+vTitle+' feed currently unavailable</li></ul></div>'
									}
								}
							}
							oR.send(null);
						}
					}
							
		}()};