function hideRest( object ) {
	if( isLargeImageHidden( object ) ) {
		// find all divs with hidden class and hide them again
		$('div.content_main').find('.gallerySection').removeClass('openedBlock');
		$('div.content_main').find('.hidden').hide();
		$('div.content_main').find('.seeMore').show();
	}
}


function isLargeImageHidden( object ) {
	if( 0 < object.parent().parent().prev('div.largeImage:hidden').length ) {
		return true;
	}
	else {
		return false;
	}
}


$(document).ready( function() {
	$('div.thumb img').bind('click', function() {
		//show all hidden pictures in this div if the largeImage is hidden
		if( isLargeImageHidden( $(this) ) ) { 
			hideRest( $(this) );
			$(this).parent().siblings('.seeMore').hide();
			$(this).parent().siblings('.hidden').toggle();
		}
		
		// change the big picure img src depeneding on which small picture was selected 
		var newSrc = $(this).attr('src').toString().replace('small', 'medium');
		var newTitle = $(this).attr('alt');
		$(this).parent().parent().parent().addClass('openedBlock');
		$(this).parent().parent().prev('div.largeImage').children('img:first').attr({ 'src': newSrc });
		$(this).parent().parent().prev('div.largeImage').children('img:first').attr({ 'alt': newTitle });
		$(this).parent().parent().prev('div.largeImage').children('p.imageTitle').html(newTitle);
		
		if( isLargeImageHidden( $(this) ) ) {
			// show the big picture
			$(this).parent().parent().prev('div.largeImage').toggle();
		}
	})
	
		// the seeMore has to be click on the first image of the row
	$('div.seeMore a').bind( 'click', function() {
		$(this).parent().parent().children('div.thumb:first').children('img').click();
		return false;
	})
})