/*
---
description:     MooDialog

authors:
  - Arian Stolwijk

license:
  - MIT-style license

requires:
  core/1.2.4:   '*'

provides:
  - [MooDialog.Confirm,Element.confirmLinkClick]
...
*/

MooDialog.Confirm = new Class({	
	
	Extends: MooDialog,	
  
	initialize: function(msg,b1,b2,fn,fn1,options){
		this.parent(options);
		
		fn = fn ? fn : $empty;
		fn1 = fn1 ? fn1 : $empty;
		
		var cancelButton = new Element('input',{
			type: 'button',
			events: {
				click: function(){
					fn1();
					this.close();
				}.bind(this)
			},
			value: b1,
			'class': 'buttonConfirm'
		});
		
		this.setContent(
			new Element('div')
				.adopt(
					new Element('p',{
						'class': 'MooDialogConfirm',
						text: msg
					})
				).adopt(
					new Element('div',{
						'class': 'buttons'
					}).adopt(cancelButton).adopt(
						new Element('input',{
							type: 'button',
							events: {
								click: function(){
									fn();
									this.close();
								}.bind(this)
							},
							value: b2,
							'class': 'buttonConfirm'
						})
					)
				)
		).open();
		
		if(this.options.focus){
			this.addEvent('show',function(){
				cancelButton.focus();
			});
		}
	}
});


Element.implement({
	confirmLinkClick: function(msg,b1,b2,options){
		this.addEvent('click',function(e){
			e.stop();
			new MooDialog.Confirm(msg,b1,b2,function(){
				location.href = this.get('href');
			}.bind(this),null,options)
		});
	}
	
});



