/**
* WebProduction Packages
* Copyright (C) 2007-2010  WebProduction <webproduction.com.ua>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/**
* Класс позволяет строить всплывающие JS-окошки с заданными стилями.
*
* @author Max
* @author Kate
* @copyright WebProducton
* @package JSWindow
*/
JSWindow = new Object();

JSWindow.classNameBase = 'jswindow';
JSWindow.classNameAddon = 'mywindow';

// открыть всплывающее окошко
// данные брать из url, id окну назначить windowID
JSWindow.open = function (url, windowID) {
    new Ajax.Request(url, {
        method: 'get',
        parameters: {
            windowid: windowID
        },
        onSuccess: function(transport) {
            JSWindow.make(windowID, transport.responseText);
        },
        onFailure: function(){ alert('Something went wrong...') }
    });

    return false;
};

// создать окошко на основе html-контента
JSWindow.make = function (windowID, content) {
    if ($(windowID)) {
        // если окошко было до этого - обновляем ему контент
        $(windowID).innerHTML = content;
    } else {
        // иначе создаем новое окошко (добавляем его в конец body)
        var body = $$('body')[0];
        body.insert({bottom: "<div id=\""+windowID+"\" class=\""+this.classNameBase+' '+this.classNameAddon+"\">"+content+"</div>"});

        // делаем окошко тягающимся
        // new Draggable(windowID);
    }
};

// закрыть окошко (убрать DOM-модели)
JSWindow.close = function (windowID) {
    if ($(windowID)) {
        $(windowID).remove();
    }

    return false;
};

// скрыть окошко
JSWindow.hide = function (windowID) {
    if ($(windowID)) {
        $(windowID).hide();
    }

    return false;
};

// показать окошко
JSWindow.show = function (windowID) {
    if ($(windowID)) {
        $(windowID).show();
    }

    return false;
};
