function resizeImage() {
	// this should work in almost any browser
	var winWidth, winHeight, d=document;
	if (typeof window.innerWidth!='undefined') {
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	} else {
		if (d.documentElement && typeof d.documentElement.clientWidth!='undefined' 
		&& d.documentElement.clientWidth!=0) {
			winWidth = d.documentElement.clientWidth;
			winHeight = d.documentElement.clientHeight;
		} else {
			if (d.body && typeof d.body.clientWidth!='undefined') {
				winWidth = d.body.clientWidth
				winHeight = d.body.clientHeight
  			}
		}
	}
    //alert ("self.innerWidth: " + self.innerWidth + "\nself.innerHeight: " + self.innerHeight);
    //alert ("Available width: " + self.screen.availWidth);
    //alert ("Available height: " + self.screen.availHeight);
    //alert ("innerWidth: " + self.innerWidth);
    //alert ("innerHeight: " + self.innerHeight);
    // get our inmage height and width
    var old_imgHeight = document.images[0].height;
    var old_imgWidth = document.images[0].width;
    var img_ratio = old_imgHeight/old_imgWidth;
    var imgWidth = 10;
    var imgHeight = 10;
    // check if our width is image size plus 140
    if (winWidth < (old_imgWidth + 140)) {
        //resize image wifth
        imgWidth = winWidth - 140;
    } else {
        imgWidth = old_imgWidth;
    }
    // check if our height is image size plus 139
    if (winHeight < (old_imgHeight + 139)) {
        imgHeight = winHeight - 139;
    } else {
        imgHeight = old_imgHeight;
    }

    // check img ratio
    if (imgHeight/imgWidth == img_ratio) {
        //ratio ok. do nothing
    } else if (imgHeight/imgWidth > img_ratio) {
        // img width less than what is required for img height
        // decrease img height
        imgHeight = img_ratio * imgWidth;
    } else if (imgHeight/imgWidth < img_ratio) {
        // img height less than what is required for img width
        // decrease img height
        imgWidth = imgHeight / img_ratio;
    }

    // set our new img height and width
    document.images[0].height = imgHeight;
    document.images[0].width = imgWidth;
    document.getElementById("pic").style.width = imgWidth + 'px';
    document.getElementById("caption").style.width = imgWidth + 'px';
    var imageLocation = document.images[0].src;
    parent.updateViewImageLink(imageLocation, old_imgHeight, old_imgWidth);
}