ndebug = 0;
var nBox;

var NImage = Class.create({
    initialize	    : function(){

    },

    title	    : '',

    image	    : '',

    thumb	    : ''
});

var NBox = Class.create({
    initialize	    : function() {
	
	try {
	    this.id = $(this.id);
	    if(!this.id){
		throw ('Main div not found.');
	    }

	    this.idThumbs = $(this.idThumbs);
	    if(!this.idThumbs){
		throw ('Thumbs div not found.');
	    }

	    this.idImages = $(this.idImages);
	    if(!this.idImages){
		throw ('Images div not found.');
	    }

	    this.idThumbs.select('div').invoke('observe', 'click',function(el){
		nBox.onThumbClick(el);
	    });
	    
	}catch(e){
	    if(ndebug){
		console.log(e);
	    }
	}
    },

    /**
     * div with box id
     */
    id		    : 'main-box',

    /**
     * div with thumbs
     */
    idThumbs	    : 'main-box-thumbs',

    /**
     * div with big images
     */
    idImages	    : 'main-box-images',

    /**
     * array of NImages
     */
    images	    : new Array(5),

    activeImageId   : 0,


    /**
     * thumb click
     */
    onThumbClick    : function( event ){
	var id = -1, i=0;
	this.idThumbs.select('div').each(function(el){
	   if( el == event.target.parentNode ){
	       id = i;
	       return;
	   }
	   i++;
	});
	if(id<0){
	    throw ("Click thumb not found.");
	}

	this.idImages.select('div').invoke('hide');
	this.idImages.select('div')[id].show();

	this.idThumbs.select('div').invoke('removeClassName','main-box-active-thumb');
	this.idThumbs.select('div')[id].addClassName('main-box-active-thumb');
    }

});

document.observe("dom:loaded", function() {
    nBox = new NBox();
});
