	$(document).ready(function(){
	
		$(".panelHeader").click(function(){
		  $(".expandingPanel", $(this).parent()).slideToggle("fast");
		});
	
		$("#newsPanel .newsColumnItem").each(function(){
			$("#newsItemSelector").append("<div class='newsItemSelectorLink'><a class='newsItemSelectorText' href='#'>" + ($(".newsColumnItem").index(this) + 1) + "</a></div>");
		   });
	
		$(".newsColumnItem:first").show();
		
		$(".newsItemSelectorText").bind("click", function(){
			$(".newsItemSelectorLink").removeClass("activeItem");
			$(".newsItemSelectorText").removeClass("activeItem");			
			$("#newsPanel .newsColumnItem").hide();
			var itemID = $(this).text();
			$(".newsColumnItem:eq(" + (itemID - 1) + ")").fadeIn("slow");
			var currentLink = $(".newsItemSelectorLink:eq(" + (itemID - 1) + ")");
			currentLink.addClass("activeItem");
			$(currentLink).find(".newsItemSelectorText").addClass("activeItem");
		});
			
		//Show first item
		
		function rotateItems(index){
			$(".newsItemSelectorText:eq(" + index + ")").triggerHandler("click");			
			$(".newsItemSelectorText:eq(" + index + ")").animate({opacity: "1.0"}, 4000, function(){
				if(index >= 4) {
					index = 0;
				} else {
					index++;	
				}
				rotateItems(index);
			});			
		}
		
		rotateItems(0);
		
		function rotateThumbs(index){
			$(".projectThumb").hide();
			$(".projectThumb:eq(" + index + ")").fadeIn("slow");
			$(".projectThumb:eq(" + index + ")").animate({opacity: "1.0"}, 3000, function(){
				if(index >= 4) {
					index = 0;
				} else {
					index++;	
				}
				rotateThumbs(index);
			});			
		}		
		
		$.ajax({
			type: "GET",
			url: "world_class_projects.xml?tfrm=4",
			dataType: "xml",
			success: function(xml) {			
							
				//Add World Class project thumbs
				var projects = $(xml).find("Navigation[Name='Projects']");
	
				$(projects).find('Page').each(function(){
					$("#projectThumbContainer").append("<div class='projectThumb' id='" + $(this).attr("ID") + "'><img border='0' alt='" + $(this).attr("Header") + "' src='Images/" + $(this).attr("Image") + "'/></div>");
				 });
				 rotateThumbs(0);				
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				$("#projectsPanel").append("<p>An error occurred retrieving the XML</p>");
			}
	
		});		
			
		
			
	});