window.addEvent('domready', function(){
	
	// THIS CODE TAKES CARE OF THE LOGIN AND QUICK SEARCH SWITCH
	
	var lLogin = document.getElementById("lLogin");
	var lQuick = document.getElementById("lQuick");
	
	var divLogin = document.getElementById("login");
	var divQuick = document.getElementById("quick-search");
	
	var loginstate = readCookie('loginstate');
	
	var fxQuick = new Fx.Slide(divQuick);
	var fxLogin = new Fx.Slide(divLogin);
	
	createCookie('profilestate', '');
	
	if (loginstate == null || loginstate == "") 
	{
		fxQuick.hide();
		createCookie('loginstate', 'login');
	}
	
	if (loginstate == "login") 
	{
		fxQuick.hide();
		fxLogin.show();
		lQuick.style.color = "#900";
		lLogin.style.color = "#222";
	}
	else if (loginstate == "quick") 
	{
		fxLogin.hide();
		fxQuick.show();
		lQuick.style.color = "#222";
		lLogin.style.color = "#900";
	}
	else
	{
	    fxQuick.hide();
		fxLogin.show();
		lQuick.style.color = "#900";
		lLogin.style.color = "#222";
	}
	
	$("lLogin").addEvent("click", function() {
		fxQuick.slideOut();
		fxLogin.slideIn.delay(900,fxLogin);
		lQuick.style.color = "#900";
		lLogin.style.color = "#222";
		createCookie('loginstate', 'login');
	});
	
	$("lQuick").addEvent("click", function() {
		fxLogin.slideOut();
		fxQuick.slideIn.delay(900,fxQuick);
		lLogin.style.color = "#900";
		lQuick.style.color = "#222";
		createCookie('loginstate', 'quick');
	});
	
	// END
	
	// GET THE COOKIE INFORMATION

	var selected = $('collapsable-menu-selected');
	var current = selected.getParent();

	$$('div.collapsable-menu-group').each(function(div){
		var link = div.getElement('a');
		var block = link.getNext();
		
		var fx = new Fx.Slide(block);
		
		fx.hide();
		
		link.addEvent('click', function(){

			var current_style = link.getAttribute("id");

			if (current_style.length > 2){
				current_style = current_style.substr(0,2);
				link.setAttribute("id",current_style);
				link.setAttribute("className","closed");
				link.setAttribute("class","closed");
				//alert("closed");
			}
			else {
				link.setAttribute("id",current_style + "O");
				link.setAttribute("className","opened");
				link.setAttribute("class","opened");
				//alert("opened");
			}
			fx.toggle();
		});
		
	})
	
	new SmoothScroll();
	
});
