function DeepLink()
{
	/* PROPERTIES
	 --------------------------------------------------------------------------------------------------------------------*/
	var baseURL = "";
	var basePath = "";
	var baseTitle = "";
	var subWin = null;
	
	/* METHODS
	 --------------------------------------------------------------------------------------------------------------------*/
	/**
	 * On first loading page 
	 *	1) 	set basic variables for URIs, paths etc
	 *	2) 	check whether deep link has been specified	EITHER
	 * 		a)	through hash (e.g. "/#director/spot")	OR
	 * 		b)	path (e.g. "/#director/spot")
	 *	3) 	check whether can log to console
	 *
	 * @param {String} baseURL
	 * @param {String} basePath
	 */
	this.init = function(baseURL, basePath, baseTitle)
	{
		this.baseURL = baseURL;
		this.basePath = basePath;
		this.baseTitle = baseTitle;
		
		var hash = this.getAddressHash();
		var path = this.getPath();
		var f = document.getElementById("address_form");
		
		if (hash) 
		{
			f.q.value = hash;
			f.submit();
		}
		else if (path) 
		{			
			f.q.value = path;
			f.submit();
		}
	}
	
	/**
	 * get a string of the hash value (e.g. "#director/spot")
	 */
	this.getAddressHash = function()
	{
		return document.location.hash.replace(/#/g, "");
	}
	
	/**
	 * get a string of the pathname value (e.g. "director/spot")
	 * by stripping basePath from the URL
	 */
	this.getPath = function()
	{
		return document.location.pathname.replace(this.basePath, "");
	}
	
	/**
	 * @param {String} title
	 * @param {String} url
	 * @param {Number} wVal
	 * @param {Number} hVal
	 * @param {Boolean} displayScroll
	 */
	this.openSubWin = function(title, url, wVal, hVal, displayScroll)
	{
		var scrollbars = (displayScroll) ? "yes" : "no";
		var name = "subWin";
		var main_w = screen.width;
		var main_h = screen.height;
		var win_w = (wVal) ? wVal : main_w - 200;
		var win_h = (hVal) ? hVal : main_h - 200;
		var left = Math.floor((main_w - win_w) / 2);
		var top = Math.floor((main_h - win_h) / 2);
		var winParams = "top=" + top;
			winParams += ",left=" + left;
			winParams += ",width=" + win_w;
			winParams += ",height=" + win_h;
			winParams += ",title=" + title + ",directories=no,menubar=no,scrollbars=" + scrollbars + ",status=no,toolbar=no,resizable=no";
		
		this.subWin = window.open(url, name, winParams);
		
		if (!this.subWin) 
		{
			alert("In order to view this content please set your browser's preferences to allow pop-ups.");
		}
		else 
		{
			this.subWin.focus();
		}
	};
	
	/**
	 * @param {String} siteRef
	 * @param {String} deepLink
	 * @param {String} itemTitle
	 */
	this.submitBookmark = function(siteRef, deepLink, itemTitle)
	{
		var enc_url = encodeURIComponent(this.baseURL + deepLink);
		var enc_title = encodeURIComponent(document.title);
		
		var address;
		var width;
		var height;
		var scrollbars = false;
		
		switch (siteRef)
		{
			case "delicious":
				width = 700;
				height = 400;
				address = 'http://del.icio.us/post?v=4;noui=yes;jump=close;url=' + enc_url + ';title=' + enc_title;
				break;
				
			case "facebook":
				width = 626;
				height = 436;
				address = 'http://www.facebook.com/sharer.php?u=' + enc_url + '&t=' + enc_title;
				break;
				
			case "digg":
				width = 960;
				height = 600;
				scrollbars = true;
				address = 'http://digg.com/submit?url=' + enc_url + '&title=' + enc_title + '&media=video&topic=television&thumbnails=0';
				break;
		}
		
		this.openSubWin("submit to " + siteRef, address, width, height, scrollbars);
	}
	
	/**
	 * function called by Flash on every click
	 * update document's title and metadata for bookmarking w/ FaceBook Share schema
	 * @param {String} hashVal
	 * @param {String} pageLabel
	 * @param {Object} spotData
	 */ 
	this.setAddressHash = function(hashVal, pageLabel, spotData)
	{
		var path = document.location.pathname;
		if (path == this.basePath) 
		{
			document.location.hash = hashVal;
		}
		
		if (pageLabel && !spotData) 
		{
			document.title = this.baseTitle + " | " + pageLabel;
		}
		else 
		{
			if (pageLabel && spotData) 
			{
				var itemClient = spotData['client'];
				var itemTitle = spotData['title'];
				var separator = (itemClient && itemTitle) ? ": " : "";
				var itemHeading = itemClient + separator + itemTitle;
				
				var itemImage = baseURL + "assets/showreels/" + spotData['dir_ref'] + "/" + spotData['image'] + ".jpg";
				
				document.title = this.baseTitle + " | " + pageLabel + " | " + itemHeading;
			}
			else 
			{
				document.title = this.baseTitle;
			}
		}
		window.pageTracker._trackPageview("/" + hashVal);
	}
}

