/***********************************************************************
 Slider
 Code impilments a slider that allows user to slide slider
 to a position that will cause the page to change.

 Set up the following goes at the end of the page in a javascript

 This sets up all the posible choices parms are
    width of graphic for choice
    left psoition of graphic for choice
    url that that choice should take you to
    last 3 are not implimented yet, but allow you to change the choice image on arivale etc.
  var sliderchoices = new Array();
  sliderchoices[0]= new choiceOBJ(61,280,'index1.html',"","","");
  sliderchoices[1]= new choiceOBJ(95,410,'index1.html',"","","");
  sliderchoices[2]= new choiceOBJ(86,574,'index1.html',"","","");

 This stuff sets up the slider and some browser sniffing. Tolerance is the distance
 on either side of the center of a choice that the slider image will change and
 if the user releases the mouse the slider will jump to it. Delay is the time in
 ms that position will wait to change hrefs after a reposition that is not initilization.
  sliderOBJ.prototype.choices = sliderchoices;
  var slider=0;
  var tolerence = 20;
  var delay = 2000;
  var moz=document.getElementById&&!document.all;
  var noPx = document.childNodes ? 'px' : 0;
 The followind goes inside a script tag in the head section and identifies which
 slider position the page belongs to.
     var pagegroup=1;

 The following needs to be located in a onload function for the body as it
 must run after the page is loaded so the elements will exist. sliderOBJ Parms are
    name(id) of the div with the slider
    name(id) of the img object in the div that repersents the slider
    width of the graphic
    source for the graphic
    source for an alternate graphic to use when slider is w/i tolerance of a choice
 The function slider.position sets the initial position of the slider. Use a javascript variable in the head section to
 identify the choice that this page belongs to.  The second parm if true says that the use of position is for initialization
 versus a call trigered by some other action, thus position should not change the href of the page.
  slider = new sliderOBJ("sliderdiv","sliderimg",92,"graphics/sliderbase.gif","graphics/sliderbaseo.gif");
  slider.position(pagegroup,true);

 Example HTML
  <DIV name="hometext" id="hometext">
  <A class="gbutton" HREF="index.shtml"><IMG WIDTH="61" HEIGHT="18" onClick="slider.position(0,false);" ALT="Home of the SAS editor" SRC="graphics/homebase.gif" BORDER="0" ></A>
  </DIV>
  <DIV name="prodtext" id="prodtext">
  <A class="gbutton" HREF="index.shtml"><IMG WIDTH="95" HEIGHT="18" onClick="slider.position(1,false);"  ALT="SAS editing tool" SRC="graphics/prodbase.gif" BORDER="0"></A>
  </DIV>
  <DIV name="supptext" id="supptext">
  <A class="gbutton" HREF="index.shtml"><IMG WIDTH="86" HEIGHT="22" onClick="slider.position(2,false);"  ALT="Support for your SAS toolkit" SRC="graphics/suppbase.gif" BORDER="0"></A>
  </DIV>
  <DIV name="sliderdiv" id="sliderdiv"  onMouseDown="slider.startmove(event);" >
  <IMG name="sliderimg" id="sliderimg"   WIDTH="92" HEIGHT="27"  ALT="Tools for SAS programming" SRC="graphics/sliderbase.gif" BORDER="0">
  </DIV>
 Example CSS
  #hometext { top: 21px; left: 280px;   height: 18px;   position: absolute;   display: block;   }
  #prodtext {   top: 20px;   left: 410px;   height: 18px;   position: absolute;   display: block;   }
  #supptext {   top: 19px;   left: 574px;   height: 22px;   position: absolute;   display: block;   }
  #sliderdiv {   top: 44px;   left: 266px;   height: 27px;   width:200px;   position: absolute;   display: block;   cursor: hand;   cursor: pointer;   }


       /***# Comment Out Start Debug *********************
function debug(message) {
  if (window.netscape) {
    try {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
      jsConsoleService = Components.classes['@mozilla.org/consoleservice;1'].getService();
      jsConsoleService.QueryInterface(Components.interfaces.nsIConsoleService);
      jsConsoleService.logStringMessage(message)
    } catch (e) {
    }
  } else {
    //alert(message);
  }
}
       **************************** Comment Out End #***/
var cursorX = 0;

function choiceOBJ( width,left,url,imgname,pic,altpic )
/*****************************************************************
  Creates object to hold atributes of each slider location
    width - width of graphic used to represent a choice
    left - left px relitive to client area for graphic
    url - place to go when slider moved to there
    imgname - name or id of img holding graphic
    pic - graphic that is normal version of choice
    altpic - location of graphic to change to when slider arrives
                              6/13/2005 4:32PM
*****************************************************************/
{

  this.width = width;
  this.left = left;
  this.center = Math.floor(left + (width/2));
  this.url = url;
       /***# Comment Out Start Debug *********************       This functionality not implimented yet
  this.altpic = altpic;
  this.pic = pic;
  //get handle to image
  this.imgobj = new Image() ;
  stringe =  'document.all.' +imgname ;
  stringm = 'document.getElementById("'+imgname+'")';
  this.imgobj = document.all? eval(stringe) : eval(stringm)  ;;
       **************************** Comment Out End #***/

}  // choiceOBJ

function sliderOBJ( divname,imgname,width,pic,altpic )
/*****************************************************************
  Create an object to hold slider atributes
    width - width of graphic used to represent a choice
    imgname - name or id of img holding graphic
    divname - name or id of div holding the img
    pic - location of graphic that is normal version of choice
    altpic - location of graphic to change to when slider arrives

                              6/13/2005 4:55PM
*****************************************************************/
{

  this.width = width;
  this.center = Math.floor(width/2);
  this.moving = false;
  this.inzone = -1;      // -1 is not in any zone otherwise = choice index

  var maxchoice = this.choices.length - 1;
  this.min = this.choices[0].center - this.center;
  this.max = this.choices[maxchoice].center - this.center;

  this.altpic = altpic;
  this.pic = pic;

  //get handle to style of object
  var stringe =  'document.all.' +divname+ '.style' ;
  var stringm = 'document.getElementById("'+divname+'").style';
  this.divobj = document.all? eval(stringe) : eval(stringm)  ;

  //get handle to image
  this.imgobj = new Image() ;
  stringe =  'document.all.' +imgname ;
  stringm = 'document.getElementById("'+imgname+'")';
  this.imgobj = document.all? eval(stringe) : eval(stringm)  ;;

  this.position = positionFunction;
  this.startmove = startmoveFunction;
  // sliderOBJ.prototype.choices = sliderchoices;   is done after choice array created


}  // sliderOBJ

function positionFunction( choicenum,initial )
/*****************************************************************
  Sets the position of slider
    choicenum - index of choice that this is page for. This should be
                set in the head to reflect what page group this
                page belongs to.
                              6/13/2005 5:28PM
*****************************************************************/
{
 var left = this.choices[choicenum].center - this.center;
 this.divobj.left = left + noPx;
 this.inzone = choicenum;
 if ( !initial ) {
  //jump to new page
   window.setTimeout(window.location.href=this.choices[choicenum].url,delay) ;
 }
 else {
  this.divobj.visibility = 'visible';
 }

}  // positionFunction


function premove( e )
/*****************************************************************
  this deals with mozilla probs with onmousemove
                              6/15/2005 8:55AM
*****************************************************************/
{
 cursorX = moz ? e.clientX : event.clientX ;
 window.setTimeout("moveit(cursorX)",5);

}  // premove

function moveit(cursorX)
/*****************************************************************
  Intial function called when slider must move
                              6/14/2005 9:48AM
*****************************************************************/
{
  if ( slider.moving ) {
    //var cursorX = event.clientX;
    //var cursorX = moz ? e.clientX : event.clientX ;
    if ( cursorX < (slider.min +slider.center) ) {
      slider.divobj.left = slider.min + noPx;
    }
    else if ( cursorX > slider.max+slider.center ) {
      slider.divobj.left = slider.max + noPx;
    }
    else {
      var left = cursorX - slider.center;
      slider.divobj.left = left + noPx;
    }

    var slidecenter = parseInt(slider.divobj.left) + slider.center ;
        if ( slider.inzone != -1  ) {
      if ( !( (slidecenter <= (slider.choices[slider.inzone].center + tolerence) ) &&
              (slidecenter >= (slider.choices[slider.inzone].center - tolerence) ) ) ) {
        //debug("out of zone "+slider.inzone+" slidecenter="+slidecenter);
        //slider.swap();
        slider.imgobj.src = slider.pic ;
        slider.inzone = -1;
      }

    }
    else {
      var maxchoice = slider.choices.length - 1;
      var i=0;
      while ( i <= maxchoice  ) {
        if ( (slidecenter <= (slider.choices[i].center + tolerence) ) &&
             (slidecenter >= (slider.choices[i].center - tolerence) ) ) {
        //debug("in to zone "+i+" slidecenter="+slidecenter+" maxchoice="+maxchoice);
          //slider.swap();
          slider.imgobj.src = slider.altpic ;
          slider.inzone = i;
          i=maxchoice;
        }
        i++;
      }
    }

  }//if moving


}  // moveFunction


function endmove( event )
/*****************************************************************
  Toggles moving atribute to stop move from working
                              6/14/2005 10:13AM
*****************************************************************/
{
  //debug("standalone stopping");
  slider.moving = false;
  if ( slider.inzone != -1 ) {
    slider.position(slider.inzone);
    slider.imgobj.src = slider.pic ;
    window.location.href=slider.choices[slider.inzone].url ;
    slider.inzone = -1;
  }
  if (!moz) {
  document.detachEvent("onmousemove", premove);
  document.detachEvent("onmouseup", endmove);
  }
  if (moz) {
  document.removeEventListener("mousemove", premove, true);
  document.removeEventListener("mouseup", endmove, true);
  }

}  // endmoveFunction

function startmoveFunction( event )
/*****************************************************************
  Toggles moving atribute to allow move to work
                              6/14/2005 10:13AM
*****************************************************************/
{

  this.moving = true;
  if (!moz) {
  document.attachEvent("onmousemove", premove);
  document.attachEvent("onmouseup", endmove);
  window.event.cancelBubble = true;
  window.event.returnValue = false;
  }
  if (moz) {
  document.addEventListener("mousemove", premove, true);
  document.addEventListener("mouseup", endmove, true);
  event.preventDefault();
  }

}  // startmoveFunction




