//--------------------------------------------------
//  IMAGE ROLLOVERS
//--------------------------------------------------

if(typeof(tamar_rollover_warnings) == 'undefined') {
  tamar_rollover_warnings = false;
}

tamar_rollovers = new Array();

function tamar_rollover(obj, onSrc, offSrc) {

  //if the objects already in the array, leave it
  for (var i=0; i<tamar_rollovers.length; i++) {
    if (obj == tamar_rollovers[i].obj) return
  }

  //assign image object to this object and create image objects
  this.obj     = obj;
  this.off     = new Image();
  this.off.src = offSrc || obj.src;
  this.on      = new Image();

  //see if an onSrc image was supplied
  if (onSrc) {
    //it was so set the mouseover image source the supplied one
    this.on.src = onSrc;

    //see if the on and off images supplied are the same. If they are fail. We only need to check here
    //as if an onSrc wasn't supplied we know they should take the form _on/_off
    if (this.off.src == this.on.src) {
      this.error_msg('image with tamar_rollover has the same mouseover/mouseout image');
      return;
    }
  } else {
    //a mouseover image was not supplied, so we're going to work it out
    //the original image should have the format imagename_off.ext
    //the new image will have the format imagename_on.ext
    
    //onSrc = /(\w*)_off\.(\w\w\w\w?)$/.exec(this.off.src)
    
    if (this.off.src.indexOf('_off') > -1) {
      //transforms the _off filename to be an _on filename
      newString = this.off.src.replace(/_off/i,"_on");
      this.on.src = newString;
    } else {
      //the image didn't follow the pattern imagename_off.ext
      this.error_msg('image with tamar_rollover failed to load a correct filename.\n(file should be called [name]_off.gif)');
      return;
    }
  }
  
  //check the mouseover images filesize to see if it has been loaded properly

  if ((this.on.width != this.off.width || this.on.height != this.off.height) && tamar_rollover_warnings) {
    this.error_msg('warning: image with tamar_rollover, dimensions of rollover images don\'t match');
  }

  //assign this object (tamar_rollover) to variable so we can assign it in functions below
  var thisObject  = this;
  
  //create handlers for image that change the image
  obj.onmouseover = function() { obj.src = thisObject.on.src  }
  obj.onmouseout  = function() { obj.src = thisObject.off.src }
  
  //push this object into the rollovers array
  tamar_rollovers[tamar_rollovers.length] = this;
}

tamar_rollover.prototype.error_msg = function(message) {
  alert(message);
  this.obj.style.border = '3px solid #ff3333';
}


//--------------------------------------------------
//  END IMAGE ROLLOVERS
//--------------------------------------------------


function go (selectOb) {
   var new_url = selectOb[selectOb.selectedIndex].value;

   if ( ! new_url ) return;

   if ( window.location.href == new_url ) return;

   window.location.href = new_url;
}

/* 
   openPopupPos creates a popup at (winnX, winnY)
*/
function openPopupPos (linkOb, thewidth, theheight, winnX, winnY, params) {
    var aname = 'popup';
    var url   = linkOb.href;

    if ( ! url ) {
        return true; // failed because no link to open!
    }
    
    if ( params ) {
        params = ',' + params;
    }

    str_WinParams = 'top=' + winnY+',left=' + winnX + params + ',width='+thewidth+',height='+theheight;

    thewindowobject = window.open(url,aname, str_WinParams);

    if (window.focus) thewindowobject.focus()

    if ( thewindowobject )
        return false; // success!!
    else
        return true; // failed
}

/* a slightly strange function because it returns 'true' when it fails
   and 'false' when it succeeds. This means that it can be used in an onclick event

   onclick="return openPopup(this, '')"

   openPopup creates a centered popup
*/
function openPopup (linkOb, thewidth, theheight, params) {
    var url  = linkOb.href;
    var winX = 0;
    var winY = 0;
    var winnX = 0;
    var winnY = 0;

    if ( ! url ) {
        return true; // failed because no link to open!
    }

    if ( screen ) {
        if ( thewidth != 0 ) {
            var diffX = (screen.width-thewidth); /* don't want to do a division by 0 */
            if ( diffX > 0 ) winnX = diffX / 2;
        } else {
            thewidth  = screen.width - 10;
        }

        if ( theheight ) {
            var diffY = (screen.height-theheight);
            if ( diffY > 0 ) winnY = diffY / 2;
        } else {
            theheight = screen.height - 10;
        }
    } else {
        if ( ! thewidth ) thewidth   = 795;
        if ( ! theheight ) theheight = 595;
    }

    return openPopupPos(linkOb, thewidth, theheight, winnX, winnY, params);
}

//--------------------------------------------------
//  NAV
//--------------------------------------------------

var navTimeout;
var delayAfterMouseOver = 200; /* in milliseconds */

function hideMenu() {
    obj=MM_findObj("menu_div1")
    if (obj.style) {
        obj.style.visibility = 'hidden';

    }
    navCont=MM_findObj("nav_container")
    navCont.style.visibility = 'hidden';
}

function dMM_showHideLayers(itemToShow) { //v3.0

  var itemCount = 1
  if ( navTimeout ) {
      clearTimeout(navTimeout);
      navTimeout = '';
  }

  if (itemToShow){
    obj=MM_findObj("menu_div" + itemToShow)
    if (obj.style) {
       obj.style.visibility = 'visible';
    }
    navCont=MM_findObj("nav_container")
    navCont.style.visibility = 'visible';
//    if ( navTimeout ) clearTimeout(navTimeout);
  } else if ( ! navTimeout ) {
    navTimeout = setTimeout("hideMenu()", delayAfterMouseOver);
  }
}

function MM_findObj(n, d) { //v4.0

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && document.getElementById) x=document.getElementById(n); return x;

}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//alert("common.js");