/****************************/
/* author: Tomasz Nabrzeski */
/****************************/

var gallery = {
    loading: false,
    
    init: function(selector) {
        var elements = $('a.photo');
        
        elements.click(gallery.loadPhoto);
        
        $('#photo').html('<img src="' + $(elements[0]).attr('big') + '" alt="" />');
        $('img', elements[0]).addClass('active');
    },
    
    left: function() {
        $('div.thumbs').animate({'scrollLeft': '-=300'}, 800);
    },
    
    right: function() {
        $('div.thumbs').animate({'scrollLeft': '+=300'}, 800);
    },
    
    loadPhoto: function() {
        this.blur();
        
        if (gallery.loading == false) {
            gallery.loading = true;
            
            $('div.thumbs a img').removeClass('active');
            $('img', $(this)).addClass('active');
            
            $('#photo').append('<div id="loading-photo" style="position:absolute;top:0px;left:0px;width:600px;height:'+($('#photo img').height())+'px;background:#fff url(images/loading.gif) no-repeat center center;"></div>');
            $('#loading-photo').css('opacity', 0.8);
            
            var LoadedImage = new Image();
            LoadedImage.onload = function() {
                $('#loading-photo').remove();
                $('#photo img').animate({'opacity': 0, 'height': LoadedImage.height}, 200, function(){
                    $('#photo img').attr('src', LoadedImage.src);
                    $('#photo img').animate({'opacity': 1});
                    gallery.loading = false;
                });
            }
            LoadedImage.src = $(this).attr('big');
        }
        
        return false;
    }
}

$(document).ready(function(){
    $('a[rel*=ext]').attr('target', '_blank');
});