jQuery(document).ready(function() {
    jQuery('#colors .color').click(function() {
            jQuery('#hiddencolor').attr("value", jQuery(this).find("span").text());
    });

    // Submit the product form using AJAX
        jQuery("form.product_form_new").live('submit', function() {
                form_values = jQuery(this).serialize();
                jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
                     var RegExp = /is out of stock/;
                     var Match = returned_data.search(RegExp);

                     if(Match != -1){
                        jQuery('#itemnotadded').slideDown('slow').delay(3000).slideUp('slow');
                     }else{
                         jQuery('#itemadded').slideDown('slow').delay(3000).slideUp('slow');

                         jQuery.get('/ajax.php', function(data) {
                         var data = jQuery.parseJSON(data)
                          jQuery("#cartitems span").fadeOut("fast", function() {
                                jQuery("#cartitems span").text(data.items);
                                jQuery("#cartitems span").fadeIn("fast");


                          });

                          jQuery("#carttotal").fadeOut("fast", function() {
                                jQuery("#carttotal").text(data.total);
                                jQuery("#carttotal").fadeIn("fast");


                          });
                        });
                     }

                     //jQuery('#itemadded').slideDown('slow').delay(3000).slideUp('slow');
                });
                return false;
        });

        jQuery(".item").hoverIntent(
        function(){jQuery(this).find(".info").fadeIn(500)},
        function(){jQuery(this).find(".info").fadeOut(500)}
        );

});
