


//remember if we've found the object
var havefound = false;


//preload the end image
var img = new Image;
img.src = 'addons/hahaha.gif';



//view change callback
function viewchange(x, y, dir, inst)
{
	//try to duplicate the map contents
	//dunno why we need this try ... i couldn't replicate the error alex saw
	//meh
	try { top.document.getElementById('map').innerHTML = inst.map.innerHTML; } catch(err) {}

	//if the found object element is currently present, remove it
	var obj = document.getElementById('foundobject');
	if(obj) { obj.parentNode.removeChild(obj); }

	//if we reach the end position
	if(x == 64 && y == 10 && dir == 2)
	{
		//get a reference to the dungeon view's parent element
		var parent = inst.dungeon.parentNode;

		//create the found object, inside the parent,
		//superimposed on top of everything else
		//(and so that in source order this will also come out after the caption)
		obj = parent.appendChild(inst.tools.createElement('p', {
				'id' : 'foundobject'
				}));

		//move it to center position and show it
		obj.style.left = (parent.offsetWidth / 2) - (obj.offsetWidth / 2) + 'px';
		obj.style.top = (parent.offsetHeight / 2) - (obj.offsetHeight / 2) + 'px';
		obj.style.visibility = 'visible';

		//replace the captiontext
		inst.captiontext.innerHTML = 'Accessible JavaScript will never be defeated!<br />'
			+ 'Oh yeah, and here\'s a $10 discount to learn how I put this monstrosity '
			+ 'together, in my latest book &#8212; '
			+ '<a href="https://sitepoint.com/bookstore/go/130/b8d6aa/e8cfbb2347" target="_top">The Art &amp; Science Of JavaScript</a>';
	}

	//don't allow movement over the end square itself
	//move it back to the previous square
	if(x == 64 && y == 12 && dir == 2)
	{
			inst.applyDungeonView(64, 10, 2);
	}
}

