if (typeof(modalWindow) == 'undefined') modalWindow = new Array();

function showPopupScriptPage(href, e)
{
	clickX = (e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft))) - $0(window).scrollLeft();
	clickY = (e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop))) - $0(window).scrollTop();

	var modalWindowId = 'popup' + modalWindow.length;
	modalWindow[modalWindow.length] = {id: modalWindowId, x: clickX, y:clickY};

	var modalWindowHtml = '<div class="jqmWindow" id="' + modalWindowId + '">';
	modalWindowHtml += '<div class="jqDrag title">Dialog Title</div>';
	modalWindowHtml += '<input type="image" src="/i/ssm/closediv.gif" class="jqmdX jqmClose" />';
	//modalWindowHtml += '<img src="/i/ssm/resize.gif" alt="resize" class="jqResize" />';
	modalWindowHtml += '<div class="content"></div>';
	modalWindowHtml += '</div>';

	$0('body').append(modalWindowHtml);
	$0('#'+modalWindowId)
	.jqDrag('.jqDrag')
  // .jqResize('.jqResize')
	.jqm({ajax: href, target: '.content', onLoad: showWindow, onShow: doNothing, onHide: hideWindow});

	$0('#'+modalWindowId).jqmShow();

}

function showWindow(hash)
{
	positionByClick(hash);
	hash.w.slideDown();
}

function hideWindow(hash)
{
	 hash.w.slideUp("slow",function() { if(hash.o) hash.o.remove(); });
}

function positionByClick(hash)
{
	var windowData = _findWindowData(hash.w.attr('id'));

	var alignRight = windowData.x <= ($0(window).width()/2)
	var alignBottom = windowData.y <= ($0(window).height()/2)

	var position = document.all ? 'absolute' : 'fixed';
	var left = alignRight ? windowData.x : windowData.x - hash.w.width();
	var top = alignBottom ? windowData.y : windowData.y - hash.w.height();

	hash.w.css('position', position);
	hash.w.css('left', left + 'px');
	hash.w.css('top', top + 'px');
}

function doNothing(){}

function _findWindowData(windowId)
{
	var result = null;
	for (var i=0; i<modalWindow.length; i++)
	{
		if (modalWindow[i].id == windowId) result = modalWindow[i];
	}
	return result;
}