$(function(){
	if($('body').hasClass('blog')){
		blogGallery.activateThumbnails();
		blogGallery.activateItemDeepLinking();
	}
});

var blogGallery = {
	changeItemURL: function(sItemId){
		var sCurrentUrl = location.href;
		var aCurrentUrlHash = sCurrentUrl.split('#');		
		location.href = aCurrentUrlHash[0]+'#item-'+sItemId;	
	},	
	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.find('.link').click();	
			} 
		}		
		else if($('.gallery .block .list .item:first')[0] != null){
			$('.gallery .block .list .item:first').find('.link').click();
		}
	},		
	activateThumbnails: function(){	
		$('.gallery .block .list .item .link').click(function(){
			var oCurrentItem = $(this).parents('.item');
			var sCurrentItemId = oCurrentItem.attr('id').replace("item-", "");
			var oCurrentGalleryItem = $('#'+oCurrentItem.attr('id').replace("item-", "item-content-"));
			
			oCurrentGalleryItem.parents('.gallery').find('.item-content').removeClass('current');
			oCurrentGalleryItem.addClass('current');
			
			oCurrentItem.parents('.list').find('.item').removeClass('current');
			oCurrentItem.addClass('current');

			var sCurrentUrl = location.href;
			var aCurrentUrlHash = sCurrentUrl.split('#');		
			location.href = aCurrentUrlHash[0]+'#'+sCurrentItemId;				
			
			/*TRACKING*/
			//tracking.event.activate('trackingevent', {EventClass: "blogGallery", Action: "ViewImage", Vehicle: VEHICLE_ABBR, Image: sCurrentItemId, Section: "blogGallery", Type: "blogGalleryItem"});
			
			return false;
		});
	}
}
