Deeplinking = function(containerPrefix, url) {
	this.containerPrefix = containerPrefix;
	this.container = $("#"+containerPrefix+"Container");
	this.url = url;
	this.oldloc = location.hash;
	try {
		action = new Deeplinking.Action();
	} catch(e) {  }
	
	this.setup();
};

Deeplinking.prototype = {
	setup: function() {
		this.setListeners();
		this.checkUrl();
		this.timer();
	},
	
	checkUrl: function() {
		if(location.hash != "") {
			$("body").trigger("urlchange");
		} else {
			this.onUrlChange("");
		}
	},
	
	setListeners: function() {
		var parent = this;
		$("body").bind("urlchange", function() {
			var dummy = location.href.split('#');
			if(dummy[1] != "") {
				parent.onUrlChange(dummy[1]);
			}
		});
	},
	
	timer: function() {
		var parent = this;
		var timer = setTimeout(function() {
			if(location.hash == parent.oldloc) {
				parent.timer();
			} else {
				parent.oldloc = location.hash;
				$("body").trigger("urlchange");
				parent.timer();
			}
		},1000);
	},
	
	onUrlChange: function(dlUrl) {
		var parent = this;
		if(dlUrl != "") {
			if(action) {
				action.start(dlUrl, this);
			}
		}
	}
};
