//---------------------------------------------------------------

function thumb(source,w,h,alt) {

//  function can handle 2 types of source input

// standardize the source - cut off both ends if  source is in the form ./../image/...jpg
if (source.substring(0,11) == './../image/'
&& source.substring(source.length-4,source.length) == '.jpg') {
    var stdSource = source.substring(11,source.length-4);
    } else {
    var stdSource = source;
}

// use DV for IE
if (MSIE4 || MSIE6) {
  var DVimage = '<img src="http://www.istok-ev.org/image/' + stdSource + '.jpg" border="0" alt="" width="' + w + '" height="' + h + '">';
     // --- display for debugging ---
    //alert(DVimage);
  dv.showDV(DVimage);
  return;
}


/*  --- display for debugging ---
alert("source = " + source +
"\nsource.substring(0,11) = " + source.substring(0,11) +
"\nsource.substring(source.length-4,source.length) = " + source.substring(source.length-4,source.length) +
        "\nw = " + w + 
        "\nh = " + h +
        "\nalt = " + alt);
*/
  
// capitalise first letter
var sourceName = stdSource.charAt(0).toUpperCase() + stdSource.substring(1,source.length);

// replace any underscores or slashes by space.
 for (var i = 0; i < 5; ++i) {
  sourceName = sourceName.replace(/_/,' ');   
  sourceName = sourceName.replace(/\//,' ');    
 }          

// capitalise letter after number or space.
 for (i = 0; i < sourceName.length; ++i) {
  if (sourceName.charAt(i)     == ' '
  || (sourceName.charCodeAt(i) >= 48    // ascii code for 0
  &&  sourceName.charCodeAt(i) <= 57 )) // ascii code for 9              
   sourceName = sourceName.substring(0,i + 1)
              + sourceName.charAt(i + 1).toUpperCase() 
              + sourceName.substring(i + 2,sourceName.length);
 } 
 
// if nothing was specified for alt then use sourceName.
 if (typeof alt != 'string' || alt == '') alt = sourceName;


// ---------------------------------------------------------------------------------------------------------------------
// position photo in middle of screen

var screenWidth,screenHeight;

if (MSIE4) {
  screenWidth  = document.body.clientWidth;
  screenHeight = document.body.clientHeight;
} else {
  if (MSIE6) {
    screenWidth  = document.body.offsetWidth;
    screenHeight = document.body.offsetHeight;
  } else {
    screenWidth  = innerWidth;
    screenHeight = innerHeight;
  }
}

var x = Math.ceil((screenWidth  - w) / 2);
var y = Math.ceil((screenHeight - h) / 2);

var appearance = 'left=' + x + ',top=' + y + ',width=' + w + ',height=' + h + ',scrollbars=no,status=no,toolbar=no,menubar=no,screenX=' + x + ',screenY=' + y

var target = sourceName.substring(sourceName.lastIndexOf(' ') + 1, sourceName.length-1); 
// target = .jpg name because MSIE freaks if there is a space in the target

var photo = window.open('',target,appearance);

 photo.focus();
 
 with (photo.document) {

  open();
  writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">');
  writeln('<html><head>');
  writeln('<title>Istok Photo: ' + sourceName + '</title>');
  writeln('<meta http-equiv="content-type" content="text/html; charset=windows-1251">');
  writeln('</head>');
  
  writeln('<body onclick="javascript:close();" onblur="javascript:close();" style="margin:0; text-align: center; vertical-align:middle; background-color: #a4ffff; background-image:url(./image/background_head.jpg);">');

//  writeln('<a href="javascript:close();" title="' + alt + '">'); firefox produced scrollbars
  writeln('<img style="border:0; text-align: center; vertical-align:middle;" src="./../image/' + stdSource + '.jpg" alt="' + alt + '" title="' + alt + '">'); // for everyone except firefox 3.0
  writeln('<img style="border:0; text-align: center; vertical-align:middle;" src="./image/' + stdSource + '.jpg" alt="' + alt + '" title="' + alt + '">'); // firefox 3.0 changes curent directory to root
  writeln('</body></html>'); 
  close(); 
 }
}


/*=============== DHTML-Bibliothek start=====================*/

var DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false, MSIE6 = false;

if (document.getElementById) {
  DHTML = true;
  DOM = true;
  if (typeof(innerWidth) == 'undefined') MSIE6 = true;
} else {
  if (document.all) {
    DHTML = true;
    MSIE4 = true;
  } else {
    if (document.layers) {
      DHTML = true;
      NS4 = true;
    }
  }
}




if (window.opera) {
  OP = true;
}

//alert('DHTML = ' +DHTML+ '\nDOM = ' +DOM+ '\nMSIE4 = ' +MSIE4+ '\nNS4 = ' +NS4+ '\nOP = ' +OP+ '\nMSIE6 = ' +MSIE6);
/*-------------------------------------------------------*/

function getElement (Mode, Identifier, ElementNumber) {
  var Element;
  if (DOM) {
    if (Mode.toLowerCase() == "id") {
      if (typeof document.getElementById(Identifier) == "object") {
        Element = document.getElementById(Identifier);
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "name") {
      var ElementList = document.getElementsByName(Identifier);
      if (typeof ElementList == "object" || (OP && typeof ElementList == "function")) {
        Element = ElementList[ElementNumber];
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      var ElementList = document.getElementsByTagName(Identifier);
      if (typeof ElementList == "object" || (OP && typeof ElementList == "function")) {
        Element = ElementList[ElementNumber];
      } else {
        Element = false;
      }
      return Element;
    }
    return null;
  }
  if (MSIE4) {
    if (Mode.toLowerCase() == "id") {
      if (typeof document.all[Identifier] == "object") {
        Element = document.all[Identifier];
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      if (typeof document.all.tags(Identifier) == "object") {
        Element = document.all.tags(Identifier)[ElementNumber];
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "name") {
      if (typeof document[Identifier] == "object") {
        Element = document[Identifier];
      } else {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (NS4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      if (typeof document[Identifier] == "object") {
        Element = document[Identifier];
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "index") {
      if (typeof document.layers[Identifier] == "object") {
        Element = document.layers[Identifier];
      } else {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  return false;
}


/*-------------------------------------------------------*/

function getContent (Mode, Identifier, ElementNumber) {
  var Content;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    if (Element.firstChild.nodeType == 3) {
      Content = Element.firstChild.nodeValue;
    } else {
      Content = "";
    }
    return Content;
  }
  if (MSIE4) {
    Content = Element.innerText;
    return Content;
  }
  return false;
}


/*-------------------------------------------------------*/

function getAttribute (Mode, Identifier, ElementNumber, AttributeName) {
  var Attribute;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM || MSIE4) {
    Attribute = Element.getAttribute(AttributeName);
    return Attribute;
  }
  if (NS4) {
    if (typeof Element[ElementNumber] == "object") {
      Attribute = Element[ElementNumber][AttributeName];
    } else {
      Attribute = Element[AttributeName]
    }
    return Attribute;
  }
  return false;
}


/*-------------------------------------------------------*/

function setContent (Mode, Identifier, ElementNumber, Text) {
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    Element.firstChild.nodeValue = Text;
    return true;
  }
  if (MSIE4) {
    Element.innerText = Text;
    return true;
  }
  if (NS4) {
    Element.document.open();
    Element.document.write(Text);
    Element.document.close();
    return true;
  }
 return false; // firefox 3.0 complained about "function does no t alwasy return a value"
}


/*==============DHTML-Bibliothek end===========================*/

