var NetManagerPluginWizard = NetManagerBase.extend({
					   
	options: {
		
		url	        : '',
		entity_id	: 0,
		project_id	: 0,
		title		: '',
		width		: 400,
		height		: 400,
		zindex		: 1,
		closable	: true,
		instanceId  : 0,
		message		: '',
		description	: ''
	},
	
	initialize: function(options) {
		
		this.setOptions(options);
		this.generateWizard();
		
	},
	
	generateWizard: function() {
		
		this.wizard = new Element('div').addClass('NetManagerWizard').setProperty('id', 'wizard_instance_' + this.options.instanceId);
		
		this.wizardHeader = new Element('div').addClass('NetManagerWizardHeader').inject(this.wizard);
			
		this.wizardHeaderTitle = new Element('h3').inject(this.wizardHeader);
		
		if (this.options.description !== '')
			this.wizardHeaderDescription = new Element('p').setHTML(this.options.description).injectAfter(this.wizardHeaderTitle);
			
		this.wizardContent = new Element('div').addClass('NetManagerWizardContent').inject(this.wizard);
			
		this.wizardFooter = new Element('div').addClass('NetManagerWizardFooter').inject(this.wizard);
		
		this.wizardStatus = new Element('div').addClass('NetManagerWizardStatus').inject(this.wizardFooter);
		this.wizardStatusText = new Element('p').inject(this.wizardStatus);
		
		this.wizardButtons = new Element('div').addClass('NetManagerWizardButtons').inject(this.wizardFooter);
				
		if(this.options.closable) {
			
			this.wizardHeaderClose = new Element('div').addClass('close').setProperties({
					'title': 'Sluit het scherm'
				}).addEvents({
					'click': this.hide.bindWithEvent(this)
				}).inject(this.wizardHeader);
		}
		
		this.wizard.inject(document.body);
		
	},
	
	setDescription : function (sDescription) {
		if (!this.wizardHeaderDescription)
			this.wizardHeaderDescription = new Element('p').addClass('description').injectAfter(this.wizardHeaderTitle);
			
		this.wizardHeaderDescription.setHTML(sDescription)
	},
	
	setDimensions: function() {
		
		this.wizard.setStyles({
			'width': this.options.width,
			'height': this.options.height,
			'z-index': this.options.zindex
		});
		
		this.wizardContent.setStyles({
			'width': this.options.width - 40,
			'height': this.options.height - 130
		});
		
		this.wizard.makeDraggable({
			handle: this.wizardHeader,
			snap: 0,
			limit: {
				x: [0, window.getWidth() - this.options.width],
				y: [0, window.getHeight() - this.options.height]
			}
		});
	},
	
	setPosition: function() {
		
		this.wizard.setStyles({
			'top': (window.getHeight() - this.options.height) / 2 + window.getScrollTop(),
			'left': (window.getWidth() - this.options.width) / 2 + window.getScrollLeft()
		});
	},
	
	setTitle: function() {
		
		this.wizardHeaderTitle.setHTML(this.options.title);
	},
	
	setIframe: function() {
		oOverlay = new NetManagerPluginOverlay();
		
		var url = this.options.url;
		this.elmIframe = new Element('iframe').setProperties({src:url, width:'740px', height:'540px', frameborder: 0}).inject(this.wizardContent);
		
		this.setOptions({width: 740, height: 560});
		this.setDimensions();
		this.setPosition();
		this.setTitle();
		
		if(this.options.has_save) {
			this.addSaveFormButton();	
		}
		
		this.wizard.setStyle('display', 'block');
	},
	
	showForm: function(formName, entityId, parentId) {
		
		oOverlay = new NetManagerPluginOverlay();
		
		this.setDimensions();
		this.setPosition();
		this.setTitle();
		
		var url = '/form/get/' + formName;
		
		if(this.options.parentId > 0) {
			url = url + '/iItemId/' + entityId + '/iParentId/' + parentId;	
		}
		else {
			url = url + '/iItemId/' + entityId;
		}
		
		var onGetForm = this.updateContent.bind(this);
		
		oAjax = new NetManagerPluginAjax();
		
		oAjax.getAjax(url, onGetForm, true);
		
		this.wizard.setStyle('display', 'block');
	},
	
	updateContent: function(sResponse) {
		this.wizardContent.setHTML(sResponse);
		if ($defined(this.options.fnComplete)) {
			this.options.fnComplete();
		}
	},
	
	closeWizard: function() {
		
		oOverlay.closeOverlay();
		this.wizard.setStyle('display', 'none');
		this.setOptions({
			title		: 'Wizard',
			width		: 400,
			height		: 400,
			closable	: true
		});
		
		this.setDimensions();
		this.setPosition();
		this.setTitle();
		this.clearContent();
	},
	
	clearContent: function() {
		this.wizardContent.empty();
		this.wizardButtons.empty();
		
	},
	
	closeForm: function() {
		this.closeWizard();
	},
	
	saveForm: function() {
		
		oForm = new NetManagerPluginForm({form:$(this.options.form), onValid: function() {oProject.getWizard().closeForm();}});
		oForm.processForm();
	},
	
	show: function() {
		
		oOverlay = new NetManagerPluginOverlay();
		this.setDimensions();
		this.setPosition();
		this.setTitle();
		this.wizard.setStyle('display', 'block');
	},
	
	hide: function() {
		this.closeWizard();
	},
	
	setContent: function(obj) {
		this.wizardContent.adopt(obj);
	},
	
	getContent: function(url) {
		oAjax = new NetManagerPluginAjax();
		oAjax.getAjax(url, this.updateContent.bind(this), true);
	},
	
	setStatus: function(status) {
		
		this.wizardStatusText.empty();
		var statIcon = new Element('span').addClass('icon').addClass(status.icon).inject(this.wizardStatusText);
		var statText = new Element('span').addClass('value').setText(status.text).inject(this.wizardStatusText);
		
	},
	
	addButton: function(button) {
		if ($type(button) == 'object') {
			var buttonLink = new Element('a').addClass('button').inject(this.wizardButtons);
			var buttonIcon = new Element('span').addClass('icon');
			if ($defined(button.icon)) {
				buttonIcon.addClass(button.icon);
			}
			buttonIcon.inject(buttonLink);
			if ($defined(button.text)) {
				var buttonText = new Element('span').addClass('value').setText(button.text).inject(buttonLink);
			}
			if ($defined(button.event)) {
				
				
				buttonLink.addEvent('click', button.event);
			}
		} else {
			alert('Er is een fout opgetreden bij het opmaken van een button.');
		}
		
	},
	
	getInstanceId: function() {
		return this.wizard.getProperty('id');
	},
	
	showConfirm: function() {
		if (this.options.message !== '') {
			
			this.confirmMessage = new Element('p').setText(this.options.message).inject(this.wizardContent);
			this.show();
		} else {
			return false;
		}
	},
	
	showImage: function(fileId) {
		oImage = new Asset.image('/image/get/iImageId/' + fileId, {});
		oImage.inject(this.wizardContent);
		this.show();
	}

});

NetManagerPluginWizard.implement(new Options);