       var player;

       function playerReady(obj) {
          player = document.getElementsByName(obj.id)[0];
       };

       function loadandplay(file, type, author, title, description, image) {
          player.sendEvent('LOAD', { file: file, type: type, author: author, title: title, description: description, image: image });
          player.sendEvent('PLAY', 'true');
       };

       // Jquery
       $(document).ready(function() {
          var firstVideoSrc = $("ul.video-list li:first a:first").attr("href");
          var vidFirstTitle = $("ul.video-list li:first a:first").text();
          var vidBackgroundImage = $("ul.video-list li:first img").attr("src");
          var strVideoHRef;

          if($("ul.video-list a.video").length > 0){
             strVideoHRef = firstVideoSrc.substring((firstVideoSrc.indexOf("=")) + 1, firstVideoSrc.length);
             ResetVideoListVisibility();
             $("ul.video-list li:first").hide(); // hide first video as this is our selected one to start with
          }

	// hide the list if we only have one video
	if($("ul.video-list a.video").length <= 1){
            $("ul.video-list").hide();
         }

          var vidFirstSource = strVideoHRef;
          // setup first video to load
          var flashvars =
         {
            autostart: 'false',
            fullscreen: 'true',
            controlbar: 'bottom',
            file: vidFirstSource,
            author: 'Bolton School',
            title: vidFirstTitle,
            image: vidBackgroundImage 
         };
          var params = { allowscriptaccess: 'always', allowfullscreen: 'true' };
          var attributes = { name: 'mediaplayer', id: 'mediaplayer' };
          // set our h3
          $("h3.youtube-selected").text(vidFirstTitle);

          // load video
          swfobject.embedSWF('/boltonschool/swf/player.swf', 'player', '271', '210', '9.0.124', false, flashvars, params, attributes);

          $("a.video").click(function() {

             var intSubstringStart = ($(this).attr("href").indexOf("=") + 1);
             var intSubstringEnd = ($(this).attr("href")).length;
             var strVideoHRef = $(this).attr("href").substring(intSubstringStart, intSubstringEnd);
             var strVideoTitle = $(this).attr("title");
             var strImageBackgroundSource = $(this).parent().find('.video-background').attr("src");
               var strType = "video";
               if (strVideoHRef.indexOf(".mp3") > 0) strType = "sound";

               loadandplay(strVideoHRef, strType, 'Bolton School', 'Bolton School', strVideoTitle, strImageBackgroundSource);
             $("h3.youtube-selected").text($(this).text());

             ResetVideoListVisibility(); // show all videos
             $(this).parent().hide(); // hide our current selected video

             return false;
          });

	  // show all videos again
	  function ResetVideoListVisibility() {

             $("ul.video-list").children().each(function() {
                $(this).show();
                $(this).find('.video-background').hide();
             })

          }
       });
