$(document).ready(function() {
        display_message = true;
        display_loading_button = false;
        display_loading_check = true;
        display_customized_message = true;
        xtc_root = ''; //PFAD ZU XTCM-INSTALLATION








        //CATCHING FORM BASED SUBMISSIONS
        //FORMULARBASIERTE AKTIONEN ABFANGEN
        $('form.add2cart_ajax_mod').submit( function(){

                var form = $(this);

                if (display_loading_button){
                      $(this).find('.a2c_button').hide();
                      $(this).find('img.a2c_loading').show();


                }


                if (display_loading_check){
                      $(this).find('.a2c_loading_check').show();


                }

                var t = $(this).attr("action");
                var da = $(this).serialize();
    $.ajax({
            url: t,
            data: da,
            async:false,
            type: "POST",
            success: function(data){
                      if (display_loading_check){
                             form.find('.a2c_loading_check').hide();
                             form.find('.a2c_check').show(function(){
                                                $('.a2c_check').delay(2000).hide(200);
                             });
                      }
                      a = data.split('<a2c>');
                      b = a[1];
                      c = b.split('</a2c>');
                      d = c[0];
                      $('#a2c_cart').html(d);
            }
                });






                a2c_a($('.a2c_button'), $(this).find('.a2c_pid').val(), da);
                return false;
        });

        //CATCHING LINK BASED SUBMISSIONS
        //LINKBASIERTE AKTIONEN ABFANGEN
        $('a.add2cart_ajax_mod_a').live("click", function () {
                var t = $(this).attr('href');
          if (display_loading_button){
                  $(this).find("img").hide();
      $(this).find("img.a2c_loading").show();
    }

    if (display_loading_check){
                      $(this).parent().find('.a2c_loading_check').show();
                }

          $.ajax({
                  url: t,
            async:false,
            success: function(data){
                    a = data.split('<a2c>');
                    b = a[1];
                    c = b.split('</a2c>');
                    d = c[0];
                    $('#a2c_cart').html(d);
                  }
                });
                if (display_loading_button){
                          $(this).find("img").show();
        $(this).find("img.a2c_loading").hide();
                }

                if (display_loading_check){
                      $(this).parent().find('.a2c_loading_check').hide();
                      $(this).parent().find('.a2c_check').show();
                }


                a2c_a($('a.add2cart_ajax_mod_a'), $(this).attr('a2c_pid'));
                return false;
        });
});
//FUNCTION TRIGGERED AT SUBMISSION  (FADING BACKGROUND)
//FUNKTION, DIE NACH AKTION AUFGERUFEN WIRD (FADING BACKGROUND EFFECT)
function a2c_a(element, pid, add){
        var hc = '#ffaaaa'; //SETTING THE HIGHLIGHT COLOR
        var o = $('.a2c_highlight').css("background-color");
        $('.a2c_highlight').css("background-color", hc);
        $('.a2c_highlight').animate({ backgroundColor: o}, 'slow');
        if (display_message){
                $('.a2c_overlay').show();
          if (display_customized_message){
                  $.ajax({
                    url: xtc_root + 'a2c_ajax_helper.php?pid=' + pid,
                    data: add,
                    type:"POST",
              async:false,
              success: function(data){
                      a = data.split('<a2c_overlay>');
                b = a[1];
                c = b.split('</a2c_overlay>');
                d = c[0];
                $('.a2c_overlay').html(d);
				$('.nyroModal').nyroModal();
              }
            });


          }
          $('.a2c_overlay').show();
          $('.a2c_success_message').show();
        }
}

