if(typeof(DM) == "undefined") { DM={}; }

// bouncy menu ball
DM.bouncyBall = {

	loffset: 30,
	tHome: 0,
	gohome:0,
	menu: 'home',

	init: function(){
		var p = $("#nav1_"+this.menu).offset()
		$("#navcol").prepend('<div id="bb"></div>');
		this.tHome = p.top;
		$("#bb").css({top:p.top+'px'});
	},

	ballMove: function(prnt) {
		clearTimeout ( this.gohome );
		var p = $("#"+prnt).offset()
		this.animateBall(p.top);
	},

	ballHome: function() {
		clearTimeout ( this.gohome );
		this.gohome = setTimeout('DM.bouncyBall.animateBall()',150);
	},

	animateBall: function(t) {
		if(typeof(t) == "undefined") { t = this.tHome }
		$("#bb").stop();
		$("#bb").animate( {top:t+"px"}, 200, 'swing' );
	}
}

// page slider
DM.slider = {

	p: 0,

	init:function(c,w,n) {
		this.c = c;
		this.w = w;
		this.n = n;
		$("#status").text("Project 1 of "+$("#scroll-wrap li").size());
		$("#prev").addClass("bDisabled");
	},

	animate:function(dir){

		r = this.p + dir;

		if(r < 0 || r > this.n) {
			return;
		}

		this.p = r;

		$("#status").text("Project "+(r+1)+" of "+$("#scroll-wrap li").size());
		$(".button").removeClass("bDisabled");
		if(r == 0) {
			$("#prev").addClass("bDisabled");
		} else if(r == this.n) {
			$("#next").addClass("bDisabled");
		}

		$("#scroll-wrap ul").animate( {left:(this.p * this.c) * -1+"px"}, 1000, 'swing' );
	},

	jumpto:function(page) {

		this.p = page;

		$("#scroll-wrap ul").css( {left:(this.p * this.c) * -1+"px"} );
	}
};

$(function(){

	// external Links
	$("a[rel='external'], .el a").click(function(){
		window.open($(this).attr("href"));
		return false;
	})

	// handlers for moving the menu ball
	$("li.menu_level_1 a").hover(
		function(){
			DM.bouncyBall.ballMove($(this).closest("li.menu_level_1").attr("id"));
		},
		function(){
			DM.bouncyBall.ballHome();
		}
	)

	// slider settings
	DM.slider.init(505,$("#scroll-wrap li").width() * $("#scroll-wrap li").size(),$("#scroll-wrap li").size() -1)

	// slider handlers
	$("#prev").click(function(){DM.slider.animate(-1) })
	$("#next").click(function(){DM.slider.animate(1) })

});