// homepage.js

$(function() {

    $.ajax({
      type: "GET",
      url: "/newsstories/images.xml",
      dataType: "xml",
      success: function(xml) {
        $(xml).find('items').each(function(){
          var i = 1;
          $(this).find('imageName').each(function(){
            var linkto = jQuery(this).attr('html');
            var headline = jQuery(this).attr('headline');
			var image = jQuery(this).attr('image');
            if(i == 1) {
                var active = ' class="active"';
                i++;
            } else var active ='';
            $('<a href="' + linkto + '"><img src="' + image + '" alt="' + headline + '" /></a>').appendTo('#newsstories'); 
          });
    
        });


$('#newsstories')
.after('<div id="news-nav">')
.cycle({ 
    speed:  500,
	pager: '#news-nav',
	timeout: 8000,
	pauseOnPagerHover: true,
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
		var img = $(slide).children().eq(0).attr("src");
		img = img.replace("newsstories/", "newsstories/t_");
        return '<a href="#"><img src="' + img + '" width="80" height="45" alt="' + idx + '"></a>'; 
    }
});

      }
    });   

});

