$(function () {
	var hash = window.location.hash;
	if(hash != "")
	{
		$("dd").fadeTo(0,0).hide();
		var currentTab;
		if(hash=="#program-overview")
		{
			currentTab = "program-overview";
		}
		else if(hash=="#pictures")
		{
			currentTab = "pictures";
		}
		else if(hash=="#bachelor-of-music")
		{
			currentTab = "degree31";
		}
		else if(hash=="#associate-of-arts")
		{
			currentTab = "degree36";
		}
		else if(hash=="#certificate")
		{
			currentTab = "degree33";
		}
		else if(hash=="#non-certificate")
		{
			currentTab = "degree34";
		}
		else if(hash=="#degree-emphasis")
		{
			currentTab = "degree38";
		}
		else if(hash=="#ss-performance")
		{
			currentTab = "ss-performance";
		}
		else if(hash=="#ss-rising-stars")
		{
			currentTab = "ss-rising-stars";
		}
		else if(hash=="#ss-recording")
		{
			currentTab = "ss-recording";
		}
		else if(hash=="#ss-songwriter")
		{
			currentTab = "ss-songwriter";
		}
		else if(hash=="#ss-producer")
		{
			currentTab = "ss-producer";
		}
		else if(hash=="#ss-howtoapply")
		{
			currentTab = "ss-howtoapply";
		}
		else if(hash=="#ss-guitarbuilder")
		{
			currentTab = "ss-guitarbuilder";
		}
		
		$("dt").find("h3." + currentTab).parent().addClass('highlight-on').parent().parent().next("dd").fadeTo(0,1).show();
	}
	else
	{
		$("dd:not(dd.open)").fadeTo(0,0).hide();
		$("dt.open").find('span:first').addClass('highlight-on');
	}
	
	$("div.toggler").click(function(){	
		if ($("dd:visible").get()[0] === $(this).parent().next().get()[0]) {
			$("dd:visible").fadeTo(500, 0);
			$("dd:visible").slideUp(500);
			$("#accordion").find('span.highlight-on').removeClass('highlight-on');
		}else{
			
					
			if($("dd:visible").length<1)
			{
				$(this).parent().next().slideDown(500).fadeTo(500, 1);
			}
			else
			{
				var $this = $(this);
				$("dd:visible").fadeTo(500, 0).slideUp({
					duration:500,
					easing:"easeOutSine",
					complete:function(){
						$this.parent().next().slideDown(500).fadeTo(500, 1);	
					}
				});
			}
			
			$("#accordion").find('span.highlight-on').removeClass('highlight-on');
			$(this).find('span:first').addClass('highlight-on');
		}
		
 		
		//put hash
		var newHash = $(this).find('h3').attr('class');
		if(newHash=="degree31")
		{
			newHash = "bachelor-of-music";
		}
		else if(newHash=="degree36")
		{
			newHash = "associate-of-arts";
		}
		else if(newHash=="degree33")
		{
			newHash = "certificate";
		}
		else if(newHash=="degree34")
		{
			newHash = "non-certificate";
		}
		else if(newHash=="degree38")
		{
			newHash = "degree-emphasis";
		}
		window.location.hash = newHash;
		
		return true;
 	});
	
	
	//HOVER FUNCTION
	if ($.browser.msie && $.browser.version < 7) return;
  
  $('.toggler span').removeClass('highlight').find('h3').append('<span class="hover" />').each(function () {
      
	  var $span = $('> span.hover', this).css('opacity', 0);
      
	  $(this).hover(function () {
        
		$span.stop().fadeTo(420, 1);
      }, function () {
        $span.stop().fadeTo(420, 0);
      });
    });
});
