$(function(){
	if($('body').hasClass('features')){
		featuresGallery.activateThumbnails();
		featuresGallery.activateItemDeepLinking();
	}
});

var featuresGallery = {
	activateItemDeepLinking: function(){
		var sCurrentUrl = location.href;
		var aCurrentUrl = sCurrentUrl.split('#');
		
		if((aCurrentUrl[1] != null) && (aCurrentUrl[1] != '')){
			oSelectedItem = $('#item-'+aCurrentUrl[1]);
			if(oSelectedItem[0] != null){
				oSelectedItem.click();	
			} 
		}
	},		
	activateThumbnails: function(){	
		$('.features-gallery .gallery-header ul.tabs li').click(function(){
			var oCurrentItem = $(this);
			var sCurrentItemId = oCurrentItem.attr('id').replace("item-", "");
			var oCurrentGalleryItem = $('#'+oCurrentItem.attr('id')+'-content');
			
			oCurrentGalleryItem.parents('.gallery-content').find('.viewer').removeClass('current');
			oCurrentGalleryItem.addClass('current');
			
			oCurrentItem.parents('ul.tabs').find('li').removeClass('current');
			oCurrentItem.addClass('current');

			var sCurrentUrl = location.href;
			var aCurrentUrlHash = sCurrentUrl.split('#');		
			location.href = aCurrentUrlHash[0]+'#'+sCurrentItemId;				
			
			return false;
		});
	}
}
