$(document).ready(function(){
	$('#close, .bigImg').click(function(){
		$('.bigImg, #divImg').fadeOut(500);
		$('#bigImg').attr('src','/data/images/loading.gif');
	});
	
	$('.galleryItem:first').addClass('first');
	$('.galleryItem:last').addClass('last');
	
	$('.galleryItem').click(function(){		
		$('.bigImg, #divImg').fadeIn(500);
		$('.activeGallery').removeClass('activeGallery');
		$(this).addClass('activeGallery');
		$('#bigImg').attr('src',$(this).attr('url'));
		$('#bigImg').load(function(){
			$('#loadImg').fadeOut();
			$('#bigImg').fadeIn(1000);
		});
	});
	
	$('#divImg').click(function(){
		$('#loadImg').fadeIn(500);
		$('#bigImg').hide();		
		activeGallery = $('.activeGallery');
		if(activeGallery.hasClass('last')==true){
			activeGallery.removeClass('activeGallery');
			$('.first').addClass('activeGallery');
			$('#bigImg').attr('src',$('.first').attr('url'));
		}else{
			activeGallery.removeClass('activeGallery');
			activeGallery.next('div.galleryItem').addClass('activeGallery');
			$('#bigImg').attr('src',activeGallery.next('div.galleryItem').attr('url'));			
		}		
		$('#bigImg').load(function(){
			$('#loadImg').fadeOut();
			$('#bigImg').fadeIn(500);
		});
	});
	
});
