$(document).ready(function() {
	// menu
	$('#nav li').hover(
		function () {
			//show its submenu
			$('ul', this).slideDown(0);

		}, 
		function () {
			//hide its submenu
			$('ul', this).slideUp(50);			
		}
	);
	// hide search label on click
	$("#searchForm label").click(function(){  
		$("#searchForm label").hide();
		$("#searchForm input").focus();
	});
	$("#searchForm input").focus(function(){
		$("#searchForm label").hide();
	});
	$("#searchForm input").blur(function(){
		if($(this).val() == "") {
			$("#searchForm label").show();
		}
	});
	if($("#searchForm input").val() != "") {
		$("#searchForm label").hide();
	}
}); 

$(window).load(function() {
	// run calendar
	$("#calendar").compactCal({
	 offsetLeft: 20,   
	 offsetTop: 12      
	});
		
	$.ajax({
        type: "GET",
		url: "/xml/sb_newhopecs/rotatingStory1.xml?_nc= " + Math.random(),
		dataType: "xml",
		success: function(slide_xml) {
			setupHTMLandSlideshow(slide_xml);
		}
	});  

});        

var home_slideCount = 0;

function setupHTMLandSlideshow(slide_xml) {
	// setup html                       
	var newHTML = "";
	$(slide_xml).find('story').each(function(){
		newHTML += "<div><a href='" + $(this).attr('pageLink') + "'><img src='" + $(this).attr('imageLink') + "' /></a></div>";
		home_slideCount++;
	});                                                                                                                     
		
	$("#home_slider").html(newHTML);
	$("#home_slider").cycle({
		fx: "fade", prev: "#home_slideshow .prev", next: "#home_slideshow .next", speed: 1000, timeout: 5000, pause: 1, before: slideUpdated
	});                                                                                                  
	$("#home_slideshow .num").html("1/" + home_slideCount);
	
}                                            

function slideUpdated(a, b, opts) {
	$("#home_slideshow .num").html((opts.nextSlide + 1) + "/" + home_slideCount);
}
