var awardBoxes;
var awardBoxHeights = new Array();
var currentAwardIdx = 0;

function prepare_awards()
{
    // get the award boxes
    awardBoxes = $(".award_box");
    // get their heights
    awardBoxes.each(function(i) {
        awardBoxHeights[i] = $(this).height();
    });

    // remove the award list
    $(".box_list").remove();
    
    // display the first award
    $("#award_display").append(awardBoxes.first().clone());
    $(".award_box").hide(0, function() {
        $(this).fadeIn(500);
    });
    
    // change the behaviour of the award links
    $(".award_link").each(function(i) {
        // set href to '#' to do nothing
        $(this).attr("href", "#");
        // set click event handler
        $(this).click(function() {
            if (i == currentAwardIdx)
            {
                return;
            }
            currentAwardIdx = i;
            var incomingBox = awardBoxes.eq(i);
            var duration = 500;
            $(".box_title").fadeOut(duration);
            $(".award_image").fadeOut(duration);
            $(".award_product_image_text").fadeOut(duration);
            $(".award_box").animate({
                height: awardBoxHeights[i]
            }, duration, function() {
                $(".box_title").replaceWith(incomingBox.children(".box_title").clone());
                $(".award_product_image_text").replaceWith(incomingBox.children(".award_product_image_text").clone());
                if (incomingBox.children(".award_image").length)
                {
                    $(".award_image").replaceWith(incomingBox.children(".award_image").clone());
                    $(".award_image").hide(0, function() {
                        $(this).fadeIn(500);
                    });
                }
                $(".box_title").hide(0, function() {
                    $(this).fadeIn(500);
                });
                $(".award_product_image_text").hide(0, function() {
                    $(this).fadeIn(500);
                });
            });
        });
    });
    
    
}

