	var pg_MAX_WEIGHT_TIME=0;
	var pg_MAX_RETRIES=10;

	function refreshHeadlines() {
		pg_newsIndex+=4;
		http("GET","/Home_getNextStories.do?pageStart="+pg_newsIndex+"&pageLength=4",newsCallback,null);	
		
	}
	function newsCallback(result) {
		var latestNews=docGet("latestNews");
		pg_newsIndex=parseInt(result["pageStart"]);
		var stories=result["stories"];
		if (!stories || stories==null || stories.length==0) {
			pg_newsIndex=0;
			if (pg_NUM_RETRIES<pg_MAX_RETRIES) 
				refreshHeadlines();
			return;
		} 
		for (var i=0;i<stories.length;i++) {
			new Effect.Fade("newsItem"+i,{afterFinish:function(effect) {
					var objid=effect.element.id;
					objid=objid.replace("newsItem","");
					effect.element.parentNode.removeChild(effect.element);
					showNewStories(stories,objid);
			}}); 
 
		} 
		setTimeout("refreshHeadlines()",8000);

	}
	
function adjustImagefornews(img) {
	var maxWidth=img.getAttribute("maxwidth");
	var maxHeight=img.getAttribute("maxheight");
	var w=img.width;
	var h=img.height;
	var nw=0;
	var nh=0;
    if (w<=0) w=100;
    if (h<=0) h=100;
	if (w<maxWidth && h<maxHeight) {
		return;
	}
	else if (w>h && maxWidth>0) {
		nh=maxWidth*h/w;
		nw=maxWidth;
		img.width=nw;
	    img.height=nh;
	    return;
	}
	else if (w==h && maxHeight>0) {
		nw=maxHeight;
		nh=maxHeight;
	    img.width=nw;
	    img.height=nh;
	    return;
		
	}
	else if (h>w && maxHeight>0) {
		nw=(maxHeight*w/h);
		nh=maxHeight;
	    img.width=nw;
	    img.height=nh;
	    return;
	}
//	if (nh>maxHeight && maxHeight>0) {
//		nw=(maxHeight*nw/nh);
//		nh=maxHeight;
//	}
	if (nw==0) nw=w;
	if (nh==0) nh=h;
	if (nw>maxWidth && maxWidth>0) {
		nh=(maxWidth*nh/nw);
		nw=maxWidth;
	}
	
	img.width=nw;
	img.height=nh;
}

	
function showNewStories(stories,i) {
	var story=stories[i];
	var latestNews=docGet("latestNews");
	var obj=docMake("a");
	obj.style.display="none";
	var strHTML="";
	strHTML+='<div class="feature">';
	strHTML+='<div class="featureImg" style="overflow:hidden;text-align:center;"><img onLoad="adjustImagefornews(this);" maxwidth="100"  maxheight="60"';
	strHTML+='		class="news-item-pic" border=0 ';
	strHTML+='		src="'+story.img+'"></div>';
	strHTML+='<div class="featurecopy" >'+story.title+'</div> ';
	strHTML+='<div style="clear:both"></div> ';
	strHTML+='</div>';
	obj.innerHTML=strHTML;
	obj.href="/Story/"+story.permalink;
	obj.id="newsItem"+i;
	obj.className='featureLink';
	latestNews.appendChild(obj);
	Effect.Appear("newsItem"+i);
	}
