/*****************************************
 *  sneBlockUI.js BlockUI widget.        *
 *  Copyright Snertill ehf.              * 
 *  Author: Tomas Gudmundsson            *
 *  Date: 15th of May 2008.              *
 *****************************************/

Fusion.Tool.sneBlockUI = Class.create(); 
Fusion.Tool.sneBlockUI.prototype =  {
    dialog : null,
    print : true,
    initialize : function() {
        Object.inheritFrom(this, Fusion.Widget.prototype, [this.widgetTag, true]);
        var json = this.widgetTag.extension;
        this.dialogContentURL = Fusion.getFusionURL() + widgetTag.location + 'sneBlockUI/sneBlockUIDefault.html';
        this.imageBaseUrl = json.ImageBaseUrl ? json.ImageBaseUrl[0] : 'images';

	var size = Element.getPageDimensions();
	var o = {
		title: OpenLayers.String.translate('Loading'),
		id: 'Loading',
		contentURL : this.dialogContentURL,
		onContentLoaded: this.contentLoaded.bind(this),
		imageBaseUrl: this.imageBaseUrl,
		width: 120,
		height:80,
		titleHeight:0,
		resizeable: false,
		top: (size.height-300)/2,
		left: (size.width-420)/2,
		actionNeeded : 'none'
	};
        this.dialog = new Jx.Dialog(o);
        this.getMap().registerForEvent(Fusion.Event.MAP_BUSY_CHANGED,
		OpenLayers.Function.bind(this.mapBusyChange, this));
	if(this.print)
		console.log('This BlockUI has been created:' + (new Date().getTime()));
    },
    mapBusyChange: function() { 
        if (this.getMap().isBusy()) {
            this.blockUI();
        } else {
            this.unBlockUI();
        }
    },
    /*
     *
     */
    unBlockUI: function() {
      if(this.print)
        console.log('unblock');
	this.dialog.close();
    },
    blockUI: function() {
      if(this.print)
        console.log('block');
        this.dialog.open();
    }
};

