﻿var CURRENT_SLIDER_INNER = "#currentSliderInner"
var CURRENT_SLIDER_ITEM_1 = "#currentSliderItem1"
var CURRENT_SLIDER_ITEM_2 = "#currentSliderItem2"
var CURRENT_SLIDER_TIMEOUT = 10000;
var CURRENT_SLIDER_ANIMATION_SPEED = 1000;
var CURRENT_SLIDER_ITEM_HEIGHT = 24;
var CURRENT_REFRESH_TIMEOUT = 30000;

var getCurrentTimeout = null;
var sliderSwitchTimeout = null;
var currentShow = null;

jQuery.noConflict()

jQuery(document).ready(function() {
    currentShow = jQuery(CURRENT_SLIDER_ITEM_2).html();
    getCurrent()
});

function currentSliderSwitch() {
   jQuery(CURRENT_SLIDER_INNER).animate({ top: CURRENT_SLIDER_ITEM_HEIGHT + 'px' }, CURRENT_SLIDER_ANIMATION_SPEED, function() {
      var temp = jQuery(CURRENT_SLIDER_ITEM_1).html();
      jQuery(CURRENT_SLIDER_ITEM_1).html(jQuery(CURRENT_SLIDER_ITEM_2).html());
      jQuery(CURRENT_SLIDER_ITEM_2).html("");

      jQuery(CURRENT_SLIDER_INNER).css("top", "-" + CURRENT_SLIDER_ITEM_HEIGHT + "px");

      jQuery(CURRENT_SLIDER_INNER).animate({ top: '0px' }, CURRENT_SLIDER_ANIMATION_SPEED, function() {
         jQuery(CURRENT_SLIDER_ITEM_2).html(temp);
         sliderSwitchTimeout = setTimeout(currentSliderSwitch, CURRENT_SLIDER_TIMEOUT);
      });
   });
}

function getCurrent() {
    clearTimeout(sliderSwitchTimeout);
    clearTimeout(getCurrentTimeout);

		var ran = new Date().getTime(); // unique random number to workaround IE cache issue

    jQuery.ajax({
        type: "GET",
        cache: "false",
        url: "log.current_event.php?r=" + ran,
        success: function(result) {
            var currentTune	= result.split(";;")[0];
            var currentShow	= result.split(";;")[1];

            jQuery(CURRENT_SLIDER_INNER).css("top", "0px");
            jQuery(CURRENT_SLIDER_ITEM_1).html(currentTune);
            jQuery(CURRENT_SLIDER_ITEM_2).html(currentShow);

            sliderSwitchTimeout = setTimeout(currentSliderSwitch, CURRENT_SLIDER_TIMEOUT);
            getCurrentTimeout = setTimeout(getCurrent, CURRENT_REFRESH_TIMEOUT);
        }
    });
}
