var ModalController = {
	// variables
	modals:{},
	active:false,
	
	// methods
	Config:function(data)
	{
		/*
			id,
			template,
			file
		*/
		for(m in data)
		{
			var modal 	= data[m];
			var id		= modal.id;
			
			this.modals[id] = {};
			
			for(prop in modal)
			{
				this.modals[id][prop] = modal[prop];
			}
		}
	},
	
	Load:function(id, data)
	{
		var modal 		= this.modals[id];
		var id			= modal.id;
		var template 	= modal.template;
		if(modal.file){var file		= modal.file;}
		if(data){modal.data = data;}
		
		this.active		= id;
		
		// call data transport
		DataTransport.Get({}, template, "ModalController.Template", "html");
	},
	
	Template:function(template)
	{
		$("body").append(template);
		
		var file	= ModalController.modals[ModalController.active].file;
		var data	= ModalController.modals[ModalController.active].data;		
		if(file)
		{
			DataTransport.Get({}, file, "ModalController.Content", "html");
		}
		else
		{
			ModalController.Inline(data);
		}
	},
	
	Content:function(content)
	{
		$("#ModalContent").append(content);
		ModalController.Adjust();
		$("#Modal").fadeIn();
	},
	
	Inline:function(data)
	{
		var h1 = $(document.createElement("h1"));
		h1.html(data.title);
		
		var p = $(document.createElement("p"));
		p.html(data.message);		
		
		$("#ModalContent").append(h1, p);
		
		this.Adjust();
	},
	
	Adjust:function()
	{
		var modal	= $("#Modal");
		var blocker	= $("#PageBlocker");
		var content	= $("#ModalContent");
		
		if(document.innerHeight){temp=document.innerHeight;}else if(document.documentElement.clientHeight){temp=document.documentElement.clientHeight;}else if(document.body){temp=document.body.clientHeight;}			

		w	= $('body').width();
		h	= $('body').height() > temp ? $('body').height() : temp;
		
		x	= (w/2) - (content.width()/2);
		y	= $('body').height() > temp ? (temp/2) - (content.height()/2) - 25 : (h/2) - (content.height()/2) - 25;
		
		// background
		blocker.css(
			{
				width:w,
				height:h,			
				opacity:.60
			}
		)
		
		// foreground
		content.css(
			{
				left:x,
				top:y				
			}
		)
	},
	
	Close:function()
	{
		var modal	= $("#Modal");
		var blocker	= $("#PageBlocker");
		var content	= $("#ModalContent");
		
		content.fadeOut(
			'fast',
			function()
			{
				blocker.fadeOut(
					'fast',
					function()
					{
						modal.remove();
					}
				)
			}
		);		
	},
	
	Kill:function()
	{
		var modal	= $("#Modal");
		modal.remove();
	}
}
