//**************************************************************************************
// MAIN.JS

/*
   Main JavaScript file for the University of Surrey website.*/

//**************************************************************************************

// Start of activate_swf_links.min.js - 36982
$(document).ready(function(){$('.swfLink').each(function(){var so=new SWFObject($(this).attr('href'),'abc',$(this).find('.swfWidth').text(),$(this).find('.swfHeight').text(),'8','#ffffff');so.write($(this).parent().attr('id'));});});
// End of of activate_swf_links.min.js - 36982	   
// Start of activatemp3links.js - 41567
$(document).ready(function(){
  var i = 0;
  var linkId,playerName,mp3Filename = '';
  $('.mp3Link').each(function(){
    i+=1;
    mp3Filename = $(this).find('a').attr('href');
    linkId = 'mp3link' + i;
    playerName = 'mp3player' + i;
    $(this).attr('id', linkId);
    var so = new SWFObject('http://www.surrey.ac.uk/assets/swf/mp3player.swf', playerName, '300', '80', '8', '#ffffff');
    so.addVariable('mp3Filename', mp3Filename);
    so.write(linkId);
    });
  });
// End of of activatemp3links.js - 41567	   
// Start of activatevideooverlaylinks.js - 46272
  $(document).ready(function(){
    $('body').append('<div id="videoOverlay"><div id="vo_title"></div><div id="vo"></div><div id="vo_close">Close</div></div>');
    $('a.videoOverlayLink').bind('click', function(e){
	  var videoFile, stillFile, videoId, filmWidth, filmHeight, totalWidth, totalHeight, videoClass, videoTitle;
      var playerWidth = 0, playerHeight = 20;
	  videoTitle = $(this).attr('title');
	  e.preventDefault();
	  filmWidth = 640;
	  filmHeight = 360;
      //i+=1;
      videoFile = $(this).attr('href');      
	  stillFile = $(this).find('.videoStill').attr('title');	  
      videoClass = $(this).attr('class').split(' ');
      for(var j=0; j<videoClass.length; j++){
        if(videoClass[j].indexOf('width') > -1){
          filmWidth = parseInt(videoClass[j].replace('width', ''));
          }
        if(videoClass[j].indexOf('height') > -1){
          filmHeight = parseInt(videoClass[j].replace('height', ''));
          }
        }
      totalWidth = filmWidth + playerWidth;
      totalHeight = filmHeight + playerHeight;
      //videoId = 'video' + i;
      //$(this).attr('id', videoId);
      var playerURL = 'http://www.surrey.ac.uk/files/swf/flash_video_player.swf';
	  playerURL = playerURL.replace(/amp;/g, '');
	  var so = new SWFObject(playerURL, 'thevideo', totalWidth, totalHeight, '6', '#ffffff');
	  so.addVariable('MM_ComponentVersion', '1');
      so.addVariable('height', totalHeight);
      so.addVariable('width', totalWidth);
      so.addVariable('file', videoFile);
	  //so.addVariable('file', encodeURIComponent(videoFile));
	  so.addParam('allowfullscreen','true');
	  if(stillFile){
	    so.addVariable('image', stillFile);
		}
	  so.addVariable('searchbar', 'false');
	  so.addVariable('autostart', 'true');
      so.addVariable('showstop', 'true');
      so.write('vo');
	  $('#vo_title').text(videoTitle);	  
	  tb_show(videoTitle,'#TB_inline?height=' + (totalHeight + 60) + '&width=' + (totalWidth + 0) + '&inlineId=videoOverlay&modal=true',null);
	  $('#vo_close').bind('click', function(e){
	    tb_remove();
		});
	  });
	});
// End of of activatevideooverlaylinks.js - 46272	   
// Start of media_coverage_expander.js - 59274
$(document).ready(function(){
  $('.mediaIntro').hide();
  $('.mediaCoverageItem:first').before('<p class="mediaCoverageInstruction">Click on the headlines below to find out more.</p>');
  $('.mediaCoverageItem h3').css('cursor', 'pointer').bind('click', function(e){
    $(this).parent().find('.mediaIntro').toggle('medium');
    e.preventDefault();		
    });
  });
// End of of media_coverage_expander.js - 59274	   


