$(document).ready(function(){
  
  var selectedSpotId = 'sp-video';
  var spotMenuElem = $('#spot-menu li a');
  var vbSpotIcon = $('#spotlight-r-content-sp-icon');
  var spotImgContainerElem = $('#sp-img-container .img-hide-content');
  var spotTypeTitle = $('.hide-sp-title');
  var tabContent = $('.sp-tab-content');
  
  spotMenuElem.mouseenter(function(e){
    e.preventDefault();
    
    var parent = $(this).parent();
    
    manageSpotMenuBkg(parent);
    manageSpotContent(parent);
  });
  
  manageSpotMenuBkg = function(parent)
  {
    var parentId = parent[0].id;
    var parentSpan = parent.find('span');
    
    switch(parentId)
    {
      case 'sp-video':
      {
        parent.css('background-position', '-212px bottom');
        parentSpan.css('background-position', '-212px top');
        $('#sp-photo, #sp-game').css('background-position', 'left bottom');
        $('#sp-photo span').css('background-position', '-424px top');
        $('#sp-game span').css('background-position', '-848px top');
      $('h2#sp-video-title').parent().parent().parent().addClass('vb');
      $('h2#sp-video-title').parent().parent().parent().removeClass('pv gm');
        break;
      }
      case 'sp-photo':
      {
        parent.css('background-position', '-424px bottom');
        parentSpan.css('background-position', '-636px top');
        $('#sp-video, #sp-game').css('background-position', 'left bottom');
        $('#sp-video span').css('background-position', 'left top');
        $('#sp-game span').css('background-position', '-848px top');
      $('h2#sp-photo-title').parent().parent().parent().addClass('pv');
      $('h2#sp-photo-title').parent().parent().parent().removeClass('vb gm');
        break;
      }
      case 'sp-game':
      {
        parent.css('background-position', '-636px bottom');
        parentSpan.css('background-position', '-1060px top');
        $('#sp-video, #sp-photo').css('background-position', 'left bottom');
        $('#sp-video span').css('background-position', 'left top');
        $('#sp-photo span').css('background-position', '-424px top');
      $('h2#sp-game-title').parent().parent().parent().addClass('gm');
      $('h2#sp-game-title').parent().parent().parent().removeClass('vb pv');
        break;
      }
    }
  }
  
  manageSpotContent = function(el)
  {
    var currentEl = $(el);
    var currentElId = el[0].id;
    
    if(selectedSpotId != currentElId)
    {
      spotImgContainerElem.fadeOut();
      spotTypeTitle.parent().parent().hide();
      spotTypeTitle.hide();
	  
	  tabContent.hide();
      
      $('#'+currentElId+'-img').fadeIn();
      $('#'+currentElId+'-title').parent().parent().show();
      $('#'+currentElId+'-title').show();
	  
      $('#'+currentElId+'-tab').show();
	  	eaAutoShrink($('#spotlight-r-content .header .title h2:visible div'), 180, 60,18);
		eaAutoShrink($('#'+currentElId+'-tab p.start_btn a.btn-red span'), 284, 40,12);

	  
    }
    vbSpotIcon.fadeOut('fast', function(){
      $(this).attr('class', currentElId+'-icon').fadeIn();
      if(currentElId == 'sp-firsttime')
      {
        $(this).css('visibility', 'hidden');
      }
      else
      {
        $(this).css('visibility', 'visible');
      }
    });
    spotMenuElem.removeClass('active');
    currentEl.addClass('active');
    
    selectedSpotId = currentElId;
  };
  
});
