var imagemove = 1;

var vispics = 6;

var startpic = 1;

imagemove = 0;

var anime = 1;

var smallpic = new String;

var picnum = 0; 

var first = 0;

var second = 0;

var working = 0;

numpic = 0;

min = 0;

max = 0;

third=0;

speedtest = 2;



scrollerdist = 0;

distance = 0;

imagesrc = " ";



xMousePos = 0; // Horizontal position of the mouse on the screen

yMousePos = 0; // Vertical position of the mouse on the screen

xMousePosMax = 0; // Width of the page

yMousePosMax = 0; // Height of the page



direction = "null";

overobject = 0;



scrollerwidth = 0;

scrollerleft = 0;

g = 0;

scrollerfirst = 0;

scrollersecond = 0;

scrollerthird = 0;

scrollerclick = 0;

scrollermove = 0;



function loading() {



picnum = 0;

smallpic = "smallpic" + picnum;

while (document.getElementById(smallpic) != null) {

      numpic++;

      picnum++;

      smallpic = "smallpic" + picnum;

   }

min = 0 - ((numpic * 104) - ((vispics) * 104));

     //((numpic * 104) - ((vispics * 2) * 104));

if (numpic < 22) {

scrollerwidth = ((vispics * 104) - (((numpic * 104) - ((vispics) * 104))/4));

scrollerdist = 4;

}

if (numpic >= 22) {

scrollerdist = ((numpic * 104)/(vispics * 104));

scrollerwidth = ((vispics * 104) - (((numpic * 104) - ((vispics) * 104))/scrollerdist));

}

document.getElementById("scroller").style.width = scrollerwidth;

}



function thingyon() {

 if ((working == 0) && (overobject == 0)) {

      overobject = 1;

      captureMousePosition();

      first = xMousePos;   

 }

}



function thingyoff() {

      overobject = 0;

      if (working == 1) {

      working = 0;

      clearInterval(timer);      

      }

}



function mousemoving() {

     third = second; 

     if (overobject == 1) {

           captureMousePosition();

      second = xMousePos;

      if ((first != second) && (overobject == 1) && (working == 0)) {

            slider();    

      }

      else {

            help();

      }

      }

}



function slider() {

 if ((working == 0)  && (overobject == 1)) {

 if (second != first) {

    if ((second < (first - 100)) && (second > (first - 120))) {

       working = 1;

       timer = setInterval('movePicLeft(2)', 1);

       direction = "left";

    }

    if ((second < (first - 120)) && (second > (first - 140))) {

       working = 1;

       timer = setInterval('movePicLeft(4)', 1);

       direction = "left";

    }

    if (second < (first - 140)) {

       working = 1;

       timer = setInterval('movePicLeft(6)', 1);

       direction = "left";

    }





    if ((second > (first + 100)) && (second < (first + 120))) {

       working = 1;

       timer = setInterval('movePicRight(2)', 1);

       direction = "right";

    }

    if ((second > (first + 120)) && (second < (first + 140))) {

       working = 1;

       timer = setInterval('movePicRight(4)', 1);

       direction = "right";

    }

    if (second > (first + 140)) {

       working = 1;

       timer = setInterval('movePicRight(6)', 1);

       direction = "right";

    }

 }

 }

document.onMousemove = help();

}



function isdefined( variable)

{

    return (typeof(window[variable]) == "undefined")?  false: true;

}





function help() {

    if ((second == (first - 120)) && isdefined("timer")) {

    working = 0;

    clearInterval(timer);

    }

    if ((second == (first - 140)) && isdefined("timer")) {

    working = 0;

    clearInterval(timer);

    }







    if ((second <= (first + 100)) && (second >= (first - 100)) && isdefined("timer")) {

    working = 0;

    clearInterval(timer);

    }

    if ((second == (first + 120)) && isdefined("timer")) {

    working = 0;

    clearInterval(timer);

    }

    if ((second == (first + 140)) && isdefined("timer")) {

    working = 0;

    clearInterval(timer);

    }

    if (((second - third) == (0-1)) && (direction == "right") && (second > (first + 100))) {

    first = (second - 10);

    }

    if (((second - third) == 1) && (direction == "left") && (second < (first - 100))) {

    first = (second + 10);

    } 

}



function captureMousePosition(e) {

    if (document.layers) {

        xMousePos = e.pageX;

    } else if (document.all) {

        xMousePos = event.clientX + document.body.scrollLeft;

    } else if (document.getElementById) { 

        xMousePos = e.pageX;

    }

}



function buttonleft() {

if (imagemove <= (max- 1)) {

document.getElementById("previous").src = "leftbuttondown.jpg";

if (working == 0) {

         timer = setTimeout('buttonleft()', 1);

         movePicLeft(6);

         g += 6;

         if ((g >= 104) || (imagemove >= max)) {

             clearTimeout(timer);

             g = 0;

             document.getElementById("previous").src = "leftbutton.jpg";

         }

     }

}

}

         



function buttonright() {

if (imagemove >= (min)) {

document.getElementById("next").src = "rightbuttondown.jpg";

if (working == 0) {

         timer = setTimeout('buttonright()', 1);

         movePicRight(6);

         g += 6;

         if ((g >= 104) || (imagemove <= min)) {

             clearTimeout(timer);

             g = 0;

             document.getElementById("next").src = "rightbutton.jpg";

         }

     }

}

}



function movePicLeft(speed) {

picnum = 0;

smallpic = "smallpic" + picnum;

if (imagemove <= max) {

   while (document.getElementById(smallpic) != null) {

      document.getElementById(smallpic).style.left = imagemove;

      picnum++;

      smallpic = "smallpic" + picnum;

   }

      scrollerleft -= ((1/ scrollerdist) * speed) ;

      document.getElementById("scroller").style.left = scrollerleft;

      picnum = 1;

      imagemove += speed;

}

      imagesrc = (document.getElementById("previous").src).substring(((document.getElementById("previous").src).lastIndexOf('/'))+1);



      if ((imagemove <= max) && (imagesrc == "leftbuttondown.jpg")) {

          document.getElementById("previous").src = "leftbuttondown.jpg";

      }

      if ((imagemove <= max) && (imagesrc == "leftbutton.jpg")) {

          document.getElementById("previous").src = "leftbutton.jpg";

      }

      if ((imagemove <= max) && (imagesrc == "leftbuttonun.jpg")) {

          document.getElementById("previous").src = "leftbutton.jpg";

      }

      if (imagemove >= max) {

          document.getElementById("previous").src = "leftbuttonun.jpg";

      }

 imagesrc = (document.getElementById("next").src).substring(((document.getElementById("next").src).lastIndexOf('/'))+1);



      if ((imagemove >= min)  && (imagesrc == "rightbuttondown.jpg")) {

          document.getElementById("next").src = "rightbuttondown.jpg";

      }

      if ((imagemove >= min)  && (imagesrc == "rightbutton.jpg")) {

          document.getElementById("next").src = "rightbutton.jpg";

      }

      if ((imagemove >= min)  && (imagesrc == "rightbuttonun.jpg")) {

          document.getElementById("next").src = "rightbutton.jpg";

      }

      if (imagemove <= min) {

          document.getElementById("next").src = "rightbuttonun.jpg";

      }

}



function movePicRight(speed) {

picnum = 0;

smallpic = "smallpic" + picnum;

if (imagemove >= min) {

   while (document.getElementById(smallpic) != null) {

      document.getElementById(smallpic).style.left = imagemove;

      picnum++;

      smallpic = "smallpic" + picnum;

   }

      scrollerleft += ((1/ scrollerdist) * speed);

      document.getElementById("scroller").style.left = scrollerleft;

      picnum = 1;

      imagemove -= speed;

}

      imagesrc = (document.getElementById("previous").src).substring(((document.getElementById("previous").src).lastIndexOf('/'))+1);



      if ((imagemove <= max) && (imagesrc == "leftbuttondown.jpg")) {

          document.getElementById("previous").src = "leftbuttondown.jpg";

      }

      if ((imagemove <= max) && (imagesrc == "leftbutton.jpg")) {

          document.getElementById("previous").src = "leftbutton.jpg";

      }

      if ((imagemove <= max) && (imagesrc == "leftbuttonun.jpg")) {

          document.getElementById("previous").src = "leftbutton.jpg";

      }

      if (imagemove >= max) {

          document.getElementById("previous").src = "leftbuttonun.jpg";

      }

 imagesrc = (document.getElementById("next").src).substring(((document.getElementById("next").src).lastIndexOf('/'))+1);



      if ((imagemove >= min)  && (imagesrc == "rightbuttondown.jpg")) {

          document.getElementById("next").src = "rightbuttondown.jpg";

      }

      if ((imagemove >= min)  && (imagesrc == "rightbutton.jpg")) {

          document.getElementById("next").src = "rightbutton.jpg";

      }

      if ((imagemove >= min)  && (imagesrc == "rightbuttonun.jpg")) {

          document.getElementById("next").src = "rightbutton.jpg";

      }

      if (imagemove <= min) {

          document.getElementById("next").src = "rightbuttonun.jpg";

      }

}



function slideshow(picname,callpic) {



picnum = 0;

smallpic = "smallpic" + picnum;

   while (document.getElementById(smallpic) != null) {

        document.getElementById(smallpic).style.border = "none";

        picnum++;

        smallpic = "smallpic" + picnum;

   }

document.getElementById(callpic).style.border = "1px solid #FFFFFF";

document.getElementById("bigpic").src="loading.gif";



  pic1= new Image(100,25); 

  pic1.src= picname + ".jpg";

  pic1.onload = document.getElementById("bigpic").src=picname + ".jpg";



}





var mousex = 0;

var mousey = 0;

var grabx = 0;

var graby = 0;

var orix = 0;

var oriy = 0;

var elex = 0;

var eley = 0;

var algor = 0;



var dragobj = null;



function falsefunc() { return false; } // used to block cascading events



function init()

{

  document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE

  update();

}



function getMouseXY(e) // works on IE6,FF,Moz,Opera7

{ 

  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)



  if (e)

  { 

    if (e.pageX || e.pageY)

    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)

      mousex = e.pageX;

      mousey = e.pageY;

      algor = '[e.pageX]';

      if (e.clientX || e.clientY) algor += ' [e.clientX] '

    }

    else if (e.clientX || e.clientY)

    { // works on IE6,FF,Moz,Opera7

      mousex = e.clientX + document.body.scrollLeft;

      mousey = e.clientY + document.body.scrollTop;

      algor = '[e.clientX]';

      if (e.pageX || e.pageY) algor += ' [e.pageX] '

    }  

  }

}



function update(e)

{

  getMouseXY(e); // NS is passing (event), while IE is passing (null)





}



function grab(context)

{

  document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection

  dragobj = context;

  document.onmousemove = drag;

  document.onmouseup = drop;

  grabx = mousex;

  graby = mousey;

  elex = orix = dragobj.offsetLeft;

  eley = oriy = dragobj.offsetTop;

     scrollerfirst = scrollersecond;

  update();

}



function drag(e) // parameter passing is important for NS family 

{

  if (dragobj)

  {

     update(e);

     scrollersecond = mousex;

     if (scrollerfirst != 0) {

        scrollermove = ((Math.abs(scrollersecond - scrollerfirst)) * scrollerdist);

     }

     if (scrollerfirst < scrollersecond) {

       movePicRight(scrollermove);

     }

     if (scrollersecond < scrollerfirst) {

       movePicLeft(scrollermove);

     }

  }

  update(e);

  scrollerfirst = mousex;

  return false; // in IE this prevents cascading of events, thus text selection is disabled

}



function drop()

{

  if (dragobj)

  {

    dragobj.style.zIndex = 0;

    dragobj = null;

  }

  update();

  document.onmousemove = update;

  document.onmouseup = null;

  document.onmousedown = null;   // re-enables text selection on NS

}
