<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2014, Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<script src="js/jquery.js" type="text/javascript"></script>
	<script src="js/CSInterface.js" type="text/javascript"></script>
</head>
<body ondragover="return false;" ondragstart="return false;" ondrop="return false;">
</body>
<script type="text/javascript">

    var kAnchorEvent = "com.adobe.URLAnchorExtract.anchor";
    var kReadyForInitializationEvent = "com.adobe.URLAnchorExtract.readyForInitialization";
    var kInitializationEvent = "com.adobe.URLAnchorExtract.initialization";
    var kDebugEvent = "com.adobe.URLAnchorExtract.debug";

	var csInterface = new CSInterface();

	/*
	**
	*/
	window.onload = function()
	{
		dispatchDebugEvent('entered onload');
		dispatchReadyForInitializationEvent();
	};

	/*
	**
	*/
	function dispatchReadyForInitializationEvent()
	{
		dispatchDebugEvent('entered dispatchReadyForInitializationEvent');
		csInterface.addEventListener(kInitializationEvent, handleInitializationEvent);
		console.log('Dispatching ready for initialization event');
		var csEvent = new CSEvent(kReadyForInitializationEvent, 'APPLICATION');
		csInterface.dispatchEvent(csEvent);
	}

	/*
	**
	*/
	function handleInitializationEvent(event)
	{
		dispatchDebugEvent('entered handleInitializationEvent');
		csInterface.removeEventListener(kInitializationEvent, handleInitializationEvent);
		console.log('Target url received: ' + event.data);

		if (window.location.hash)
		{
			dispatchAnchorEvent(window.location.hash);
		}
		else
		{
			window.location = event.data;
		}
	}

	/*
	**
	*/
	function dispatchAnchorEvent(anchor)
	{
		dispatchDebugEvent('entered dispatchAnchorEvent');
		console.log('Dispatching anchor event for ' + anchor);
		var csEvent = new CSEvent(kAnchorEvent, 'APPLICATION');
		csEvent.data = anchor;
		csInterface.dispatchEvent(csEvent);
	}

	/*
	**
	*/
	function dispatchDebugEvent(anchor)
	{
		var csEvent = new CSEvent(kDebugEvent, 'APPLICATION');
		csEvent.data = anchor;
		csInterface.dispatchEvent(csEvent);
	}

</script>
</html>