$(window).load(function() {
	$.ajax({
        type: "GET",
		url: "/xml/sb_realityvancouver/rotatingStory2.xml?_nc= " + Math.random(),
		dataType: "xml",
		success: function(slide_xml) {
			setupHTMLandSlideshow(slide_xml);
		}
	});
});  

var home_slideCount = 0;

function setupHTMLandSlideshow(slide_xml) {
	// setup html
	var slideHTML = "";
	var modalHTML = "";
	$(slide_xml).find('story').each(function(){
		if ($(this).find('popup').text()) {
			slideHTML += "<div><a href='#' data-reveal-id='myModal" + $(this).find('popup').attr('id') + "'><img src='" + $(this).attr('imageLink') + "' /></a></div>";
			modalHTML += "<div id='myModal" + $(this).find('popup').attr('id') + "' class='reveal-modal'>" + $(this).find('popup').text() + "<a class='close-reveal-modal'>&#215;</a></div>";
		} else {
			slideHTML += "<div><a href='" + $(this).attr('pageLink') + "'><img src='" + $(this).attr('imageLink') + "' /></a></div>";
		}
		home_slideCount++;
	});
	$("#home_slider").html(slideHTML);
	$("#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);
	$("#modalContainer").append(modalHTML);
}                                            

function buildOverlay(modalDiv) {
	$("#modalContent").prepend($("#" + modalDiv.html()));
}		

function slideUpdated(a, b, opts) {
	$("#home_slideshow .num").html((opts.nextSlide + 1) + "/" + home_slideCount);
}

