function docSize(axis) { // return viewable doc width or height based on given axis
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if(axis=='y') return myHeight;
  else return myWidth;
}
function imgPlSize() {
	var nimg = new Image();
	nimg.src = $('bigimgsrc').src;
	iwidth = nimg.width;
	iheight = nimg.height;
	gwidth = docSize()/1.25;	// set image maximum width to 80% of viewable doc
	gheight = docSize('y')/1.25;	// set image maximum height to 80% of viewable doc
	
	//$('bigimgsrc').style.width='';
	//$('bigimgsrc').style.height='';
	//$('bigimgcap').style.width='';
	
	eval_r = iwidth/iheight > gwidth/gheight;	// If the ratio > goal ratio 
	eval_w = iwidth > gwidth;			// and the width > goal width resize down to goal width
	eval_h = iheight > gheight;			// Otherwise, if the height > goal, resize down to goal height
	$('bigimgsrc').style.width = (eval_r && eval_w) ? gwidth+'px' : (eval_h) ? (gheight/iheight*iwidth)+'px' : '';
	$('bigimgsrc').style.height = (eval_r && eval_w) ? (gwidth/iwidth*iheight)+'px' : (eval_h) ? gheight+'px' : '';
	$('bigimgcap').style.width = (eval_r && eval_w) ? gwidth+'px' : (eval_h) ? (gheight/iheight*iwidth)+'px' : iwidth+'px';
	
	$('bigimgsrc').style.marginTop=((docSize('y')/10)-10)+'px';	// push the image down 10% from top of viewable doc, account for padding
	$('bigimg').style.display='';
}
function preload_bimg() {
	var imgLoad = new Array();
	//var arLen=imgpl.length;
	//for ( var i=0, len=arLen; i<len; ++i ){  }
	// http://stackoverflow.com/questions/1284212/prototype-add-event-listener/1284282#1284282
	$$('.bimglink').each(function(elm, i) {
		imgLoad[i] = new Image();
		imgLoad[i].src = imgpl[i][0];
		imgpl[i][1] = (imgpl[i][1] == '&nbsp;') ? ' ' : imgpl[i][1];
		elm.observe('click', function(event) {
			$('bigimgsrc').src=imgpl[i][0];
			imgPlSize();
			$('bigimgcap').innerHTML='<strong>'+imgpl[i][1]+'</strong>';
		});
	});
}

