
jQuery(function( $ ){
	/**
	 * Demo binding and preparation, no need to read this part
	 */
	//borrowed from jQuery easing plugin
	//http://gsgd.co.uk/sandbox/jquery.easing.php
	$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	};

	function fader()
	{
		
		 $('#bottom_content div').fadeOut('fast', function() {
		 
		 		if(move_on)
				{
				move_on=false;
					
				$('#bottom_content div').html($(open_page+" .bottom_content").html())
				
				var c_height=$('#bottom_content div').height()
				var c_pad=$('#bottom_content').css("padding-top")
				var c_padb=$('#bottom_content').css("padding-bottom")
				var new_height=561+80+c_height
				//alert(c_height)
				$('#mainContent, #standbox').animate({  height:new_height},"fast",function(){$('#bottom_content div').fadeIn('fast')})

				init_arrows(open_page)
				$("body").css("position","fixed")
				$("body").css("width","100%")

				window.location.hash=open_page

				$("body").css("position","relative")
				//$("title").html($(open_page+" .title").html())
				
				//window.scrollTo(0,0);
				}

				
		})
	}
	
	function scrollback()
	{
		$("body").css("position","relative")
	}
	
	function init_arrows(hash)
	{
		hash=hash.split("#")[1]
		$("#standbox a").css("display","block");
		if(handsbow_list[hash]['handsbow_top']=="")
			$(".arrow_top").css("display","none")
		else
			$(".arrow_top").attr("href",handsbow_list[hash]['handsbow_top'])
			
		if(handsbow_list[hash]['handsbow_bottom']=="")
			$(".arrow_bottom").css("display","none")
		else
			$(".arrow_bottom").attr("href",handsbow_list[hash]['handsbow_bottom'])
			
		if(handsbow_list[hash]['handsbow_left']=="")
			$(".arrow_left").css("display","none")
		else
			$(".arrow_left").attr("href",handsbow_list[hash]['handsbow_left'])
			
		if(handsbow_list[hash]['handsbow_right']=="")
			$(".arrow_right").css("display","none")
		else
			$(".arrow_right").attr("href",handsbow_list[hash]['handsbow_right'])
	}
	
	function init_menu()
	{
		var a=$("#jsddm > li")
		totwidth=0
		var alef
		$.each (a, function(){totwidth+=$(this).width()})
		$("#nav").css("width",totwidth+"px")
		if($("#nav").html().indexOf("Legal Updates")==-1)
			$("#right_bot,#right_bottest").css("display","none");
		
	}
	var open_page
	
	$(document).ready(function() {
	
	init_menu()
	
	open_page=window.location.hash
	
	//alert(window.location.hash=="")
	if(open_page=="")open_page="#Home"
	
	init_arrows(open_page)

	window.scrollTo(0,0);
	move_on=true;
	fader()

	$('#nav a,#paneContainer a,#standbox a,#bottom_content a').live("click",function(){
			open_page=this.hash
			//alert(open_page)
			//window.location.hash=this.hash
			//window.scrollTo(0,0);
			//$('#mainContent, #standbox').css("height","571px")
			
			move_on=true;
			$('div.pane').scrollTo(this.hash,500,{queue:true,onAfter:fader});
			//$('div.pane').scrollTo(this.hash,500,{queue:true});
			//fader()

			return false;
		});
	/*
			$('#paneContainer a').click(function(){
			$('div.pane').scrollTo(this.hash,1000,{queue:true});
			window.location.hash=this.hash
		
			return false;
		});*/
	});

});
