/**
 *
 * Hash Change Plugin (http://jquery.lukelutman.com/plugins/hashchange)
 * Trigger a custom event when location.hash changes.
 * 
 * Version 1.0
 * December 8th, 2006
 *
 * Copyright (c) 2006 Luke Lutman (http://www.lukelutman.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Examples: 
 * 
 * $('#example').bind('hashchange', function(e, then, now) {
 *     if(!then && !now) {
 *         // somewhere.html -> page.html
 *     } else if(then && !now) {
 *         // page.html#foo -> page.html
 *     } else if(!then && now) {
 *         // page.html -> page.html#foo
 *         // somewhere.html -> page.html#foo
 *     } else if(then && now) {
 *         // page.html#foo -> page.html#bar
 *     }
 * });
 *
 * $('#example').unbind('hashchange');
 *
**/ 
jQuery(document).ready(function(){

	var now, then, bang = setInterval(function(){
		now = location.hash;
		if(now != then)
			jQuery.event.trigger('hashchange', [
				then.length ? then : undefined, 
				now.length ? now : undefined
			]);
		then = now;
	}, 100);
		
	jQuery(window).bind('unload', function(){
		clearInterval(bang);
	});

});