// @author Matthew Foster
 var BookmarkListener = Class.create();
        
Object.extend(Object.extend(BookmarkListener.prototype, EventDispatcher.prototype),
				{
					initialize : function(){
						
						this.createListener();
						
					},
					createListener : function(){
						
						this.serviceHandle = this.handleRequest.bind(this);
					
					},
					handleRequest : function(obj){
						var cache = this.getCache();
						
						cache[obj.action] = obj;
						
						this.setCache(cache);
						
						this.dispatchEvent("refresh", this.getCache());
						
					},
					getCache : function(){
						
						if(!this.bookmarkHash)
							return this.bookmarkHash = $H();
						
						return this.bookmarkHash;
														
					},
					
					setCache : function(obj){
						
						if(!this.bookmarkHash)
							this.bookmarkHash = {};
							
						Object.extend(this.bookmarkHash, obj || {});
						
					}
					
					
				
				}
			);
var BookmarkPrimer = Class.create();

Object.extend(Object.extend(BookmarkPrimer.prototype, EventDispatcher.prototype),
				{
					initialize : function(service, url){
						this.service = service;
						
						this.parseBookmark(url);
					
					},
					parseBookmark : function(url){
						if(url == "" || url.search(/#[[a-z{}%0-9]+/gi) == -1)
							return false;
							
						var q = this.parseURL(url);
						if(!q.isJSON())
							return false;
						
						var obj = q.evalJSON();
						
						this.processBookmark(obj);
						
						
					},
					parseURL : function(str){
						
						return str.match(/((\.[a-z]{3,}|\/)#)(.*)/i, "").last().replace(/%22/g, "\"").replace(/%20/g, " ");
					
					},
					processBookmark : function(obj){
						if(obj.length)
							obj.each(this.dispatchAction.bind(this))
						else
							this.dispatchAction(obj);
						
					
					},
					dispatchAction : function(obj){
						
						this.service.sendRequest(obj, this.service.getOperation(obj.action));
					
					}
				
				}
			);