jQuery(document).ready(function($) {

Cufon.replace('.cufon');

// What's in store
    $(function() {
        $("#carousel").jCarouselLite({
            btnNext: ".next",
            btnPrev: ".prev",
            visible: 2,
            scroll: 2
        });
    });

// Product
    if ($("#slideshow").length > 0) {
        $('#slideshow').cycle({
            fx: 'fade',
            speed: 'fast',
            timeout: 0,
            next: '#slideshow-next',
            prev: '#slideshow-previous'
        });
    }

if ($("a.lightbox").length > 0) {
    $('a.lightbox').lightBox({
        imageLoading: '/wordpress/wp-content/themes/twoofhearts/style/images/lightbox/lightbox-ico-loading.gif',
        imageBtnClose: '/wordpress/wp-content/themes/twoofhearts/style/images/lightbox/lightbox-btn-close.gif',
        imageBtnPrev: '/wordpress/wp-content/themes/twoofhearts/style/images/lightbox/lightbox-btn-prev.gif',
        imageBtnNext: '/wordpress/wp-content/themes/twoofhearts/style/images/lightbox/lightbox-btn-next.gif',
        imageBlank: '/wordpress/wp-content/themes/twoofhearts/style/images/lightbox/lightbox-blank.gif'
    });
}





    if ($("select#colour").length > 0 && $("select#size_id").length > 0) {
        $("select#colour").bind('change', function() {
            $.ajax({
                type: "POST",
                url: "/wordpress/wp-content/themes/twoofhearts/includes/update-variations.php",
                data: $(".product-detail form").serialize(),
                success: function(response){
                    $("#size_id_wrapper").html(response)
                }
            });
        });
        // Initial trigger for conditional selects
        $("select#colour").trigger("change");
    }


    $('.add-to-cart').bind("click", function() {
        if ($("form.validate").validate().form()) {
            $.ajax({
                type: "POST",
                url: "/wordpress/wp-content/themes/twoofhearts/includes/add-to-cart.php",
                data: $("#product form").serialize(),
                success: function(response){
                    $("#cart-summary").html(response)
                }
            })
        }
        return false;
    });


    if ($("select#delivery-differs").length > 0) {
        $("select#delivery-differs").bind('change', function() {
            if ($(this).val()) {
                if ($(this).val() == '1') {
                    $('fieldset#delivery-details').show();
                    $('fieldset#delivery-details :input').removeAttr("disabled")
                } else {
                    $('fieldset#delivery-details').hide();
                    $('fieldset#delivery-details :input').attr("disabled","disabled");
                }
            }
        })
    }


    if ($("form.validate").length > 0) {
        $("form.validate").validate({
            submitHandler: function(form) {
                //*/$("input.submit").attr('disabled', 'disabled');
                form.submit();
            }
        });
    }

});
