/**
 * DigizineObject is the Flash Digizine Object
 *
 * Changelog
 * ---------
 *
 * Niels Nijens - Mon Jul 14 2008
 * -------------------------------
 * -
 *
 * @since Mon Jul 14 2008
 * @author Niels Nijens (niels@connectholland.nl)
 **/
var DigizineObject = Class.create(SWFObject, {
	
	/**
	 * initialize
	 *
	 * Initialize a new DigizineObject
	 *
	 * @since initial
	 * @param string swfname
	 * @param string swffile
	 * @param integer width
	 * @param integer height
	 * @param string bgcolor
	 * @param object swfvars
	 * @return void
	 **/
	initialize: function($super, swfname, swffile, width, height, bgcolor, swfvars) {
		this.pageId = swfvars.pageId;
		this.requestURL = {ct: "preview", "__cms_Wmdigizine": "true", "__function_Wmdigizine": "savepreview"};
		
		$super(swfname, swffile, width, height, bgcolor, swfvars);
	},
	
	/**
	 * saveAll
	 *
	 * Saves all changes and submits the wizardform
	 *
	 * @since Tue Jul 22 2008
	 * @param element wizardform
	 * @return void
	 **/
	saveAll: function(wizardform) {
		this.wizardform = wizardform;
		if (this.methodExists("saveSubmit") ) {
			$(this.getAttribute("swfname") ).saveSubmit();
		}
		else {
			this.saveAll.applyWithTimeout(this, 100, wizardform);
		}
	},
	
	/**
	 * submit
	 *
	 * Submits the wizardform
	 *
	 * @since Tue Jul 22 2008
	 * @return void
	 **/
	submit: function(key, previewimage) {
		var url = new WJUrl(this.requestURL);
		url.addParameter("__key_Wmdigizine", key);
		url.addParameter("pageid", this.pageId);
		url.addParameter("previewimage", previewimage);
		var spin = new WJSpin();
		spin.content(url, [this.ajaxUpdate.bind(this)] );
	},
	
	/**
	 * ajaxUpdate
	 *
	 * Handles the AJAX response
	 *
	 * @since Fri Jul 25 2008
	 * @param XML response
	 * @return void
	 **/
	ajaxUpdate: function(response) {
		this.wizardform.submit();
	}
});
