var windowName = "preview";
//var HighlightedElement = null;
//var HighlightedElementState = null;

function InitSpecificMenu(mode, name)
{
	context.command.InitSpecificMenu(mode, name);
}

function rClick()
{
	showNode();
	context.menuManager.printWindow = window;
	var res = context.menuManager.rClick(event, context.mode.state);
	context.menuManager.printWindow = null;
	return res;
}

function keyUp()
{
	context.command.processKey("preview", event);
}
function showNode()
{
	/*
	var element = context.command.getHTMLPivot(window.event.srcElement);
	if(element == null) return;
	var node = context.command.getXMLPivot(window.event.srcElement, "preview");
	while(node != null) {
		var definition = context.model.getDefinition(node);
		if(definition == null || definition.visible == true) break;
		node = node.parentNode;
	}
	if(node != null) {
		context.setCurrentNode(node, false);
	}
	context.console.dump("preview click");
	*/
	context.previewClick(event.srcElement);
}

function unregisterWindow()
{
	if(window == context.processor.window) {
		context.processor.window = null;
		context.processor.resize = null;
	}
}

function resize()
{
	if(window != context.processor.window) return;
	switch(context.zoom) {
	case "fitToPage":
		var zoom = parseFloat(document.body.style.zoom);
		if(isNaN(zoom)) zoom = 1.0;
		var width = document.body.clientWidth;
		document.body.style.zoom = "" + (zoom*width/800);
		break;
	default:
		if(typeof(context.zoom) == "string") {
			document.body.style.zoom = context.zoom;
		} else {
			document.body.style.zoom = "";
		}
	}
}

function onHelp()
{
	context.command.cmdHelp("preview");
}

function registerWindow()
{
	if(!window.external.isPopupWindow()) {
		context.processor.window = window;
		context.processor.resize = resize;
	}
	document.body.onbeforeunload = unregisterWindow;
	document.body.onhelp = onHelp;
	resize();
}


addLoadAction(registerWindow);
addResizeActions(resize);

