//Namespace
if (typeof(EnergyApps)=== "undefined"){ EnergyApps = { Form: {} };}
if (typeof(EnergyApps.Form) === "undefined"){
	EnergyApps.Form = {};
}

/**
 * @class EnergyApps.Form.Layer
 * @namespace EnergyApps.Form
 * @extends Publicis.Lightbox
 * @constructor
 * @param {Object} cfg Configuration options
 * @author Sebastian Sauer
 */
EnergyApps.Form.Layer = function (config) {

	EnergyApps.Form.Layer.superclass.constructor.call( this, config );

	/**
	 * @cfg {Sring} url Url to load in iframe
	 */
	if(typeof this.url === "undefined") {
		this.url = !! config.url
			? config.url
			: $( this.trigger ).readAttribute('href');

		var url = Publicis.getAbsolutePath( this.url );
		if( url ) {
			this.url = url;
		}
	}

	this.addListener( "open", function () {
		var container = $( this.idContainer ).firstDescendant(),
			iframe = new Element( "iframe", {
				src : this.url,
				frameborder : 0,
				width : "auto",
				height : "auto"
			});

		container.update( iframe );

		if( location.hash.indexOf( "#form" ) == -1 ) {
			window.location.hash += "#form=" + this.url;
		}

	}.bind( this ) );

	this.addListener( "close", function () {

		if( location.hash.indexOf( "#form" ) != -1 ) {
			window.location.hash = window.location.hash.replace( /#form=.*/,  "" );
		}

	}.bind( this ) );
};

Publicis.extend( EnergyApps.Form.Layer , Publicis.Lightbox, {} );

