


$(document).ready(function(){

  // alert("Running document.ready");

    // menu rollovers
    $("#menubar div").each( function() {
      var menubar = this;
      menubar.onmouseover = function() {
      $(menubar).children("ul:first").css("display",'block');
      }
      menubar.onmouseout = function() {
      $(menubar).children("ul:first").css("display",'none');
      }

      });

    // if this is a popup for admin-editor
  var index = $(document).getUrlParam("wympreview");
  // alert("Got wympreview = "+index+"\n"+ "Got typeof(wympreview) = "+typeof(index));
  if (index && window.opener) {
    // alert("Filling in html");
    var xhtml = window.opener.document.forms[0].content.value;
    $("#content").html(xhtml);
  }
  $("#searchtext").focus();

   $("#imagetool").each( function() {
       var toolmode = false;
       $("#imagetool p").text("Click to annotate an image");
       var imagetool = this;
       imagetool.onclick = function() {
       if (toolmode) {
         toolmode = false;
         $("#imagetool p").text("Click to annotate an image");
         $(".annotateimage").each( function() {
             this.onclick = this.oldonclick;
             this.oldonclick = null;
          });
       } else {
         toolmode = true;
         $("#imagetool p").text("Click to cancel image-selection");
         $(".annotateimage").each( function() {
             if (this.onclick) {
               this.oldonclick = this.onclick;
             } else {
               this.oldonclick = null;
             }
             this.onclick = function() {
               var filename2 = this.src.substr(this.src.indexOf('//')+2);
               var filename = "image:"+filename2.substr(filename2.indexOf('/'));
               filename = filename.replace(/\//g,'%2F');
               filename = filename.replace(/\%20/g,'+');
               filename = filename.replace(/\,/g,'%2C');
               // alert("Got filename = "+filename);
               if (!document.getElementById(filename)) {
                 alert("ERROR -- cannot find image filename -- "+filename);
               } else {
                 // alert("Setting num = "+num);
                 var fileid = $(document.getElementById(filename)).text();
                 window.open("/Image_Draw.php?id="+fileid);
                 return false;
               }
             };
         });
        }
       }
    });

// setup search-box
/*
  var searchobj = document.getElementById("search");
  if (searchobj) {

    if ((searchobj.value == "")||(searchobj.value=="Search")) {
      searchobj.className = "dimmed";
      searchobj.value = "Search";
    }
    searchobj.onclick = function() {
      var thisobj = document.getElementById("search");
      if (thisobj.className=="dimmed") {
        thisobj.value = "";
        thisobj.className = "";
      }
    }
    searchobj.onblur = function() {
      var thisobj = document.getElementById("search");
      if (thisobj.value=="") { // return to dimmed
        thisobj.className = "dimmed";
        thisobj.value = "Search";
      }
    }
  }
*/
    
  /*
  $("#searchtext").each(function() {
    $("#subnav a").click(function() {
       var target = $(this).attr("href");
       var srch = $("#searchtext").attr("value");
       if (target.indexOf('?') == -1) {
           location.href=target+'?searchtext='+escape(srch);
         } else {
           location.href=target+'&searchtext='+escape(srch);
         }
       return false;
    });
    });
    */
});

function screen_size() {
  var screenW = 640, screenH = 480;
  if (screen) {
    if (screen.width) {
      screenW = screen.width;
      screenH = screen.height;
    }
  }
  document.screenW = screenW;
  document.screenH = screenH;
}
// create popup window for image
function image_popup (id,name,heightd,widthd) {
  var topd, leftd;

  heightd = heightd+250;
  widthd = widthd+100;

  screen_size();

  if (widthd>document.screenW) {
    leftd=0;
    widthd=document.screenW;
  } else {
    leftd=Math.round(document.screenW/2)-Math.round(widthd/2);
  }
  
  if (heightd>document.screenH) {
    topd=0;
    heightd=document.screenH;
  } else {
    topd=Math.round(document.screenH/2)-Math.round(heightd/2);
  }

  // Patch for IE window-name compatibility
  name2 = name.replace(/ /g,'_');
  name3 = name2.replace(/\-/g,'_');

  window.open("/admin/image_detail.php?id="+id, name3, "top="+topd+",left="+leftd+",width="+widthd+",height="+heightd+",toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=1,copyhistory=0,menuBar=0");

}



