
function getPageDimensions () { 

  //Thanks to http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = document.getElementsByTagName('html')[0].offsetHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.getElementById('body').scrollHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array(myWidth,myHeight);
}

function getPageWidth () {
  var dimensions = getPageDimensions ();
  return dimensions[0];
}

function getPageHeight () {
  var dimensions = getPageDimensions ();
  return dimensions[1];
}

function getImageSize (fillin, swidth, sheight, dwidth, dheight) {
    if (fillin == "fit-in") {
        var dratio = dwidth/dheight;
        var sratio = swidth/sheight;
     
        if (dratio < sratio) {
            diff = dwidth/swidth;
            width = dwidth;
            height = diff*sheight;
            }
        else {
            diff = dheight/sheight;
            height = dheight;
            width = diff*swidth;
        }
        left = (dwidth/2)-(width/2);
        topp = (dheight/2)-(height/2);
   
        return [left, topp, width, height];
    }
    else {
        var dratio = dwidth/dheight;
        var sratio = swidth/sheight;
    
        if (dratio > sratio) {
            diff = dwidth/swidth;
            width = dwidth;
            height = diff*sheight;
        }
        else {
            diff = dheight/sheight;
            height = dheight;
            width = diff*swidth;
        }
        left = (dwidth/2)-(width/2);
        topp = (dheight/2)-(height/2);
        return [left, topp, width, height];
    }
}


