/*function RecreateSelect(sel_id, items){
    if (!$('select#' + sel_id).parents('.sel').find('.selectArea').attr('id'))
        return;
    var _customId = $('select#' + sel_id).parents('.sel').find('.selectArea').attr('id').replace('sarea','');
    $('#optionsDiv'+_customId).find('.jScrollPaneContainer').css('height',items.length*20+2); // 3 - это количество options
    $('#optionsDiv'+_customId).find('.scroll-pane').css('height',items.length*20+2); // 3 - это количество options
    new_cont = '';
    for (i=0; i<items.length; i++)
        new_cont += "<li><a href='javascript:showOptions(" + _customId + "); selectMe(\""+ sel_id +"\"," + i + "," + _customId + ");'>" + items[i][0] + "</a></li>";
    $('#optionsDiv'+_customId).find('ul').html(new_cont);
}
*/

function RecreateSelect(sel_id, items){
    // if have'nt items, get it from DOM Select
    if (typeof(items) == 'undefined' && $('select#' + sel_id)[0]){
        var sel = $('select#' + sel_id)[0];
        items = [];
        for (i=0; i<sel.options.length; i++)
            items[i] = [sel.options[i].text, sel.options[i].value];
    }
    if($('select#' + sel_id).parents('.sel').find('.customSelect').attr('id')){
        var dom_select = $('select#' + sel_id)[0];
        //alert(dom_select.options[dom_select.selectedIndex].text);
        var _customId = $('select#' + sel_id).parents('.sel').find('.customSelect').attr('id').replace('customSelect','');
        $('#customOptions'+_customId).find('.jScrollPaneContainer').css('height',items.length*20+2);
        $('#customOptions'+_customId).find('.scroll-pane').css('height',items.length*20+2);
        new_cont = '';
        for (i=0; i<items.length; i++)
            new_cont += "<li><a href='javascript:displayOptions(" + _customId + "); customSelectEvent(\""+ sel_id +"\"," + i + "," + _customId + ");'>" + items[i][0] + "</a></li>";
        $('#customOptions' + _customId).html('<div class="select-holder"><div class="scroll-pane"><ul>' + new_cont + '</ul></div></div>');
        $('select#' + sel_id).parents('.sel').find('.replacedSelect .bg-select-center').html(items[0][0]);
        setInnerCustomScroll(_customId);
        //alert($('#customSelectText' + _customId).html());
        $('#customSelectText' + _customId).html(dom_select.options[dom_select.selectedIndex].text);
    }
}

// функция пересчета кастом скролла, выполняется внутри предыдущей
function setInnerCustomScroll(customSelectId){
    $('#customOptions' + customSelectId).removeClass('customOptionsHidden');
    $('#customOptions' + customSelectId).addClass('customOptions');
    if(parseInt($('#customOptions' + customSelectId).height())<220){
        $('#customOptions' + customSelectId).find('.scroll-pane').css('height',$('#customOptions' + customSelectId).height());
    }
    else{
        $('#customOptions' + customSelectId).find('.scroll-pane').css('height','220px');
    }
    $('#customOptions' + customSelectId).find('.scroll-pane').jScrollPane({
        showArrows:true,
        scrollbarWidth:25,
        scrollbarMargin: 0
    });
    $('#customOptions' + customSelectId).removeClass('customOptions');
    $('#customOptions' + customSelectId).addClass('customOptionsHidden');
}

