﻿width_popup   = 0;
height_popup  = 0;

width_popup_folder  = 0;
height_popup_folder = 0;

url_to_post   = '';
current_id    = 0;
max_id        = 1000;

code_id       = '';// код уникального поля для хранения в базе, например menu_code
old_code      = '';// старый код, необходим для сравнения

textAreaFields = new Array();//содержит id всех текущих полей textarea. Пример: textAreaFields = {'id':true} Параметр true - использовать средства сохранения редактора или нет.
//exception = new Array(); // исключения id полей при записи в пост.

JSON          = new JSON_STR;
var arr       = new Array({"name":'test', 'result':'success'});
// определяется для каждой формы popup - набор id формы для проверки полей
// Пример использования
// allFields = new Array({"menu_code":{"min":5, "rule":/^[a-z]([0-9a-z_])+$/i, "info":"test"},
//                        "menu_name":{"min":3, "max":10, "rule":/^[a-z]([0-9a-z_])+$/i, "info":"test"}
//                      });

$(document).ready(function() {
    DOCUMENT_ROOT = 'http://'+ document.domain + '/';

    lMC  = new leftMenuControl(max_id);
    lMC.toggleSlide();

    cCLC = new centerContentListControl(max_id);
    if (!cCLC) alert(max_id);
    cCLC.showEditButton();
	
    cb = new listFlag();

    $('.crumbs li.s14').css("background","none");
    $('.crumbs li:last').css("background","none");


    /* блок сортировки и присваивания нового порядка элемента в списке*/
    $('#productList').sortable({
         //handle : '.ui-icon',
         stop: function(event, ui) {
             var result = $('#productList').sortable('toArray');
             $.post(DOCUMENT_ROOT + url_to_post, {action:'set_order', id_order: '' + result + ''}, function(data){});
             //$("input#test-log").val($('#productList').sortable('toArray'));
         }
    });

    /******************************************************************************
     * @author Terry Wooton
     * @desc Adds a background layer to an element
     * @version 1.1
     * @example
     * $("#element").add_background("url('/test.gif') bottom left no-repeat");
     * @license free
     * @param background css
     *
     */
    $.fn.add_layer = function(bg,params) {
        $(this).each(function() {
            s = $(this).extend({},params || {});

            $last = ($(this).find('.add_background:last').length > 0 ? $(this).find('.add_background:last') : $(this));
            $last.html('<div class="add_background"><div>'+$last.html()+'</div></div>');
            $last = $(this).find('.add_background:last');
            $last.css({'background':bg,'width':'100%','height':'100%'});

            $last = $(this).find('.add_background div:last');

            if(s.insideCss)   $last.css(s.insideCss);
            if(s.insideClass) $last.addClass(s.insideClass);
        });
    }
    dialogChecker = new dialogChecker;
    /******************************************************************************/
    
    $('#edit').click(function() {
        openDialogEdit(0, 'dialog');
    });

    $('#folder').click(function() {
        openDialogEdit(0, 'dfolder');
    });
    
    $('#delete').click(function() {
        deleteListItem();
    });

    $('#mult_visibility').click(function() {
        visibility();
    });

    $('#help').click(function() {
        helpinitialization();
    });
});
