/**
 * Iframe widget.
 * 
 * ----
 * 
 * LICENCE
 * 
 * This work is licensed under Creative Commons Attribution-Share Alike 3.0 (Germany).
 * For details on this licence visit http://creativecommons.org/licenses/by-sa/3.0/de/
 * 
 * All rights reserved
 * 
 * @author Jakob Hohlfeld | http://www.netronaut.de
 * @copyright 2010 by Jakob Hohlfeld
 * 
 */
var NetronautUI_Widgets_Iframe = new Class
({
	Extends: NetronautUI_Widget,
	
	initialize: function ( el, options ) {
		this.parent(el, options);
		
		this.addEvent('addedToWidget', function ( target ) {
			target.addEvent('resize', function(size) {
				this.setSize(size);
				this.dom.loader.setPosition({
					x: (this.getSize().x-parseInt(this.dom.loader.getStyle('width')))/2,
					y: (this.getSize().y-parseInt(this.dom.loader.getStyle('height')))/2
				});
			}.bind(this));
		});
		this.dom.iframe.addEvent('load', function () {
			this.dom.loader.setStyle('display', 'none');
			this.dom.iframe.setStyle('display', 'block');
		}.bind(this))
	},
	
	render: function () {
		this.dom.el.addClass('netronautui-widgets-iframe');
		this.dom.loader = new Element('div', {'class':'netronautui-loader', styles:{'position':'relative', 'display':'none'}}).inject(this.dom.el);
		this.dom.iframe = new Element('iframe').set('frameborder', 0);
		if(this.options.name) {
			this.dom.iframe.name = this.options.name;
		}
	},
	
	load: function ( url ) {
		url = url || '';
		this.dom.loader.setStyle('display', 'block');
		this.dom.iframe.setStyle('display', 'none').inject(this.dom.el).src = url;
	}
});
