var gallery = null;

function GalleryImage() {
	var src;
	var desc;
}

function Gallery( bindElement )
{
	var _imgs = null;

	this.init = function( bindElement ) {

		this._imgs = new Array();

		$(bindElement).html( '<div class="gallery"><div id="gallery-arrow-left"></div><div id="gallery-arrow-right"></div><div id="gallery-view"><div id="gallery-container"></div></div></div>' );

		$('#gallery-arrow-left').click( function() {

			$('#gallery-view').animate({
				'scrollLeft': '-=102px'
			},
			'normal');
		});

		$('#gallery-arrow-right').click( function() {
			$('#gallery-view').animate({
				'scrollLeft': '+=102px'
			},
			'normal');
		});




	}

	this.add = function( src, desc ) {
		var img = new GalleryImage();

		img.src = src;
		img.desc = desc;

		this._imgs.push( img );
	}

	this.paint = function()
	{
		$('#gallery-container').empty();
		
		var html = '';

		for( var i in this._imgs ) {

			var img = this._imgs[ i ].src;
			var tmb = 'thumb-' + this._imgs[ i ].src;
			var dir = 'gallery';

			var dsc = this._imgs[ i ].desc;

			if( !dsc ) dsc = '';

			//html += '<a href="' + dir + '/' + img + '" rel="lightbox"><img class="gallery-thumb" src="' + dir + '/' + tmb + '"></img></a>';
			html += '<a href="' + dir + '/' + img + '" title="' + dsc +'" rel="lightbox"><div class="gallery-thumb" style="background-image:url(' + dir + '/' + tmb + ');"></div></a>';
 
			$('#gallery-container').html( html );
		}

		$('#gallery-container').width( ( 102 * this._imgs.length ) );  

		$('a[rel*=lightbox]').lightBox();

	}

	this.init( bindElement );
}


