// ==UserScript==
// @name			ViewPermalinkForLiveMaps_Firefox
// @namespace		http://www.stchur.com/greasemonkey/
// @description		Adds "View Permalink" option to the share menu for Firefox users
// @include		http://maps.live.com/*
// @include		http://local.live.com/*
// @include		http://www.virtualearth.com/*
// ==/UserScript==


unsafeWindow.addEventListener('load', addLink, false);

function addLink()
{
	var g = unsafeWindow.g;
	var list = g('#taskBar').select('#taskBar_shareMenuAnchor+div.dropDownPanel > ul').element();
	
	var li = document.createElement('li');
	var button = document.createElement('button');
	button.id = 'sstchur_view_permalink';
	button.appendChild(document.createTextNode('View Permalink'));
	li.appendChild(button);
	list.appendChild(li);
	
	g(button).addEvent('click', showPermalink, false);
}

function showPermalink()
{
	var mask = document.createElement('div');
	mask.id = 'sstchur_mask';
	mask.style.position = 'absolute';
	mask.style.background = '#fff';
	mask.style.opacity = '.5';
	mask.style.top = mask.style.left = '0';
	mask.style.width = mask.style.height = '100%';
	mask.style.zIndex = '9000';
	
	var dialog = document.createElement('div');
	dialog.style.position = 'absolute';
	dialog.style.top = '35%';
	dialog.style.left = '50%';
	dialog.style.height = '15em';
	dialog.style.width = '70em';
	dialog.style.marginLeft = '-35em';
	dialog.style.background = '#eee';
	dialog.style.border = '2px solid #000';
	dialog.style.padding = '1em';
	dialog.style.zIndex = '9001';
	dialog.style.textAlign = 'center';
	
	var h2 = document.createElement('h2');
	h2.appendChild(document.createTextNode('Enjoy your permalink!'));
	dialog.appendChild(h2);
	
	var thePermalink = document.createElement('a');
	var link = unsafeWindow.state.GetPermalink();
	thePermalink.href = link;
	thePermalink.appendChild(document.createTextNode(unsafeWindow.WrapLongText(link)));
	dialog.appendChild(thePermalink);
	
	var closeBtn = document.createElement('button');
	closeBtn.appendChild(document.createTextNode('Close'));
	closeBtn.addEventListener('click', function()
	{
		document.body.removeChild(dialog);
		document.body.removeChild(mask);
	}, false);
	closeBtn.style.display = 'block';
	closeBtn.style.margin = '3em auto';
	dialog.appendChild(closeBtn);
	
	
	document.body.appendChild(mask);
	document.body.appendChild(dialog);
	
	
};