/**
 * Frontend Javascripts
 */
 
/**
 * Unobtrusive Javascript
 * - Keep the views clear of javascripts by 
 *   working on the DOM when ready
*/
$(document).ready(function() {
  
  // handle #search submit image-button
  $('.submit-image').hover(
    function() {
      $(this).fadeTo(250, 0.5);
    },
    function() {
      $(this).fadeTo(250, 1);
    }
  );
  
  // handle #header rollovers
  $('#search h1 a').hover(
    function() {
      $(this).css('background-position', 'bottom left');
    },
    function() {
      $(this).css('background-position', 'top left');
    }
  );
  
  $('#dead ul li').hover(
    function() {
      if ($(this).hasClass('contact')) $('#header ul li.contact').css('background-position', '-175px -59px');
      if ($(this).hasClass('home')) $('#header ul li.home').css('background-position', '0px -59px');
      if ($(this).hasClass('press')) $('#header ul li.press').css('background-position', '-58px -59px');
    },
    function() {
      if ($(this).hasClass('contact')) $('#header ul li.contact').css('background-position', '-175px -14px');
      if ($(this).hasClass('home')) $('#header ul li.home').css('background-position', '0px -14px');
      if ($(this).hasClass('press')) $('#header ul li.press').css('background-position', '-58px -14px');
    }
  );
  
  // handle logo rollovers
  $('#content ul.logos li img').hover(
    function() {
      $(this).fadeTo(250, 0.35);
    },
    function() {
      $(this).fadeTo(250, 1);
    }
  );
  
  // replace html inside of #main-promo with swf content
  if ($('#main-promo').length > 0) {
    swfobject.embedSWF(
      "/flash/cw_main.swf", 
      "main-promo", 
      "689", "260", 
      "9.0.0", 
      "/flash/expressInstall.swf",
      false,
      {wmode: 'transparent'}
    );
  }

  // place adverts on Global and E! Entertainment custom network pages
  if ($('#advert-global').length > 0) {
    swfobject.embedSWF(
      "/flash/global-home.swf", 
      "advert-global", 
      "260", "213", 
      "9.0.0", 
      "/images/common/flash/expressInstall.swf",
      false,
      {wmode: 'transparent'}
    );
  }
  
  if ($('#advert-entertainment').length > 0) {
    swfobject.embedSWF(
      "/images/frontend/flash/entertainment-home.swf", 
      "advert-entertainment", 
      "260", "213",
      "9.0.0", 
      "/images/common/flash/expressInstall.swf",
      false,
      {wmode: 'transparent'}
    );
  }
  
});
