$(document).ready(function(){
	//Get the section anchor if there is one
	var pageURL = document.location.toString();
	
	//Setup Collapse/Expand Sections
	$(".etu-start-closed .etu-module-header").addClass("etu-rhc-close");
	$(".etu-start-closed .etu-module-header img").attr("src", "/plt/cd/channel/channel/irc/iln/images/icns/icns-expand.gif");	
	
	//Perform Collapse/Expand
	$(".etu-module-header").click(
		function(e){
			$(this).toggleClass("etu-rhc-close");
			$(this).siblings().toggle(50);
			if($(this).hasClass("etu-rhc-close")){
				$(this).children("img").attr({src:"/plt/cd/channel/channel/irc/iln/images/icns/icns-expand.gif"});
			}else{
				$(this).children("img").attr({src:"/plt/cd/channel/channel/irc/iln/images/icns/icns-collapse.gif"});
			}
		}
	);
	
	//Perform Expand from anchor tags
	$('#etu-anchor-links a').click(
		function(e){
			var selectAnchor = $(this).attr("href");
			if(($(selectAnchor).parent().hasClass("etu-rhc-close"))){ //Check if open, don't close
				var anchorParent = $(selectAnchor).parent();
				anchorParent.toggleClass("etu-rhc-close");
				anchorParent.siblings().toggle(50);
				if(anchorParent.hasClass("etu-rhc-close")){
					anchorParent.children("img").attr({src:"/plt/cd/channel/channel/irc/iln/images/icns/icns-expand.gif"});
				}else{
					anchorParent.children("img").attr({src:"/plt/cd/channel/channel/irc/iln/images/icns/icns-collapse.gif"});
				}
			}
			
		}
	);
	
	//Perform Expand section to open based on anchor in URL
	if(pageURL.match('#')){
		var pageAnchor = "#"+pageURL.split('#')[1];
		$(pageAnchor).parent().click();
	}
	
	//Perform Collapse from "back to top"
	$('.totop').click(
		function(e){
			$(this).parent().parent().prev('.etu-module-header').click();
		}
	);
});
