function startGallery(hideThumbs) {

    $("#initial-image").hide();
    if (hideThumbs) {
        $('#thumbs_container').hide();
    }

    var gallery = $('#thumbs').galleriffic({
        delay: 5000,
        // in milliseconds
        imageContainerSel: '#slideshow',
        // The CSS selector for the element within which the main slideshow image should be rendered
        loadingContainerSel: '#loading',
        // The CSS selector for the element within which should be shown when an image is loading
        renderSSControls: false,
        // Specifies whether the slideshow's Play and Pause links should be rendered
        renderNavControls: false,
        // Specifies whether the slideshow's Next and Previous links should be rendered
        autoStart: true,
        // Specifies whether the slideshow should be playing or paused when the page first loads
        syncTransitions: false,
        // Specifies whether the out and in transitions occur simultaneously or distinctly
        defaultTransitionDuration: 1000,
        // If using the default transitions, specifies the duration of the transitions
    });
}

function addSubmitLink() {

    $("#submit-btn").hide();
    $("#submit-btn").after(
    "<a id='add-to-basket' href='#'>Add to basket</a>"
    );

    $("#add-to-basket").click(function() {
        $("#basket-form").submit();
        return false;
    })

}

var initial_price;

function sortPriceDropDown() {
    initial_price = parseFloat($('#product-price').text().split('£')[1]);

    $("#basket-form select").change(function(e) {
        var total_change = 0;
        $("#basket-form select :selected").each(function(i, el) {
            inner = $(el).text();
            try {
                price_change = parseFloat(inner.split(':')[1].split(' ')[1]);
            }
            catch(err) {
                price_change = 0;
            }
            total_change += price_change;
        });
        $('#product-price').text("£" + (initial_price + total_change).toFixed(2));
    });

    $("#basket-form select").each(function(i, el) {
        $('option', el).each(function(i, el) {
            el = $(el);
            inner = el.text();
            price_change = parseFloat(inner.split(':')[1].split(' ')[1]);
            if (price_change === 0) {
                el.text(inner.split(":")[0]);
            }
        });
    });

}

jQuery(document).ready(function($) {
    addSubmitLink();
    sortPriceDropDown();
});