// JavaScript Document

function $(id) { return document.getElementById(id); }

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
	errors = "";
	var i,p,q,nm,test,num,min,max,args=MM_validateForm.arguments;
	for (i=0; i<(args.length-2); i+=3) { 
		test=args[i+2]; val=MM_findObj(args[i]); myName=args[i+1];
		if (val) { nm=val.name; if ((val=val.value)!="") {
			if (test.indexOf('isEmail')!=-1) { 
				p=val.indexOf('@');
				if (p<1 || p==(val.length-1)) errors+='- '+myName+' must contain an e-mail address.\n';
			} else if (test!='R') {
				num = parseFloat(val);
				if (isNaN(val)) errors+='- '+myName+' must contain a number.\n';
				if (test.indexOf('inRange') != -1) {
					p=test.indexOf(':');
					min=test.substring(8,p); max=test.substring(p+1);
					if (num<min || max<num) errors+='- '+myName+' must contain a number between '+min+' and '+max+'.\n';
				} 
			} 
		} else if (test.charAt(0) == 'R') errors += '- '+myName+' is required.\n'; 
		} 
	}
	if (errors) alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
}




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;
    }
}

function getLayerHt(wLayerObj){
	if (document.layers) {
		contHt = wLayerObj.style.clip.bottom;
	} else if (document.getElementById || document.all) {
		contHt = wLayerObj.obj.offsetHeight;
	}
	return contHt;
}



function buildScroller() {
	/*
	scrollDiv = new getObj('scrollLinks');
	contDiv = new getObj('lyr1');
	
	if (getLayerHt(contDiv) > 460) {
		scrollDiv.style.visibility = 'visible';
		initScrollLayer();
	} else {
		scrollDiv.style.visibility = 'hidden';
	}
	*/
	$(document).ready(
		function(){
			$(window).resize(function() {
				sizeContent();
			});
			sizeContent();
		}
	);
}

function initScrollPane(){
	$('#hold').jScrollPane({showArrows:true, scrollbarWidth:13, scrollbarMargin:0});
}

function sizeContent(){
	$("#hold").css({
		"height" : '40px'
	});
	$('#hold').jScrollPaneRemove();
	arrPageSizes = ___getPageSize();
	var pageHeight = arrPageSizes[1];
	var windowHeight = arrPageSizes[3];
	
	itemBodyOffset = $("#hold").offset();
	itemBodyHeight = windowHeight - itemBodyOffset.top - 60;
	
	var artworkHeight = $("#content .col2").innerHeight();
	itemBodyHeight = Math.max(artworkHeight, itemBodyHeight);
	
	$("#hold").css({
		// "height" : Math.min(728, itemBodyHeight)
		"height" : itemBodyHeight
	});
	
	initScrollPane();
}




function popupImg(wID, wWidth, wHeight){
	myWindow=window.open('popup_img.php?id='+wID,'','status=yes,width='+wWidth+',height='+wHeight+',scrollbars=0');
	myWindow.focus();
}




/*
 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;
};