$(document).ready(function () {

	$("#topents").append("<div id='event_image'></div>");
	
	var eventImages = $("#topents").find(".msl_event_image").parent();
	var eventList = $("#topents").find("dl");
	var resetHover = {'color' : '#fff', 'background-color' : '#000'};
	var setHover = {'color' : '#333', 'background-color' : 'silver'};
	var numberEvents = eventList.length;

	var random = Math.floor(Math.random()*numberEvents);


// The variable k determines which event is highlighted on pageload, for the top event set it to 0, for the second set to 1 etc. - to randomly select set it to the word random (all lowercase)

	var k = random;

// The variable youTube is the ID of the video you would like to embed - it's the bit at the end of the URL after the equals sign - just put it in here (in between single quotes) and it will be embedded automatically

	var youTube = '5_LxtJLQoHU';


	function eventHighlight () {
		eventList.each(function () {
			var eventLink = $(this).find('a:first').attr('href');
			$(this).find(".msl_event_tickets").remove();
			var eventTitle = $(this).find('a').text();
			$(this).find('dt').empty().append(eventTitle);
			$(this).wrap('<a href="' + eventLink + '"></a>');
			
			$(this).parent().bind('mouseenter', function () {
				var j = $(this).index();
				if (k != j) {
					$("#topents").find(".msl_eventlist").find('a').css(resetHover);
					$(this).css(setHover);
					$("#event_image > *").css('display', 'none');
					$(eventImages[j]).fadeIn("normal");
					k = j;
				}
			});
		});
		$("#event_image").append(eventImages);
		$("#event_image > *").css('display', 'none');
		$(eventImages[k]).fadeIn("normal");
		$("#topents").find('a:eq(' + k +')').css(setHover);
		$("#topents").find('.event:last').css('margin-bottom', '-1px');
	}

	eventHighlight ();		
	
	function addVideo () {
		var currVideo = '<object width="280" height="250"><param name="movie" value="http:\/\/www.youtube.com\/v\/' + youTube + '&hl=en&fs=1&"><\/param><param name="allowFullScreen" value="true"><\/param><param wmode="transparent"<\/param><param name="allowscriptaccess" value="always"><\/param><embed src="http:\/\/www.youtube.com\/v\/' + youTube + '&hl=en&fs=1&" type="application\/x-shockwave-flash" allowscriptaccess="always" wmoed="transparent"allowfullscreen="true" width="280" height="250"><\/embed><\/object>';
		$('#video').append(currVideo);
	}

	addVideo();

});
