$(document).ready(function(){
	newsStructure = "<div id='storyX' class='story'><img border='0'><p class='headline'></p><p class='author'></p><p class='pubdate'></p><p class='brief'></p><a class='readmore'></a></div>";
	grabNews(SpotlightNewsGroup,"spotlight",false);
	grabNews(LatestNewsGroup,"latest",true);
	//we still need to set up the self managed photo group
	
	$('#search').pdSearch({showButton:true, showButtonClass:'searchSubmit',showButtonText:''});
});

function grabNews(groupid,targetElement,doCycle){
	$.ajax({
		url:"/data/xml.asp?sid="+schoolid+"&type=news&id="+groupid,
		dataType:"xml",
		success: function(xml){
			$(xml).find('item').each(function(){
				var imgData = {}, mainData = {};
					mainData = {
						newsid: $(this).find('newsid').text(),
						headline: $(this).find('title').text(),
						author: $(this).find('author').text(),
						readMoreLink: $(this).find('url').text(),
						brief: $(this).find('brief').text(),
						pubDate: $(this).find('pubDate').text()
					};
				$(this).find('image').each(function(){
					imgData = {
						thumbImg: $(this).find('tpath').text(),
						thumbHeight: $(this).find('tpath').attr('height'),
						thumbWidth: $(this).find('tpath').attr('width')					
					};
				});

				$(newsStructure).appendTo("#"+targetElement);
					$("#storyX").attr("id",mainData.newsid);
			
				useThumbHeight = (imgData.thumbHeight>100) ? 100 : imgData.thumbHeight;
				$("#"+targetElement + " div#" + mainData.newsid + " img")
					.attr("src",imgData.thumbImg)
					.attr("height",useThumbHeight)
					.css("visibility","visible");
				$("#"+targetElement + " div#" + mainData.newsid + " .headline")
					.html(mainData.headline ? mainData.headline : "")
					.fSplit({maxChar:65});
				$("#"+targetElement + " div#" + mainData.newsid + " .author").html(mainData.author ? mainData.author : "");
				$("#"+targetElement + " div#" + mainData.newsid + " .pubdate").html(mainData.pubDate ? mainData.pubDate : "");
				$("#"+targetElement + " div#" + mainData.newsid + " .brief")
					.html(mainData.brief ? mainData.brief : "")
					.fSplit({maxChar:180});
				$("#"+targetElement + " div#" + mainData.newsid + " a.readmore")
					.attr("href",mainData.readMoreLink ? mainData.readMoreLink : "")
					.html("Read More")
					.css("visibility","visible");
			});
		},
		complete: function(){ if(doCycle){ $("#"+targetElement).cycle({timeout:4000,speed:500,pause:1}); } }
	});
}


function submitSearch(){ window.location = "/podium/default.aspx?t=52392&q="+document.getElementById("search").value+"&pt=Bishop Guertin High School Search"; }
function SubmitOnEnter(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if(charCode == "13" || charCode == "26"){ submitSearch(); return false; }
}

