var PageHelpDialogTemplate = '\
	<div class="PageHelpDialog Dialog">\
		<div class="DialogTitle">\
			<h3></h3>\
			<a href="#" class="CloseButton"></a>\
		</div>\
		<div class="DialogContent">\
		</div>\
		<div class="DialogFooter">\
		</div>\
	</div>\
';

//alert(PageHelpDialogTemplate);

var PageHelpDialog = Class.create(EventClass, {
	'initialize': function(alias) {
		this.dialog = jQuery(PageHelpDialogTemplate);
		this.dialog.appendTo('body');
		this.alias = alias;
		
		this.dialog.find('.CloseButton').unbind();
		this.dialog.find('.CloseButton').click(this.callback(function() {
			this.close();
			return false;
		}));
	},
	'loadContent': function() {
		jQuery.post('/foodordering/index/gethelp', { 'alias': this.alias }, this.callback(function(responseText) {
			var response = JSON.parse(responseText);
			
			this.dialog.find('.DialogTitle h3').text(response.Title);
			this.dialog.find('.DialogContent').html(response.Content);
		}));
	},
	'open': function() {
		this.loadContent();
	
		var windowWidth = jQuery(window).width();
		var windowHeight = jQuery(window).height();
		
		this.dialog.css('left', ((windowWidth - this.dialog.width()) / 2) + 'px');
		this.dialog.css('top', ((windowHeight - this.dialog.height()) / 2) + 'px');
		this.dialog.show();
		
		this.shade = jQuery('<div class="BackgroundShade"></div>');
		this.shade.css('width', windowWidth + 'px').css('height', windowHeight + 'px');
		this.shade.appendTo('body');
	},
	'close': function() {
		this.shade.remove();
		this.dialog.hide();
	}
});

jQuery(function($) {
	$('a.HelpButton').live('click', function() {
		var a = $(this);
		var alias = a.attr('href');
		
		var dialog = a.data('dialog');		
		if (!dialog) { 
			dialog = new PageHelpDialog(alias);
			a.data('dialog', dialog);
		}
		
		dialog.open();
		return false;
	});
	
	// $('a.HelpButton').each(function() {
		// var a = $(this);
		// var alias = a.attr('href');
		
		// var dialog = new PageHelpDialog(alias);
		
		// a.click(function() {
			// dialog.open();
			// return false;
		// });
	// });
});
