$(document).ready(function(){
    /*$("table.tab").css({"border-collapse": "collapse"});
    $("table.tab td:first-child").css({"height": "25px", "border-bottom": "1px solid #808080", "border-top": "1px solid #808080", "text-align": "left"});
    $("table.tab td:last-child:not([colspan=2])").css({"height": "25px", "border-left": "1px dotted #808080", "border-bottom": "1px solid #808080", "border-top": "1px solid #808080", "text-align": "center"});
    $("table.tab td[colspan=2]").css("text-align", "center");*/

    $("table.tab").css({"border-collapse": "collapse"});
    $("table.tab td").css({"height": "25px", "border-bottom": "1px solid #808080", "border-top": "1px solid #808080", "text-align": "left", "border-right": "1px dotted #808080", "text-align": "center"});
    $("table.tab td:first-child").css({"text-align": "left"});
    $("table.tab td:last-child:not([colspan=2])").css({"height": "25px", "border-right": "none", "border-bottom": "1px solid #808080", "border-top": "1px solid #808080", "text-align": "center"});
    $("table.tab td[colspan=2]").css({"text-align": "center", "border-right": "none"});

    $("table.tab2").css({"border-collapse": "collapse"});
    $("table.tab2 td").css({"height": "25px", "border-bottom": "1px solid #808080", "border-top": "1px solid #808080", "text-align": "left", "border-right": "1px dotted #808080", "text-align": "center"});
    $("table.tab2 .left").css({"text-align": "left"});
    $("table.tab2 td:last-child:not([colspan=2])").css({"height": "25px", "border-right": "none", "border-bottom": "1px solid #808080", "border-top": "1px solid #808080", "text-align": "center"});
    $("table.tab2 td[colspan=2]").css({"text-align": "center", "border-right": "none"});


    $('#menumain li').hover(
        function() {
            $(this).children('ul').show();
        },
        function() {
            $(this).children('ul').hide();
        }
    );

    $('.popupinfo').hover(
        function() {
            $(this).children('.popupdesc').show();
        },
        function() {
            $(this).children('.popupdesc').hide();
        }
    );


    $('.orderLink').hover(
        function(e) {
            $(this).prev('.orderPreview').css({'top':(e.pageY+15)+'px', 'left':(e.pageX+3)+'px'}).show();
        },
        function() {
            $(this).prev('.orderPreview').hide();
        }
    );

    $('.addToBasket').click(function() {
        var id = $(this).attr('id').substr(3);
        var parent = $(this).parent('.basket');
        
        $('.neworder').remove();
        
        $('<div class="neworder ui-corner-all"><div style="text-align:center; padding-top:12px"><img src="/images/load.gif" /></div>')
            .prependTo( parent )
            .css({'top':(parent.position().top-35)+'px', 'left':(parent.position().left-5)+'px'})

        
        $.getJSON('/shop/addtobasket/', {id:id}, function(data){
            $('#allorders').text('товаров: '+data['allProducts']+' шт.');
            $('.neworder').html('<div align="right" style="position:absolute; right:10px"><a class="closeorder choose" href="#">Закрыть</a></div>Товар добавлен в корзину<br /><br /><div align="center"><a href="/shop/order/">Оформить заказ</a></div>');
        });
        
        return false;
    });
    
    $('.closeorder').live('click', function() {
        $('.neworder').hide();
        
        return false;
    });
});
