
(function($){

	$(document).ready(function(){

		if ($.browser.msie && $.browser.version < 7) {
			// set parent heights for colorbox.
			$('html, body').css('height', '100%');
		}

		$('#main div.details a[rel=map]').colorbox({
			opacity: 0.6
		});	

		$('#main div.shop').each(function(){

			// setup image gallery.
			$('div.images ul a', this)
				.each(function(){
					// preload image.
					var img = new Image();
					img.src = this.href;

					$(this)
						// add large photo to image container.
						.closest('div.images')
							.find('div.large')
								.append('<img src="'+ img.src +'" />')
							.end()
						.end()

						// thumbnail click handler.
						.click(function(){
							if (!$(this).hasClass('on')) {
								var thumbnailList = $(this).closest('ul');
								$('a.on', thumbnailList).removeClass('on');

								// get clicked index.
								var index = $('a', thumbnailList).index(this);

								// switch large photo.
								$(this)
									.addClass('on')
									.closest('div.images')
										.find('div.large img')
											.hide()
											.eq(index)
												.fadeIn()
											.end()
										.end()
									.end()
								;
							}

							return false;
						})
					;
				})
				// show first photo.
				.eq(0)
					.trigger('click')
				.end()
			;
		});

	});

})(jQuery);
