$(document).ready(function() {
	
	// Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
		opacity('container', 100, 20, 1000);
	});	
	
	// Expand Panel from button
	$(".openfrombutton").click(function(){
		ScrollToElement(getElementById('content'));
		$("div#panel").slideDown("slow");
		$("#toggle a").toggle();
		opacity('container', 100, 20, 1000);
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");
		opacity('container', 20, 100, 1000);
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});	
	
	function ScrollToElement(theElement){

		var selectedPosX = 0;
		var selectedPosY = -50;
		  
		while(theElement != null){
			selectedPosX += theElement.offsetLeft;
			selectedPosY += theElement.offsetTop;
			theElement = theElement.offsetParent;
		}
								  
		window.scrollTo(selectedPosX,selectedPosY);

	}
	
		
});
