$(document).ready(function()
{
    
//    $('.mini_photos').mouseover(function()
//    {
//        var src = $(this).attr('src');
//
//        var src_parts = src.split('/');
//
//        var image_file = src_parts.pop().replace('bw_', '');
//
//        var image_src = '/';
//
//        var parts_length = src_parts.length;
//
//        for (var i = 0; i < parts_length; i++) {
//            image_src += src_parts[i] + '/';
//        }
//
//        image_src += image_file;
//        image_src = image_src.replace('//', '/');
//
//        $(this).attr('src', image_src);
//    });
//
//
//    $('.mini_photos').mouseout(function()
//    {
//        var src = $(this).attr('src');
//
//        var src_parts = src.split('/');
//
//        var image_file = 'bw_' + src_parts.pop();
//
//        var image_src = '';
//
//        var parts_length = src_parts.length;
//
//        for (var i = 0; i < parts_length; i++) {
//            image_src += src_parts[i] + '/';
//        }
//
//        image_src += image_file;
//        image_src = image_src.replace('//', '/');
//
//        $(this).attr('src', image_src);
//    });



});



function galleryOnMain() {


    var self = this;

    this.count = 0;
    //this.scale = 161 + 20;
    this.scale = 340;

    this.offset = 0;
    this.maxOfset = 0;



    this.init = function(mainBox) {
        this.mainBox = $(mainBox);
        this.imgBox = $(".gal_in", this.mainBox);
        this.count = $("li", this.imgBox).length;

        var liWidth = 0;

        $("li", this.imgBox).each(function() {
            liWidth += $(this).width();
        });

        this.maxOffset = liWidth - this.imgBox.width();


        this.initButtons();

    


        imgLoader = new Image();
        imgLoader.src = "/img/default/ajax-loader.gif";
      
        tb_init('a.thickbox');
    };


    this.initButtons = function() {
        $(".gal_left", self.mainBox)[0].onclick = function() {
            self.leftButtonEvent();
        };
        $(".gal_right", self.mainBox)[0].onclick = function() {
            self.rightButtonEvent();
        };
    };



    this.leftButtonEvent = function() {
        var scale = this.scale;
        if (this.offset + scale > 0)
            scale = 0 - this.offset;

        this.offset += scale;
        this.imgBox.animate({"margin-left": this.offset}, 500);
    };



    this.rightButtonEvent = function() {
        var scale = this.scale;

        if (this.maxOffset + this.offset < scale)
            scale = this.maxOffset + this.offset + 20;

        if (scale < 0) return;

        this.offset -= scale;
        this.imgBox.animate({"margin-left": this.offset}, 500);
    };



    return this;

}
