var rotatorr = {};

$(document).ready(function()	{
  rotatorr.ui.mainPromote();
  //rotatorr.ui.tabs();
});

rotatorr.ui = {
	
  mainPromote: function() { //rotate and animate main promote
    $('#mainPromo ul.panels').css({ overflow:'hidden'});
    $('#mainPromo ul.panels li').css({ position:'absolute',top:0,right:2,zIndex:100 }).filter(':first').css({zIndex:200})
    var promotes = $('#mainPromo ul.panels li');
    
    //set up main promote
    promotes.hide().filter(':first').show();
    $('#mainPromo ul.tabs li').animate({opacity: 0.6}, 300).filter(':first').animate({opacity: 1.0}, 50);
    $('#mainPromo ul.tabs a').filter(':first').addClass('activeTab').end().filter(':last').addClass('lastTab');
    

    //bind click event to main promote tabs
    $('#mainPromo ul.tabs a').bind('click', function() {
      promotes.fadeOut().filter(this.hash).fadeIn();
      $(this).parents('li').animate({opacity: 1.0}, 300).siblings().animate({opacity: 0.6}, 300).find('a').removeClass('activeTab');
      $(this).addClass('activeTab');
      return false;
    });
    
    var rotateInt = '';
    function startRotation() {
      if (rotateInt == '') { rotateInt = window.setInterval('rotatorr.ui.mainPromoteAnimate()', 6000); }
      else { stopRotation(); }
    }
    function stopRotation() {
      if (startRotation != '') {
        window.clearInterval(rotateInt);
        rotateInt = '';
      }
    }
    startRotation();
    
    $('#mainPromo').hover(
      function() { stopRotation(); },
      function() { startRotation(); }
    );
  },
  
  mainPromoteAnimate: function() {
    var $active = $('#mainPromo ul.tabs a.activeTab');
    if ($active.hasClass('lastTab')) {
      var $next = $active.parents('li').parents('ul').find('li a:first').click();
    } else {
      var $next = $active.parents('li').next('li').find('a').click();
    }
  }
};
