/* movable container technique, by garvin hicking <me@supergarv.de> - 2003-08-08 */

/* set some defaults: */
var scrollstyle = 'Up'; // which direction first?
        // Scrollstart modified from original to allow the page height to change midway and still
        // start where it should, like in the hosting prices page.
// var scrollstart = '';   // start  in pixels where the scrolling starts (will be definded later automagically)
var scrollstartup = '';
var scrollstartdw = '';
var scrollend   = '';   // end    in pixels where the scrolling ends   (will be defined later automagically)
var scrollheight= 114;   // height in pixels, defined how large the scrollable item is. Has to be set manually
var finished    = true; // this variable defines whether an animation loop is finished. While it is not finished, no new loop can be started
var speed       = 5;

/* the 'constructor' function */
function scroller(element) {
    if (document.getElementById && finished) { // only use this function if no other loop is running and only if the browser supports DOM

        // Get the target element
        target           = document.getElementById(element);
        foot = document.getElementById('footer');

        
        // Scrollstart modified from original to allow the page height to change midway and still
        // start where it should, like in the hosting prices page.
        // Get current position
        //scrollstart      = position(target, 'y');
        if (browser.isIE4x || browser.isIE5x || browser.isIE6x) {
          scrollstartup = position(foot, 'y') + 7;
        } else {
          scrollstartup = position(foot, 'y');
        }
        scrollstartdw = position(target, 'y');
        
        // Next line moved into the 'if' that selects if we are going up or down. Jose
        // Set the current position. The container is placed absolutely, so this can be done easily.
        // target.style.top = scrollstart + 'px';

        // Does the user want to hide or show the box?
        if (scrollstyle == 'Up') {
            
            // Showing the box...
            target.style.top = scrollstartup + 'px';
            target.style.visibility = 'visible'; 
            scrollend = scrollstartup - scrollheight;
            scroll(element, speed, 1, scrollstartup);
        } else {
            
            // Hiding the box...
            target.style.top = scrollstartdw + 'px';
            scrollend = scrollstartdw + scrollheight;
            scroll(element, 2, -1, scrollstartdw);
        }
    }
}

// Repeatedly call this function to scroll down the element
// Jose -> Added 'init' to make clipping exact.
function scroll(elementname, speed, direction, init) {
    // Get object reference
    element = document.getElementById(elementname);

    // Get current location
    current = parseInt(element.style.top);
    what_is_left = Math.abs(current - scrollend);
    // Check if the box is still in our scrollable range
    if (what_is_left > 1) {

        // Jose -> We follow this formula: a = c - e 
        // a is the distance we want to travel. c is the current position and e is the final one.
        // we want a new a, let's call it h, that follows this formula:     h = a - a/s
        // s being the speed from 1 to whatever, fastest is 1
        // given that we can only modify c, we find h in function of c in the way up
        // c - e = a - a/s    [...]   c = e + a - a/s
        // and in function of e       c = e - a + a/s
        // I know it's not clear, but my maths are a bit rotten ;)
        new_current = scrollend + (direction * what_is_left) - ((direction * what_is_left)/speed);
        element.style.top = new_current + 'px';        
        // Of course we want to clip the area, only show what we want to see
        // Jose -> Use init and parseInt instead of counter for exact clipping.
        if (scrollstyle == 'Down') {
            element.style.clip = 'rect(0px 800px ' + (scrollheight-((parseInt(element.style.top)-init)+1)) + 'px 0px)';
        } else {
            element.style.clip = 'rect(0px 800px ' + ((init-parseInt(element.style.top))-1) + 'px 0px)';
        }

        // Make sure this animation is NOT FINISHED
        finished = false;

        // Call the next instance
        setTimeout('scroll("' + elementname + '", ' + speed + ', ' + direction + ', ' + init + ')', 30);
    } else {

        // Place the box at the final position.
        element.style.top = scrollend + 'px';
        // Jose -> and clip accordingly
        element.style.clip = 'rect(0px 800px ' + scrollheight + 'px 0px)';

        // Reverse the scrollstyle for the next loop
        if (scrollstyle == 'Down') {
            // Hides the element completely, if it has reached the end.
            element.style.visibility = 'hidden';
            scrollstyle = 'Up';
        } else {
            scrollstyle = 'Down';
        }

        // Yes, we are!
        finished = true;
    }
}

// Gets a position of an element on a certain axis
function position(element, axis) {
    if (axis == 'x') {
        return (element.x) ? element.x : subposition(element, 'Left');
    } else {
        return (element.y) ? element.y : subposition(element, 'Top');
    }
}

// Calculate possible referenced subpositions to really get the absolute position.
function subposition(element, axis) {
    currentPos = 0;
    while (element != null) {
        currentPos += element['offset' + axis];
        element     = element.offsetParent;
    }

    return currentPos;
}

/* Toggle table description. Jose Fandos 25/12/2003 */

function tdesc(el) {
  

  if (document.getElementById) {
    var tc   = document.getElementById(el);
    var tc_n = document.getElementById(el + "_n");
    var tc_i = document.getElementById(el + "_i");
    if (scrollstyle == 'Down' && finished) {
      scroller('moveablecontainer');
      setTimeout('tdesc("' + el + '")', 300);
    } else if (scrollstyle == 'Up' && finished) {
      if (!tc.style.display || tc.style.display == "none" ) {
        if (browser.isIE4x || browser.isIE5x || browser.isIE6x) {
          tc.style.display = "inline";
        } else {
          tc.style.display = "table-cell";
        }
        tc_i.style.background = "#fff url(/img/minfoicons.gif) no-repeat 0 -60px";
        tc_n.style.background = "#fff url(/img/tdescbg.gif) no-repeat left top";
      } else {
        tc.style.display = "none";
        tc_i.style.background = "#d6d1c7 url(/img/minfoicons.gif) no-repeat 0 0";
        tc_n.style.background = "#d6d1c7";
      }
    } 
  }
} 

// Browser Detect Lite  v2.1.4
// http://www.dithered.com/javascript/browser_detect/index.html
// modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)


function BrowserDetectLite() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser name
   this.isGecko     = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isMozilla   = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   this.isIE        = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) ); 
   this.isSafari    = (ua.indexOf('safari') != - 1);
   this.isOpera     = (ua.indexOf('opera') != -1); 
   this.isKonqueror = (ua.indexOf('konqueror') != -1 && !this.isSafari); 
   this.isIcab      = (ua.indexOf('icab') != -1); 
   this.isAol       = (ua.indexOf('aol') != -1); 
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isNS && this.isGecko) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
   }
   else if (this.isOpera) {
      if (ua.indexOf('opera/') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
      }
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isIcab) {
      if (ua.indexOf('icab/') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
      }
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin   = (ua.indexOf('win') != -1);
   this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac   = (ua.indexOf('mac') != -1);
   this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetectLite();
