<!--

function artworkPop(artworkId, showPrice, ids) {
	if (showPrice == 1) {
		window.open('artwork_popup.php?wid='+artworkId+'&ids='+ids+'&pre=1', '', 'resizable=0,width=400,height=580,scrollbars=0');
	} else {
		window.open('artwork_popup.php?wid='+artworkId+'&ids='+ids, '', 'resizable=0,width=400,height=580,scrollbars=0');
	}
}

if (jQuery.browser.mozilla == true && jQuery.browser.version.substring(0, 5) == "1.8.1" && parseFloat(jQuery.browser.version.substring(6)) < 12) {
	var flashWithOpacity = false;
} else {
	var flashWithOpacity = true;
}




var zooming;
var hidingZoom;
var zoomInt = 0;

$().ready(function(){
	
	if ($('#imgZoomTable').length > 0) {
		origImgWidth = $('#imgOrigTable').width();
		origImgHeight = $('#imgOrigTable').height();
		
		zoomImgWidth = $('#imgZoomTable').width();
		zoomImgHeight = $('#imgZoomTable').height();
	
		viewPortWidth = $('#imgZoomCell').width();
		viewPortHeight = $('#imgZoomCell').height();
	
		if (zoomImgWidth > origImgWidth || zoomImgHeight > origImgHeight) {
			
			$('#imgZoomCell').append('<a id="zoomButton" href="#" title="Click for detail" style="position: absolute; z-index: 6; width: '+viewPortWidth+'px; height: '+viewPortHeight+'px"></a>');
			$('#zoomButton').click(
				function(){
					openZoom();
					return false;
				}
			);
			$('#imgZoomCell').mouseleave(function(){
				closeZoom();
			});
		}
	}
	
});



function openZoom(){
	if (zooming == 1) {
		closeZoom();
	}
	
	$('#imgZoomTable').show();
	
	viewPortWidth = $('#imgZoomCell').width();
	viewPortHeight = $('#imgZoomCell').height();
	
	origImgWidth = $('#imgOrigTable').width();
	origImgHeight = $('#imgOrigTable').height();
	
	zoomImgWidth = $('#imgZoomTable').width();
	zoomImgHeight = $('#imgZoomTable').height();
	
	zoomAmount = zoomImgWidth / origImgWidth;
	
	$('#imgZoomTable').hide();
	
	if (zoomImgWidth > origImgWidth || zoomImgHeight > origImgHeight) {
		
		$('#zoomButton').hide();
	
		zooming = 1;
		//build column table
		if ($("#imgZoomClm").length == 0) {
			var cellTop = $('#imgZoomCell').offset().top;
			$("#zoomClm").append('<table id="imgZoomClm" width="190" height="100%" style="background: #FFF; position: absolute; z-index: 80; top: 0px;"><tr><td valign="top"><div id="clmZoomCell" style="margin-top: '+cellTop+'px;"></div></td></tr></table>');
			zoomFrameWidth = Math.round(170 / zoomAmount);
			zoomFrameHeight = Math.round(360 / zoomAmount);
			$('#clmZoomCell').html('<div id="zoomClmImg">'+$('#imgZoomTable').html()+'</div>');
			$('#imgZoomCell').append('<div id="zoomFrame" style="width: '+zoomFrameWidth+'px; height: '+zoomFrameHeight+'px;"><div class="border" style="width: '+(zoomFrameWidth-2)+'px; height: '+(zoomFrameHeight-2)+'px;"><div class="background" style="width: '+(zoomFrameWidth-2)+'px; height: '+(zoomFrameHeight-2)+'px;"></div></div></div>');
				$('#zoomFrame .background').css({ 'opacity' : 0.6 });
		}
		$("#zoomFrame").hide().fadeIn(400,function(){});
		$("#imgZoomClm").hide().fadeIn(400,function(){});
		
		$('#imgZoomCell').mousemove(function(e){
			zoomMouseX = e.pageX;
			zoomMouseY = e.pageY;
			calcZoom();
		});
	}
}

var zoomMouseX = 0;
var zoomMouseY = 0;

var viewPortWidth = 0;
var viewPortHeight = 0;

var zoomImgWidth = 0;
var zoomImgHeight = 0;

var origImgWidth = 0;
var origImgHeight = 0;

var zoomFrameWidth = 0;
var zoomFrameHeight = 0;

var zoomAmount = 0;

function calcZoom(){
	mouseX = zoomMouseX - $('#imgZoomCell').offset().left;
	mouseY = zoomMouseY - $('#imgZoomCell').offset().top;

	frameX = mouseX - (zoomFrameWidth/2);
	frameY = mouseY - (zoomFrameHeight/2);
	
	frameX = Math.max(0, Math.min(frameX, origImgWidth-zoomFrameWidth));
	frameY = Math.max(0, Math.min(frameY, origImgHeight-zoomFrameHeight));
	
	$('#zoomFrame').css({ "left": frameX+"px", "top" : frameY+"px" });
	
	$('#zoomClmImg').css({ "left": ((0-frameX)*zoomAmount)+"px", "top" : ((0-frameY)*zoomAmount)+"px" });

/*
	posXPerc = mouseX/viewPortWidth;
	posYPerc = mouseY/viewPortHeight;
	
	xPosMove = zoomImgWidth-viewPortWidth;
	yPosMove = zoomImgHeight-viewPortHeight;
	
	zoomImgX = (0 - (posXPerc*xPosMove));
	zoomImgY = (0 - (posYPerc*yPosMove));
	
	if (zoomImgWidth < viewPortWidth) {
		zoomImgX = 0;
	}
	if (zoomImgHeight < viewPortHeight) {
		zoomImgY = 0;
	}
	
	$('#imgZoomTable').css({ "left": zoomImgX+"px", "top" : zoomImgY+"px" });
	*/
}
function closeZoom(){
	zooming = 0;
	$('#imgZoomCell').mousemove(function(){});
	$("#imgZoomClm").fadeOut(400,function(){});
	$("#zoomFrame").fadeOut(400,function(){});
	$('#zoomButton').show();
}












var showingLightbox = 0;

function closeLightbox(doFade){
	showingLightbox = 0;
	$('#jquery-lightbox').remove();
	if (doFade == 1) { 
		$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
	} else {
		$('#jquery-overlay').remove();
	}
	$('select').css({ 'visibility' : 'visible' });
}

function openLightbox(imageFile){
	showingLightbox = 1;
	$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="jquery-lightbox-back"></div><div class="lightbox-container-image-box"><div class="lightbox-container-image"><div class="lightbox-content"></div><div class="lightbox-loading"><a href="#" class="lightbox-loading-link"></a></div></div></div></div>');
	
	var arrPageSizes = ___getPageSize();
	$('#jquery-overlay').css({
			opacity:			flashWithOpacity == false ? 1 : 1,
			width:				arrPageSizes[0],
			height:				arrPageSizes[1]
		}).fadeIn();
	var arrPageScroll = ___getPageScroll();
	$('#jquery-lightbox').css({
			top:	arrPageScroll[1],
			left:	arrPageScroll[0]
		}).show();
	$('#jquery-overlay, #jquery-lightbox-back').click(function() {
			closeLightbox(1);
			return false;
		});
	
	$('.lightbox-content').hide();
	var imgPreloader = new Image();
	imgPreloader.onload = function() {
		if (showingLightbox == 1) {
			$('.lightbox-content').html('<a href="#" onclick="closeLightbox(1); return false">Return to Details</a><img src="'+imgPreloader.src+'" title="click to close" /><div id="overImg"></div>');
			$('.lightbox-content').show();
			$('.lightbox-loading').hide();
			$('.lightbox-container-image-box').click(function() {
				closeLightbox(1);
				return false;
			});
			
			$('.lightbox-container-image-box').css({ width: imgPreloader.width, height: 552 + 101 }); // imgPreloader.height
			
			imgPreloader.onload=function(){};
		}
	};
	imgPreloader.src = imageFile;
	
	setupWindowResize();
}
	
function setupWindowResize(){
	$(window).resize(function() {
			// Get page sizes
			var arrPageSizes = ___getPageSize();
			// Style overlay and show it
			$('#jquery-overlay').css({
				width:		arrPageSizes[0],
				height:		arrPageSizes[1]
			});
			// Get page scroll
			var arrPageScroll = ___getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			$('#jquery-lightbox').css({
				top:	arrPageScroll[1],
				left:	arrPageScroll[0]
			});
			$('#jquery-blank-anchor').css({
					top: arrPageScroll[1]
				})
		});
	
	var arrPageScroll = ___getPageScroll();
	$('#jquery-blank-anchor').css({
			top: arrPageScroll[1]
		})
}



function pdf(pdffile, title) {
	msg=window.open("","janmurphygallery",",width=670,height=550,left=20,top=20,resizable=yes,menubar=no,location=no,directories=no,status=yes");
	msg.document.write("<html><title>" + title + "</title>");
	msg.document.write("<frameset border=0 rows='100%,*' frameborder='no' marginleft='0' margintop='0' marginright='0' marginbottom='0'>");
	msg.document.write("<frame src='" + pdffile + "' scrolling='auto' frameborder='no' border='0' noresize>");
	msg.document.write("<frame  topmargin='0' marginwidth='0' scrolling='no' marginheight='0' frameborder='no' border='0' noresize>");
	msg.document.write("</frameset><noframes><a href='" + pdffile + "'>Pdf File</noframes></html>");
}

function getObj(objectId)
{
// cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	this.obj = document.getElementById(objectId);
	this.style = document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	this.obj = document.all(objectId);
	this.style = document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	this.obj = document.layers[objectId];
	this.style = document.layers[objectId];
    } else {
	return false;
    }
}

//------------End Floating Objects---------------

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

//-->







/*
 THIRD FUNCTION
 getPageSize() by quirksmode.com
 
 return Array Return an array with page width, height and window width, height
*/
function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

/*
 THIRD FUNCTION
 getPageSize() by quirksmode.com
 
 return Array Return an array with page width, height and window width, height
*/
function ___getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};
