/*
* Base JavaScript Files to handle common tasks
*/

/* delete this line to add popup ability
// add _blank to any link with class="popup"
$(document).ready(function() {
$('a.popup').click(function() {
this.target = "_blank";
});
});
/* */

/* delete this line to add IE6 dropdown nav solution
// fix IE6's inability to have :hover on anything other than an anchor tag
$(document).ready(function() {
$("#topNav li").bind("mouseenter", function(){
$(this).addClass("over");
});
$("#topNav li").bind("mouseleave", function(){
$(this).removeClass("over");
});
});
/* */


jQuery(function($) {

  // prepend article tools to Streaming Media Pages
  $('#streamingMediaPage .articleTools ul').append('<li class="clickabilityEmail"><a href="#" onclick="return(ET());" onMouseOver="return(ETMouseOver());" onMouseOut="return(ETMouseOut());">Email</a></li><li class="clickabilitySave"><a href="#" onclick="return(ST());" onMouseOver="return(STMouseOver());" onMouseOut="return(STMouseOut());">Save</a></li><li class="clickabilityPrint"><a href="#" onclick="return(PT());" onMouseOver="return(PTMouseOver());" onMouseOut="return(PTMouseOut());">Print</a></li><li class="reprint"><a href="http://www.icopyright.com/' + icopy + '?icx_id=' + siteURL + '">Reprint</a></li>');

  // prepend article tools to contentWell
  $('#article .articleTools ul').append('<li class="clickabilityEmail"><a href="#" onclick="return(ET());" onMouseOver="return(ETMouseOver());" onMouseOut="return(ETMouseOut());">Email</a></li><li class="clickabilitySave"><a href="#" onclick="return(ST());" onMouseOver="return(STMouseOver());" onMouseOut="return(STMouseOut());">Save</a></li><li class="clickabilityPrint"><a href="#" onclick="return(PT());" onMouseOver="return(PTMouseOver());" onMouseOut="return(PTMouseOut());">Print</a></li><li class="reprint"><a href="http://www.icopyright.com/' + icopy + '?icx_id=' + siteURL + '">Reprint</a></li>');

  // getting cells to be the same height
  $('.whiteBox.split.one .leftColumn, .whiteBox.split.one .rightColumn').equalHeight();
  $('.whiteBox.split.two .leftColumn, .whiteBox.split.two .rightColumn').equalHeight();
  $('.whiteBox.split.three .leftColumn, .whiteBox.split.three .rightColumn').equalHeight();
  $('.whiteBox.split.four .leftColumn, .whiteBox.split.four .rightColumn').equalHeight();
  $('#latestVideo .subFeature.one, #latestVideo .subFeature.two, #latestVideo .subFeature.three').equalHeight();

  // Display random images for bannersidebox
  var randomnumber = Math.floor(Math.random() * $("#bannerSideBox").children().length);
  $(function() {
    $("#bannerSideBox > a:eq(" + randomnumber + ")").show();
  });

  // Set up the tabbing
  $(".tabber").each(function() {
    $(this).children('div').each(function() {
      $(this).addClass('tabbed-content');
    });
    var tabberId = $(this).attr('id');
    var cookiedTab = $.cookie(tabberId);
    if (cookiedTab == null) {
      var cookiedTab = "0";
    };
    $(this).children('.tabbed-content:eq(' + cookiedTab + ')').addClass('visible');
    $(this).children('.tabbed-content:first').before('<div class="tab-controls"></div>')
    $(this).children('.tabbed-content').children('h2').each(function(index) {
      var $tabTitle = $(this).text();
      $(this).closest('.tabber').children('.tab-controls').append('<span>' + $tabTitle + '</span>');
      $(this).remove();
    });
    $(this).children('.tab-controls').children('span:eq(' + cookiedTab + ')').addClass('active-tab');
  });
  // Handle the clicking
  $('.tab-controls span').click(function() {
    if ($(this).hasClass('active-tab')) {
    } else {
      var index = $(this).parent().children().index(this);
      var tabberId = $(this).closest('.tabber').attr('id');
      $.cookie(tabberId, index, { expires: 1, path: '/' });
      $(this).siblings().removeClass('active-tab');
      $(this).addClass('active-tab');
      $(this).parent().siblings('.visible').removeClass('visible');
      $(this).parent().siblings('div:eq(' + index + ')').addClass('visible');
    };
  });

});
