/*
 * Copyright (c) 2009 Andreas Blixt <andreas@blixt.org>
 * Contributors: Aaron Ogle <aogle@avencia.com>,
 *               Matti Virkkunen <mvirkkunen@gmail.com>
 * This and more JavaScript libraries: http://blixt.org/js
 * MIT License: http://www.opensource.org/licenses/mit-license.php
 * 
 * Hash handler
 * Keeps track of the history of changes to the hash part in the address bar.
 */
var HashHandler=(function(){var window=this,documentMode=document.documentMode,history=window.history,location=window.location,callback,hash,iframe,getHash=function(){var index=location.href.indexOf("#");return(index==-1?"":location.href.substr(index+1))},poll=function(){var curHash=getHash();if(curHash!=hash){hash=curHash;callback(curHash,false)}},setIframe=function(newHash){try{var doc=iframe.contentWindow.document;doc.open();doc.write("<html><body>"+newHash+"</body></html>");doc.close();hash=newHash}catch(e){setTimeout(function(){setIframe(newHash)},10)}},setUpIframe=function(){try{iframe.contentWindow.document}catch(e){setTimeout(setUpIframe,10);return}setIframe(hash);var data=hash;setInterval(function(){var curData,curHash;try{curData=iframe.contentWindow.document.body.innerText;if(curData!=data){data=curData;location.hash=hash=curData;callback(curData,true)}else{curHash=getHash();if(curHash!=hash){setIframe(curHash)}}}catch(e){}},50)};return{init:function(cb,ifr){if(callback){return}callback=cb;hash=getHash();cb(hash,true);if(window.ActiveXObject){if(!documentMode||documentMode<8){iframe=ifr;setUpIframe()}else{window.attachEvent("onhashchange",poll)}}else{if(history.navigationMode){history.navigationMode="compatible"}setInterval(poll,50)}},go:function(newHash){if(newHash==hash){return}if(iframe){setIframe(newHash)}else{location.hash=hash=newHash;callback(newHash,false)}}}})();
