/**
 * Schedule Display
 *
 */
var schedule;
var currentDate = new Date();
function showSchedule(view) {
	var target;
	if(schedule) {
		schedule.options.view = view;
		schedule.display("#"+view);
	} else {
		$.get( "/shared/schedule.xml", function(xml, statusText){ 
			if(statusText == "success")	{
				schedule = new Schedule(xml, { now: currentDate });
				showSchedule(view);
			} else {
				// XML not successfully retrieved
			}
		});
	}
}

/**
 * Look for media - convert to tabs and appropriate display
 */
$(function(){
	var tabinst = 0;
	$('ul.media').each(function(){
		
		$links = $(this).find('li a');
		if($links.length == 0) return;
		
		var count = 0;
		var mediatabs = $('<ul id="#mediatabs-'+tabinst+'"></ul>');
		tabinst++;
		
		if($links.length > 1) {
			$links.each(function(){
				count++;
				var tabid = 'tab-'+tabinst+'-'+count;
				$(this).parent().attr("id",tabid);
				$(this).media();
				mediatabs.append('<li><a href="#'+tabid+'" title="'+this.text+'">&nbsp;'+count+'&nbsp;</a></li>');
			});
			$(this).before(mediatabs);
			mediatabs.tabs({ fxFade: true });
		} else {
			$links.media();
		}
	});
});




