$(document).ready(function(){
	$("#headerNav li:last-child")
        .css({border:"none", padding:"0 12px 0 10px"})
	$("#subheaderNav li:last-child")
        .css({border:"none", padding:"0 12px 0 10px"})
        /*.hover(function () {
              $(this).addClass("solast");
            }, function () {
              $(this).removeClass("solast");
            });
		*/
	$("#mediaControl").hide();
	$(".mediaBtn").click(function () { 
      	$("#events").hide();
		$("#eventsControl").hide();
	  	$("#media").css({'position':'relative','z-index':'0'}).show();
		$("#mediaControl").show();
		
		//play the first video from the medialinks list in the flash player
		var firstVideo = $('a.mediaLink:first').attr('id');
		function loadFirstVideo() {sendToActionScript(firstVideo);}
		setTimeout(loadFirstVideo, 1000);
		
		//or change to html5 h264 video/mp3 if on ios
		if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) { 					//Create audio and video elements to create where needed
				var audioEl = "<audio id='mediaAlt' style='visibility:visible;margin-left:4px;' controls='controls' autoplay='autoplay'></audio><p id='vidtitle'></p>";
				var videoEl = "<video id='mediaAlt' style='visibility:visible;margin-left:4px;' width='480' height='270' type='video/mp4' controls='controls' autoplay='autoplay' poster='<?php bloginfo('template_url'); ?>/images/mediaplayerimg.png'></video><p id='vidtitle'></p>";
				var firstVideo = $('a.mediaLink:first');
				
				//Get the details of the first featuredLink item and set it playing
				var firstVideoSrc = $(firstVideo).attr('id').split('&')[0].substr('4');
				var firstVideoExt = $(firstVideo).attr('rel');
				var firstVideoTtl = $(firstVideo).attr('title');
				if (firstVideoExt == 'mp3'){
					$('#mediaRight').html(audioEl);
					$('#mediaAlt').attr('src', firstVideoSrc);
					$('#vidtitle').attr('class','audiobg');
				}else {
					$('#mediaRight').html(videoEl);
					$('#mediaAlt').attr('src', firstVideoSrc);
					$('#vidtitle').attr('class','videoobg');
				}
				$('#vidtitle').append(firstVideoTtl);
				//end first item autoplay
				
				//on subsequent clicks of items show them and play them
				$('.featuredLink,.mediaLink').click(function(){
					var firstVideoSrc = $(this).attr('id').split('&')[0].substr('4');
					var firstVideoExt = $(this).attr('rel');
					var firstVideoTtl = $(this).attr('title');
					if (firstVideoExt == 'mp3'){
						$('#mediaRight').html(audioEl);
						$('#mediaAlt').attr('src', firstVideoSrc);
						$('#vidtitle').attr('class','audiobg');
					}else {
						$('#mediaRight').html(videoEl);
						$('#mediaAlt').attr('src', firstVideoSrc);
						$('#vidtitle').attr('class','videobg');
					}
					$('#vidtitle').html(firstVideoTtl);
					return false;
				});
			}
			return false;
    });
	$(".eventsBtn").click(function () {
		$("#media").hide();
		$("#mediaControl").hide();
      	$("#events").show();
		$("#eventsControl").show();
    });
	$("#sortAudio").click(function () { 
      	$('#mediaListCont').hide();
		$('#mediaListVideoCont').hide();
		$('#mediaListAudioCont').show();
    });
	$("#sortVideo").click(function () { 
		$('#mediaListCont').hide();
		$('#mediaListVideoCont').show();
		$('#mediaListAudioCont').hide();
    });
	$("#sortAll").click(function () {
	  	$('#mediaListCont').show();
		$('#mediaListVideoCont').hide();
		$('#mediaListAudioCont').hide();
    });
	
	
	/* FANCY BOX :: This is basic - uses default settings */
	$("a.eventsLink").fancybox({ 'hideOnContentClick': false });
	$(".eventsDiv").hide();
	/* Using custom settings
	$("a#test2").fancybox({ 'hideOnContentClick': true });
	$("a.test3").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); */ 
	
	$('#eventsList').jScrollPane();	
	$('#mediaList').jScrollPane();
	$('#mediaListVideo').jScrollPane();
	$('#mediaListAudio').jScrollPane();
	
	$('#mediaListVideoCont').hide();
	$('#mediaListAudioCont').hide();
	$("#media").hide();

	//INITIALISE THE FLASH EXTERNAL INTERFACE
	pageInit();
	
});
