function constrain(str,n){ 
	if(str.length > n){  
		var s = str.substr(0, n);
		var words = s.split(' '); 
		words[words.length-1] = '';
		str = words.join(' ') + '&hellip;'
	}
	return str;
}

String.prototype.stripHTML = function(){
        // What a tag looks like
        var matchTag = /<(?:.|\s)*?>/g;
        // Replace the tag
        return this.replace(matchTag, "");
};

$(document).ready(function(){
	
	jQuery.get("/news/", function(newsxml){

		bTitles = Array(); bLinks = Array(); bDesc = Array(); i=0; j=0; k=0;
		$(newsxml).find("div.post>h1").each(function(){
			bTitles[i++] = $(this).text();
		});
		//alert(bTitles);
		$(newsxml).find("div.post>h1>a").each(function(){
			bLinks[j++] = $(this).attr("href");
		});
		
		$(newsxml).find("div.post>div.text").each(function(){
			bDesc[k++] = $(this).text().stripHTML();
		});
		//alert(bDesc);
		for (z=0;z<=2;z++) {
			htmls = "<p><strong>"+ bTitles[z] +"</strong><br />"+ constrain(bDesc[z],120) +"<br /><a href=\""+ bLinks[z] +"\">Click here for more ></a></p>";
			$("#newsblock .padding").append(htmls);
		}
	});
	
	$('#newsblock .padding p:last').css("padding","0");
});
