﻿var videoItemWidth = 0;
var videoListWidth = 0;
var videoListMoving = false;

$(document).ready(function() {
 
  videoItemWidth = $("#videolistwrapper ul li").eq(0).width() + 1;
  videoListWidth = ($("#videolistwrapper ul li").size() - 5) * videoItemWidth;

  $("#videolist .left").click(
    function() {
      moveVideoItems(-1)
    }
  );

  $("#videolist .right").click(
    function() {
      moveVideoItems(1)
    }
  );
  
  
  $("#videolist .left").hover(
      function () {
		$(this).css('backgroundImage', 'url(/platformPlayer/sidebarAssets/prevButtonOver.jpg)'); 
      }, 
      function () {
        $(this).css('backgroundImage', 'url(/platformPlayer/sidebarAssets/prevButtonUp.jpg)'); 
      }
  );  
  
  $("#videolist .right").hover(
      function () {
        $(this).css('backgroundImage', 'url(/platformPlayer/sidebarAssets/nextButtonOver.jpg)'); 
      }, 
      function () {
        $(this).css('backgroundImage', 'url(/platformPlayer/sidebarAssets/nextButtonUp.jpg)'); 
      }
  );   
  
});

function setVideoSlider(id) {
  var el = $("#videoitem_" + id).parent();

  if ( !el.hasClass("selected") ) {
    el.addClass("selected").append("<span>Playing</span>");
    el.siblings().removeClass("selected").find("span").remove();
  }
}

function moveVideoItems(direction) {
  var nextMargin = parseInt($("#videolistwrapper ul").css("margin-left")) + videoItemWidth;

  if ( videoListMoving == false && ((direction == 1 && nextMargin >= -videoListWidth) || (direction == -1 && nextMargin <= 0)) ) {
    videoListMoving = true;

    $("#videolistwrapper ul").animate(
      {
        marginLeft: (direction == -1 ? "+" : "-") + "=" + videoItemWidth
      },
      "fast",
      function()
      {
        videoListMoving = false;
      }
    );
  }
}
