 
$(function() {

    function getRaspuns(str) {
        re=/<raspuns>[\w\s]*<\/raspuns>/;
        raspuns=str.match(re);
        return raspuns[0].replace(/<raspuns>/,'').replace(/<\/raspuns>/,'');
    }

    function getRezumat(str) {
        re=/<rezumat>[\w\s]*<\/rezumat>/;
        raspuns=str.match(re);
        return raspuns[0].replace(/<rezumat>/,'').replace(/<\/rezumat>/,'');
    }

    $('.item form.adauga').submit(function() {
        return false;
    })
    $("input.adauga[type=button]").click(
        function() {
            form=$(this).parent();
            data="cantitate=" + form[0].cantitate.value+"&id_produs=" +form[0].id_produs.value +"&imagine" +form[0].imagine.value ;
            $.ajax({
                url: form.attr('action'),
                data: data,
                success: function(raspuns) {
                    //                    $('#rezumat').html(getRezumat(raspuns));
                    alert(getRaspuns(raspuns));
                    refreshCos();
                }
            });
        })

    function refreshCos() {
        
        $.ajax({
            url: '/cart-rezumat',
            data: '',
            success: function(raspuns) {
                $('#cart').html(raspuns); 
            }
        })

        $.ajax({
            url: '/cart-detaliat',
            data: '',
            success: function(raspuns) {
                $('#cos_detaliat').html(raspuns);
            }
        })
    }



    // pentru meniuri
    $(".more").click(
        function () {
            $(this).children('ul').slideDown('slow');
            //            $('.expanded').children('ul').slideUp('slow');
            //            $('.expanded').removeClass('expanded');
            $(this).addClass('expanded');
        }
        );


    /* Popup Image*/

    $("a#single_image").fancybox();

    /* Using custom settings */

    $("a#inline").fancybox({
        'hideOnContentClick': true
    });

    /* Apply fancybox to multiple items */

    $("a.group").fancybox({
        'transitionIn'	:	'elastic',
        'transitionOut'	:	'elastic',
        'speedIn'		:	600,
        'speedOut'		:	200,
        'overlayShow'	:	false
    });



    $(".show").click(
        function() {
            if($(".hide").hasClass('vizibil')) {
                $(".hide").hide();
                $(".hide").removeClass('vizibil');
            }
            else {
                $(".hide").show();
                $(".hide").addClass('vizibil');
            }
        })
})


