/*
 * jQuery history plugin
 *
 * Copyright (c) 2006 Taku Sano (Mikage Sawatari)
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Modified by Lincoln Cooper to add Safari support and only call the callback once during initialization
 * for msie when no initial hash supplied.
 * API rewrite by Lauris Bukšis-Haberkorns
 */
(function(b){function a(){this._curHash="";this._callback=function(c){}}b.extend(a.prototype,{init:function(d){this._callback=d;this._curHash=location.hash;if(b.browser.msie){if(this._curHash==""){this._curHash="#"}b("body").prepend('<iframe id="jQuery_history" style="display: none;"></iframe>');var c=b("#jQuery_history")[0].contentWindow.document;c.open();c.close();c.location.hash=this._curHash}else{if(b.browser.safari){this._historyBackStack=[];this._historyBackStack.length=history.length;this._historyForwardStack=[];this._isFirst=true;this._dontCheck=false}}this._callback(this._curHash.replace(/^#/,""));setInterval(this._check,100)},add:function(c){this._historyBackStack.push(c);this._historyForwardStack.length=0;this._isFirst=true},_check:function(){if(b.browser.msie){var c=b("#jQuery_history")[0];var f=c.contentDocument||c.contentWindow.document;var h=f.location.hash;if(h!=b.history._curHash){location.hash=h;b.history._curHash=h;b.history._callback(h.replace(/^#/,""))}}else{if(b.browser.safari){if(!b.history._dontCheck){var d=history.length-b.history._historyBackStack.length;if(d){b.history._isFirst=false;if(d<0){for(var e=0;e<Math.abs(d);e++){b.history._historyForwardStack.unshift(b.history._historyBackStack.pop())}}else{for(var e=0;e<d;e++){b.history._historyBackStack.push(b.history._historyForwardStack.shift())}}var g=b.history._historyBackStack[b.history._historyBackStack.length-1];if(g!=undefined){b.history._curHash=location.hash;b.history._callback(g)}}else{if(b.history._historyBackStack[b.history._historyBackStack.length-1]==undefined&&!b.history._isFirst){if(document.URL.indexOf("#")>=0){b.history._callback(document.URL.split("#")[1])}else{b.history._callback("")}b.history._isFirst=true}}}}else{var h=location.hash;if(h!=b.history._curHash){b.history._curHash=h;b.history._callback(h.replace(/^#/,""))}}}},load:function(f){var g;if(b.browser.safari){g=f}else{g="#"+f;location.hash=g}this._curHash=g;if(b.browser.msie){var c=b("#jQuery_history")[0];var e=c.contentWindow.document;e.open();e.close();e.location.hash=g;this._callback(f)}else{if(b.browser.safari){this._dontCheck=true;this.add(f);var d=function(){b.history._dontCheck=false};window.setTimeout(d,200);this._callback(f);location.hash=g}else{this._callback(f)}}}});b(document).ready(function(){b.history=new a()})})(jQuery);