jQuery(function($){
        $('.tooltip > li').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 250;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popup', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: 40,
                        left: 0,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });

		/* Tabber tabs */
		$('#tabber-nested > h2:first a').addClass('first');
		$('#tabber-nested > h2:last a').addClass('last');
		
		/* Tabber alternative */
		var tabContainers = $('div.tabberalt > .tabberalt-content');

	    $('div.tabberalt ul.tabberalt-nav a').click(function () {
	        tabContainers.hide().filter(this.hash).show();

	        $('div.tabberalt ul.tabberalt-nav a').removeClass('selected');
	
	        $(this).addClass('selected');
	        return false;
	    }).filter(':first').click();


	$('.apply-now .apply-domestic').click(function(){
		$('#tabber-nested > h2 > a').removeClass('tabup');
		$('#tabber-nested > h2:nth-child(4) > a').addClass('tabup');
		
		$('#tabber-nested .tab-content').hide();
		$('#tabber-nested .tab3').show();
		$('#tabber-nested .tab3').show();
		window.scroll(0,0);
		return false;
	});

	$('#course-completion-requirements-link').click(function(){
		$('#tabber-nested > h2 > a').removeClass('tabup');
		$('#tabber-nested > h2:nth-child(2) > a').addClass('tabup');
		
		$('#tabber-nested .tab-content').hide();
		$('#tabber-nested .tab1').show();
		$('#tabber-nested .tab1').show();
		
		var $arrowImg = $('#course-completion-requirements > h2 > a > img');
		$arrowImg.attr('src', $arrowImg.attr('src').replace('right', 'bottom')).attr('alt', '-');
		$('#course-completion-requirements .slickbox').show();

		$.scrollTo($arrowImg, 100 );
		return false;
	});

  $('.slickbox').hide();
 

	
	
  $('a.slick-toggle').click(function() {
	var $container = $(this).parent().next();
	var $arrowImg = $(this).find('img');
	if ($container.is(':visible'))
	{
		$arrowImg.attr('src', $arrowImg.attr('src').replace('bottom', 'right')).attr('alt', '+');
		$container.slideUp();
	} else
	{
		$arrowImg.attr('src', $arrowImg.attr('src').replace('right', 'bottom')).attr('alt', '-');
		$container.slideDown();
	}
    return false;
  });
  $('a.slick-open').click();
});



//Available tabs
var tabs = new Array("tab-1", "tab-2", "tab-3", "tab-4");
var hideTabs; 

function change(oldClass, newClass) 
{
   var tagged=document.getElementsByTagName('a');
   for(var i = 0 ; i < tagged.length ; i++)
   {
      if (tagged[i].className==oldClass)
      {
         tagged[i].className=newClass;
      }
   }
}

function displayTab(tab)
{
   for (var i=0; i < 4; i++)
   {
     if (document.getElementById("group" + (i+1))) {
      document.getElementById("group" + (i+1)).style.display = "none";
     }
   }
   
   if (tab != -1)
   {
      document.getElementById("group" + (tab+1)).style.display = "block";
   }
}

function switchTab(tabNum)
{
   for (var i=0; i<tabs.length; i++)
   {
      //We just want to apply the CSS on start-up
      //Clear all the Ids if any exists      
      if (document.getElementById("tablink-" + (i+1)))
         document.getElementById("tablink-" + (i+1)).id = "";
         
      if (document.getElementById("group-" + (i+1)))
         document.getElementById("group-" + (i+1)).id = "";
         
      change(tabs[i] + "on", tabs[i]);       
   }
   
   if (tabNum != -1)
   {
      change(tabs[tabNum], tabs[tabNum] + "on");       
   }
   
   displayTab(tabNum);
   
   //Clear any timeout of hiding tabs
   clearTimeout(hideTabs);
}

//Hide all tabs and link groups
function hideAllTabs()
{
   hideTabs = setTimeout("switchTab(-1)",10000);
}
