var podcastUrl = "podcast/ascc.xml";

var newDiv = "<div></div>";
var newSpan = "<span></span>";
var newA = "<a></a>";
var newB = "<b></b>";

function Episode() {}
Episode.prototype.direction=1 // 0 = forward, 1 = backward

function markUp(element) {

	$(element + "Container").show();
	var thisMarkup = $(newDiv).attr("id", this.guid).attr("class", "episode");
		$(newA).attr("href", this.link).html(this.title).appendTo(thisMarkup);
		var meta = $(newDiv);
		$(newB).html(this.author + " - ").appendTo(meta);
		$(newB).html(this.subtitle).appendTo(meta);
		$(newSpan).html(this.description).appendTo(meta);
		$(newSpan).html("(duration: " + this.duration + ", size: " + this.size + " MB)").appendTo(meta);
		$(meta).appendTo(thisMarkup);
	if (this.direction == 1)
	{
		$(thisMarkup).prependTo(element);
	} else {
		$(thisMarkup).appendTo(element);
	}
}


Episode.prototype.markUp=markUp;



function loadPodcast() {
$.ajax({
    type: "GET",
	url: podcastUrl,
	dataType: "xml",
	success: function(xml) {

		 $(xml).find('item').each(function(){
			  var entry = $(this);
			  var thisEpisode = new Episode();
			  thisEpisode.title=entry.find("title").text();
			  thisEpisode.guid=entry.find("guid").text();
			  thisEpisode.duration=entry.find("durationHack").text();
			  thisEpisode.author=entry.find("authorHack").text();
			  thisEpisode.subtitle=entry.find("subtitleHack").text();
			  thisEpisode.description=entry.find("description").text();
			  thisEpisode.link=entry.find("enclosure").attr("url");
			  thisEpisode.size=parseInt(entry.find("enclosure").attr("length"))/1000000;

			  thisEpisode.pubDate=entry.find("pubDate").text();

			  thisEpisode.series=entry.find("series").text();

//			  thisEpisode.markUp("#foo");
			  thisEpisode.markUp("#" + thisEpisode.series);

		  });

		  $("#bar").hide();
	}
});

}

