function liveplayerxml() {
  	$.ajax({
		type: "GET",
		url: "http://www.roseslive.com/data/livebfmxml.php",
		dataType: "xml",
		success: function(xml) {
			var spanShowName = $('p.show'),
				spanPresenter = $('p.djs');
			
			$(xml).find('liveShow').each(function(){
				var xmlShowName = $(this).find('showName').text(),
					xmlPresenter = $(this).find('presenter').text();
				
				spanShowName.empty();
				spanShowName.append(xmlShowName);
				if($(xmlPresenter) == "BCX") {
					spanPresenter.empty();
					spanPresenter.append(xmlPresenter);
				}	
			});
			
		}
	});
}


function getScoreData(lancs, york, played) {
	// Pass jQuery objects into function
	var lancs_score = lancs.text(),
		york_score = york.text(),
		played_matches = played.text();	
	// lancs.empty();
	// york.empty();
	// played.empty();
	$.getJSON('/json/get_points.json', function(data) {
		if(data.lancs_points >= lancs_score) {
			lancs.text(data.lancs_points);
		}
		if(data.york_points >= york_score) {
			york.text(data.york_points);
		}
		if(data.events >= played_matches) {
			dateString = date_string(data.last_update);
			played.text('last update at ' + dateString + ' after ' + data.events + ' contests.');
		}
	});
}

function padTime(timeToPad) {
	
	var paddedTime = timeToPad;
	if(timeToPad < 10) {
		paddedTime = "0" + timeToPad;
	}

	return paddedTime;
}

function date_string(timestamp) {
	var d = new Date( );
	var weekday=new Array(7);
	weekday[0]="Sunday";
	weekday[1]="Monday";
	weekday[2]="Tuesday";
	weekday[3]="Wednesday";
	weekday[4]="Thursday";
	weekday[5]="Friday";
	weekday[6]="Saturday";
	
	d.setTime( timestamp*1000 );	
	return padTime(d.getHours()) + ':' + padTime(d.getMinutes()) + " " + weekday[d.getDay()];
}

function getWriteups(writeuplist) {

	var writeup_list = writeuplist;
	
	$.getJSON('/json/get_writeups.json', function(data) {
		var output = '';
		for(var i = 0; i < data.length; i++) {
			var item = data[i];
			 
                output += '<li><a href="/writeups/index.php#writeup_' + item.id + '">';
                if(typeof item.sport_title == "string") {
                    output += item.sport_title + ' - ';
                }
                output += item.title + '</a></li>';
	
			}	
		writeup_list.html(output);					
	});

}

function getDetailedWriteups(writeuplist) {

	var writeup_list = writeuplist;
	
	$.getJSON('/json/get_writeups.json', function(data) {
		var output = '';
		for(var i = 0; i < data.length; i++) {
			var item = data[i];
			 
                output += '<li>';
                if(typeof item.sport_title == "string") {
                    output += '<p class="sport">' + item.sport_title + '</p>';
                }
                output += '<h3>' + item.title + '</h3><p>' + item.content + '</p></li>';
	
			}	
		writeup_list.html(output);					
	});

}

