var disciplinesXML;

$(document).ready(function() { 
	$.get('admin-resources/repository/assets/discipline/list.xml', {}, function(xml) {
        disciplinesXML = xml;
    	loadInit();
    });
});

function loadInit() {
	$('#selector .start li')
		.mouseover(function () { 
			// Get the properties
            updateDisplay(this);
		})
		.click(function() {
		    updateDisplay(this);
	    })
	updateDisplay($('#selector .start li:first'));
}

function updateDisplay(element) {
    var properties = $('[discipline-id=' + $('.hitstate .id', element).text() + ']', disciplinesXML);
    
    // Set the background rollover
	$('#selector .start li .hitstate').css('backgroundImage', '');
	$('#selector .start li .hitstate').css('width', '');
	$('.hitstate', element).css('backgroundImage', 'url(uploads/' + $('discipline-background-rollover-image', properties).text() + ')');
	$('.hitstate', element).css('width', '197px');
	$('img', element).show();

    // Title
	$('#selector .end .info h1')
		.text($('discipline-title', properties).text())
		.css('color', $('discipline-colour', properties).text());
	$('#selector .end .info .more')
		.css('color', $('discipline-colour', properties).text())
		.text('More about ' + $('discipline-title', properties).text());
	
	// Background Image
	$('#selector .end').css('backgroundImage', 'url(uploads/' + $('discipline-background-image', properties).text() + ')');
	
	// Introduction
	$('#selector .end .info .intro')
		.text($('discipline-introduction', properties).text());
	
	// Set the rollover colours
	$('#selector .start li h3').css('color', '');
	$('#selector .start li p').css('color', '');
	$('h3', $(element)).css('color', '#FFFFFF');
	$('p', $(element)).css('color', '#FFFFFF');
	
	// Substitute the links
	$('#selector .end .more').attr('href', $('discipline-more-link url', properties).text());
	$('#selector .end .more').attr('title', 'Learn more about training in ' + $('discipline-title', properties).text());
	$('#selector .end .learn').attr('href', $('discipline-more-link url', properties).text());
	$('#selector .end .learn').attr('title', 'More information on ' + $('discipline-title', properties).text() + ' including class time and timetables');
	$('#selector .end .freeLesson').attr('href', $('discipline-free-lesson-link url', properties).text());
	$('#selector .end .freeLesson').attr('title', 'Come along for a free ' + $('discipline-title', properties).text() + ' lesson!');
	
}