jQuery(function($) {
	/* these functions resize the popup window to allow enlarged images to show as much of the image as possible/necessary */
	if(!!getURLParamValue('pic')) {
		prepareToResize();
	}
});

/*function resizeBiggestImage() {
	fIH = $("#featureImage").height();
	fIW = $("#featureImage").width();
	wH = $(window).height();
	topBar = 39;
	bottomPart = 45;
	newH = wH - topBar - bottomPart;
	newW = Math.floor((fIW / fIH) * newH);
	$("#featureImage").height(newH);
	$("#featureImage").width(newW);
}*/
function prepareToResize() {
	$("#featureImage").each(function() {
		if(this.complete) {
			resizeThings(this.naturalHeight, this.naturalWidth);
		}
		else {
			window.setTimeout('prepareToResize();',100);
		}
	});
}
function resizeThings(imgH,imgW) {
	//fIH = $("#featureImage").height();
	//fIW = $("#featureImage").width();
	if($("#cHeight").size()) {
		imgW += 380;
	}
	var supposedW = 950,
		supposedH = 579,
		maxWindowSizeY = screen.availHeight,
		maxWindowSizeX = screen.availWidth,
		aspect = imgH / imgW,
		topBar = $(".topt").height() + $('p.cHeight').height() + 15,
		bottomPart = 45,
		lrPad = 7 * 2, //2 sides
		wH = $(window).height(),
		wW = $(window).width(),
		resizeByX = Math.max(imgW - wW + lrPad, supposedW - wW),
		resizeByY = Math.max(imgH + topBar + bottomPart - wH, supposedH - wH);
	window.moveTo(0,0);
	window.resizeBy(resizeByX, resizeByY);
	return;
}
function registerSidechangeMouseovers() {
	$showcase.data('original-src', $showcase.attr('src'));
	$(".sidechange").mouseenter(function(e) {
		$(this).css('backgroundColor', '#ddd');
		var imageSrc = $('img', this).attr('src');
		$showcase.attr('src', imageSrc.split('/tn').join(''));
	}).mouseleave(function(e) {
		$(this).css('backgroundColor', '');
		$showcase.attr('src', $showcase.data('original-src'));
	});
}


jQuery(function($) {
	/* BEGIN: Related images mouseovers */
	$showcase = $("#showCase"); // global var $showcase
	$(".sidechange").click(function(e) {
		var currImgParts = showsrc.split("/");
		var currImgID = currImgParts[currImgParts.length - 1].replace(".jpg","");
		var imageSrc = $('img', this).attr('src');
		var imgIdParts = imageSrc.split('/');
		var imgID = imgIdParts[imgIdParts.length - 1].replace(".jpg","");
		go(window.location.href.split(currImgID).join(imgID));
	});
	/* To avoid immediately triggering mouseover when you click on an image and your mouse 
	 * is still in the same spot, wait 1 second before registering mouseover events
	 */
	window.setTimeout(registerSidechangeMouseovers, 500); 
	
	/* these functions are for controlling the next and previous buttons, which are based on checking the parent opener for next/prev links */
	imgID = $('.CatID').text();
	$('a.tagLink').click(function(e) {
		// tag collections like 'High Altitude - Cirrus'
		// opener is in the DOM2 spec
		if(!!opener) {
			e.preventDefault();
			opener.location=this.href;
		}
	});
	if(typeof opener === "undefined" || opener === null || typeof opener.getPrevNext === "undefined") return;
	
	if(hasPrev(imgID)) { 
		$("#prevButton").show().attr('href', getNextPrevHREF(imgID, true)); 
	}
	else {
		//console.log('no previous');
		noPrev = true;
		//$(".prevOff").show();
	}
	if(hasNext(imgID)) { 
		$("#nextButton").show().attr('href', getNextPrevHREF(imgID, false)); 
	}
	else {
		//console.log('no next');
		noNext = true;
		//$(".nextOff").show();
	}
	if(typeof noPrev === "undefined" || typeof noNext === "undefined") {
		// if these are both defined, don't show anything -- customer must have navigated away from the opener page
		if(typeof noPrev !== "undefined") { $(".prevOff").show(); }
		if(typeof noNext !== "undefined") { $(".nextOff").show(); }
	}
	if(!hasNext(imgID) && !hasPrev(imgID) && typeof noPrev !== "undefined" && typeof noNext !== "undefined") { $(".nav b.pipe").hide(); }
	else { $(".nav b.pipe").show(); }

});

		jQuery(function($) {
			
		});

function getNextPrevHREF(imgID, previous) {
	var theHref = '/library/showimage.php?img=' + opener.getPrevNext(imgID, previous) + '&section=' + section;
	if(!!getURLParamValue('pic')) {
		theHref += '&pic=big';
	}
	return theHref;
}
function hasPrev(imgID) { return hasPrevNext(imgID, true); }
function hasNext(imgID) { return hasPrevNext(imgID, false); }
function hasPrevNext(imgID, previous) {
	if(opener.getPrevNext(imgID, previous)) { return true; }
}

function SideChange(ImgC) { 
	document.ShowCase.src="catalogimages/" + ImgC + ".jpg"; 
	document.mag.src="/s.gif"; 
}
function SideChange2(ImgC) { 
	document.ShowCase.src=ImgC; 
	document.mag.src="catalogimages/magnify.gif"; 
}

