function Infobox2(id, url, data) {
    this.id = id;
    this.placeHolderId = id + '_ib_ph';
    this.placeHolder = $('#' + this.placeHolderId);
    this.header = $('#' + id + '_ib_header');

    //  If URL is NULL then it means that box has a static content that shouldn't be loaded dynamically...
    this.url = url;
    this.data = data;

    this.loader = null;

    this.init();
}

Infobox2.prototype.init = function() {
    var oThis = this;

    this.toggleBtn = $('<a href="#" />')
                            .prependTo(this.header)
                            .click(function() { oThis.toggle(); return false; });

    this.toggleImg = $('<img src="/images/infobox/expand.gif" alt="Details..." class="ui-corner-all" style="border: 1px solid #AAA;" />')
                            .hover(
					            function() { $(this).addClass('ui-state-hover'); }, 
					            function() { $(this).removeClass('ui-state-hover'); }
				            )
                            .prependTo($(this.toggleBtn));

    if (this.url != null) {
        this.loader = new ContentLoader(this.placeHolderId, this.url, this.data);
    }

    if ($.cookie(this.id + '_needShow') == '1') {
        this.show();
    }

}

Infobox2.prototype.toggle = function() {
    var oThis = this;

    if (this.placeHolder.is(':hidden')) {
        this.show();
    }
    else {
        this.hide();
    }
}

Infobox2.prototype.reload = function(url, data) {
    var oThis = this;

    if (oThis.loader != null) {
        if( url != null ) oThis.loader.url = url;
        oThis.loader.data = data;
        oThis.loader.reloadContent();
    }
}

Infobox2.prototype.show = function() {
    var oThis = this;
    $(this.toggleImg).attr('src', '/images/infobox/collapse.gif');

    this.placeHolder.slideDown('fast', function() {
        if ( oThis.loader != null && !oThis.loader.loaded) {
            oThis.loader.load();
        }
    });

    $.cookie(this.id + '_needShow', '1', { expires: 365 });
}

Infobox2.prototype.hide = function() {
    $(this.toggleImg).attr('src', '/images/infobox/expand.gif');
    this.placeHolder.slideUp('fast');

    $.cookie(this.id + '_needShow', null);
}
