/**
 * $Id: voltimum.app.window.js,v 1.6 2009-06-24 07:09:39 vladimir Exp $
 */
voltimum = window.voltimum || {};
voltimum.app = voltimum.app || {};

voltimum.app.window = function(config){
    var $ = voltimum.jQuery;
    this.config = config || {};
    this.data={};
    if(this.config.container){
        this.container = $('#'+this.config.container);
    }
    if(!this.container || !this.container.length){
        this.id = this.config.id || Math.random().toString().slice(2);    
        this.container=$('<div style="display:none;" id="volti_container'+this.id+'"></div>');
        $('body').append(this.container);    
    }
    this.load = function(url,container){
        if(container){
            container = $('#'+container);
        }else {
            container = this.container;
        }
        if(this.data[url]){
            container.html(this.data[url]);
            this.bindEvents();
        }else{
        	container.addClass('loading');
            var _this = this;
            $.ajax({
                type: "GET",
                url:    url,
                dataType: 'html',
                success: function(data){
                    _this.data[url] = data;
                    container.html(data);
                    _this.container.show();
                    _this.bindEvents();
                    container.removeClass('loading');
                }
            });
        }
    };
    this.open = function(){
        this.container.show();
		this.onopen();
    };
    this.close = function(){
        this.container.hide();
        this.onclose();
    };
    this.onopen = function(){};
    this.onclose = function(){};
    this.bindEvents = function(){};
};
