// McGowan

var playRightFeatures = true;
var playRightFeaturesTimeoutId;
var playRightFeaturesDelay = 5000;
var currentFeature = 0;
var jqNews;

var rightFeatureImgs = new Array();

rightFeatureImgs[rightFeatureImgs.length] = 'http://www.wildcatnyc.org/static/uploads/images/years.jpg';

rightFeatureImgs[rightFeatureImgs.length] = 'http://www.wildcatnyc.org/static/uploads/images/02.jpg';

rightFeatureImgs[rightFeatureImgs.length] = 'http://www.wildcatnyc.org/static/uploads/images/03.jpg';

rightFeatureImgs[rightFeatureImgs.length] = 'http://www.wildcatnyc.org/static/uploads/images/cleaning.jpg';

rightFeatureImgs[rightFeatureImgs.length] = 'http://www.wildcatnyc.org/static/uploads/images/05.jpg';


function showRightFeature(index)
{
  currentFeature = index;
  playRightFeatures = false;
  window.clearTimeout(playRightFeaturesTimeoutId);
  changeRightFeature(index,'fast');
}

function initRightFeature()
{
  // if image doesn't yet exist, insert
  if ($('#featureRightBottom .wrapper img').length == 0) {
    var newEl = '<img src="'+rightFeatureImgs[0]+'" alt="Feature Image"/>';
    $('#featureRightBottom .wrapper').prepend(newEl);
  }

  currentFeature = 0;
  changeRightFeature(0,0);
  window.clearTimeout(playRightFeaturesTimeoutId);
  playRightFeaturesTimeoutId = window.setTimeout(autoShowNextRightFeature, playRightFeaturesDelay);
}

function changeRightFeature(index, speed)
{
  var buttons = $('#featureRightBottom .navButtons a');
  buttons.removeClass('roNavButtonOn');
  buttons.eq(index).addClass('roNavButtonOn');
  $('#featureRightBottom img').stop(true,true);
  $('#featureRightBottom img').fadeOut(speed, function() {
    $(this).attr('src', rightFeatureImgs[index]);
  });
  $('#featureRightBottom img').fadeIn(speed);
}

function initLeftFeature()
{
  $('#featureLeftContent .display').html($('#featureLeftContent .source div:first-child').html());
}

function showLeftFeature(el)
{
  var tab = $(el);
  $('#featureLeft .featureNavList li').removeClass('active');
  tab.parent().addClass('active');

  if ($('#featureLeft .featureNavList li:last ').hasClass('active')) {$('#featureLeft').addClass('lastTabActive');} else {$('#featureLeft').removeClass('lastTabActive');}
  
  $('#featureLeftContent .display').stop(true,true);
  $('#featureLeftContent .display').fadeOut('fast', function() {
    $(this).html($('#featureLeftContent .source .'+tab.attr('id')).html());
  });
  $('#featureLeftContent .display').fadeIn('fast');
}

// clicked
function showPrevRightFeature(speed)
{
  playRightFeatures = false;
  window.clearTimeout(playRightFeaturesTimeoutId);
  showPrevRightFeature2(speed);
}

// clicked
function showNextRightFeature(speed)
{
  playRightFeatures = false;
  window.clearTimeout(playRightFeaturesTimeoutId);
  showNextRightFeature2(speed);
}


function showPrevRightFeature2(speed)
{
  if (speed == null)
    speed = 'fast';
    
  var features = $('#featureRightBottom .navButtons a');
  currentFeature--;
  if (currentFeature < 0)
    currentFeature=features.length-1;
  changeRightFeature(currentFeature, speed);
}

function showNextRightFeature2(speed)
{
  if (speed == null)
    speed = 'fast';
    
  var features = $('#featureRightBottom .navButtons a');
  currentFeature++;
  if (currentFeature >= features.length)
    currentFeature=0;
  changeRightFeature(currentFeature, speed);
}

function autoShowNextRightFeature()
{
  if (playRightFeatures)
  {
    showNextRightFeature2(600);
    playRightFeaturesTimeoutId = window.setTimeout(autoShowNextRightFeature, playRightFeaturesDelay);
  }
}

function initPageFeatures() {
  initLeftFeature();
  initRightFeature();
  if ($("ul#ticker01 li").length > 0) {
    $("ul#ticker01").liScroll({travelocity: 0.05});
  }
}
