$(function(){

	// timeline interactions
	$(".timeline-entry").hover(
		function(){ $(this).addClass("tl-over") },
		function(){ $(this).removeClass("tl-over") }
	).click(function(){
		$("#tm-detail").block().load($(this).find("a").attr("href"));
	})

	SHOOT.slider.init();

	$("#tmPrev").click(function(){	SHOOT.slider.animate(-1) })
	$("#tmNext").click(function(){ SHOOT.slider.animate(1) })

	// image zoom
	$("a.li-image").live("click",function(e) {
		e.preventDefault();
		$("div.main-pic img").attr("src",$(this).attr("href"));
	})


})


SHOOT.slider = {

	// the current page
	p: 0,

	// width of visible area (should be divisible by total item width)
	c: 350,

	// width of category header
	cw: 57,

	// width of mag entry
	mw: 118,

	// set some defaults
	init: function() {

		wdth = this.measureWidth();
		this.n = Math.ceil(wdth / this.c) -1; // number of 'pages'

		if(this.n > 1) {
			$(".tmNav").addClass("tm-interactive");
		} else {
			$(".tmNav").addClass("tm-hidden");
		}
	},

	// measure the width of the entries
	measureWidth: function(){
		cats = $("#timeline .cat-image").size();
		mags = $("#timeline .timeline-entry").size();
		return (cats * this.cw )  + (mags * this.mw);
	},

	// animate one page up or down
	animate:function(dir){

		// requested page
		r = this.p + dir;

		// prevent out of range
		if(r < 0 || r > this.n) {
			return;
		}

		// confirm next page
		this.p = r;

		// animate element to new position
		$("#timeline").animate( {left:(this.p * this.c) * -1+"px"}, 1000, 'swing' );
	}

};
