var origWidth = 0;
var origHeight = 0;
var vspace = 280;
var hspace = 350;

function resizeImage() {
    var img = document.getElementById('bigimg');
    var loading = document.getElementById('loading');
    var firstTime = false;
    if (!origWidth) {
        firstTime = true;
        origWidth = img.width;
        origHeight = img.height;
    }
    var pageSize = getPageSize();
    var height = pageSize[3] - vspace;
    var width = (origWidth / origHeight) * height;
    
    if (width > pageSize[2] - hspace) {
        width = pageSize[2] - hspace;
        height = (origHeight / origWidth) * width;
    }
    if (height > origHeight) {
        height = origHeight;
        width = origWidth;
    }
    img.style.width = 0;
    img.style.height = 0;
    loading.style.display = 'none';
    img.style.visibility = 'visible';
    document.getElementById('imgdiv').style.height = 'auto';
    if (firstTime) {
        img.style.width = width + 'px';
        doHeightChangeMem(img,0,height,10,3,3);
    }
    else {
        img.style.width = width + 'px';
        img.style.height = height + 'px';
    }
}

function doHeightChangeMem(elem,startHeight,endHeight,steps,intervals,powr) { 
//Width changer with Memory by www.hesido.com
	if (elem.heightChangeMemInt)
	window.clearInterval(elem.heightChangeMemInt);
    var actStep = 0;
    elem.heightChangeMemInt = window.setInterval(
	function() { 
	  elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
	  elem.style.height = elem.currentHeight + 'px'; 
	  actStep++;
	  if (actStep > steps) window.clearInterval(elem.heightChangeMemInt);
	} 
	,intervals);
}
function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) { 
//Generic Animation Step Value Generator By www.hesido.com 
    var delta = maxValue - minValue; 
    var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta); 
    return Math.ceil(stepp) 
} 

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function handleKeyPress(evt) {
    if (!evt) { // for IE
        evt = window.event;
    }
    if (evt.keyCode == 37) { //left
        document.location = document.getElementById('prev').href;
    }
    else if (evt.keyCode == 39) { //right
        document.location = document.getElementById('next').href;
    }
}

