﻿/* Function for Image Rollovers */
$(function() {
  $('.rollover').hover(function() {
    $(this).attr('src', $(this).attr('src').replace(/_Out/i, '_Over'));
  }, function() {
    $(this).attr('src', $(this).attr('src').replace(/_Over/i, '_Out'));
  });
});

function manualImageRollover(strID) {
  $(strID).hover(function() {
    $(this).attr('src', $(this).attr('src').replace(/_Out/i, '_Over'));
  }, function() {
    $(this).attr('src', $(this).attr('src').replace(/_Over/i, '_Out'));
  });
}

/* BG Colour Function */
function changeBGColor(elemToChange, newColor) {
    elemToChange.style.backgroundColor = newColor;
}

function checkText(objTB, strText, isFocus) {

  strText = jQuery.trim(strText);
  objTB.value = jQuery.trim(objTB.value);

  if (isFocus) {

    if (objTB.value == strText) {
      objTB.value = '';
    }

  } else {

    if (objTB.value == '') {
      objTB.value = strText;
    }

  }

}

/* Navigation */
$(document).ready(function() {

  $('#divNavigation li').each(function(index) {
    $(this).children("div:even").addClass("alt");
  });

  $("#divNavigation div").mouseover(function() {
    $(this).addClass("over");
  });

  $("#divNavigation div").mouseout(function() {
    $(this).removeClass("over");
  });

  $("#divNavigation li:has(div)").mouseover(function() {
    $(this).stop().animate({ height: ((($(this).children("div").length) * 42) + 31).toString() + 'px' }, { queue: false, duration: 300 })
    $(this).children("h6").css({ 'background-color': '#00bff3' });
  });

  $("#divNavigation li:has(div)").mouseout(function() {
    $(this).stop().animate({ height: '30px' }, { queue: false, duration: 300 })
    $(this).children("h6").css({ 'background-color': 'transparent' });
  });

});

/* Slideshow */
function slideSwitch(slideCat, activeCat) {

  var $active = $('#' + slideCat + ' DIV.' + activeCat);

  if ($active.length == 0) $active = $('#' + slideCat + ' DIV:last');

  // use this to pull the divs in the order they appear in the markup
  var $next = $active.next().length ? $active.next()
          : $('#' + slideCat + ' DIV:first');

  // uncomment below to pull the divs randomly
  var $sibs = $active.siblings();
  var rndNum = Math.floor(Math.random() * $sibs.length);
  var $next = $($sibs[rndNum]);

  $active.addClass('last-' + activeCat);

  $next.css({ opacity: 0.0 })
          .addClass(activeCat)
          .animate({ opacity: 1.0 }, 1000, function() {
            $active.removeClass(activeCat + ' last-' + activeCat);
          });
}

/* ToolTips */
$(document).ready(function() {

  $("#toolTipList li[title]").hover(function() {
    $(this).append("<div></div>")

    var divHover = $(this).children("div:first");

    divHover.text($(this).attr("title"));
    divHover.css("margin-top", (($(this).outerHeight() + divHover.outerHeight()) * -1).toString() + "px")
    divHover.animate({ opacity: "show" }, "500");
    
  }, function() {
  
    var divHover = $(this).children("div:first");

    divHover.animate({ opacity: "hide" }, "500");
    divHover.remove();
    
  });

});

/* sIFR */
$(document).ready(function() {
  $.sifr({
    path: 'Fonts/',
    save: true
  });
  $('h5').sifr({ font: 'Kristen ITC' });
});

/* Ticker */
$(document).ready(function() {
  
  var stopAnim = false;
  
  var ticker = function() {
    setTimeout(function() {
      if (stopAnim == false) {
        $("ul.tweetPanel li:first").animate({ marginTop: "-120px" }, 1200, function() {
          $(this).detach().appendTo('ul.tweetPanel').removeAttr("style");
        });
      }
      ticker();
    }, 10000);
  };
  ticker();

  $("ul.tweetPanel").hover(function() {
    stopAnim =  true;
  }, function() {
    stopAnim =  false;
  });
  
});

