/* 
	info
	1 button only
*/
mmDialog.Info = new Class({	
	Extends: mmDialog
	, options: {
		buttons : {
			'ok': '<span class="mmIcon icon-ok"></span> Ok'
		}
		, autosize: true
		, focus: true
		, classes: {
			btnOk: 'mmBtn btn-l btn-default'
			, msgContainer: 'mmDialogInfoMessage'
		}
		, template: '<div class="rel ptb-10"><div class="row"><div class="col c1-7 tC"><span class="mmIcon icon-info icon-xxl"></span></div><div class="col c6-7 clast"><div class="rel mmDialogInfoMessage f-l tL pt-5 plr-5 tsb-w"></div></div></div></div>'
	}
	, initialize: function(msg, options){
mm.log('INFO INIT OPT:'+options);		
		this.parent(options);
		this.setupDialogElements();
		this.setDefaultContent(msg);
		this.setupDialogEvents();
	}
	, setupDialogElements: function() {
		this.btnOk = new Element('a',{
			'class': this.options.classes.btnOk
			, 'href': '#'
			, events: {
				click: function(e){
					e.stop();					
					this.close();
				}.bind(this)
			},
			html: this.options.buttons.ok
		});	
		this.buttons = new Element('div', {'class':'rel'}).adopt(this.btnOk);
		this.btnOk.addEvent('keydown', this.keyDown.bindWithEvent(this, this.btnOk));		
		this.dialogTabIndex	= [this.btnOk];		
		this.setFooter(this.buttons);
	}
	, setDefaultContent:function(msg) {
		var el = this.options.template.toHTML();
		this.setContent(el);
		this.msgContainer = this.dialogBody.getElement('div.'+this.options.classes.msgContainer);
// mm.log(this.dialogBody);		
		if (msg != '') {
			this.setMessage(msg);
		}
	}	
	, setupDialogEvents:function() {
		if(this.options.focus){
			this.addEvent('show',function(){
				this.btnOk.focus();
			});
		}		
	}
	, setMessage:function(msg) {
		var setDefaultButtonTexts = false;
		
		if (msg.contains('::')) {
			setDefaultButtonTexts = true;
			var msg_array = msg.split('::');
			var msg = msg_array[0];
			if (msg_array[1] != undefined && msg_array[1] != '') {
				setDefaultButtonTexts = false;
				this.btnOk.set('html', msg_array[1]);				
			}			
		} else {
			setDefaultButtonTexts = true;
		}		
		if (setDefaultButtonTexts) {
			this.setDefaultButtonTexts();
		}				
		this.msgContainer.set('html', msg);
		this.reSize();
		this.parseContent();
		return this;
	}
	, setDefaultButtonTexts:function() {
		this.btnOk.set('html', this.options.buttons.ok);		
	}	
	, parseContent:function() {
		if (mm.objects != undefined) {
			mm.objects.scan(this.dialogBody);
		}
	}	
	, keyDown:function(e, el) {
// mm.log('confirm keyDown el:'+el);		
		if (this.dialogTabIndex.contains(el) && e.key=='tab') {
			e.preventDefault(); 
			if (e.shift) {
				this.setFocusElement.delay(50, this, [el, true]);
			} else {
				this.setFocusElement.delay(50, this, [el, false]);				
			}
			return false;			
		}
		if (this.dialogTabIndex.contains(el) && (e.key =='space' || e.key =='enter' )) {
			e.stop();
			el.addClass('btn-active');
			el.fireEvent('click', e);
			el.removeClass.delay(500, el, 'btn-active');
		}
	}	
	, setFocusElement:function(el, back) {
// mm.log('setNextFocusElement el.id:'+el.get('id'));		
		var curPos = 0;
		var elList = [];
		elList = this.dialogTabIndex;
		curPos = elList.indexOf(el);
		if (back) {
			nextEl = elList[curPos-1] || elList.getLast() || false;			
		} else {
			nextEl = elList[curPos+1] || elList[0] || false;
		}
// mm.log('next el = '+nextEl.get('id'));				
		if (nextEl) { nextEl.focus(); }
	}
		
});

