function InfoPanel(options) {
    if (options == null) options = {}

    // PANEL ELEMENTS   
    this._window = null;
    this._overlay = null;
    this._title = null;
    this._message = null;
	this._btnOK = null;
	
	this.$WINDOW = $(window);

    // UTILITIES	
    this.skin = options.skin || '';
    this.duration = options.duration || 250;
    this.TITLE_DEFAULT = 'Info Window';
    this._id = 0;
	
	this.IE6 = typeof document.addEventListener !== 'function' && !window.XMLHttpRequest;
	
	this.overlayOpacity = options.overlayOpacity || 0.75;	
	this.opts = options;

    _self = this; // REFERENCE TO THE CLASS	
    // FIRE IT OFF
    this.init();
}

InfoPanel.prototype = {
    init: function () {
        // SET ID
        this._id = "InfoPanel_" + this._getId();
		
		this._overlay = $("<div></div>").addClass("InfoPanelOverlay").appendTo('body');
		this._window  = $("<div></div>").attr("id",  this._id).attr('class',"InfoPanel" + " " + this.skin)
		$("<div></div>").addClass("InfoPanelIcon").appendTo(this._window);
		
		var infoContent = $("<div></div>").addClass("InfoPanelContent")
		this._title = $("<div></div>").addClass("InfoPanelTitle").appendTo(infoContent);
		this._message = $("<div></div>").addClass("InfoPanelMessage").appendTo(infoContent);
		this._btnOK = $("<div></div>").addClass("InfoPanelOK").attr('title','Click To Close').html('OK').appendTo(infoContent);
		
		infoContent.appendTo(this._window);
		this._window.appendTo('body');
		
		if(this.IE6)
		{
			this._overlay.css('position','absolute');
			this._window.css('position','absolute');	
		}	
		
		 // HIDE IT
        this._destroyModal(true);

        // CALL ATTACH HANDLERS AFTER GLOBALS HAVE BEEN SET		
        if (this._window.length > 0) this._attachHandlers();		
	}, 

    _attachHandlers: function () {
        var $this = this;
        this._window.find('.InfoPanelOK').click(function (ev) 
		{			
			if($this.opts.onOK)
			{
				if(typeof $this.opts.onOK == 'function') $this.opts.onOK.call($this,$this);			
			}			
			$this._destroyModal()							
        })
    },

    _destroyModal: function (b) {
        var $this = this;

		this._overlay.stop().animate({'opacity': 0}, (b == null || b == false) ? this.duration : 0, 'swing');
        this._window.stop().animate({'opacity': 0}, (b == null || b == false) ? this.duration : 0, 'swing', function () {

            $this._title.html("");
            $this._message.html("");
            $this._window.css('visibility', 'hidden')
			$this._overlay.css('visibility', 'hidden')
			
			if($this.opts.onHide)
			{
				if(typeof $this.opts.onHide == 'function')	$this.opts.onHide.call($this, $this);
			}		

        }) // end of animate callback			
        return false;
    },

    hide: function () {
        this._destroyModal();
    },

    show: function (options) {
		
		var $this = this;		
        if (options == null) options = {};

		this._overlay.css({'opacity': 0,'visibility': 'visible'}).stop().animate({'opacity': this.overlayOpacity}, this.duration, 'swing');
        this._window.css({'opacity': 0,'visibility': 'visible'}).stop().animate({'opacity': 1}, this.duration, 'swing', function(){ $this._window.focus()});	
		
        this._title.html(options.title || this.TITLE_DEFAULT);
        this._message.html(options.message || "No Information Provided");
        this.resize()
    },

    removeSkin: function (skin) {
        if (this._window.hasClass(skin)) {
            this._window.removeClass(skin);
        }
    },

    addSkin: function (skin) {
        this._window.removeClass(skin).addClass(skin);
    },

    resize: function () {
        if (this._window.is(":hidden") == false) {
            var _nTop = (this.$WINDOW.height() - this._window.outerHeight()) / 2;
            var _nLeft = (this.$WINDOW.width() - this._window.outerWidth()) / 2;
			
			if(!this.IE6)
			{
				this._window.css({
					'top': _nTop + 'px',
					'left': _nLeft + 'px'
				})	
				
			} else 
			{		
				this._overlay.css('height', $(document).height());
				this._window.css({
               	    'top': Number(_nTop + this.$WINDOW.scrollTop()) + 'px',
                	'left': _nLeft + 'px'
            	})
			}	
				
        }
    },

    _getId: function () {
        var _nTotal = Number($('div.InfoPanel').length)
        return (_nTotal + 1);
    }
}
