function update_price (book_price, special_price){
    var choice = $('select#select_product').find("option:selected")[0]
    $('#id_shipping').val(parseFloat($(choice).val()))
    if(! $(choice).hasClass('special-edition')){
        tax = book_price*5.5/100
        $('#id_amount').val((book_price-tax).toFixed(2));
        $('#id_tax').val(tax.toFixed(2));
    } else {
        tax = special_price*5.5/100
        $('#id_amount').val((special_price-tax).toFixed(2));
        $('#id_tax').val(tax.toFixed(2));
    }
}

$(document).ready(function() {
    // Show Big Image
    $("a.thumbnail").live("click", function(e){
        e.preventDefault();
        var snippet = new String();
        snippet += '<img src="';
        snippet += $(this).attr('href');
        snippet += '" id="main_image" title="';
        snippet += $('img.thumbnail', $(this)).attr('title');
        snippet += '" alt=' + $('img.thumbnail', $(this)).attr('alt');
        snippet += '" />';
        $('#main_image').replaceWith(snippet);
    });
    
    
        // Yellow Rollover on Images
    $('a img').live("mouseover", function(){
        img = $(this)
        $('span#yellow').css('display', 'block').css('height', $(this).css('height')).css('width', $(this).css('width')).css('top', $(this).offset().top).css('left', $(this).offset().left);
        // If image is a thumbnail, changes the main image
        if ($(this).hasClass('thumbnail')) {
            $('span#yellow').click( function(e){
                e.preventDefault();
                var snippet = new String();
                snippet += '<img src="';
                snippet += img.closest('a').attr('href');
                snippet += '" id="main_image" title="';
                snippet += img.attr('title');
                snippet += '" alt=' + img.attr('alt');
                snippet += '" />';
                $('#main_image').replaceWith(snippet);
           });
        }
        // If image is anything but a thumbnail, copy/paste the image link on the yellow div
        else {
            $('span#yellow').unbind('click');
            $($('span#yellow').parents()[0]).attr('href', $($(this).parents()[0]).attr('href'))
        }
  
        });
    $('span#yellow').live("mouseout", function(){
       $(this).css('display', 'none');
    });
    
    
    // Manage too many thumbnails
    var container = $('div#thumbnails-container')
    $('div#thumbnails-container').css('height', '367px').css('overflow', 'hidden');
    $('div#thumbnails').css('position', 'relative');
    y = 0
    $('div#thumbnails-arrow-up').hover( function(){
        $(this).css('background-color', 'yellow');
    }, function(){
        $(this).css('background-color', 'transparent');
    });
    $('div#thumbnails-arrow-down').hover( function(){
        $(this).css('background-color', 'yellow');
    }, function(){
        $(this).css('background-color', 'transparent');
    });
    
    $('div#thumbnails-arrow-down').live('click', function(){
        if (parseInt($('div#thumbnails').css('top')) > ($('div#thumbnails > a').length-5)*-75 ){
            y -= 75;
            $('div#thumbnails').css('top', y+'px');
        }
    });
    $('div#thumbnails-arrow-up').live('click', function(){
        if (parseInt($('div#thumbnails').css('top')) < 0){
            y += 75;
            $('div#thumbnails').css('top', y+'px');
        }
    });
    
});

