/*
 * Open-Dialog Ctrl
 */


dialog = {};


dialog.open = function(target)
{
	target += '&d[method]=async';
	// target = target.replace('$amp;', '&');
	var 
		$block = 
			$('<div class="ui ui-helper ui-helper-block"><!--IFRAME IE HACK to cover SELECT dropdown list boxes. Iframe needs to be resized for menu height and width. --><!--[if lte IE 6]><iframe src="javascript:\'\';" marginwidth="0" marginheight="0" align="bottom" scrolling="no" frameborder="0" style="position:absolute; width: 100%; height: 100%; left: 0; top: 0px; display: block; opacity: 0; filter:alpha(opacity=0);" ></iframe><![endif]--></div>')
			.appendTo('body')
			.fadeTo(0, 0)
			.fadeTo('slow', 1),

		$loadIndicator = 
			$('<img src="static/shared/css/images/load-indicator-000.gif" alt="" border="0" />')
			.appendTo($block)
			.css({
				'position': 'absolute',
				// 'top': ($block.height()/2)+'px',
				'top': '10em',
				'left': ($block.width()/2)+'px'
			});

	$block.mousemove(function(e)
	{
		$loadIndicator
			.css({
				'left': (e.pageX-40)+'px',
				'top': (e.pageY-40)+'px'
			});
	});

	$.get(target, function(html)
	{
		// var html = decodeURIComponent(html);
	
		setTimeout(function()
		{
			var 
				$body = $('body'),
				$html = $(html)
				.appendTo($body);
	
			$block.remove();
	
			n$.signal('dom.reset');
	
		}, 500);
	});
}

$(function() {	
	$('a.ui-ctrl-open-dialog').click(function(e)
	{
		var linkProtokolMatches = 
				$(this).attr('href').match(/^([a-z]+):\/\/+/i);
		if ( linkProtokolMatches && linkProtokolMatches.length > 0 ) {
			var windowLocationProtocol = 
					window.location.href.match(/^([a-z]+):\/\/+/i);

			if ( windowLocationProtocol[1] !== linkProtokolMatches[1] ) {
				return;
			}
		}
		e.preventDefault();
		dialog.open($(this).attr('href'));
	});
});

