$(window).load(function() {
	$.ajax({
        type: "GET",
		url: "/xml/sb_brokerforce/rotatingStory1.xml?_nc= " + Math.random(),
		dataType: "xml",
		success: function(slide_xml) {
			setupHTMLandSlideshow(slide_xml);
		}
	});   
	
	$.ajax({
        type: "GET",
		url: "/xml/sb_brokerforce/quotes.xml?_nc= " + Math.random(),
		dataType: "xml",
		success: function(quotes_xml) {
			setupHomepageQuotes(quotes_xml);
		}
	});   
});        

function setupHTMLandSlideshow(slide_xml) {
	// setup html                       
	var newHTML = "";
	var storyCount = 0;
	$(slide_xml).find('story').each(function(){
		newHTML += "<div><a href='" + $(this).attr('pageLink') + "'><img src='" + $(this).attr('imageLink') + "' /></a></div>";
		storyCount++;
	});                                                                                                          
	
	$("#slider").html(newHTML);
	$("#slider").cycle({
		fx: "fade", pager: "#slideshow_controls_list", speed: 1000, timeout: 3000, pause: 1
	});                                      
	var newControlWidth = $(".slideshow_controls").width() * storyCount;
	$(".slideshow_controls").css("width", newControlWidth + "px");   

}

function setupHomepageQuotes(quotes_xml) {
	// setup html       
	var newHTML = "<h3>Testimonials</h3><div class='quotes'>";
	var quotesCount = 0;
	$(quotes_xml).find('quote').each(function(){
		newHTML += "<div><blockquote>" + $(this).text() + "</blockquote><div class='author'>" + $(this).attr('author') + "</div></div>";
		quotesCount++;
	});                                                                                                          
	newHTML += "</div>";
	
	$("#testimonials").html(newHTML);
	$("#testimonials .quotes").cycle({
		fx: "fade", speed: 1000, timeout: 8000, pause: 1
	});     
}
