var rollImgPath = "";
var orgImgPath = "";
var initDone, i, thisOrgSrc, thisImgSrcName, HoverImgSrc, thisImgTail, thisImgMain, thisHoversrc;;
var rollExt = '.down';
var splitAr = new Array();
var iNArray = new Array();
var counter = 0;
var HoverArray = new Array();
var iNarrayOrgSrc = new Array();
var ImgContainer = new Array();
var AllImgNameContainer = new Array();

function initNavRollover(){
  if (document.images) {
    for(i=0; i<= document.images.length-1; i++){
      if(document.images[i].name != ""){
        thisOrgSrc = document.images[i].src;
        splitAr = thisOrgSrc.split("/");
        thisImgSrcName = splitAr[splitAr.length-1];
        if(document.images[i].name == thisImgSrcName){
          rollImgPath = thisOrgSrc.substr(0,thisOrgSrc.length-thisImgSrcName.length);
          HoverImgSrc = getHoverImg(thisImgSrcName);
          iNarrayOrgSrc[document.images[i].name] = document.images[i].src;
          HoverArray[document.images[i].name] = new Image;
          HoverArray[document.images[i].name].src = HoverImgSrc;
          ImgContainer[counter] = document.images[i].name;
          counter++;
          AllImgNameContainer[document.images[i].name] = true;
        } else {
          AllImgNameContainer[document.images[i].name] = false;
        }//if
      }//if
    }//for
    initDone=true;
  } else {
    initDone=false;
  }//if

}//function


function getHoverImg(OrgImgSrc){
  thisImgTail = OrgImgSrc.substring(OrgImgSrc.length-4,OrgImgSrc.length);
  thisImgMain = OrgImgSrc.substring(0,OrgImgSrc.length-4);
  thisHoversrc = rollImgPath+thisImgMain+rollExt+thisImgTail;
  return thisHoversrc;
}

function checkImageName(name){
  if(AllImgNameContainer[name])
    return true;
  else
    return false;
}

function place(name) {
  if ((initDone) && (checkImageName(name))) {
    document.images[name].src=HoverArray[name].src;
  } // if
}//function
function remake(name) {
  if ((initDone) && (checkImageName(name))) {
    document.images[name].src=iNarrayOrgSrc[name];
  } // if
}//function


/**
 * Opens a simple popup-window
 *
 * @param string url
 * @param integer width
 * @param integer height
 * @return object
 */
function openPopup(url, width, height)
{
  // i guess this way every window will have its unique name
  i = 0;
  opts = 'width='+width+', height='+height+', top=150, left=150, '+
         'scrollbars=no, location=no, menubar=no, resizable=no, '+
         'status=no, toolbar=no';
  return window.open(url, 'window_'+i++, opts);
} // end open	up()


/**
 * Opens a pop up window
 *
 * @param   string  url
 * @param   integer width
 * @param   integer height
 * @param   string  title
 * @return  boolean
*/
function popup(url) {

  var width = (arguments.length > 1) ? parseInt(arguments[1]) : 620;
  var height = (arguments.length > 2) ? parseInt(arguments[2]) : 620;
  var title = (arguments.length > 3) ? arguments[3] : '';
  var props = "width=" + width + ",height=" + height + ",resizable=yes,menubar=no,locationbar=no,status=no,scrollbars=yes,depend=yes,top=140,left=220";
  var popup;

  if (popup == window.open(url, title, props)) {

    popup.focus();
    return true;
  }

  return false;
} // end function popup

