/* CLIQUE */
/* Editorial Widget Press Viewer
----------------------------------------------------------------------------- */


	$(window).load(function() {
	
	
		photos();
		
		
	});


/* PHOTOS
----------------------------------------------------------------------------- */


	function photos() {
			
		if ($('#viewer').length > 0) {
			
			var $photos = $('#viewer');

			// Unhide after page load
			$photos.find('div.story').show();
		

/* PHOTOS > BROWSER > THUMBNAILS
----------------------------------------------------------------------------- */
				
				
				// Remove Empty Thumbnail Rows
				
				
					/* $photos.children('div.story').each(function() {
					
						var placeholderCount = $(this).children('p').length;
						var thumbnailCount = $(this).children('p:has(img)').length;
						
						// Hide thumbnails if there's only one image
						if (thumbnailCount < 2) $(this).hide();
						
						var firstToGo = (Math.ceil(thumbnailCount / 4)) * 4 + 1;
						for (i = firstToGo; i <= placeholderCount; i++) $(this).children('p:last-child').remove();
					
					}); */
				
			
				
				
				// Create Enlarged Viewer and Populate
				
				var image = $photos.find('div.story p img:first').attr('src');
				$photos.prepend('<div class="enlarged"><img src="' + image + '" alt="" /></div>');
		
				var $enlarged = $photos.children('div.enlarged');
						
				// Remove alt Tags from Thumbnails (They interfere with the hover event in Firefox)
				
				$photos.find('img').attr('title', '');
	
		
/* Thumbnail Click */


				$photos.find('div.story img').click(function() {
							
					$enlarged.children('img').hide();

					var image = $(this).attr('src');
		
					if ($enlarged.children('img[src=' + image + ']').length > 0) {
					
						// Show Enlarged Image if Already Exists
						$enlarged.children('img[src=' + image + ']').show();
					
					} else {
					
						// Prepend Enlarged Image if Not Present
						$enlarged.prepend('<img src="' + image + '" alt="" />');
						$enlarged.children('a').click(function() { return false; });
						
					}
		
					// Set Selected Thumbnail Class
					$(this).siblings().removeClass('selected');
					$(this).addClass('selected');
		
					return false;
				
				});
			
			
			}
		
		}

