function nxcGalleryChanger( spimages, sphref, spdescription, currentImage )
{
	if ( typeof imageGallery != 'undefined' )
	{
		imageGallery.destroyGallery();
	}
	delete imageGallery;
	$('#nxc-image-gallery-top').html('');
	$('#nxc-image-gallery-bottom').html('');
	
	var imageGallery = new imageGalleryKernel();
	
	imageGallery.imageSize = { 'width': 117, 'height': 76 };
	imageGallery.imageMargin = 7;
	imageGallery.autoScrollOn = false;
	imageGallery.autoScroll = 0;
	imageGallery.aspectRatio = 0.5517241;
	imageGallery.position = 'horizontal';
	imageGallery.typeOfShow = 1;
	imageGallery.topImageHref = true;
	imageGallery.speed = 20;
	imageGallery.existSpecialBlock = false;
	imageGallery.existDescription = true;
	imageGallery.possibleScrollButton = false;
	imageGallery.specialScrollButton = false;
	imageGallery.bottomHeight = 78;
	imageGallery.secondThumbnail = false;
	imageGallery.dontRepeatImages = true;
	imageGallery.movingOn = 1;
	imageGallery.movingIterationCount = 10;
	//imageGallery.autoScrolling = { 'status' : true, 'time' : 10000, 'to' : 'right' };
	imageGallery.fadeNonActiveImages = { 'status' : true, 'fadeTime' : 300, 'fadeOpacity' : 0.3 };
	imageGallery.currentImage = 0;
	imageGallery.movingWhenMouseEnter = false;
	imageGallery.initialize( spimages, spdescription, false, sphref, "span.image-caption", "#nxc-image-gallery-top", "#nxc-image-gallery-bottom", "a.btn-previous", "a.btn-next" );
	window.gallery = imageGallery;
}

function nxcGalleryChangerLoader()
{
	nxcGalleryChanger( images[ 0 ], href[ 0 ], description[0], 0 );
	var allCattegoies = $( 'ul.gallery-categories li' );
	window.globalGalleryNumber = 0;
	allCattegoies.each(
		function(index, item)
		{
			$( item ).click(
				function(e)
				{
					e.preventDefault();
					if( window.globalGalleryNumber != index )
					{
						window.lastTime = new Date().getTime();
						nxcGalleryChanger( images[ $( this ).attr( 'rel' ) ], href[ $( this ).attr( 'rel' ) ], description[ $( this ).attr( 'rel' ) ], 0 );
						$( allCattegoies[window.globalGalleryNumber] ).removeClass( 'selected' );
						window.globalGalleryNumber = index;
						$( allCattegoies[window.globalGalleryNumber] ).addClass( 'selected' );
					}
				}
			);
		}
	);
}

function imageGalleryScroller()
{
	window.globalGalleryNumber = 0;
	window.globalImageNumber = 0;
	window.directions = 0;
	window.lastTime = 0;
	window.currentTime = new Date().getTime();
	window.mouseovergallery = false;
	
	$( 'div.gallery-content' ).mouseenter(
		function(e)
		{
			window.mouseovergallery = true;
		}
	);
	$( 'div.gallery-content' ).mouseleave(
		function(e)
		{
			window.mouseovergallery = false;
		}
	);
	
	
	
	function rotationImages()
	{
		if( !window.mouseovergallery || ( window.directions != 0 ) )
		{
			window.currentTime = new Date().getTime();
			if( ( ( window.currentTime - window.lastTime ) >= 6000 ) || ( window.directions != 0 ) )
			{
				if( window.directions == 0 )
				{
					window.directions = 1;
				}
				window.lastTime = new Date().getTime();
				if( window.gallery.galleryIsReady )
				{
					cur = parseInt( window.gallery.currentImage ) + 0;
					window.globalImageNumber = cur;
					if( window.gallery.specialBlockLikeImage )
					{
						var count = window.gallery.specialBlockCount;
					}
					else
					{
						var count = window.gallery.galleryImageCount;
					}
					if( window.directions == 1 )
					{
						if( (cur + 1) > ( count - 1 ) )
						{
							window.globalGalleryNumber++;
							if( window.globalGalleryNumber == images.length )
							{
								window.globalGalleryNumber = 0;
							}
							window.globalImageNumber = 0;
							nxcGalleryChanger(images[window.globalGalleryNumber], href[window.globalGalleryNumber], description[window.globalGalleryNumber], window.globalImageNumber );
							$('.gallery-categories li.selected').removeAttr('class');
							var galleryCategory = $('.gallery-categories li');
							//$( galleryCategory ).each(function(index, value) { 
							//	$(value).removeClass('selected');
							//});
							
							$( galleryCategory[window.globalGalleryNumber] ).attr('class', 'selected');
						}
						else
						{
							window.globalImageNumber++;
							window.gallery.rotateImage( window.globalImageNumber, window.directions );
						}
					}
					else
					{
						if( (cur - 1) < 0 )
						{
							window.globalGalleryNumber--;
							if( window.globalGalleryNumber < 0 )
							{
								window.globalGalleryNumber = images.length - 1;
							}
							window.globalImageNumber = 0;
							nxcGalleryChanger(images[window.globalGalleryNumber], href[window.globalGalleryNumber], description[window.globalGalleryNumber], images[window.globalGalleryNumber].length - 1);
							$('.gallery-categories li.selected').removeAttr('class');
							var galleryCategory = $('.gallery-categories li');
							//$( galleryCategory ).each(function(index, value) { 
							//	$(value).removeClass('selected');
							//});
							
							$( galleryCategory[window.globalGalleryNumber] ).attr('class','selected');
						}
						else
						{
							window.globalImageNumber--;
							window.gallery.rotateImage( window.globalImageNumber, window.directions );
						}
					}
				}
			}
		}
		window.directions = 0;
	}
	setInterval( rotationImages, 2000 );
	$( 'a.btn-previous' ).each(
		function(index, item)
		{
			$( item ).click(
				function( e )
				{
					e.preventDefault();
					window.directions = -1;
					rotationImages();
				}
			);
		}
	);
	$( 'a.btn-next' ).each(
		function(index, item)
		{
			$( item ).click(
				function( e )
				{
					e.preventDefault();
					window.directions = 1;
					rotationImages();
				}
			);
		}
	);
}

