$(document).ready(function () {
	$("#Decisions h2").hide();
	$("#Decisions").not($(".open")).get(0).style.display="none";
	$("#scrollbar").get(0).style.display="block";
	L=$(".logo").get(0).style;

// Decisions
	$("#decisions-link").click(function () {
      $("#Decisions").slideToggle("slow");
	  return false;
    });

	T=$("#track");
	D=$("#Decisions ul").get(0).style;
	D.width="2520px";

	function DecisionsResize() {
		Cw=$("#Content").width();
		Cw1=$("#Container").width();
		Dlm=-(2520-Cw);
		Dl=Dlm/2;
		Tlm=(Cw-448);
		Tl=Tlm/2;
		Dk=Dl/(Tl-19);
		if(Cw) {
			D.marginLeft=Dl+"px";
			T.get(0).style.marginLeft=Tl+"px";
		}
		L.left=Cw1/100*12.5+"px";
	}
	DecisionsResize();
	$(window).resize(function() {DecisionsResize();});

	T.bind("mousedown", function(e) {
		Mp=e.pageX;
		st=0;
		$().mousemove(function(e) {
			Mpn=Mp-e.pageX;
			Tln=Tl-Mpn;
			Dln=Dl-(Mpn*Dk);
			if((Tln>19 && Tln<Tlm-19) || st==0) {
				st=1;
				T.get(0).style.marginLeft=Tln+"px";
				D.marginLeft=Dln+"px";
			}
			else {
				if(Tln<19) {Tln=19; Dln=0;}
				else if(Tln>Tlm-19) {Tln=Tlm-19; Dln=Dlm;}
				T.get(0).style.marginLeft=Tln+"px";
				D.marginLeft=Dln+"px";
			}
		}).bind("mouseup", function() {
			$().unbind('mousemove');
			$(this).unbind('mouseup');
			if(st==1) {Tl=Tln; Dl=Dln;}
			st=0;
		})
	});

	scrolling = function(Tk, Dkn) {
		Tl=Tl+Tk; Dl=Dl+Dkn;
		if(Tl>=19 && Tl<=Tlm-19) {
			if(Tl==19) {Dl=0;}
			else if(Tl==Tlm-19) {Dl=Dlm;}
			T.get(0).style.marginLeft=Tl+"px";
			D.marginLeft=Dl+"px";
			if(Tl!=19 && Tl!=Tlm-19) {scrollingT = setTimeout("scrolling("+Tk+", "+Dkn+")",16);}
			else if(cd) {cd.className="";}
		}
		else {
			if(Tl<19) {Tl=19; Dl=0;}
			else if(Tl>Tlm-19) {Tl=Tlm-19; Dln=Dlm;}
			T.get(0).style.marginLeft=Tl+"px";
			D.marginLeft=Dl+"px";
			if(cd) {cd.className="";}
		}
	}

	var cd;
	$("#rarr, #larr").bind("mousedown", function() {
		cd=$(this).get(0);
		if($(this).attr("id")=="larr") {Tk=-3; Dkn=Dk*(-3);}
		else {Tk=3; Dkn=Dk*3;}
		if((Tl!=19 && Tk==-3) || (Tl!=Tlm-19 && Tk==3)) {scrolling(Tk, Dkn);}
	}).bind("mouseup", function() {
		if(Tl!=19 && Tl!=Tlm-19) {clearTimeout(scrollingT);}
	}).hover(function() {
			if((Tl!=19 && $(this).attr("id")=="larr") || (Tl!=Tlm-19 && $(this).attr("id")=="rarr")) {$(this).get(0).className="hover";}
		}, function() {
			if((Tl!=19 && $(this).attr("id")=="larr") || (Tl!=Tlm-19 && $(this).attr("id")=="rarr")) {$(this).get(0).className="";}
		}
	)

	$("#rmask, #lmask").hover(function() {
			if($(this).attr("id")=="lmask") {Tk=-3; Dkn=Dk*(-3);}
			else {Tk=3; Dkn=Dk*3;}
			if((Tl!=19 && Tk==-3) || (Tl!=Tlm-19 && Tk==3)) {scrolling(Tk, Dkn);}
		}, function() {
			if(Tl!=19 && Tl!=Tlm-19) {clearTimeout(scrollingT);}
		}
	)
//
// Logo animation
	pt=0;
	changePos = function() {
		pt--;
		L.backgroundPosition="121px "+pt+"px";
		changePosT = setTimeout("changePos()",60);
	}
	changePos();
//

	$("#Right li > div").hide();
	$("#Right li strong").click(function () {
		$(this).toggleClass("open").next("div").slideToggle("slow");
	});
	$(".close").click(function () {
		$(this).parent("div").slideUp("slow").parent("li").find("strong").toggleClass("open");
	});

});
