Bliss = 
{
	nextImage : function( id, selectedItem )
	{
		var parent = $('#' + id).parent().attr('id')
		
		if ( parent == 'photoItems' )
		{
			var galleryItems = $( '#' + id + ' .scrollable .items img' );
		}
		else
		{
			var galleryItems = $( '#' + parent + ' .scrollable .items img' );
		}
		
		var galleryItemsLength = galleryItems.length;
		
		$.each( galleryItems, function( i, value )
		{
			if( value.className.indexOf('active') > 0 )
			{
				if( i < galleryItemsLength )
				{
					parent;
					var itemSelected = i;
					var nextImagei;
					var previousImage;

					// Show the next button
					if( selectedItem )
					{
						nextImage = i;
						previousImage = i+1;
					}
					else
					{
						nextImage = i+1;
						previousImage = i;
					}
					
					if( i < nextImage )
					{
						var item = galleryItems[nextImage];
						
						// calclulate large image's URL based on the thumbnail URL
						var url = item.alt;

						// get handle to element that wraps the image and make it semi-transparent
						var wrap = $(this).parent().parent().parent().parent().children(".image_wrap").fadeTo("medium", 0.5);
						var img = new Image();

						// call this function after it's loaded
						img.onload = function(uh )
						{
							// make wrapper fully visible
							wrap.fadeTo("fast", 1);
							// change the image
							wrap.find("img").attr("src", url);
						};

						img.src = url;

						// activate item
						$( galleryItems ).removeClass("active");
						$(item).addClass("active");
					}
					
					if( itemSelected < galleryItemsLength )
					{
						// Show the next link
						$( '#' + parent + ' .nextButton' ).show();
					}
					
					if( selectedItem != null )
					{
						if( nextImage == (galleryItemsLength -1 ) )
						{
							// Hide the next link
							$( '#' + parent + ' .nextButton' ).hide();
						}

					}
					else
					{
						if( nextImage == (galleryItemsLength -1 ) )
						{
							// Hide the next link
							$( '#' + parent + ' .nextButton' ).hide();
						}

						if( nextImage > 0 )
						{
							$( '#' + parent + ' .previousButton' ).show();
						}
					}
					
					return false;
				}
				else
				{
					return false;
				}
			}
			
		});
	},

	previousImage : function( id, selectedItem )
	{
		var parent = $('#' + id).parent().attr('id')
		
		if ( parent == 'photoItems' )
		{
			var galleryItems = $( '#' + id + ' .scrollable .items img' );
		}
		else
		{
			var galleryItems = $( '#' + parent + ' .scrollable .items img' );
		}
		
		var galleryItemsLength = galleryItems.length;
		
		$.each( galleryItems, function( i, value )
		{
			if( value.className.indexOf('active') > 0 )
			{
				if( i < galleryItemsLength )
				{
					parent;
					var itemSelected = i;
					var previousImage = i-1;
					var nextImage;
					// Show the next button
					if( selectedItem )
					{
						nextImage = i;
					}
					else
					{
						nextImage = i-1;
					}
					
					
					
					if( i > 0 && previousImage != -1 )
					{
						var item = galleryItems[nextImage];
						
						// calclulate large image's URL based on the thumbnail URL
						var url = item.alt;

						// get handle to element that wraps the image and make it semi-transparent
						var wrap = $(this).parent().parent().parent().parent().children(".image_wrap").fadeTo("medium", 0.5);

						var img = new Image();

						// call this function after it's loaded
						img.onload = function()
						{
							// make wrapper fully visible
							wrap.fadeTo("fast", 1);
							// change the image
							wrap.find("img").attr("src", url);
						};

						img.src = url;

						// activate item
						$( galleryItems ).removeClass("active");
						$(item).addClass("active");
					}
					
					if( itemSelected < galleryItemsLength )
					{
						// Show the next link
						$( '#' + parent + ' .nextButton' ).show();
					}
					
					if( selectedItem != null )
					{
						if( nextImage == -1 )
						{
							// Hide the next link
							$( '#' + parent + ' .previousButton' ).hide();
						}
						
						if( nextImage > -1 )
						{
							$( '#' + parent + ' .previousButton' ).show();
						}
					}
					else
					{
						if( nextImage == 0 )
						{
							// Hide the next link
							$( '#' + parent + ' .previousButton' ).hide();
						}
						
						if( nextImage > 0 )
						{
							$( '#' + parent + ' .previousButton' ).show();
						}
					}
					
					return false;
				}
				else
				{
					return false;
				}
			}
			
		});
	}
}
$(document).ready(function()
{
	$('#menu-item-950 a:first, #menu-item-952 a:first, #menu-item-970 a:first').click(function()
	{
		return false;
	});
	
	// Set's the target for blog and alist events to open in a new tab
	$('#menu-item-954 a, #menu-item-989 a').attr('target', '_blank');
	
	// Sets the width of the first drop down menu to be wide enough for alist events to be on a single line
	$('#menu-item-950 .sub-menu').css('width', '143px');
	$('#access ul#menu-main li#menu-item-950 ul li a').css('width', '110px');
	
	$("img[rel]").overlay(
	{
		mask: {
			color: '#000',
			loadSpeed: 200,
			opacity: 0.5
		}
	});
	
	$('a[data-image-thumb]').prepend(function(index)
	{
		var thumbImage = $(this).attr('data-image-thumb');
		var fullImage = $(this).attr('data-image-link');
		var imageClass = $(this).attr('class');
		return '<img width="75" height="75" class="' + imageClass + '" alt="' + fullImage + '" src="' + thumbImage + '">'
	});
	
	//$(".scrollable").scrollable();

	$('.album img').click(function()
	{
	
		var galleryIDValue = $(this).parent().next().attr('id');
		var galleryID = '#' + galleryIDValue + ' .scrollable .items img';
		var galleryItems = $( galleryID );
		
		
		$(".items img").click(function()
		{
		
			galleryIDValue = $(this).parent().parent().attr('id');
			galleryID = '#' + galleryIDValue + ' .scrollable .items img';
			galleryItems = $( galleryID );
			
			// Place a div around every 5 image items
			for(var i = 0; i < galleryItems.length; i+=5) 
			{
				galleryItems.slice(i, i+5).wrapAll("<div></div>");
			}
			
			// see if same thumb is being clicked
			if ($(this).hasClass("active"))
			{
				return;
			}

			// calclulate large image's URL based on the thumbnail URL (flickr specific)
			var url = $(this).attr("alt");

			// get handle to element that wraps the image and make it semi-transparent
			var wrap = $(this).parent().parent().parent().parent().children(".image_wrap").fadeTo("medium", 0.5);

			var img = new Image();

			// call this function after it's loaded
			img.onload = function()
			{
				// make wrapper fully visible
				wrap.fadeTo("fast", 1);
				// change the image
				wrap.find("img").attr("src", url);
			};

			img.src = url;

			// activate item
			$(".items img").removeClass("active");
			$(this).addClass("active");
			
			// set the width of scrollable to fix an IE issue of not setting the width to the container
			if ($.browser.msie)
			{
				var scrollableItems = $('#' + galleryIDValue + ' a' ).length;
				var itemsWidth = (scrollableItems * 95) - 15;
				$('#' + galleryIDValue).css('width', itemsWidth );
			}
			
			var parentID = $(this).parent().parent().parent().parent().parent().attr('id');
			var images = $( '#' + parentID + ' .scrollable img');
			
			
		});
		
		// get the items in the gallery
		
		var galleryContainer = $(this).parent().siblings(':first').attr('id');
		var galleryID = '#' + galleryIDValue + ' .scrollable .items img';
		var galleryItems = $( galleryID );
		
		$( '#' +  galleryIDValue + ' .nextButton' ).show();
		
		// when page loads simulate a "click" on the first image
		$(galleryItems).filter( ':first' ).click();
	});
	
	$('.scrollable').children( $('.gallery') ).addClass('items');
});

