/**************************************/
/* Copyright © Jürgen Reule 2010-2012 */                      // RESIZE
/**************************************/

function error() {
  return true;
}
function size() {

    w =  image2.width;
    h =  image2.height;

    if  (w > 30
    &&   h > 30) {
         maxWidth   = 0;
         maxWidth2  = 0;
         maxHeight  = 0;
         maxHeight2 = 0;
         window.clearTimeout(resizeTimeout);
         window.onorientationchange = resize;
         resizeImage(32);
    }
    else window.setTimeout("size()", 1);
}
function resize() {
         window.clearTimeout(resizeTimeout);
         resizeImage(16);
}
function resizeImage(count) {

    if (count <= 0) return;

    maxWidth  = windowWidth();
    maxHeight = windowHeight();

    if ((maxWidth2  != maxWidth)
    ||  (maxHeight2 != maxHeight)) {
         maxWidth2   = maxWidth;
         maxHeight2  = maxHeight;

         maxWidth    = maxWidth  - 48;
         maxHeight   = maxHeight - 36;

         w1 = w;
         h1 = h;

         if (h/w >= 4/3)
             maxHeight =
             maxHeight * (1/3 + h/w);

         if (w1 > maxWidth) {
             w1 = maxWidth;
             h1 = maxWidth  * h/w;
         }
         if (h1 > maxHeight) {
             h1 = maxHeight;
             w1 = maxHeight * w/h;
         }
         image1.width  = Math.round(w1);
         image1.height = Math.round(h1);

     if (image1.src != image2.src)
         image1.src  = image2.src;
    }
    if ((navigator.userAgent.indexOf("iPad")      >= 0)
    ||  (navigator.userAgent.indexOf("iPod")      >= 0)
    ||  (navigator.userAgent.indexOf("iPhone")    >= 0)
    ||  (navigator.userAgent.indexOf("Mobile")    >= 0)
    ||  (navigator.userAgent.indexOf("Android")   >= 0)
    ||  (navigator.userAgent.indexOf("PlayBook")  >= 0)
    ||  (navigator.userAgent.indexOf("BlackBerry")>= 0)
    ||  (navigator.userAgent.indexOf("webOS")     >= 0)) count--;

    resizeTimeout = window.setTimeout("resizeImage("+count+")", 1);
}
function windowWidth() {

       if (window.innerWidth)
    return window.innerWidth;

       if (document.body
       &&  document.body.clientWidth)
    return document.body.clientWidth;

       if (document.documentElement
       &&  document.documentElement.clientWidth)
    return document.documentElement.clientWidth;

    return 0;
}
function windowHeight() {

       if (window.innerHeight)
    return window.innerHeight;

       if (document.body
       &&  document.body.clientHeight)
    return document.body.clientHeight;

       if (document.documentElement
       &&  document.documentElement.clientHeight)
    return document.documentElement.clientHeight;

    return 0;
}
window.onerror = error;

if (document.images
&&  document.getElementsByTagName) {

    scripts    = document.getElementsByTagName("script");
    scriptsrc  = scripts[scripts.length - 1].src;
    scriptname = scriptsrc.substring(0,
                 scriptsrc.lastIndexOf("."))

    image1     = document.images[document.images.length - 1];
    image2     = new Image();

    if (typeof(image2.width) == "number") {
         image2.src = image1.src; image1.src = scriptname + ".gif"; }
    else image2     = image1;

    resizeTimeout  = window.setTimeout("", 0);

    window.setTimeout("size()", 0);
}


