//BEGIN RIGHT SIDE TABBED CONTENT
var currentTab = 0; // Set to a different number to start on a different tab.

// JS CLASS ON BODY
$(document).ready(function(){
    $('body').removeClass('js-loading');
    $('body').addClass('js');
});

function openTab(clickedTab) {
   var thisTab = $(".tabbed-box .tabs a").index(clickedTab);
   $(".tabbed-box .tabs li a").removeClass("active");
   $(".tabbed-box .tabs li a:eq("+thisTab+")").addClass("active");
   $(".tabbed-box .tabbed-content").hide();
   $(".tabbed-box .tabbed-content:eq("+thisTab+")").show();
   currentTab = thisTab;
}

$(document).ready(function() {
   
   $(".tabbed-box .tabs li a").click(function() {
	if($(this).hasClass("followlink")){
		return true;
	} else {
      openTab($(this)); return false;
	}
   });
   
   $(".tabbed-box .tabs li a:eq("+currentTab+")").click()
});
//END RIGHT SIDE TABBED CONTENT

//BEGIN MAIN TABBED CONTENT
var currentTab2 = 0; // Set to a different number to start on a different tab.

function openTab2(clickedTab) {
   var thisTab = $(".tabbed-box2 .tabs a").index(clickedTab);
   $(".tabbed-box2 .tabs li a").removeClass("active");
   $(".tabbed-box2 .tabs li a:eq("+thisTab+")").addClass("active");
   $(".tabbed-box2 .tabbed-content").hide();
   $(".tabbed-box2 .tabbed-content:eq("+thisTab+")").show();
   currentTab = thisTab;
}

$(document).ready(function() {
   
   $(".tabbed-box2 .tabs li a").click(function() { 
      openTab2($(this)); return false; 
   });
   
   $(".tabbed-box2 .tabs li a:eq("+currentTab+")").click()
});
//END MAIN TABBED CONTENT

//BEGIN LIBRARY TABBED CONTENT
var libcurrentTab = 0; // Set to a different number to start on a different tab.

function libopenTab(libclickedTab) {
   var libthisTab = $(".libtabbed-box .libtabs a").index(libclickedTab);
   $(".libtabbed-box .libtabs li a").removeClass("active");
   $(".libtabbed-box .libtabs li a:eq("+libthisTab+")").addClass("active");
   $(".libtabbed-box .libtabbed-content").hide();
   $(".libtabbed-box .libtabbed-content:eq("+libthisTab+")").show();
   libcurrentTab = libthisTab;
}

$(document).ready(function() {
   
   $(".libtabbed-box .libtabs li a").click(function() { 
      libopenTab($(this)); return false; 
   });
   
   $(".libtabbed-box .libtabs li a:eq("+libcurrentTab+")").click()
});
//END LIBRARY TABBED CONTENT

$(document).ready(function() {
 // hides the login_dropdown as soon as the DOM is ready
 // (a little sooner than page load)
  $('#login_dropdown').hide();
 // toggles the login_dropdown on clicking the noted link
  $('a#main_menu_login').click(function() {
 $('#login_dropdown').toggle(400);
 return false;
  });
});

//SEND PAGE TO A FRIEND
function mailpage()
{
mail_str = "mailto:?subject=Check out the " + escape(document.title);
mail_str += "&body=I thought you might be interested in the " + escape(document.title);
mail_str += ". You can view it at, " + location.href;
location.href = mail_str;
}

//MENU DROPDOWNS
sfHover = function() {
	var sfEls = document.getElementById("main_menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//IE6 FIX FOR MAIN MENU HOVER
$(document).ready(function() {
	$('.mm li a span').mouseover(function() {
	  $(this).css('background-position', 'bottom right');
	});
	
	$('.mm li a span').mouseout(function() {
	  $(this).css('background-position', 'top right');
	});
});

//IE6 FIX FOR INFO BOX HOVER
$(document).ready(function() {
	$('.info_box').mouseover(function() {
	  $(this).css('background-position', '0 -125px');
	});
	
	$('.info_box').mouseout(function() {
	  $(this).css('background-position', 'top');
	});
});

//ALIGN CONTENT BOXES
$(document).ready(function(){
	$('.content_box:visible').each(function(){

	    if($(this).hasClass('heightset') != true){

		//LOOP THROUGH SIBLINGS AND FIND NEXT VISIBLE
		var nextvisible;
		while(nextvisible == null){
			nextvisible = $('#content_box_wrapper .content-box:last-child'); //Set as final element to avoid infinite loop
			$(this).nextAll().each(function(){
				if($(this).is(':visible')){
					nextvisible = $(this);
					return false;
				}
			});
		}

		//SET HEIGHT BASED ON NEXT VISIBLE SIBLING
		if($(this).height() <= nextvisible.height()){
		    var setheight = nextvisible.height();
		    $(this).css('height', setheight).addClass("heightset");
		    nextvisible.css('height', setheight).addClass("heightset");
		}
		else if($(this).height() > nextvisible.height()){
		    var setheight = $(this).height();
		    $(this).css('height', setheight).addClass("heightset");
		    nextvisible.css('height', setheight).addClass("heightset");
		}
		nextvisible = "";
	    }

	});
});
