

function getWindowHeight() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
return myHeight;
}

function getWindowWidth() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
return myWidth;
}

function origSize() {
    getSizes();
    document.getElementById('pic').style.width = myPicOrigWidth + "px";
    document.getElementById('pic').style.height = myPicOrigHeight + "px";
}

function size_choice(command) {

    url = "/inc/sizechoice.php?choice=" +command;
    divname = "size_choice";
    loadingstate = false;
    retrieveURL(url);
    
    my_size_choice = command;
    if (command == "on") {
        picSize();
    } else if (command == "off") {
        origSize();
    }
    
}

var my_size_choice
        
function picSize() {
    if (my_size_choice == undefined) {
        my_size_choice = document.getElementById('current_choice').value;
    }

if (my_size_choice == "on") {
    getSizes();
  var myWidth = 0, myHeight = 0;
  myHeight = getWindowHeight();
    myWidth = 640;
     myHeight = myHeight - document.getElementById('picture').offsetTop - 10;
     myRatio = myWidth / myHeight;
	if (myRatio > myPicRatio) {
		myPicNewHeight = myHeight;
                myPicNewWidth = myHeight * myPicRatio;
	} else {
		myPicNewWidth = myWidth;
		myPicNewHeight = myWidth / myPicRatio;
	}
	document.getElementById('pic').style.width = myPicNewWidth + "px";
	document.getElementById('pic').style.height = myPicNewHeight + "px";
}
}

function getSizes() {
	origImg = new Image();	
	origImg.src = document.getElementById('pic').src;
    myPicOrigWidth = origImg.width;
    myPicOrigHeight = origImg.height;
    myPicRatio = myPicOrigWidth / myPicOrigHeight;
}

function thumbnail_window_size() {
    myNeededWidth = 750;
    myAvailableWidth = document.getElementById('title_block').offsetWidth - document.getElementById('thumbnails').offsetLeft;
        myMaxThumbWidth = (myAvailableWidth - 20) / 3;
        if (myMaxThumbWidth > 240) {
            myMaxThumbWidth = 240;
        }
        myThumbArray = getElementsByClassName(document, "img", "thumbnail");
        for (var n = 0; n < myThumbArray.length; n++) {
            var origImg = new Image();
            origImg.src = myThumbArray[n].src;
            myThumbWidth = origImg.width;
            myThumbHeight = origImg.height;
            myThumbRatio = myThumbWidth / myThumbHeight;
            if (myThumbRatio < 1) {
		          myThumbNewHeight = myMaxThumbWidth;
                  myThumbNewWidth = myThumbNewHeight * myThumbRatio;
	       } else {
		          myThumbNewWidth = myMaxThumbWidth;
		          myThumbNewHeight = myThumbNewWidth / myThumbRatio;
	       }
	       
	       myThumbArray[n].style.width = myThumbNewWidth + "px";
	       myThumbArray[n].style.height = myThumbNewHeight + "px";
            
        }
            
}

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}


