var ccast;
var currentDiv;
var currentBio;
var episodeId;

function init() {
	//console.log("created")
	
	/*ccast = new Swiff('Flash_Development/crohnsCast.swf', {
		width: 584,
		height: 281,
		container: $("crohnsCastPlayer"),
		events: {
			onLoad: function() { playEpisode(1, $('episode00'), $('bio00')); alert("Loaded") }
		},
		vars: {
			xmlURL: "Flash_Development/xml/live_mp3s.xml"
		}
	}) */
	
	$$('.castEpiList')[0].getElements('h3').each(function(el) { 
		var div = el.getNext();
		div.setStyle('display', 'none');
		
		var anchors = el.getElements('a')[0]
		var id = div.get('id').substr(7)
		var bio = $('bio'+id)
		
		bio.setStyle('display', 'none')
		
		anchors.set({
			events:{
				click:function(){
					playEpisode(id, true)
				}
			}
		})
	})
	
	
}

function playEpisode(id, loop) {
	try {
		currentDiv.setStyle('display', 'none');
		currentBio.setStyle('display', 'none');
	} catch(e) {}
	
	id = new String(id)
	
	id = (id.length < 2) ? "0"+new String(id) : id
	

	
	currentDiv = $("episode"+id)
	currentBio = $("bio"+id)
	episodeId = "episode"+id;
	currentDiv.setStyle('display', 'block');
	currentBio.setStyle('display', 'block');
	
	if (loop != undefined || loop == false) {
	/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	 * +++++++++++++++     flashobj.playEpisode(id)    +++++++++++++++
	 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	 */
	    
	 
		id = parseInt(id)

		getMovie("castPlayer").playEpisode(id)
	}
}


//window.addEvent('domready', init)

function getMovie(appName) {
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[appName];
  } else {
    return document[appName];
  }
}

function openDownloadLink(link) {
	 win = window.open('download.aspx?link='+link,'CrohnsCast','scrollbars=yes,resizable=no,width=630,height=516');
}