$(document).ready(function() {
	var lang = 'en';
	if ($('div#wrap').attr('lang') == 'fr_CA') {
		lang = 'fr';
	}
		
	window.VerticalScroller = new VerticalScroller(4, 3, 91, $('.scroller'));
	//var thumbnails = $('.image-gallery .thumbnail');
	$('.image-gallery .thumbnail').click(function() {
		// change the src of the large image										  
		var thumbnailImgSrc = $('img', this);
		var thumbnailImgUniqueName = $(thumbnailImgSrc).attr('src').replace(/^(.*\/)(thumbnail_)(.*)(.jpg)$/, '$3');
		var newLargeSrc = $('.image-gallery .viewing-pane img').attr('src').replace(/^(.*\/)(large-image_)(.*)(.jpg)$/, '$1$2' + thumbnailImgUniqueName +'$4');
		$('.image-gallery .viewing-pane img').attr('src', newLargeSrc);
		
		// change the annotation for the large image
		$('.annotation').addClass('hide');
		$('#annotation-' + thumbnailImgUniqueName).removeClass('hide');
		
		// add border around selected thumbnail
		$('.thumbnail').removeClass('selected');
		$(this).addClass('selected');
		
		// add opacity to non-selected thumbnails
		$('.thumbnail').find('.cover').remove();
		$('.thumbnail:not(.selected)').append($('<span class="cover"></span>'));
		
		// change the Featured Products
		$('.feature-products .products.selected').hide().removeClass('selected');
		$('.feature-products #products-' + thumbnailImgUniqueName).fadeIn('fast').addClass('selected');
		
		// Omniture Start
		s_objectID = lang + ':gallery:' + thumbnailImgUniqueName;
		// Omniture End
		
		// set cookie to remember selected thumbnail
		//$.cookie('ms-selected-thumbnail', thumbnails.index(this));
	});
	
	// check to see if a thumbnail was preselected
	/*if ($.cookie('ms-selected-thumbnail')!= null) {
		var index = Number($.cookie('ms-selected-thumbnail'));
		$('.image-gallery .thumbnail').eq(index).click();
		// scroll through the gallery to show the selected thumbnail
		if (index > 2) {
			$('.scroller .scroll-down').click();
		}
	}*/
	
	$('.call-out.category a').click(function() {
		// Omniture Start
		var name = $(this).parents('.call-out').attr('id');
		s_objectID = lang + ':collections:' + name;
		// Omniture End
	});
	
	$('.feature-products .product .btnDetails').click(function() {
		// Omniture Start
		var partNum = $.trim($(this).parents('.product').find('.partNum').text());
		s_objectID = lang + ':feature-products:' + partNum;
		// Omniture End
	});
	
	$('.services .related-page a').click(function() {									  
		// Omniture Start
		var name = $(this).parents('.related-page').attr('id');
		s_objectID = lang + ':related-links:' + name;
		// Omniture End
	});
	
	$('.video').click(function(event){
		// Omniture Start				   
		var s=s_gi(s_account);
		s.tl(this,'o', s.pageName + ': partnership video');
		// Omniture End
	});
	
	$('.hero ul li').click(function() {
		$('.hero .selected').removeClass('selected');
		$(this).addClass('selected');
		$('.hero #'+$(this).attr('id')+'-container').addClass('selected');
	});
});
