function adjustImageViewerSize() {
	var fullWidth = $('#imageViewer span img').attr('width');
	var fullHeight = $('#imageViewer span img').attr('height');
	var sizeAdjustment = ((250/fullWidth) > (180/fullHeight)) ? (180/fullHeight)*100 : (250/fullWidth) * 100;
	$('#imageViewer span img').css({
		'width': +' '+Math.round(fullWidth * sizeAdjustment / 100)+'px',
		'height': +' '+Math.round(fullHeight * sizeAdjustment / 100)+'px'
	});
}



$(document).ready(function() {
	adjustImageViewerSize();
	
	//	image zoom code for New Equipment Details pages
	$('#imageChooser .thumbBox').click(function(e){
		e.preventDefault();
		
		//	drop the image into the imageViewer span
		$('#imageViewer span').html($(this).html());

		//	size the image to 250x180 or less
		adjustImageViewerSize();
					
		//	drop the caption into its rightful place
		$('#imageCaption').text($('img', this).attr('alt'));
	});
	
	
	
	
	
	//	create image viewer lightbox
	$(function() {
		$("#imageLightBox").dialog({
			autoOpen: false,
			resizable: false,
			position: ['center', 65],
			modal: true
		});
	});		
	
	//	handle clicks that open the lightbox
	$('#imageViewIcon, #imageViewer').not('.notClickable').click(function(){
		
		//	load the image into the lightbox and remove it's dimension restrictions
		$("#imageLightBox").html($("#imageViewer span").html()).find('img').removeAttr('style');
		
		//	open the dialog box (this has to be done now even though the size isn't set because IE doesn't work if you set the size first)
		$('#imageLightBox').dialog('open');
		
		//	set the caption of on the lightbox
		$('.ui-dialog-title').html($('#imageCaption').text());

		//	set the dialog width
		$("#imageLightBox")
			.dialog("option", "width", $("#imageLightBox img").attr('width')+35)
			.dialog("option", "position", "center");
		
	});
	
	
	
	
	//	table viewer lightbox
	$(function() {
		$("#tableLightBox").dialog({
			autoOpen: false,
			resizable: false,
			width: 670,
			position: ['center', 75],
			modal: true,
			overlay: {
				backgroundColor: '#111',
				opacity: 0.5
			}
		});
	});
	$(".tableLink").click(function(e){
		e.preventDefault();
		$('#tableLightBox').dialog('open');
	});
	
	//	slideshow on home page
	$('#featuredMain').cycle({
		timeout: 3000
	});
	

	//	adjust position of productBoxLearnMore text
	$('.productBoxLearnMore').hide();
		
});
