UI.GUI = {};

// This is called on page load, it handles all initialization logic!

UI.GUI = { PreventScroll: function(e){ e.preventDefault(); } };

// Used for Creating A Dialogue Box
// Must use the create sub object to initialie the dialogue.
// Cancel function is optional
UI.GUI.Dialogue =
{
	yesNo: null,
	
	create: function(strings,confirm,cancel)
	{
		// Simplify Scope
		var th = UI.GUI.Dialogue;
		
		// Create Elements
		th.dShade = document.createElement('div');
		th.dBox = document.createElement('div');
		th.btnOk = UI.GUI.Button('db_Confirm');
		th.btnCancel = UI.GUI.Button('db_Cancel');
		th.dMessage = document.createElement('div');
		
		th.dShade.id = 'dShade';
		th.dBox.id = 'dBox';
		th.dMessage.id = 'db_Message';

		th.dMessage.innerHTML = strings.message;
		th.btnOk.innerHTML = strings.confirm;
		th.btnCancel.innerHTML = strings.cancel;
		th.confirm = confirm;

		if(!cancel) var cancel = function(){ return; };
		UI.GUI.Dialogue.cancel = cancel;

		th.btnOk.addEventListener('touchend',function()
		{
			UI.GUI.Dialogue.yesNo = true;
			UI.GUI.Dialogue.destroy();
		},false);

		th.btnCancel.addEventListener('touchend',function(){ 
			UI.GUI.Dialogue.destroy();
			UI.GUI.Dialogue.yesNo = false;
		},false);

		th.dBox.appendChild(th.dMessage);
		th.dBox.appendChild(th.btnCancel);
		th.dBox.appendChild(th.btnOk);
		th.dShade.appendChild(th.dBox);

		document.body.appendChild(th.dShade);
		th.dBox.className='show';
		th.dShade.className='show';
	},
	
	destroy: function()
	{
		// Simplify Scope
		var th = UI.GUI.Dialogue;
		
		th.dShade.addEventListener('webkitAnimationEnd',function()
		{
			console.log('err')
			$D(UI.GUI.Dialogue.dShade);
			
			if(UI.GUI.Dialogue.yesNo) UI.GUI.Dialogue.confirm();
			else UI.GUI.Dialogue.cancel();
		},false);
		
		th.dShade.className = 'hide';
	},
	
	confirm: function(){ return; },
	cancel: function(){ return; }
};

UI.GUI.Button = function(id)
{
	var btn = document.createElement('div');
	btn.id = id;
	btn.className = 'button';
	
	btn.addEventListener('touchstart',UI.GUI.Button.down,false);
	btn.addEventListener('touchend',UI.GUI.Button.up,false);
	
	return btn;
};

UI.GUI.Button.down = function(e){ this.className='button pressed'; };
UI.GUI.Button.up = function(e){ this.className='button'; };