var MiniGallery =
{
	widgets : 0,
	className : null,
	registerWidgets : function()
	{
		widgets = $('.'+this.className);
	},

	start:function( delay, className )
	{
		this.className = className;
		this.registerWidgets();
		setInterval( 'MiniGallery.slideFader()', delay );
	},
	
	slideFader:function()
	{
		widgets.each( function(index){
		
			var active = $(this).find('li.active');
			if( active.length==0 )
				active = $(this).find('li:last');
			
			var next = active.next().length? active.next():$(this).find('li:first');
			
			active.addClass('last-active');
			next.css( {opacity: 0.0});
			next.addClass('active');
			next.animate(
					{opacity: '1.0'}, 
					1000, 
					function()
					{
						active.removeClass('active last-active');
					});
		
		});
	}

};


var Gallery =
{
	images:0,
	thumbs:0,
	index:0,
	interval:0,
	
	start:function( delay, id_slider, id_thumbs )
	{
		this.delay = delay;
		this.images = $('#'+id_slider+' img');
		this.thumbs = $('#'+id_thumbs+' img');
		this.index = 0;

		for( var i=0; i<this.thumbs.length; i++ )
		{
			//this.thumbs.eq(i).
			$(this.thumbs[i]).addClass('thumb-'+i);
			
			this.thumbs.eq(i).addClass('thumb-'+i );
			this.thumbs.eq(i).attr('onclick', 'javascript:Gallery.show('+i+');');
			
			$(this.images[i]).addClass('image-'+i);
		}
		
		$('#next').click( function(){	Gallery.next();	}	);
		$('#play').click( function(){	Gallery.play();	}	);
	//	$('#pause').click( function(){	Gallery.pause();	}	);
	},

	show:function(num)
	{
		this.images.fadeOut(400);
		$('.image-'+num).stop().fadeIn(400);
	},

	next:function()
	{
		if( this.index < (this.thumbs.length-1) )
		{
			this.index++;
		}
		else
			this.index = 0;

		this.show( this.index );
	},

	play:function()
	{
		if( this.interval==0 )
		{
			Gallery.next();
			this.interval = setInterval('Gallery.next();', this.delay );
			$('#play').text('pause');
		}
		else
		{
			clearInterval( this.interval );
			this.interval = 0;
			$('#play').text('play');
		}
	}
};
