﻿var _totalItems;
var _itemHeight = 135;
var _itemHeightDouble = 135 * 2;
var _leftValue = _itemHeight * (-1);
var _leftValueDouble = _itemHeight * 2 * (-1)
var _sliderSpeed = 5000;
var _isPreviousSealShown = false;
var _bannerAnimateHeight = 265;
var _isInitial = true;
var _postUrlPath = "default.ashx";
var _animatedBanner = false;
var _animatedNav = false;
var _animatedFooter = false;
var _animatedCycle = false;
var _cycleOn = true;
var _isHovered = false;
var _isMobile = false;
var _agent = "";
var pt_x = 0;
var pt_y = 0;
var pt_l = 'out';
var pt_s = 0;
var run = null;

$(window).load(function () {
  if ($('div.home-carousel').length > 0) {
    setCarouselTimer();
  }
});

$(document).ready(function () {
  if ($('div.home-carousel').length > 0) {
    getHomeCarousel();
  }
});

/*///////////////////////General Functions////////////////////*/
function getHomeCarousel() {
  getData();
}

function setInitialState() {
  _agent = navigator.platform.toLowerCase();
  _isMobile = (_agent == 'iphone') || (_agent == 'ipad') || (_agent == 'android') || (_agent == 'blackberry');
  _totalItems = getTotalItems('.nav-container .item-container .scroll-container .item');

  //onNavigationHover('.nav-container-empty .item-container .scroll-container .item', '.nav-container .item-container .scroll-container');
  onNavigationClick('.nav-container-empty .item-container .scroll-container .item', '.nav-container .item-container .scroll-container');

  /* offset navigation to sync with main banner */
  $('.nav-container .item-container .scroll-container').css({ 'top': _leftValue + 'px' });
  $('.nav-container-empty .item-container .scroll-container').css({ 'top': _leftValue + 'px' });

  /* display first footer caption item */
  $('.home-carousel > .footer > div:first').css('display', 'block');

  /* show first item in main banner */
  $('.home-carousel .item-container-main .scroll-container > div:first').css({ 'top': '-' + _bannerAnimateHeight + 'px', 'z-index': '500' });

  /* set seal */
  setSeal('.home-carousel .seal');

  likeClick();

  $(document).bind('mousemove', function (e) {
    pt_x = e.pageX;
    pt_y = e.pageY;


    var content = $('#content');
    var container = $('.nav-container-empty .item-container');
    var pt = container.position();
    var ppt = content.position();
    var pt_w = container.css('width');
    var pt_h = container.css('height');


    var left = ppt.left + 260;
    var right = left + parseInt(pt_w);
    var top = 175;
    var bottom = 445;

    if (pt_x > left && pt_x < right && pt_y > top && pt_y < bottom) {
      pt_l = 'in';
    } else {
      pt_l = 'out';
    }



    //$('#status').html(left + ':' + right + ':' + top + ':' + bottom + ':' + pt_x + ':' + pt_y + ':' + pt_l + ':' + ppt.left + ':' + ppt.top);      
    //$('#status').html(pt_x + ',' + pt_y + ',' + pt_l + ',' + pt_s);
    updateHover();

    // trace('hit');
  });
}
function updateHover() {

  setTimeout(function () {
    var div = $('.home-carousel .nav-container .item-container .scroll-container');
    var t = parseInt(div.css('top'));
    div.find('.footer').removeClass('hover');

    if (pt_l == 'in') {
      var z = Math.abs(t);
      var n = parseInt(z / 135) + 1;
      if (pt_y > 175 && pt_y < 310) {
        div.find('.footer:eq(1)').addClass('hover');
      } else if (pt_y > 310 && pt_y < 445) {
        div.find('.footer:eq(2)').addClass('hover');
      }
    } else {
      pt_s = 0;
    }

  }, 0);

}


function getTotalItems(mainClass) {
  return $(mainClass).size() - 1;
}

function setCarouselTimer() {
  $('.home-carousel').hover(function () {
    clearInterval(run);
    _cycleOn = false;
    _isHovered = true;
  }, function () {
    _cycleOn = true;
    clearInterval(run);
    run = setInterval('rotate()', _sliderSpeed);
    _isHovered = false;
  });

  run = setInterval('rotate()', _sliderSpeed);

}


function rotate() {
  _animatedCycle = true;

  if (_animatedCycle) {
    if (_cycleOn) {
      animateDecrementTop('.home-carousel .nav-container .item-container .scroll-container', '.home-carousel .nav-container-empty .item-container .scroll-container', _itemHeight);
      slideBannerOnScrollDown('.home-carousel .item-container-main .scroll-container', _bannerAnimateHeight);
    }

    _animatedCycle = false;
  }
}

function setTimeOutOnClick() {
  _cycleOn = false;
  _animatedCycle = false;

  if (!_isHovered) {
    setTimeout("_cycleOn = true; clearInterval(run); run = setInterval('rotate()', _sliderSpeed);", 20000);
  }
}

function fadeOutSeal(sealClass) {
  $(sealClass).fadeOut();
}

function fadeInSeal(sealClass) {
  $(sealClass).fadeIn();
}

function setSeal(sealClass) {
  //.home-carousel .item-container-main .scroll-container .item .seal-info

  var currentItem = $('.home-carousel .item-container-main .scroll-container .item:first');
  var currentSealInfo = currentItem.find('.seal-info').html();

  if (currentSealInfo == 'True' || currentSealInfo == 'true' || currentSealInfo == '1' || currentSealInfo == 'on') {
    fadeInSeal(sealClass);
  } else {
    fadeOutSeal(sealClass);
  }
  //trace(currentSealInfo);
  //trace(currentIndex);
  /*
  if ((_isInitial) && (booleanConverter(currentSealInfo) == true)) {
  $(sealClass).css('display', 'block');
  _isPreviousSealShown = true;
  _isInitial = false;
  //trace('hitInitial');
  }
  else {
  if ((booleanConverter(currentSealInfo) == true) && (_isPreviousSealShown == false)) {
  fadeInSeal(sealClass);
  _isPreviousSealShown = true;
  //trace('hit1');
  }
  else if ((booleanConverter(currentSealInfo) == false) && (_isPreviousSealShown == true)) {
  fadeOutSeal(sealClass);
  _isPreviousSealShown = false;
  //trace('hit2');
  }
  }
  */
  //    trace(_isPreviousSealShown);
}

function booleanConverter(object) {
  if (object.toLowerCase() == 'false')
    return false;
  else if (object.toLowerCase() == 'true')
    return true;
}

function trace(s) {
  //if (window.console) window.console.log(s);
}

function jsonp_callback() {
  //trace('jsonp_callback');
}

function create(name) {
  return $(document.createElement(name));
}

function likeClick() {
  //trace($('.home-carousel > .footer .footer-item .right-content .right-content-inner .icon.thumb').attr('class'));
  $('.home-carousel > .footer .footer-item .right-content .right-content-inner .icon.thumb a').click(function (e) {
    e.preventDefault();



    var likeIdInfo = $(this).find('img').attr('id');
    var slideTitle = $(this).parent().parent().parent().parent().find('.left-content').find('.caption').text();
    //trace(likeIdInfo);

    var likeId = likeIdInfo.split('-');
    //trace(likeId[1]);

    var likeUrl = _postUrlPath + '?cmd=Like&like_id=' + likeId[1];
    //trace(likeUrl);
    _gaq.push(['_trackEvent', 'Social Media', 'Likes', slideTitle]);

    $.ajax({
      type: 'POST',
      url: likeUrl,
      success: function () { }
    });

    var div = $(this).parent().parent().parent().find('.like-info');
    //trace(div.outerHTML());

    var currentLikes = div.find('span').html();
    //trace(currentLikes);
    if (currentLikes == null || currentLikes.length == 0) currentLikes = 1;
    //trace(currentLikes);
    currentLikes = Number(currentLikes) + 1;
    //trace(currentLikes);
    div.find('span').html(currentLikes);
    if (currentLikes > 0) div.fadeIn();
  });
}

/*///////////////////////Data Feed/JSON Functions////////////////////*/
function getData() {
  //trace('go');
  var settings = {};
  settings.url = "default.ashx";

  settings.cache = false;
  settings.async = true;

  settings.dataType = 'json';

  var data = {};
  data.cmd = 'GetHomeCarousel';

  settings.data = data;

  settings.error = function (XMLHttpRequest, textStatus, errorThrown) { trace(textStatus); trace(errorThrown); };
  settings.success = function (data, textStatus, XMLHttpRequest) {
    //trace('success');
    var count = 1;

    $.each(data, function (i, o) {
      //trace(o);

      //build carousel
      var bannerId = 'banner-' + count;
      var navItemId = 'nav-' + count;
      var emptyNavItemId = 'empty-' + count;

      //image pre-url
      var imagePath = 'Images/Home-Carousel/';

      buildMainBanner(o, data, bannerId, imagePath, count);
      buildMainFooter(o, data, imagePath, count);
      buildEmptyNavigation(count, emptyNavItemId);
      buildNavigation(o, data, navItemId, imagePath, count);

      count++;
    });

    setInitialState();

    navScrollUp();
    navScrollDown();
  };
  $.ajax(settings);
}

function buildMainBanner(o, data, bannerId, imagePath, count) {
  //create item container
  var html = create('div').attr({ 'class': 'item', 'id': 'banner-' + count });

  //create content div
  var bannerContent = create('div').attr('class', 'content');
  var bannerLink = create('a').attr({ 'href': o.url, 'target': o.target });

  var bannerImage = create('img').attr({ 'src': imagePath + o.image_url, 'alt': o.name, 'title': o.name });
  // event tracking for clicking on the banner
  bannerImage.attr('onclick', '').click(function () { _gaq.push(['_trackEvent', 'Banners', 'Click', o.name]); });
  bannerLink.append(bannerImage);
  bannerContent.append(bannerLink);

  var sealInfo = create('div').attr('class', 'seal-info').html(o.only_at_flag);
  html.append(sealInfo);

  html.append(bannerContent);

  $('.home-carousel .item-container-main .scroll-container').append(html);

  //setSeal(o, count, '.home-carousel .seal');
}

function buildMainFooter(o, data, imagePath, count) {
  //create footer div
  var footerItem = create('div').attr({ 'class': 'footer-item', 'id': 'footer-item-' + count });

  footerItem.append(getLeftFooterContent(o, data, count));
  footerItem.append(getRightFooterContent(o, data, imagePath));

  var uaLinkBack = o.redirect_url;
  var uaTitle = o.name;
  var uaImgSrc = o.share_image_url;
  var uaDescription = o.description;

  var selector = '.home-carousel > .footer #right-content-inner-' + o.like_id;

  trace('now');
  trace(o);


  $('.home-carousel > .footer').append(footerItem);

  $(selector).each(function (i, o) {
    var ua = new gigya.services.socialize.UserAction();
    ua.setLinkBack(uaLinkBack);
    ua.setTitle(uaTitle);

    ua.setDescription(uaDescription);

    var img = { type: 'image', src: uaImgSrc, href: uaLinkBack };
    ua.addMediaItem(img);

    var params = {
      userAction: ua,
      operationMode: 'multiSelect',
      shareButtons: 'share,facebook-like,google-plusone',
      containerID: $(this).attr('id'),
      onSendDone: function () {
        trace('onSendDone');
        var url = uaLinkBack.toLowerCase().replace(app_url.toLowerCase(), '');
        trackWebEvent('Share', url);
      },
      onShareButtonClicked: function () { trace('onShareButtonClicked'); },
      onLoad: function () { trace('onLoad'); },
      onError: function (e) { trace('onError'); trace(e); },
      onClose: function () { trace('onClose'); }
    };
    gigya.services.socialize.showShareBarUI({}, params);
  });

}

function setBannerCounter(count, data) {
  return count + ' / ' + data.length; //set data.length to total items
}

function getLeftFooterContent(o, data, count) {
  var footerLeftContent = create('div').attr('class', 'left-content');
  var footerCounter = create('div').attr('class', 'counter').html(setBannerCounter(count, data));
  var footerCaption = create('div').attr('class', 'caption').html(o.name);
  footerLeftContent.append(footerCounter);
  footerLeftContent.append(footerCaption);

  return footerLeftContent;
}

function getRightFooterContent(o, data, imagePath) {
  var div = $('<div>').addClass('right-content');
  div.append($('<div>').attr('id', 'right-content-inner-' + o.like_id).addClass('right-content-inner'));
  // this is pretty easy; just show the share bar for the url
  //trace(o);
  return div;
}
function getRightFooterContentOld(o, data, imagePath) {
  var likeUrl = _postUrlPath + '?cmd=Like&like_id=' + o.like_id;

  var footerRightContent = create('div').attr('class', 'right-content');
  var footerRightInnerContainer = create('div').attr('class', 'right-content-inner');

  var footerLikeInfo = create('div').attr('class', 'like-info');
  var totalLikes = Number(o.likes);

  footerLikeInfo.html('<span>' + o.likes + '</span>' + ' Likes');

  if (totalLikes == 0) {
    footerLikeInfo.hide();
  }

  var footerIconThumb = create('div').attr('class', 'icon thumb');
  var footerIconThumbLink = create('a');
  var footerIconThumbImage = create('img').attr({ 'src': imagePath + 'Icon-Thumbs-Up.png', 'alt': 'Thumbs Up', 'title': 'Like This', 'id': 'likeid-' + o.like_id });

  var footerIconFacebook = create('div').attr('class', 'icon');
  var footerIconFacebookLink = create('a').attr({ 'href': o.facebook_url, 'target': '_blank' });

  // event tracking of Facebook sharing
  footerIconFacebookLink.attr('onclick', '').click(function () { _gaq.push(['_trackEvent', 'Social Media', 'Facebook', o.name]); });
  var footerIconFacebookImage = create('img').attr({ 'src': imagePath + 'Icon-Facebook.png', 'alt': 'Share on Facebook', 'title': 'Share On Facebook' });

  var footerIconTwitter = create('div').attr('class', 'icon');
  var footerIconTwitterLink = create('a').attr({ 'href': o.twitter_url, 'target': '_blank' });

  // event tracking of Twitter sharing
  footerIconTwitterLink.attr('onclick', '').click(function () { _gaq.push(['_trackEvent', 'Social Media', 'Twitter', o.name]); });
  var footerIconTwitterImage = create('img').attr({ 'src': imagePath + 'Icon-Twitter.png', 'alt': 'Share on Twitter', 'title': 'Share On Twitter' });

  footerIconThumb.append(footerIconThumbLink);
  footerIconThumbLink.append(footerIconThumbImage);

  footerIconFacebook.append(footerIconFacebookLink);
  footerIconFacebookLink.append(footerIconFacebookImage);

  footerIconTwitter.append(footerIconTwitterLink);
  footerIconTwitterLink.append(footerIconTwitterImage);

  footerRightInnerContainer.append(footerIconTwitter);
  footerRightInnerContainer.append(footerIconFacebook);
  footerRightInnerContainer.append(footerIconThumb);
  footerRightInnerContainer.append(footerLikeInfo);

  footerRightContent.append(footerRightInnerContainer);
  //footerRightContent.append(footerLikeInfo);

  return footerRightContent;
}

function buildEmptyNavigation(count, emptyNavItemId) {
  var emptyNav = create('div').attr({ 'class': 'item', 'id': emptyNavItemId });
  $('.nav-container-empty .item-container .scroll-container').append(emptyNav);
}

function buildNavigation(o, data, navItemId, imagePath, count) {
  var itemContainer = create('div').attr({ 'class': 'item', 'id': navItemId });
  var contentContainer = create('div').attr('class', 'content');
  var navImage = create('img').attr({ 'src': imagePath + o.thumb_url, 'alt': o.name, 'title': o.name });
  contentContainer.append(navImage);
  itemContainer.append(contentContainer);

  var footer = create('div').attr('class', 'footer');
  var footerContent = create('div').attr('class', 'content').html(o.name);
  footer.append(footerContent);
  itemContainer.append(footer);

  $('.nav-container .item-container .scroll-container').append(itemContainer);
  var parentID = count;
  var emptyElement = $('.nav-container-empty .item-container .scroll-container').find(parentID);
  emptyElement.attr('onclick', '').click(function () { _gaq.push(['_trackEvent', 'Banner Navigation', 'Impressions', o.name]); });
}

/*///////////////////////Navigation Functions////////////////////*/
function onNavigationHover(hoverClass, targetContainer) {
  $(hoverClass).hover(function () {
    var currentItem = $(this).attr('id').replace('empty-', '');
    var currentItemTarget = '#nav-' + currentItem;

    $(currentItemTarget).parent().find('.footer').removeClass('hover');
    $(currentItemTarget).find('.footer').addClass('hover');

  }, function () {
    var currentItem = $(this).attr('id').replace('empty-', '');
    var currentItemTarget = '#nav-' + currentItem;

    $(currentItemTarget).find('.footer').removeClass('hover');
  });
}

function onNavigationClick(hoverClass, targetContainer) {
  $(hoverClass).click(function () {
    //get current index
    var itemIndex = $(this).index();

    if (itemIndex == 1) {
      $('.home-carousel .nav-container-empty .bottom-arrow').click();

      setTimeOutOnClick();
    }
    else if (itemIndex == 2) {
      animateDecrementTopDouble('.home-carousel .nav-container .item-container .scroll-container', '.home-carousel .nav-container-empty .item-container .scroll-container', _itemHeightDouble);
      slideBannerOnScrollDownDouble('.home-carousel .item-container-main .scroll-container', _bannerAnimateHeight);

      setTimeOutOnClick();
    }
  });
}

function navScrollUp() {
  $('.home-carousel .nav-container-empty .top-arrow').click(function () {
    animateIncrementTop('.home-carousel .nav-container .item-container .scroll-container', '.home-carousel .nav-container-empty .item-container .scroll-container', _itemHeight);
    //animateIncrementTop('.home-carousel .nav-container-empty .item-container .scroll-container', _itemHeight);

    slideBannerOnScrollUp('.home-carousel .item-container-main .scroll-container', _bannerAnimateHeight);

    setTimeOutOnClick();
  });
}

function navScrollDown() {
  $('.home-carousel .nav-container-empty .bottom-arrow').click(function () {
    animateDecrementTop('.home-carousel .nav-container .item-container .scroll-container', '.home-carousel .nav-container-empty .item-container .scroll-container', _itemHeight);
    //animateDecrementTop('.home-carousel .nav-container-empty .item-container .scroll-container', _itemHeight);

    slideBannerOnScrollDown('.home-carousel .item-container-main .scroll-container', _bannerAnimateHeight);

    setTimeOutOnClick();
  });
}

//nav scroll up
function animateDecrementTop(containerClass, hoverClass, animateValue) {
  if (_animatedNav) return;

  //clone first item
  $(containerClass + ' .item:last').after($(containerClass + ' .item:first').clone(true));
  $(hoverClass + ' .item:last').after($(hoverClass + ' .item:first').clone(true));

  //change first item attribute name
  $(containerClass + ' .item:first').attr('id', $(containerClass + ' .item:first').attr('id') + '-old');

  var formattedValue = '-=' + animateValue + 'px';
  _animatedNav = true;
  $(containerClass).stop(true, true).animate({ 'top': formattedValue }, 550, function () {
    //take new first and add to bottom
    $(containerClass + ' .item:first').remove();
    $(containerClass).css('top', _leftValue + 'px');
    //_animatedNav = false;
  });

  $(hoverClass).stop(true, true).animate({ 'top': formattedValue }, { 'duration': 550, 'complete': function () {
    //take new first and add to bottom
    $(hoverClass + ' .item:first').remove();
    $(hoverClass).css('top', _leftValue + 'px');
    if (_isMobile) $('.nav-container .item-container .scroll-container .item .footer').removeClass('hover');
    _animatedNav = false;
  }, 'step': function (now, fx) {
    if (_isMobile) return;
    updateHover();
  } 
  });

}

function animateDecrementTopDouble(containerClass, hoverClass, animateValue) {
  if (_animatedNav) return;
  //clone first item and add after last
  $(containerClass + ' .item:last').after($(containerClass + ' .item:first').clone(true));
  $(hoverClass + ' .item:last').after($(hoverClass + ' .item:first').clone(true));

  //clone second item and add after last
  $(containerClass + ' .item:last').after($(containerClass + ' .item:nth-child(2)').clone(true));
  $(hoverClass + ' .item:last').after($(hoverClass + ' .item:nth-child(2)').clone(true));

  //change first item attribute name
  $(containerClass + ' .item:first').attr('id', $(containerClass + ' .item:first').attr('id') + '-old');

  var formattedValue = '-=' + animateValue + 'px';
  _animatedNav = true;
  $(containerClass).stop(true, true).animate({ 'top': formattedValue }, 550, function () {
    //take new first and add to bottom
    $(containerClass + ' .item:first').remove();
    $(containerClass + ' .item:first').remove();

    $(containerClass).css('top', _leftValue + 'px');
    //_animatedNav = false;
  });

  $(hoverClass).stop(true, true).animate({ 'top': formattedValue }, { 'duration': 550, 'complete': function () {
    //take new first and add to bottom
    $(hoverClass + ' .item:first').remove();
    $(hoverClass + ' .item:first').remove();

    $(hoverClass).css('top', _leftValue + 'px');
    if (_isMobile) $('.nav-container .item-container .scroll-container .item .footer').removeClass('hover');
    _animatedNav = false;
  }, 'step': function (now, fx) {
    if (_isMobile) return;
    updateHover();
  } 
  });



}

//nav scroll down
function animateIncrementTop(containerClass, hoverClass, animateValue) {
  if (_animatedNav) return;

  var formattedValue = '+=' + animateValue + 'px';
  _animatedNav = true;
  $(containerClass).stop(true, true).animate({ 'top': formattedValue }, 550, function () {
    //move last to first
    $(containerClass + ' .item:first').before($(containerClass + ' .item:last'));
    $(containerClass).css('top', _leftValue + 'px');
    //_animatedNav = true;
  });

  $(hoverClass).stop(true, true).animate({ 'top': formattedValue }, { 'duration': 550, 'complete': function () {
    //move last to first
    $(hoverClass + ' .item:first').before($(hoverClass + ' .item:last'));
    $(hoverClass).css('top', _leftValue + 'px');
    if (_isMobile) $('.nav-container .item-container .scroll-container .item .footer').removeClass('hover');
    _animatedNav = false;
  }, 'step': function (now, fx) {
    if (_isMobile) return;
    updateHover();
  } 
  });

}

/*///////////////////////Slider Functions////////////////////*/
function slideBannerOnScrollDownDouble(containerClass, animateValue) {
  if (_animatedBanner) return;

  var formattedValue = '-=' + animateValue + 'px';

  //slide second item up
  _animatedBanner = true;
  
  var banner_id = $(containerClass + ' .item:nth-child(3)').attr('id');

  $(containerClass + ' .item:nth-child(3)').stop(true, true).animate({ 'top': formattedValue }, 550, function () {
    //take first and add to bottom
    $(containerClass + ' .item:last').after($(containerClass + ' .item:first'));
    //reset new last item's top value
    $(containerClass + ' .item:last').css({ 'top': '0', 'z-index': '500' });

    //take first and add to bottom
    $(containerClass + ' .item:last').after($(containerClass + ' .item:first'));
    //reset new last item's top value
    $(containerClass + ' .item:last').css({ 'top': '0', 'z-index': '500' });

    setSeal('.home-carousel .seal');
    _animatedBanner = false;
  });

  crossFadeFooterOnScroll('.home-carousel > .footer', banner_id);
}
function slideBannerOnScrollDown(containerClass, animateValue) {
  if (_animatedBanner) return;

  var formattedValue = '-=' + animateValue + 'px';

  //slide second item up
  _animatedBanner = true;
  
  var banner_id = $(containerClass + ' .item:nth-child(2)').attr('id');
  
  $(containerClass + ' .item:nth-child(2)').stop(true, true).animate({ 'top': formattedValue }, 550, function () {
    //take first and add to bottom
    $(containerClass + ' .item:last').after($(containerClass + ' .item:first'));

    //reset new last item's top value
    $(containerClass + ' .item:last').css({ 'top': '0', 'z-index': '500' });

    setSeal('.home-carousel .seal');
    _animatedBanner = false;
  });

  crossFadeFooterOnScroll('.home-carousel > .footer', banner_id);
}

function slideBannerOnScrollUp(containerClass, animateValue) {
  if (_animatedBanner) return;

  var formattedValue = '+=' + animateValue + 'px';

  var banner_id = $(containerClass + ' .item:last').attr('id');

  //move last item up, behind current item
  $(containerClass + ' .item:last').css({ 'top': '-' + _bannerAnimateHeight + 'px', 'z-index': '450' });
  
  //slide current item down
  _animatedBanner = true;
  $(containerClass + ' .item:first').stop(true, true).animate({ 'top': formattedValue }, 550, function () {
    $(containerClass + ' .item:last').css({ 'z-index': '500' });

    //take last and add to top
    $(containerClass + ' .item:first').before($(containerClass + ' .item:last'));

    //reset new second item's top value
    $(containerClass + ' .item:nth-child(2)').css({ 'top': '0', 'z-index': '500' });

    setSeal('.home-carousel .seal');
    _animatedBanner = false;
  });

  crossFadeFooterOnScroll('.home-carousel > .footer', banner_id);

  //slide last item up
  //$(containerClass + ' .item:last').animate({ 'top': formattedValue }, 300, function () {
  //take last and add to top
  //$(containerClass + ' .item:first').before($(containerClass + ' .item:last'));

  //reset new second item's top value
  //$(containerClass + ' .item:nth-child(2)').css({ 'top': '0', 'z-index': '500' });
  //});
}

/*///////////////////////Slider Footer Crossfade Functions///////////////////////*/

function crossFadeFooterOnScroll(containerClass, banner_id){
  trace('crossFadeFooterOnScroll');
  if (_animatedFooter) return;
  _animatedFooter = true;
  var footer_item_id = banner_id.replace('banner', 'footer-item');
  $(containerClass + ' .footer-item').css({'display':'block', 'top':'-5000px'});
  $(containerClass + ' #' + footer_item_id).css({'display':'block', 'top':'0px'});
  _animatedFooter = false;
}

function crossFadeFooterOnScrollDown(containerClass) {
  if (_animatedFooter) return;

  _animatedFooter = true;
  $(containerClass + ' .footer-item:first').stop(true, true).fadeOut();
  $(containerClass + ' .footer-item:nth-child(2)').stop(true, true).fadeIn(function () {
    //move first to last
    $(containerClass + ' .footer-item:last').after($(containerClass + ' .footer-item:first'));
    _animatedFooter = false;
  });
}

function crossFadeFooterOnScrollDownDouble(containerClass) {
  if (_animatedFooter) return;

  _animatedFooter = true;
  $(containerClass + ' .footer-item:first').stop(true, true).fadeOut();
  $(containerClass + ' .footer-item:nth-child(3)').stop(true, true).fadeIn(function () {
    //move first to last
    $(containerClass + ' .footer-item:last').after($(containerClass + ' .footer-item:first'));
    $(containerClass + ' .footer-item:last').after($(containerClass + ' .footer-item:first'));
    _animatedFooter = false;
  });
}

function crossFadeFooterOnScrollUp(containerClass) {
  if (_animatedFooter) return;

  $(containerClass + ' .footer-item:first').stop(true, true).fadeOut();
  $(containerClass + ' .footer-item:last').stop(true, true).fadeIn(function () {
    //move first to last
    $(containerClass + ' .footer-item:first').before($(containerClass + ' .footer-item:last'));
    _animatedFooter = false;
  });
}

