

$(document).ready(function(){
  basket.init();
  
  $(".customersInput").focus(function(){
             $(this).val('').css('color','black');
         });
         
         
             
         $('.focus').focus(function(){
             $(this).val('').unbind('focus');
         });     
});

    function showInfo(info) {
       $(".infoMessage strong").first().html(info);

       $(".infoMessage").first().show();
       $(".errorMessage").first().hide();

       setTimeout( hide, 5000);
    }

    function hide() {
        $(".infoMessage").first().hide();
        $(".errorMessage").first().hide();
    }

var basket = {
    init: function() {
        $("#basketButton").unbind('click').click(function(e){
           e.preventDefault();
           
            var dialog = $('<div style="display:hidden"></div>').appendTo('body');

            dialog.load(
                this.href,
                {},
                function (responseText, textStatus, XMLHttpRequest) {
                    dialog.dialog({
                            title: 'San Marino Pizzerie :: Vaše objednávka',
                            modal: true,
                            width: 800,
                            close: function(event, ui) {$(this).remove();}
                    });
                    basket.bindActions();
                });
        });
        
    },
    
    load: function() {
            
              $.get(  $('#basketSource').val(),
                {}, function(data) {
                $("#shopingBasketHolder")
                                    .addClass("ui-state-highlight")
                    .animate({'opacity':0},275,function(){
                    $(this).html(data)
                    .removeClass("ui-state-highlight")
                    
                    .animate({'opacity':1},275,function(){});
                    
                    basket.init();
                    });;
                
              }
            );
                
                
    },
    bindActions: function() {
        
       var options = {
         success:   this.basketChange
       };
       
         $('#shopingBasket').ajaxForm(options);
          
       $('.basketItemActionDelete').unbind('click').click(function(e){
          e.preventDefault();
          $.get(this.href,{},function(data){
                    $("#shopingBasketDetailHolder")
                                    .addClass("ui-state-highlight")
                    .animate({'opacity':0},275,function(){
                    $(this).html(data)
                    .removeClass("ui-state-highlight")
                    
                    .animate({'opacity':1},275,function(){});
                    
                   
                    basket.bindActions();
                     basket.load();
                     basket.order();
                    });;          
          });
       });
    },
    basketChange: function(data) {
                $("#shopingBasketDetailHolder")
                                    .addClass("ui-state-highlight")
                    .animate({'opacity':0},275,function(){
                    $(this).html(data)
                    .removeClass("ui-state-highlight")
                    
                    .animate({'opacity':1},275,function(){});
                    
                    basket.load();
                    basket.bindActions();
                    basket.order();
                    });;
                
              },
    order: function() {
        if($("#orderBasket").hasClass("form_box")) {
            $.get($("#orderBasket input[name='source']").val(),{},function(data){
              $("#orderBasket")                    .addClass("ui-state-highlight")
                    .animate({'opacity':0},275,function(){
                    $(this).html(data)
                    .removeClass("ui-state-highlight")
                    
                    .animate({'opacity':1},275,function(){});
            });
        });
    }
}
}
