//jQuery image preloader
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

$(document).ready(function(){
  //Select thumbnail based off URL
  var url = window.location.href;
  $('.thumbnail a[href="'+ url + '"]').addClass('selected');
  
  if(url == 'http://shutdown.kill9studios.com/cast' || url == 'http://shutdown.kill9studios.com/crew' || url == 'http://shutdown.skimbee.com/cast' || url == 'http://shutdown.skimbee.com/crew') {
    var thumbNext = $('.thumbnail a:eq(1)').attr('href');
    $('.next a').attr('href', thumbNext);
	$('.thumbnail a:eq(0)').addClass('selected');
  }
  
  if($.browser.msie && $.browser.version == '6.0') $('#crew-badge').pngFix();

  //Fade thumbnails to 80%
  $('.thumbnail a[class!="selected"] img').fadeTo('fast', 0.75);

  //Fade effect of thumbnails on hover
  $('.thumbnail a[class!="selected"] img').hover(function(){
    $(this).fadeTo('fast', 1);
  }, function(){
    $(this).fadeTo('fast', 0.75);
  });
  
  //Take first name and last name and only display first name
  $('.thumbnail a span').each(function(){
    var thumb = $(this).text();
	
	if(thumb.length >= 14) {
	 a = thumb.split(/\W+/);
	 $(this).text(a[0]);
	} else { 
	  $(this).text(thumb); 
	}

  });
  
  //preload badge images
  $.preloadImages('/images/bg_content-cast-badge.png','/images/44.png', '/images/23.png','/images/45.png','/images/24.png','/images/49.png','/images/46.png','/images/47.png','/images/48.png');
									 
});