(function($) {
    $.preLoadImages = function(imageList,callback) {
        var pic = [], i, total, loaded = 0;
        if (typeof imageList != 'undefined') {
            if ($.isArray(imageList)) {
                total = imageList.length; // used later
                for (i=0; i < total; i++) {
                    pic[i] = new Image();
                    pic[i].onload = function() {
                        loaded++; // should never hit a race condition due to JS's non-threaded nature
                        if (loaded == total) {
                            if ($.isFunction(callback)) {
                                callback();
                            }
                        }
                    };
                    pic[i].src = imageList[i];
                }
            } else {
                pic[0] = new Image();
                pic[0].onload = function() {
                    if ($.isFunction(callback)) {
                        callback();
                    }
                }
                pic[0].src = imageList;
            }
        }
        pic = undefined;
    };
})(jQuery)

$(document).ready(function(){

    var num_thumb = $('.thumbnail_link').size();
    var thumb_list = new Array();
    for(i = 0; i < num_thumb; i++){
        thumb_list.push($('.thumbnail_link').attr('id'));
    }

    $.preLoadImages(thumb_list);

    $('#slideshow').cycle({
        fx: 'fade',
        speed: 2000,
        timeout: 500
    });

    $('#floatdiv').floating({targetX:"left", targetY:"bottom", interval:10});

    // Exhibition link rollover function
    $('.thumbnail_link').mouseover(function(){
        $("#lg_thumbnail").append("<img src=\""+$(this).attr('id')+"\"/>");
    }).mouseout(function(){
        $("#lg_thumbnail").empty();
    })

    // Colorbox code

    $("a[rel='thumbnail']").colorbox({
        transition: "none",
        maxWidth: "600px",
        opacity: "0",
        onOpen:function(){
            $('#project_thumbnails').css('visibility', 'hidden');
        },
        onClosed:function(){
            $('#project_thumbnails').css('visibility', 'visible');
        }
    });

});


