// -*- mode: javascript -*- $Id: connies.js,v 1.2 2005/11/02 06:02:47 david Exp $
// based on nicely-documented example at http://www.quirksmode.org/js/mouseov.html
// (and other stuff, too)

var W3CDOM = (document.createElement && document.getElementsByTagName);

var mouseOvers = new Array();
var mouseOuts = new Array();

window.onload = init;


function init()
{
  if (!W3CDOM) return;


  // for mouseovers:

  // /////////////////////////////////////////////////////////////
  // document object ids (divs, etc.) to check
  var mouseover_ids = new Array('mouseovers-header', 'mouseovers-title', 'mouseovers-title2', 'mouseovers-title3', 'mouseovers-footer', 'mouseovers','mouseovers1','mouseovers2','mouseovers3','mouseovers4');

  // FIXME; these are the old-style names from pre-2011 connies.org; stop checking for these when all have been converted
  // var imgnameRegexp = /^(.*)_clickable(.*)$/;
  // var imgnameReplace = '$1_mouseover$2';

  // these are the new-style names for 2011
  // Contact_Clicked_2.png       News_Clicked_2.png   : used on current page (not clickable)
  // Contact_Hover_2.png         News_Hover_2.png     : mouseover
  // Contact_UnClicked_2.png     News_UnClicked_2.png : clickable
  var imgnameRegexp2 = /^(.*)_UnClicked(.*)$/;
  var imgnameReplace2 = '$1_Hover$2';
  // /////////////////////////////////////////////////////////////

  var externalhref_ids = new Array('mainContent','googlesearch');

  // /////////////////////////////////////////////////////////////




  // we'll temporarily hold the relevant images here:
  var mouseover_images = new Array();  // for the images actually affected


  while (mouseover_ids.length)
    {
      var mouseover_id = mouseover_ids.pop();


      var nav = document.getElementById(mouseover_id);
      if (nav) 
        {
          var anchors = nav.getElementsByTagName('a');
          for (var i=0 ; i < anchors.length ; i++)
	    { 
	      var anchor = anchors[i];
              var imgs = anchor.getElementsByTagName('img');
	      for (var j=0 ; j < imgs.length ; j++)
	        {
	          var img = imgs[j];
	          if (img.getAttribute('src').match(imgnameRegexp2)) mouseover_images.push(img);
	          /*else if (img.getAttribute('src').match(imgnameRegexp)) mouseover_images.push(img); */
                }
            }

          var inputs = nav.getElementsByTagName('input');
          for (var i=0 ; i < inputs.length ; i++)
	    {
	      var input = inputs[i];
	      if (input.getAttribute("type") == "image")
	        if (input.getAttribute('src').match(imgnameRegexp2)) mouseover_images.push(input);
	        /*else if (input.getAttribute('src').match(imgnameRegexp)) mouseover_images.push(input); */
            }

//        var buttons = nav.getElementsByTagName('button');
//        for (var i=0 ; i < buttons.length ; i++)
//	    { 
//	      var button = buttons[i];
//            var imgs = button.getElementsByTagName('img');
//	      for (var j=0 ; j < imgs.length ; j++)
//	        {
//	          var img = imgs[j];
//	          if (img.getAttribute('src').match(imgnameRegexp)) mouseover_images.push(img)
//              }
//          }

        }
    }

  for (var i=0 ; i < mouseover_images.length ; i++)
    {
      thing = mouseover_images[i];
      thing.onmouseover = mouseGoesOver;
      thing.onmouseout = mouseGoesOut;
      thing.number = i;

      mouseOuts[i] = new Image();
      mouseOuts[i].src = thing.src;
      mouseOvers[i] = new Image();
      mouseOvers[i].src = thing.src.replace(imgnameRegexp2, imgnameReplace2);
	// alert(mouseOuts[i].src)
	// alert(mouseOvers[i].src)

    }



  // for rel="external" href links (to open in a separate window)

  while (externalhref_ids.length)
    {
      var externalhref_id = externalhref_ids.pop();

      var nav = document.getElementById(externalhref_id);
      if (nav) 
	{
	  var anchors = nav.getElementsByTagName("a");
  	  for (var i=0; i<anchors.length; i++) 
    	    {
      	      var anchor = anchors[i];
      	      if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
                anchor.target = "_blank";
      	      if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup") 
                anchor.target = "connies_popup";
    	    }
        }
    }

}


function mouseGoesOver()
{
  this.src = mouseOvers[this.number].src;
}


function mouseGoesOut()
{
  this.src = mouseOuts[this.number].src;
}

// ================================


//  function getMouse(e){     // set mouse coordinates
//    e=e||window.event;
//    de=document.documentElement;b=document.body;
//    xMouse=e.clientX+(de.scrollLeft||b.scrollLeft)-(de.clientLeft||0);
//    yMouse=e.clientY+(de.scrollTop||b.scrollTop) - (de.clientTop||0);
//    while (xMouse>630) {xMouse-=10;} } // move popup away from right edge
//  function hideLayer(){document.getElementById("popObj").style.top="-500px";}
//  function popLayer(a){
//    if(!cap[a]){
//      cap[a]='<span class="pop">This popup (#'+a+') needs description';
//      cap[a]+=' text!<\/span>';}
//    desc='<table class="pop" summary="*">\n<tr class="pop'><';
//    desc+='td class="pop">\n<\/td><\/tr><\/table>';
//    document.getElementById('popObj').innerHTML=desc;
//    document.getElementById('popObj').style.left=xMouse+15+'px';
//    document.getElementById('popObj').style.top=yMouse-5+'px';}
//  cap=[];  // global array of popup captions
//  cap[0]='These popups can have varying width. ';
//  cap[0]+='It is dependent upon the text message.';
//  cap[1]='You can have <strong>two<\/strong> lines<br\/>and HTML content.';
//  cap[2]='You can also have images like this:<br\/><div class="pop">';
//  cap[2]+='<img src="images/zcrypt.gif"><\/div>';
//  cap[3]='You can put in a really long<br\/>description if it is nessary to';
//  cap[3]+='<br\/>explain something in detail,<br\/>';
//  cap[3]+='like a warning about content<br\/>or privacy.';
//  cap[4]='You can also have links like these:<br\>/<br\/>';
//  cap[4]+='<a href="http://google.com/">Google<\/a><br\/>';
//  cap[4]+='<a href="http://amazon.com/">Amazon<\/a><br\/>';
//  cap[4]+='<a href="http://mapquest.com/">MapQuest<\/a><br\/>';
//  cap[4]+='With a change in the onmouseout event handler.';
//  xMouse=0;yMouse=0;document.onmousemove=getMouse; // start event handler


