$(document).ready(function() {
  
  $("a[rel='external']").attr("target", "_blank");

  var root = window.location.host;
  
  if ($.browser.msie) {
  
    $('#navigation li').hover(
      function() {
        $(this).addClass('hover');
      }, function() {
        $(this).removeClass('hover');
      }
    );
  
  }

  // Init Screen Swapper
  initScreens();

});

function initScreens() {

  var el = $('.block-screens');
  if (el.length > 0) {
  
    var title = el.find('a:visible').find('img').attr('alt');
    if (el.find('p')) {
      el.find('p').text(title);
    }
    
    // Click next button
    $('a#next').click(function(e) {
      
      // Check if next li is not last
      if (el.find('a:visible').parent('li').next().index() != el.find('ul li').size() - 1) {
        var newTitle = el.find('a:visible').parent('li').next().find('img').attr('alt');
        if (el.find('p')) {
          el.find('p').text(newTitle);
        }
        el.find('a:visible').parent('li').fadeOut('slow').next().fadeIn('slow');
        $('#next, #prev').show();
      } 
      // If li is last, hide next button and show last li
      else {
        $('#next').hide();
        el.find('a:visible').parent('li').fadeOut('slow').next().fadeIn('slow');
      }
      e.preventDefault();
    });
    
    // Click prev button
    $('a#prev').click(function(e) {
      
      // Check if li is not first
      if (el.find('a:visible').parent('li').prev().index() != 0) {
        var newTitle = el.find('a:visible').parent('li').prev().find('img').attr('alt');
        if (el.find('p')) {
          el.find('p').text(newTitle);
        }
        el.find('a:visible').parent('li').fadeOut('slow').prev().fadeIn('slow');
        $('#prev, #next').show();
      } 
      
      // If li is first, hide prev button and show first li
      else {
        $('#prev').hide();
        el.find('a:visible').parent('li').fadeOut('slow').prev().fadeIn('slow');
      }
      e.preventDefault();
    });
  
  }

}

function openLargeImage(image_path) {
	var caption = '';
	var gallery = '';
	//use function from thickbox lib manually open a thickbox window
	tb_show(caption,image_path,gallery);
}

function openVideoPlayer(video_path) {
	
	var url = "/includes/flashplayer.php?gallery=" + video_path + "&vheight=507&vwidth=880&TB_iframe=true&height=527&width=851";
	tb_show('',url,'');
}

// Frame Rate functions for Flash
function throttleFramerate() {
  document.getElementById("flashContent").throttleFrameRateJS();
}
function unThrottleFramerate() { 
  document.getElementById("flashContent").unThrottleFrameRateJS();
}
