jQuery(document).ready(function()
{
    var checkboxes = jQuery('.mod_add_to_basket form ul li input');
    jQuery('.mod_add_to_basket form ul li:first-child').find('input').attr('checked',true);
    checkboxes.click(function() {
        jQuery(this).parent().parent().find('li input').attr('checked',false);
        jQuery(this).attr('checked',true);
    });

//Tworzenie listy z wartościami atrybutów na stronie produktów : START
    var uls = jQuery('.mod_add_to_basket form ul.checkbox_list'); //wybieram wszystkie atrybuty
    var cnt_uls = jQuery(uls).length; //ilość wybranych atrybutów
    
    var attributes = "";
    for(i = 0; i < cnt_uls; i++) //iteruje dla kazdego z nich
    {
        var lis = jQuery(uls[i]).children('li'); //wybieram wszystkie wartości danego atrybutu
        var cnt_lis = jQuery(lis).length; //ilość tych wartości
        if(cnt_lis > 0) // jade z koksem jak jest wiecej niz 0
        {
            var span = jQuery(uls[i]).prev('span').text();
            attributes += '<span class="attributes_label">' + span + '</span>'; //tworze labela z nazwy atrybutu
            var select = '<select>'; //rozpoczynam tworzenie listy wartości


            for(j = 0; j < cnt_lis; j++) //iteruje dla zazdej wartości
            {
                var id = jQuery(lis[j]).children('input').attr('id'); //pobieram id wartości
                var label = jQuery(lis[j]).children('label').html(); // pobieram label wartości

                var option = '<option value="' + id + '">' + label + '</option>'; //i dodaje je do opcji

                select += option;
            }

            select += '</select>'; //koncze trzoene listy dla danego atrybutu

            attributes += select;
        }
    }
    jQuery('.attributes').html(attributes); //wyswietlam stworzone listy

    //chowie domyślne checkboxy
    jQuery('.checkbox_list').css('display', 'none');
    jQuery('.mod_add_to_basket form span').css('display', 'none');

    //dla kazdej zmiany na liście w tle zmianiają sie chenboxy
    jQuery('.attributes select').change(function() {
        var id = jQuery(this).children('option:selected').attr('value');
        id = '#' + id;
        unChecked(id);
        jQuery(id).attr('checked', 'checked');
    })

    function unChecked(id)
    {
        jQuery(id).parent('li').parent('ul').children('li').children('input:checked').attr('checked', false);
    }

//Tworzenie listy z wartościami atrybutów na stronie produktów : STOP

    jQuery('.products_tab').click(function() {
       jQuery('.products_tab').addClass('tab_hide');
       jQuery(this).removeClass('tab_hide');
       jQuery('.tab_content').addClass('tab_content_hide');
       var tab = jQuery(this).attr('id').split('_');
       var id = '#products_tab_' + tab[2];
       jQuery(id).removeClass('tab_content_hide');
    });


///* menu */
//    var li_nodes = jQuery('#menu_top ul li');
//    var cnt_node = li_nodes.length;
//    jQuery(li_nodes[cnt_node-1]).css('background', 'none');
//
//    var s = 0;
//    for(var i = 0; i < cnt_node; i++)
//    {
//        s += parseInt(jQuery(li_nodes[i]).css('width'));
//        s += 45;
//    }
//    jQuery('#menu_top ul').css('width', s + 'px');
//    jQuery('#menu_top ul').css('min-width', s + 'px');
//    jQuery('#menu_top ul').css('max-width', s + 'px');
//    jQuery('#menu_top ul').css('margin', '0 auto');
//    jQuery('#menu_top ul').css('margin-top', '5px');
///* menu */

});
