﻿
if ($.browser.webkit) {  
  /* for Nivo slider to fix chrome problem	*/
  $(window).load(function () {    
    $('#divSlider').nivoSlider({
      effect: 'random',
      directionNav: false,
      afterLoad: function () {
        $('#divSlider').css('visibility', 'visible'); 
        $('.nivo-controlNav').append("<span id='fcHack'>&nbsp;</span>");
      }
    });
  });
}
else {
  $(document).ready(function () {    
    $('#divSlider').nivoSlider({
      effect: 'random',
      directionNav: false,
      afterLoad: function () {
        $('#divSlider').css('visibility', 'visible');
        $('.nivo-controlNav').append("<span id='fcHack'>&nbsp;</span>");
      }
    });
  });
}


/* for others during document load */
$(document).ready(function () {
  $('.divModule .divModInfoWrapper').hide();
  $('.spDirectionNav').html('next >');

  $('.divModule').each(function (index) {
    $('.divModule:eq(' + index + ') .divModInfoWrapper:first').show();

    $('.divModule:eq(' + index + ') .divPaging span').not('.spDirectionNav').click(function () {
      var selIndex = $('.divModule:eq(' + index + ') .divPaging span').index(this);
      $('.divModule:eq(' + index + ') .divPaging span').removeClass('selected');
      $(this).addClass('selected');
      $('.divModule:eq(' + index + ') .divModInfoWrapper').hide();
      var currSelEle = $('.divModule:eq(' + index + ') .divModInfoWrapper').get(selIndex);
      $(currSelEle).fadeIn();

      var nextIndex = selIndex + 1;
      var divLength = $('.divModule:eq(' + index + ') .divModInfoWrapper').length;
      if (nextIndex > (divLength - 1)) { //last
        $('.divModule:eq(' + index + ') .divPaging span.spDirectionNav').hide();
      }
      else {        
        $('.divModule:eq(' + index + ') .divPaging span.spDirectionNav').show();
      }      
    });

    $('.divModule:eq(' + index + ') .divPaging span.spDirectionNav').click(function () {
      var divLength = $('.divModule:eq(' + index + ') .divModInfoWrapper').length;
      var currSelIndex = $('.divModule:eq(' + index + ') .divPaging span').index($('.divModule:eq(' + index + ') .divPaging span.selected'));
      var nextIndex = currSelIndex + 1;

      if (nextIndex <= (divLength - 1)) {
        $('.divModule:eq(' + index + ') .divPaging span').removeClass('selected');
        $('.divModule:eq(' + index + ') .divPaging span:eq(' + nextIndex + ')').addClass('selected');
        $('.divModule:eq(' + index + ') .divModInfoWrapper').hide();
        var currSelEle = $('.divModule:eq(' + index + ') .divModInfoWrapper').get(nextIndex);
        $(currSelEle).fadeIn();
      }

      if (nextIndex >= (divLength - 1)) { //last
        $(this).hide();
      }
      else {
        $(this).show();
      }

    });
  });


});
