﻿function activate(id)
{
    $(id).addClassName('active');
    //document.getElementById(id).className = 'active';
}
function deactivate(id)
{
    $(id).removeClassName('active');
    //document.getElementById(id).className = '';
}
function changeProjectImage(img_new, img_target)
{
    // highlight new 'active' image
    deactivate($('image_list').select('img.active')[0]);
    activate(img_new);

    var new_src = $(img_target).src.slice(0, $(img_target).src.lastIndexOf('/') + 1) + img_new.src.slice(img_new.src.lastIndexOf('/') + 1);
    changeImage(new_src, img_target);
}
function changeImage(new_src, img_target)
{
    // hide target image
    img_target.hide();
    img_target.src = '';

    // preload new image
    var img_preloader = new Image();
    img_preloader.onload = function()
    {
        img_target.src = img_preloader.src;
        img_target.width = img_preloader.width;
        img_target.height = img_preloader.height;
        new Effect.Appear(img_target);
        img_preloader.onload = function(){}; // clear onLoad, IE behaves irratically with animated gifs otherwise
    }
    img_preloader.src = new_src;
}
