/* Copyright (c) 2006-2007 Mathias Bank (http://www.mathias-bank.de)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * Version 2.1
 * 
 * Thanks to 
 * Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
 * Tom Leonard for some improvements
 * 
 */
jQuery.fn.extend({

	getUrlHashParam: function(strParamName){
		strParamName = escape(unescape(strParamName)).toLowerCase();
	  
		var returnVal = new Array();
		var qString = null;
	  
		if ($(this).attr("nodeName")=="#document") {
	  		//document-handler
			//alert(window.location.hash.search(strParamName));
			if (window.location.hash.toLowerCase().search(strParamName) > -1 ){
				qString = window.location.hash.substr(1,window.location.hash.length).toLowerCase().split("&");
			}
		}

		if (qString==null) return null;
	  
		for (var i=0;i<qString.length; i++){
			if (escape(unescape(qString[i].split(":")[0])) == strParamName){
				returnVal.push(qString[i].split(":")[1]);
			}
		}

		if (returnVal.length==0) return null;
		else if (returnVal.length==1) return returnVal[0];
		else return returnVal;
	}
	
	, writeUrlHashParams: function(hash){
		var URL = document.location.href.split("#")[0];
		if (hash.length > 0){
			window.location.replace(URL + '#' + hash);
		} else {
			window.location.hash = "#";
		}
	}
});