var $document = $(document);

$document.ready(function(){

    $document.on('click', '.cart_navigation a.standard-checkout', function(){
        return acceptBuilderCGV();
    });

    $document.on('click', '.builder_designs_image_comtainer .preview', function(){
        $(".full_size_preview").hide();
        $(this).next('.full_size_preview').show();
    });

    $document.on('click','.builder_designs_image_comtainer .full_size_preview .close_button', function(){
        $(this).parents('.full_size_preview').hide();
    });

    $document.on('click', '.remove_design_block a', function(){
        var $this = $(this);
        var data = {};
        data['builder_id'] = $this.attr('builder_id');
        data['view_id'] = $this.attr('view_id');
        $.ajax({
            type: 'POST',
            headers: { "cache-control": "no-cache" },
            async: false,
            url: '/modules/myswissstyle/ajax.php?subject=Builder&action=remove_design',
            data: data,
            success: function(data) {

                data = $.parseJSON(data);

                if (data.status == 'success') {
                    $this.parents('.builder_designs_image_comtainer').remove();

                    if ($('.builder_designs_image_comtainer').length == 0){
                        $('#confirm_designs_block').remove();
                    }
                }
            }
        });
        return false;
    });
});

function acceptBuilderCGV()
{
    if (typeof msg_builder_design_confirm != 'undefined' && $('#cbd').length && !$('input#cbd:checked').length)
    {
        if (!!$.prototype.fancybox)
            $.fancybox.open([
                    {
                        type: 'inline',
                        autoScale: true,
                        minHeight: 30,
                        content: '<p class="fancybox-error">' + msg_builder_design_confirm + '</p>'
                    }],
                {
                    padding: 0
                });
        else
            alert(msg_builder_design_confirm);
    }
    else
        return true;
    return false;
}