var w = this, BA = {};

BA.Countdown = function () {
	// Door Knock Date - Monday, February 16, 9:00 AM
	var now = new Date(),
		epoch = new Date('02/16/2009 9:00 AM'),
		diff = new Date(epoch-now),
		secs = Math.floor(diff.valueOf()/1000),
		intervalID;
	
	function interval(length, max) {
		return ((Math.floor(secs/length))%max).toString();
	}
	
	function days() {
		return interval(86400, 100000);
	}
	
	function hours() {
		return interval(3600, 24);
	}
	
	function minutes() {
		return interval(60, 60);
	}
	
	function seconds() {
		return interval(1, 60);
	}
	
	function tick() {
		secs = secs - 1;
		if (secs) {
			w.$('#countdown').html('<span class="days">' + days() + '</span> days <span class="hours">' + hours() + '</span> hours <span class="minutes">' + minutes() + '</span> minutes <span class="seconds">' + seconds() + '</span> seconds');
		}
		else {
			w.$('#title').html('<span class="day">00</span> days <span class="hour">00</span> hours <span class="minute">00</span> minutes <span class="second">00</span> seconds');
			w.clearInterval(intervalID)
		}
	}
	
	function init() {
		if (now <= epoch) {
			w.$('#title').append('<p id="countdown"><span class="days">' + days() + '</span> days <span class="hours">' + hours() + '</span> hours <span class="minutes">' + minutes() + '</span> minutes <span class="seconds">' + seconds() + '</span> seconds</p>');
			intervalID = w.setInterval(tick, 1000);
		}
		else {
			w.$('#title').append('<p id="countdown"><span class="day">00</span> days <span class="hour">00</span> hours <span class="minute">00</span> minutes <span class="second">00</span> seconds</p>');
		}
	}
	
	return {init: init};
}();

BA.PhotoNav = function () {
	var title = w.$('.photo-title span'),
		previous = w.$('#navigate .previous a'),
		next = w.$('#navigate .next a'),
		previous_href = previous.attr('href');
		next_href = next.attr('href'),
		previous_title = previous.attr('title');
		next_title = next.attr('title');
	
	function init() {
		if (previous_href) {
			previous = '<a href="' + previous_href + '" title="' + previous_title + '">&laquo; previous</a>';
		}
		else {
			previous = '&laquo; previous';
		}
		previous = '<span>' + previous + '</span>';
		
		if (next_href) {
			next = '<a href="' + next_href + '" title="' + next_title + '">next &raquo;</a>';
		}
		else {
			next = 'next &raquo;';
		}
		next = '<span>' + next + '</span>';
		
		title.prepend('<div id="post-nav" style="float:right;font-size:9px">' + previous + ' | ' + next + '</div>');
	}
	
	return {init: init};
}();

w.$(w.document).ready(
	function () {
		//BA.Countdown.init();
		BA.PhotoNav.init();
	}
);
