var query_strings;

function getHashStrings() { 
	var assoc  = {};
	var decode = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); };

	var queryString;
	if(window.location.hash){
		queryString = window.location.hash.substring(1); 
	}
	else{
		queryString = window.location.search.substring(1); 
	}

	var keyValues = queryString.split('&'); 
	for(var i in keyValues) { 
		var key = keyValues[i].split('=');
		if (key.length > 1) {
			assoc[decode(key[0])] = decode(key[1]);
		}
	} 
	return assoc; 
}

function getObjects(obj, key, val) {
	var objects = [];
	for (var i in obj) {
		if (!obj.hasOwnProperty(i)) continue;
		if (typeof obj[i] == 'object') {
			objects = objects.concat(getObjects(obj[i], key, val));
		} else if (i == key && obj[key] == val) {
			objects.push(obj);
		}
	}
	return objects;
}

function customStore(key, val){
	if(typeof query_strings == 'undefined'){
		var wh = getHashStrings();
	}
	else{
		var wh = query_strings;
	}
	//READ
	if (val == null){
		if($.isEmptyObject(wh)){
			return "";
		}
		else{
			if(typeof wh[key] == 'undefined'){
				return "";
			}
			else{
				return wh[key];
			}
		}
	}
	//WRITE
	else{
		wh[key] = val;
		query_strings = {};
		query_strings = wh;
	}
}

