function debug(msg) {
   var dbOut = document.getElementById('debug');
   if (dbOut) {
      document.getElementById('debug').innerHTML = msg;
      }
}

function $() {
   var elements = new Array();
   for (var i = 0; i < arguments.length; i++) {
      var element = arguments[i];
      if (typeof element == 'string') element = document.getElementById(element);
      if (arguments.length == 1) return element;
      elements.push(element);
      }
   return elements;

}

function getContent(data, op, obj) {
   //alert(obj);
   //setVisibility('busy', 'visible');
   var rnd = '?rnd=' + Math.random();
   if (data.indexOf('?') > 0) {
      rnd = rnd.replace('?', '&');
      }
   if($(op)) {
      obj.open("GET", data + rnd, true);
      obj.onreadystatechange = function () {
          if (obj.readyState == 4) {
              //setVisibility('busy', 'hidden');

              if (obj == httpNotebook) {
                  var cls = '<div onclick="setupNotebook();" align="right" style="cursor:pointer;">close&nbsp;</div>';
                  $(op).innerHTML = cls + obj.responseText;
              }
              else {
                  $(op).innerHTML = obj.responseText;
                  window.location.hash = curSecCode;
                  vBars();
                  resize();

                  //var s = window.location.hash.replace('#', '');
                  //subNavExpand(s, $('nav' + s).getAttribute('layout'), true, '');
              }




              //if not IE, then fade, 'cause IE is not great at fading
              //if (BrowserDetect.browser !== 'Explorer') {
              // fadeDiv($(op), 0);
              //}

              if (obj.responseText.toString().indexOf('contentTab') > 0) {
                  if ($('imgContent')) {
                      if ($('imgContent').getAttribute('src') != null) {
                          loadImage($('imgContent').getAttribute('src'));
                      }
                  }
                  if ($('textContent')) {
                      if (editor) {
                          $('textContent').setAttribute('editable', 'true');
                      }
                      scroller();
                      hookEvent('textContent', 'mousewheel', MouseWheel);
                  }
                  if (BrowserDetect.browser != 'Explorer') {
                      setOpacity($(op), 0);
                      new Animate($(op), 'opacity', {
                          from: 0, to: 1, time: 500, callback: function () {
                              getKeyWords('keyWords.asp?sectionCode=' + curSecCode, httpKeyWords);
                              //getHighlighted('highlights.asp?sectionCode=' + curSecCode +'&UserID='+userID, httpHighlights);
                          }
                      }
                   ).start();
                  }

              }
          }


          if (obj == httpSecondNav) {
              if (fullSectionCode.length > 2) {

                  if ($('nav' + curSecCode)) {
                      subNavExpand('nav' + curSecCode, $('nav' + curSecCode).getAttribute('layout'), false);
                      //alert($('nav' + fullSectionCode).getAttribute('layout'));
                  }
              }
          }
      }
      obj.send(null);
      }
}

function getDefinition(data, op, obj) {
   //alert(obj);
   //setVisibility('busy', 'visible');
   $(op).innerHTML = "<div align=center><img src='images/wait.gif'></div>";
   var rnd = '?rnd=' + Math.floor(Math.random() * 11);
   if (data.indexOf('?') > 0) {
      rnd = rnd.replace('?', '&');
      }
   if ($(op)) {
      obj.open("GET", data + rnd, true);
      obj.onreadystatechange = function () {
         if (obj.readyState == 4) {
            //setVisibility('busy', 'hidden');
            $(op).innerHTML = obj.responseText;
            //if not IE, then fade, 'cause IE is crap at fading
            if (BrowserDetect.browser !== 'Explorer') {
               //fadeDiv($(op), 0);
               setOpacity($(op), 0);
               new Animate($(op), 'opacity', {
                  from : 0, to : 1, time : 500, callback : function () {
                     }
                  }
               ).start();
               }
            }
         }
      obj.send(null);
      }
}

function getHighlights(data, op, obj) {
   //alert(obj);
   //setVisibility('busy', 'visible');
   var rnd = '?rnd=' + Math.random();
   if (data.indexOf('?') > 0) {
      rnd = rnd.replace('?', '&');
      }
   if ($(op)) {
      obj.open("GET", data + rnd, true);
      obj.onreadystatechange = function () {
         if (obj.readyState == 4) {
            //obj.responseText
            //setVisibility('busy', 'hidden');
            }
         }
      obj.send(null);
      }
}

function getAnimFrames(data, obj) {
   framesArray = [];
   var rnd = '?rnd=' + Math.random();
   if (data.indexOf('?') > 0) {
      rnd = rnd.replace('?', '&');
      }
   obj.open("GET", data + rnd, true);
   obj.onreadystatechange = function () {
       if (obj.readyState == 4) {
           if (obj.responseText != '') {
               imagearray = obj.responseText.split("$");
               //alert(imagearray.length);
               //setupAnim('imgContent');
               var img = new Image();
               img.onload = function () {
                   setupAnim2(img, imagearray);
                   //setupAnim('imgContent');
               }
               var maxH = $('imgContent').offsetHeight;
               var maxW = $('imgContent').offsetWidth;
               //alert('image.aspx?f=' + imagearray[0] + '&mh=' + (maxH) + '&mw=' + (maxW));
               img.src = 'image.aspx?f=' + imagearray[0] + '&mh=' + (maxH) + '&mw=' + (maxW);

           }
           else {
               //alert('no frames loaded');
           }
       }
   }
   obj.send(null);


}

function getCaseFrames(data, obj) {
    caseArray = [];
    var rnd = '?rnd=' + Math.random();
    if (data.indexOf('?') > 0) {
        rnd = rnd.replace('?', '&');
    }
    obj.open("GET", data + rnd, true);
    obj.onreadystatechange = function () {
        if (obj.readyState == 4) {
            if (obj.responseText != '') {
                caseArray = obj.responseText.split("$");
                setupCaseStudy(data.split('=')[1]);
                //alert(data.split('=')[1]);
                //setupAnim('imgContent');
                //setupAnim2(imagearray);
            }
            else {
                //alert('no frames loaded');
            }
        }
    }
    obj.send(null);

}

function getKeyWords(data, obj) {
       if ($('textContent')) {
           var rnd = '?rnd=' + Math.random();
           if (data.indexOf('?') > 0) {
               rnd = rnd.replace('?', '&');
           }
           obj.open("GET", data + rnd, true);
           obj.onreadystatechange = function () {
               if (obj.readyState == 4) {
                   keyWordsArray = obj.responseText.split("$");
                   //
                   //if (keyWordsArray.length > 1)
                   for (var i = 0; i < keyWordsArray.length - 1; i++) {
                       var tempStr = new RegExp(keyWordsArray[i], 'gi');
                       $('textContent').innerHTML = $('textContent').innerHTML.replace(tempStr, '<span style="border-bottom:2px dotted ' + getStyle(curSec + 'Head', 'color') + ';" onclick="showPop(null, null,\'' + keyWordsArray[i] + '\');">' + keyWordsArray[i] + '</span>');
                       //debug(keyWordsArray[i]);
                       //alert($('textContent').innerHTML.indexOf(/Glass/i));
                   }
               }
           }
           obj.send(null);
       }
   }

function getSearchResults(data, obj) {
           var rnd = '?rnd=' + Math.random();
           if (data.indexOf('?') > 0) {
               rnd = rnd.replace('?', '&');
           }
           obj.open("GET", data + rnd, true);
           obj.onreadystatechange = function () {
               if (obj.readyState == 4) {
                   $('search').innerHTML = obj.responseText;
               }
           }
           obj.send(null);
}

//no longer used below
 function getHighlighted(data, obj) {
       if ($('textContent')) {
           var rnd = '?rnd=' + Math.random();
           if (data.indexOf('?') > 0) {
               rnd = rnd.replace('?', '&');
           }
           obj.open("GET", data + rnd, true);
           obj.onreadystatechange = function () {
               if (obj.readyState == 4) {
                   keyWordsArray = obj.responseText.split("$");
                   //
                   //if (keyWordsArray.length > 1)
                   for (var i = 0; i < keyWordsArray.length - 1; i++) {
                       var tempStr = new RegExp(keyWordsArray[i], 'gi');
                       $('textContent').innerHTML = $('textContent').innerHTML.replace(tempStr, '<span style="background:#FFFEB9;border:1px dotted black;">' + keyWordsArray[i] + '</span>');
                       //debug(keyWordsArray[i]);
                       //alert($('textContent').innerHTML.indexOf(/Glass/i));
                   }
               }
           }
           obj.send(null);
       }
   }


function setContent(data, dest) {
   //setVisibility('busy', 'visible');
   alert("saving!");
   httpPost.open("POST", dest, false);
   httpPost.onreadystatechange = function () {
      if (httpPost.readyState == 4) {
         if (httpPost.responseText.length == 0) {
            //setVisibility('busy', 'hidden');
            }
         else {
            alert(httpPost.responseText);
            //setVisibility('busy', 'hidden');
            //stick an error image instead of disk
            }
         }
      }
   httpPost.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   httpPost.send(data.replace(/ /g, '%20'));



}

function makeLogin(data, obj) {
    var rnd = '?rnd=' + Math.random();
    if (data.indexOf('?') > 0) {
        rnd = rnd.replace('?', '&');
    }
    obj.open("GET", data + rnd, true);
    obj.onreadystatechange = function () {
        if (obj.readyState == 4) {
            if (obj.responseText.indexOf('*') == -1) {
                //setVisibility('busy', 'hidden');
                //alert(httpPost.responseText);
                //if (data == '') {
                //    window.location = 'handbook.asp';
                //}
                $('createLogin').innerHTML = obj.responseText;
                //if ($('email')) {
                //    $('email').value = '';
                //    $('pass').value = '';
                //}
            }
            else {
                userID = obj.responseText.split('*')[0];
                usersName = obj.responseText.split('*')[1];
                if ($('usersName')) { $('usersName').innerHTML = usersName; }
                //if (httpPost.responseText.split('*')[2]) {
                //    window.location = 'handbook.asp?sectionCode=' + httpPost.responseText.split('*')[2];
                //}
                //else {
                $('login').innerHTML = "<div style='color:#939393; font-family:Arial; font-size:12px; font-weight:bold; padding:10px;'>Welcome " + obj.responseText.split('*')[1] + '</div>';
                setupCreateLogin();
                //}
                //alert(httpPost.responseText);
                //setVisibility('busy', 'hidden');
                //stick an error image instead of disk
            }
        }
    }
    obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    obj.send(null);
}

function login(data, dest) {
    //setVisibility('busy', 'visible');
    httpPost.open("POST", dest, false);
    httpPost.onreadystatechange = function () {
        if (httpPost.readyState == 4) {
            if (httpPost.responseText == 'Login Failed') {
                //setVisibility('busy', 'hidden');
                //alert(httpPost.responseText);
                if (data == '') {
                    window.location = 'handbook.asp';
                }

                if ($('email')) {
                    $('email').value = '';
                    $('pass').value = '';
                }
            }
            else {
                userID = httpPost.responseText.split('*')[0];
                usersName = httpPost.responseText.split('*')[1];
                if ($('usersName')) { $('usersName').innerHTML = usersName; }
                //if (httpPost.responseText.split('*')[2]) {
                //    window.location = 'handbook.asp?sectionCode=' + httpPost.responseText.split('*')[2];
                //}
                //else {
                $('login').innerHTML = "<div style='color:#939393; font-family:Arial; font-size:12px; font-weight:bold; padding:10px;'>Welcome back " + httpPost.responseText.split('*')[1] + '</div>';

                //}
                //alert(httpPost.responseText);
                //setVisibility('busy', 'hidden');
                //stick an error image instead of disk
            }
        }
    }
    httpPost.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    httpPost.send(data.replace(/ /g, '%20'));


}

function setupEdit() {
    if (document.all) { var e = window.event.srcElement; } else { var e = event.target }
    var x = true;
    if ($('wrapper')) {
        var element2 = $('wrapper');
        element2.parentNode.removeChild(element2);
        x = false;
        disableDiv(document.getElementsByTagName("body")[0], true);
    }
    if (x != false) {
        disableDiv(document.getElementsByTagName("body")[0], true);

        var wrapper = document.createElement("div");
        wrapper.setAttribute('id', 'wrapper');
        setStyle(wrapper, 'position: absolute; right: 50%; bottom: 50%; height:50%; z-index:10000;');

        var container = document.createElement("div");
        container.setAttribute('id', 'container');
        setStyle(container, 'position: relative; left: 50%; top: 50%;');
        wrapper.appendChild(container);

        var edit = document.createElement("div");
        edit.setAttribute('id', 'edit');

        //edit.onmouseup = function () { setupEdit(); }
        var maxH = window.innerHeight - 20;
        var maxW = window.innerWidth - 20;
        //debug(maxW + '/' + maxH);
        var resizerW = maxW / e.width;
        var resizerH = maxH / e.height;
        if (resizerH < resizerW) var resizer = resizerH;
        else var resizer = resizerW;

        edit.style.width = (e.width * resizer) + 'px';
        edit.style.height = (e.height * resizer) + 'px';
        //edit.innerHTML = "admin/admin.asp";

        container.appendChild(edit);

        document.getElementsByTagName("body")[0].appendChild(wrapper);

        getContent('admin/admin.asp?sectionCode=' + curSecCode, $('edit'), httpEdit);
        //getContent('admin/getDataAdmin.asp?sql=', 'get', httpGet);

        //centerObject('zoom', 0, 0);
    }
}

function setupCreateLogin(e) {
    //var srcEl = null;
    //if (window.event) srcEl = e.srcElement; //msie
    //else
    //srcEl = e.target;

//e = srcEl;

    //if (document.all) { var e = window.event.srcElement; } else { var e = event.target }
    var x = true;
    if ($('wrapper')) {
        var element2 = $('wrapper');
        element2.parentNode.removeChild(element2);
        x = false;
        disableDiv(document.getElementsByTagName("body")[0], true);
    }
    if (x != false) {
        disableDiv(document.getElementsByTagName("body")[0], true);

        var wrapper = document.createElement("div");
        wrapper.setAttribute('id', 'wrapper');
        setStyle(wrapper, 'position: absolute; right: 50%; bottom: 50%; height:50%; z-index:10000;');

        var container = document.createElement("div");
        container.setAttribute('id', 'container');
        setStyle(container, 'position: relative; left: 50%; top: 50%;');
        wrapper.appendChild(container);

        var createLogin = document.createElement("div");
        createLogin.setAttribute('id', 'createLogin');

        //edit.onmouseup = function () { setupEdit(); }
        var maxH = document.documentElement.clientHeight - 20;
        var maxW = document.documentElement.clientWidth - 600;
        //debug(maxW + '/' + maxH);
        var resizerW = maxW / e.offsetWidth;
        var resizerH = maxH / e.offsetHeight;
        if (resizerH < resizerW) var resizer = resizerH;
        else var resizer = resizerW;

        //alert(createLogin.style.pixelWidth);

        //createLogin.style.width = (srcEl.offsetWidth * resizer) + 'px';
        //createLogin.style.height = (srcEl.offsetHeight * resizer) + 'px';
        //edit.innerHTML = "admin/admin.asp";

        container.appendChild(createLogin);

        document.getElementsByTagName("body")[0].appendChild(wrapper);

        getContent('createLogin.asp', $('createLogin'), httpCreateLogin);
        //getContent('admin/getDataAdmin.asp?sql=', 'get', httpGet);

        //centerObject('zoom', 0, 0);
    }
}

function setupSearch(e) {
    //if ($('searchBox').value != '') {
   //  if (document.all) { var e = window.event.srcElement; } else { var e = event.target }
        e = $('searchBox');
            //disableDiv(document.getElementsByTagName("body")[0], true);


            var search = document.createElement("div");
            search.setAttribute('id', 'search');
            setStyle(search, 'background-color:#FFFFFF;');

            search.style.width = "217px";
            //search.style.height = "500px";
            search.style.position = "absolute";
            search.style.background = "#dddddd";

            search.style.top = elementCoord($('searchBox'))[1]+40 + 'px';
            search.style.left = elementCoord($('searchBox'))[0]-73 + 'px';



            //search.onmouseup = function () { setupSearch(); }
            //var maxH = 500;
            //var maxW = 500;
            //debug(maxW + '/' + maxH);
            //var resizerW = maxW / e.offsetWidth;
            //var resizerH = maxH / e.offsetHeight;
            //if (resizerH < resizerW) var resizer = resizerH;
            //else var resizer = resizerW;

            //alert(createLogin.style.pixelWidth);

            //search.style.width = (maxW) + 'px';
            //search.style.height = (maxH) + 'px';
            //edit.innerHTML = "admin/admin.asp";

            //container.appendChild(search);

            document.getElementsByTagName("body")[0].appendChild(search);

            getSearchResults('search.asp?s=' + $('searchBox').value, httpSearch);


    //}
}

function setupZoom(e) {
    //if (document.all) { var e = window.event.srcElement; } else { var e = event.target }
    e = $('imgContentImg');
    var x = true;
    if ($('wrapper')) {
        var element2 = $('wrapper');
        element2.parentNode.removeChild(element2);
        x = false;
        disableDiv(document.getElementsByTagName("body")[0], true);
    }
    if (x != false) {
        disableDiv(document.getElementsByTagName("body")[0], true);

        var maxH = document.documentElement.clientHeight - 20;
        var maxW = document.documentElement.clientWidth - 20;
        //debug(maxW + '/' + maxH);
        var resizerW = maxW / e.offsetWidth;
        var resizerH = maxH / e.offsetHeight;
        if (resizerH < resizerW) var resizer = resizerH;
        else var resizer = resizerW;

        var wrapper = document.createElement("div");
        wrapper.setAttribute('id', 'wrapper');
        setStyle(wrapper, 'position: absolute; right: 50%; bottom: 50%; z-index:10000; height:' + (e.offsetHeight * resizer) + 'px;width: ' + (e.offsetWidth * resizer) + 'px;');

        var container = document.createElement("div");
        container.setAttribute('id', 'container');
        setStyle(container, 'position: relative; left: 50%; top: 50%; 500px;width: height:800px;');
        wrapper.appendChild(container);

        var zoom = document.createElement("img");
        zoom.setAttribute('id', 'zoom');
        //zoom.src = 'images/wait.gif';
        zoom.onmouseup = function () { setupZoom(); }


           //var el = $(divName);
           //el.style.pixelHeight = el.offsetHeight;
           //el.style.pixelWidth = el.offsetWidth;
        //alert(e.offsetWidth);
        zoom.style.width = (e.offsetWidth * resizer) + 'px';
        zoom.style.height = (e.offsetHeight * resizer) + 'px';

        zoom.style.zIndex = "5000";

        zoom.style.filter = "alpha(opacity=100)";
        zoom.style.opacity = "1";
        zoom.style.mozOpacity = "1";
        zoom.src = $("imgContent").getAttribute("src") + '&mh=' + maxH + '&mw=' + maxW;
        container.appendChild(zoom);

        document.getElementsByTagName("body")[0].appendChild(wrapper);
        //centerObject('zoom', 0, 0);
    }
}

function setupLinks(e) {
    if (document.all) { var e = window.event.srcElement; } else { var e = event.target }
    var x = true;
    if ($('links')) {
        var element2 = $('links');
        e.style.background = "#FFFFFF";
        element2.parentNode.removeChild(element2);
        x = false;
    }
    if (x != false) {
        //disableDiv(document.getElementsByTagName("body")[0], true);
        var links = document.createElement("div");
        links.setAttribute('id', 'links');
        links.style.width = "248px";
        links.style.height = "500px";
        links.style.position = "absolute";
        links.style.background = "#dddddd";
        e.style.background = "#dddddd";
        //overlay.setAttribute("onmouseup","disableDiv(null,false);");
        //caseStudy.onmouseup = function () { disableDiv(null, false, null); }
        //links.onmouseup = function () { setupLinks(); }

        links.style.top = elementCoord(e)[1] - 500 + 'px';
        links.style.left = elementCoord(e)[0] + 'px';
        links.style.zIndex = "5000";

        links.style.filter = "alpha(opacity=90)";
        links.style.opacity = "0.9";
        links.style.mozOpacity = "0.9";

        document.getElementsByTagName("body")[0].appendChild(links);
        getContent('links.asp?sectionCode=' + curSecCode, 'links', httpLinks);
        //centerObject('caseStudy', 0, 0);
    }
}

function setupSources(e) {
    if (document.all) { var e = window.event.srcElement; } else { var e = event.target }
    var x = true;
    if ($('sources')) {
        var element2 = $('sources');
        e.style.background = "#FFFFFF";
        element2.parentNode.removeChild(element2);
        x = false;
    }
    if (x != false) {
        //disableDiv(document.getElementsByTagName("body")[0], true);
        var sources = document.createElement("div");
        sources.setAttribute('id', 'sources');
        sources.style.width = "248px";
        sources.style.height = "500px";
        sources.style.position = "absolute";
        sources.style.background = "#dddddd";
        e.style.background = "#dddddd";
        //overlay.setAttribute("onmouseup","disableDiv(null,false);");
        //caseStudy.onmouseup = function () { disableDiv(null, false, null); }
        //sources.onmouseup = function () { setupSources(); }

        sources.style.top = elementCoord(e)[1]-500+'px';
        sources.style.left = elementCoord(e)[0] + 'px';
        sources.style.zIndex = "5000";

        sources.style.filter = "alpha(opacity=90)";
        sources.style.opacity = "0.9";
        sources.style.mozOpacity = "0.9";

        document.getElementsByTagName("body")[0].appendChild(sources);
        getContent('sources.asp?sectionCode=' + curSecCode, 'sources', httpSources);
        //centerObject('caseStudy', 0, 0);
    }
}

function setupCaseStudy(caseCode) {

    //if (document.all) { var e = window.event.srcElement; } else { var e = event.target }

    var x = true;
    if ($('wrapper')) {
        var element2 = $('wrapper');
        //e.style.background = "#FFFFFF";
        element2.parentNode.removeChild(element2);
        x = false;
        disableDiv(document.getElementsByTagName("body")[0], true);
    }
    if (x != false) {

        disableDiv(document.getElementsByTagName("body")[0], true);

        var wrapper = document.createElement("div");
        wrapper.setAttribute('id', 'wrapper');
        setStyle(wrapper, 'position: absolute; right: 50%; bottom: 50%; z-index:10000;height: 600px;width: 950px;');

        var container = document.createElement("div");
        container.setAttribute('id', 'container');
        setStyle(container, 'position: relative; left: 50%; top: 50%;height: 600px;width: 950px;');
        wrapper.appendChild(container);

        var caseStudy = document.createElement("div");
        caseStudy.setAttribute('id', 'caseStudy');
        caseStudy.style.width = "950px";
        caseStudy.style.height = '600px';
        caseStudy.style.position = "relative";
        caseStudy.style.background = "#FFFFFF";

        //overlay.setAttribute("onmouseup","disableDiv(null,false);");
        //caseStudy.onmouseup = function () { disableDiv(null, false, null); }
        //caseStudy.onmouseup = function () { setupCaseStudy(); }

        caseStudy.style.top = "0px";
        caseStudy.style.left = "0px";
        caseStudy.style.zIndex = "5000";

        caseStudy.style.filter = "alpha(opacity=100)";
        caseStudy.style.opacity = "1";
        caseStudy.style.mozOpacity = "1";

        container.appendChild(caseStudy);

        document.getElementsByTagName("body")[0].appendChild(wrapper);

        //document.getElementsByTagName("body")[0].appendChild(caseStudy);
        getContent('caseStudy.asp?caseCode=' + caseCode + '&mh=' + 500 +'&mw='+500, 'caseStudy', httpCaseStudies);
       //centerObject('caseStudy', 0, 0);
    }
}

function setupNotebook() {

    if (document.all) { var e = window.event.srcElement; } else { var e = event.target }

    var x = true;
    if ($('wrapper')) {
        var element2 = $('wrapper');
        //e.style.background = "#FFFFFF";
        element2.parentNode.removeChild(element2);
        x = false;
        disableDiv(document.getElementsByTagName("body")[0], true);
    }
    if (x != false) {

        disableDiv(document.getElementsByTagName("body")[0], true);

        var wrapper = document.createElement("div");
        wrapper.setAttribute('id', 'wrapper');
        setStyle(wrapper, 'position: absolute; right: 50%; bottom: 50%; z-index:10000;height: 600px;width: 500px;');

        var container = document.createElement("div");
        container.setAttribute('id', 'container');
        setStyle(container, 'position: relative; left: 50%; top: 50%;height: 600px;width: 500px;');
        wrapper.appendChild(container);

        var nBook = document.createElement("div");
        nBook.setAttribute('id', 'nBook');
        nBook.style.width = "500px";
        nBook.style.height = '600px';
        nBook.style.position = "relative";
        nBook.style.background = "#FAF59E";
        nBook.style.overflow = 'auto';
        //setStyle(nbook, 'overflow-y:auto;');
        //overlay.setAttribute("onmouseup","disableDiv(null,false);");
        //caseStudy.onmouseup = function () { disableDiv(null, false, null); }
        //caseStudy.onmouseup = function () { setupCaseStudy(); }

        nBook.style.top = "0px";
        nBook.style.left = "0px";
        nBook.style.zIndex = "5000";

        nBook.style.filter = "alpha(opacity=100)";
        nBook.style.opacity = "1";
        nBook.style.mozOpacity = "1";

        container.appendChild(nBook);

        document.getElementsByTagName("body")[0].appendChild(wrapper);

        //document.getElementsByTagName("body")[0].appendChild(caseStudy);
        getContent('notebook.asp?userID=' + userID, 'nBook', httpNotebook);
        //centerObject('caseStudy', 0, 0);
    }
}

function setStyle(element, text) {
    element.setAttribute("style", text);
    element.style.cssText = text;
}

function disableDiv(elm, x) {

    if ($('overlay')) {
        var element2 = $('overlay');
        element2.parentNode.removeChild(element2);
        x = false;
    }

    if ($('caseStudy')) {
        var element2 = $('caseStudy');
        element2.parentNode.removeChild(element2);
    }

    if (x != false) {
    var overlay = document.createElement("div");
    overlay.setAttribute('id', 'overlay');
    if ($(curSec + 'Head')) {
        overlay.style.backgroundColor = getStyle(curSec + 'Head', 'color');
    }
    else {
        overlay.style.backgroundColor = '#939393';
    }
        overlay.style.filter = "alpha(opacity=0)";
        overlay.style.opacity = "0.0";
        overlay.style.position = "absolute";
        overlay.style.left = '0px';
        overlay.style.top = '0px';
        //overlay.style.width = divWidth('body') ;
        //overlay.style.height = divHeight('body');
        overlay.style.mozOpacity = "0.0";


        //setOpacity($(op), 0);
        new Animate(overlay, 'opacity', {
            from: 0, to: 0.7, time: 500, callback: function () {
            }
        }
        ).start();

        elm.appendChild(overlay)

        //overlay.onmouseup = function () { disableDiv(elm, x); }
        //overlay.style.visibility = (overlay.style.visibility == "visible") ? "hidden" : "visible";
    }
}

function centerObject(obj, tOff, lOff) {
    var frame = document.getElementById(obj);
    var htmlwidth = document.body.clientWidth;
    var htmlheight = document.documentElement.clientHeight;
    var windowwidth = window.innerWidth;
    var windowheight = window.innerHeight;
    var frameheight = divHeight(obj);
    var framewidth = divWidth(obj);

    //limit going off top
    if ((((htmlheight - frameheight) / 2) + tOff) < 0) { frame.style.top = 0; }
    else
    { frame.style.top = ((htmlheight - frameheight) / 2) + tOff; }
    //limit going off left
    if ((((htmlwidth - framewidth) / 2) + lOff) < 0) { frame.style.left = 0; }
    else
    { frame.style.left = (((htmlwidth - framewidth) / 2) + lOff); }

}

function divWidth(obj) {
    var div = document.getElementById(obj);
    if (div.style.width.replace('px', '') == 0) {
        var divwidth = div.scrollWidth;
    }
    else {
        var divwidth = div.style.width.replace('px', '');
    }
    //alert(divwidth);
    return Math.round(divwidth);
}

function divHeight(obj) {
    var div = document.getElementById(obj);
    if (div.style.height.replace('px', '') == 0) {
        var divheight = div.scrollHeight;
    }
    else {
        var divheight = div.style.height.replace('px', '');
    }
    //alert(divheight);
    return Math.round(divheight);
}

function sectionHighlight(obj) {
   if (curSec != obj.getAttribute('sect')) {
      $(obj.getAttribute('sect') + 'Icon').src = 'images/' + obj.getAttribute('sect') + 'Icon.png';
      ////fadeDiv(, 0);
      //$(obj.getAttribute('sect') + 'Icon').style.display = 'block';
      //setOpacity($(obj.getAttribute('sect') + 'Icon'), 0);
      //new Animate($(obj.getAttribute('sect') + 'Icon'), 'opacity', {
      //   from: 0,
      //   to: 1,
      //   time: 500,
      //   callback : function () {
      //      }
      //   }
      //).start();
      }
}

function sectionLowlight(obj) {
   if (curSec != obj.getAttribute('sect')) {
      $(obj.getAttribute('sect') + 'Icon').src = 'images/' + obj.getAttribute('sect') + 'Icon'+'Grey.png';
      }
}

function sectionSelect(obj,layout) {
    //set current section and update the navigation

//        if (isString(obj)) {
//            curSec = obj;
//            curSecCode = $(curSec + 'Head').getAttribute('sectCode');
//        }
//        else {
//            curSec = obj.getAttribute('sect');
//            curSecCode = obj.getAttribute('sectCode');
    //        }
    for (var i = 0; i < sectionCodes.length; i++) {
        if (sectionCodes[i] == Left(obj, 2)) {
            curSec = sections[i];
            break;
        }
    }
    var prevSecName = '';
    for (var i = 0; i < sectionCodes.length; i++) {
        if (sectionCodes[i] == prevSec) {
            prevSecName = sections[i];
            break;
        }
    }

    //obj = window.location.hash;

        //get section splash page
    getContent('contentLayouts/' + layout + '.asp?sectionCode=' + obj, 'contentTabFrame', httpContent);
        //get section navigation
    getContent('getNav.asp?sectionCode=' + obj, 'secondNav', httpSecondNav);
        var table = $("navTab");
        var cells = table.getElementsByTagName("td");
        for (var i = 0; i < cells.length; i++) {
            var sect = cells[i].getAttribute("sect");
            //section icon
            if (sect != null && sect != curSec && cells[i].id != curSec + 'Head') {
                $(sect + 'Icon').src = 'images/' + sect + 'Icon'+'Grey.png';
            }
            //section header
            if (sect != null && sect != curSec && cells[i].id != curSec + 'Head') {
                $(sect + 'Head').className = 'sectionHeader';
                //set background colour to white
                //$(sect+'Head').style.backgroundColor='#FFFFFF';
            }
        }

        //slide bar into position if not at home
        if (prevSecName != '') {
            //alert(prevSecName);
            slideTo2('slider', $(prevSecName + 'Head').offsetLeft - 50, 0, false, easeSpeed);
        }
        if ($(curSec + 'Head')) {
            $(curSec + 'Icon').style.display = 'block';
            slideTo2('slider', $(curSec + 'Head').offsetLeft - 50, 0, true, easeSpeed);
            $(curSec + 'Icon').src = 'images/' + curSec + 'Icon.png';
            $(curSec + 'Head').className = 'sectionHeader' + curSec;
            $('enviro').style.color = getStyle(curSec + 'Head', 'color');
            $('slider').style.backgroundColor = getStyle(curSec + 'Head', 'color');

            //set colour of virtical bars
            vBars();
        }

    }

    function vBars() {

        //set colour (image) of vertical bars
        var virtBarsTd = document.getElementsByTagName('td');
        for (var i = 0; i < virtBarsTd.length; i++) {
            var tmp = 'url(\'' + 'images/' + curSec + 'Bar.png\')';
            if (virtBarsTd[i].id == 'virtBar') {
                virtBarsTd[i].style.backgroundImage = tmp;
            }
        }

    }

function back() {

    var code = Left(curSecCode, curSecCode.length);

    //alert(code);

    subNavExpand(code, 5);

}

function subNavExpand(sCode, layoutID,loadContent, loadNext) {
    if (sCode.indexOf("nav") != - 1) {
       sCode = sCode.replace('nav','');
    }

    var table = $("subNavTab");
    var cells = table.getElementsByTagName("td");

    for (var i = 0; i < cells.length; i++) {
        if (cells[i].id.length > sCode.length+3) {
            cells[i].style.display = "none";
        }
    }

    for (var j = 1; j < 10; j++) {
        var ext = Right('000' + j, 2);
        if ($('nav' + sCode + '.' + ext)) {
            $('nav' + sCode + '.' + ext).style.display = "block";
        }
    }

    if (loadNext != '') {sCode = loadNext; }
   // alert(sCode);
   if(sCode){
   curSecCode = sCode.replace('nav', '');
   subNavHighlight($('nav'+sCode));
   //reset anim frame
   paused = true;
   framesArray = [];
   currFrame = 0;
   prevFrame;
   nextFrame = 0;

   if (loadContent) {
        getContent('contentLayouts/' + layoutID + '.asp?sectionCode=' + curSecCode + '&userID=' + userID, 'contentTabFrame', httpContent);
   }
   }
}

function subNavHighlight(obj) {
   var table = $("subNavTab");
   var cells = table.getElementsByTagName("td");
   for (var i = 0; i < cells.length; i++) {
      subNavLowlight(cells[i]);
      }
   var lighter = lighterColor(getStyle(curSec + 'Head', 'color'), 0.25);
   obj.style.backgroundColor = lighter;
   obj.style.color = "#222222";
}

function subNavLowlight(obj) {
   if (obj.id != 'nav' + curSecCode) {
      obj.style.backgroundColor = "";
      obj.style.color = "#939393";
      }
}

function getStyle(el, styleProp) {
    var x = $(el);
    if (x) {
        if (x.currentStyle) var y = x.currentStyle[styleProp];
        else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x, null).getPropertyValue(styleProp);
        return y;
    }
    else {
        return 'sectionHeaderBar';
    }

}

var pad = function(num, totalChars) {
   var pad = '0';
   num = num + '';
   while (num.length < totalChars) {
      num = pad + num;
      }
   return num;
   };
//var darker = darkerColor('rgba(80, 75, 52, .5)', .2);
//var lighter = lighterColor('rgba(80, 75, 52, .5)', .2);
// Ratio is between 0 and 1
var changeColor = function(color, ratio, darker) {
   // Trim trailing/leading whitespace
   color = color.replace(/^\s*|\s*$/, '');
   // Expand three-digit hex
   color = color.replace( /^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i, '#$1$1$2$2$3$3' );
   // Calculate ratio
   var difference = Math.round(ratio * 256) * (darker ? - 1 : 1), // Determine if input is RGB(A)
   rgb = color.match(new RegExp('^rgba?\\(\\s*' + '(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])' + '\\s*,\\s*' + '(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])' + '\\s*,\\s*' + '(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])' + '(?:\\s*,\\s*' + '(0|1|0?\\.\\d+))?' + '\\s*\\)$' , 'i')), alpha = !!rgb && rgb[4] != null ? rgb[4] : null, // Convert hex to decimal
   decimal = !!rgb ? [rgb[1], rgb[2], rgb[3]] : color.replace( /^#?([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i, function() { return parseInt(arguments[1], 16) + ',' + parseInt(arguments[2], 16) + ',' + parseInt(arguments[3], 16); } ).split(/,/), returnValue;
   // Return RGB(A)
   return !!rgb ? 'rgb' + (alpha !== null ? 'a' : '') + '(' + Math[darker ? 'max' : 'min']( parseInt(decimal[0], 10) + difference, darker ? 0 : 255 ) + ', ' + Math[darker ? 'max' : 'min']( parseInt(decimal[1], 10) + difference, darker ? 0 : 255 ) + ', ' + Math[darker ? 'max' : 'min']( parseInt(decimal[2], 10) + difference, darker ? 0 : 255 ) + (alpha !== null ? ', ' + alpha : '') + ')' : // Return hex
   [ '#', pad(Math[darker ? 'max' : 'min']( parseInt(decimal[0], 10) + difference, darker ? 0 : 255 ).toString(16), 2), pad(Math[darker ? 'max' : 'min']( parseInt(decimal[1], 10) + difference, darker ? 0 : 255 ).toString(16), 2), pad(Math[darker ? 'max' : 'min']( parseInt(decimal[2], 10) + difference, darker ? 0 : 255 ).toString(16), 2) ].join('');
   };
var lighterColor = function(color, ratio) {
   return changeColor(color, ratio, false);
   };
var darkerColor = function(color, ratio) {
   return changeColor(color, ratio, true);

};


function setupAnim2(img,arr) {
    var el = $('imgContent');
    $('imgContent').innerHTML = '';

    off = 0;
    if ($('playPauseBar') || $('imgNavBar')) {
        off =  110;
    }

    var maxH = $('imgContent').offsetHeight - off;
    var maxW = $('imgContent').offsetWidth ;

    if ($('imgContentA')==null) {
        var imgContentA = document.createElement("div");
        imgContentA.setAttribute('id', 'imgContentA');
        imgContentA.style.top = '0px';
        imgContentA.style.left = '0px';
        imgContentA.style.width = maxW+'px';
        imgContentA.style.height = maxH+'px';
        $('imgContent').style.left.position = 'absolute';
        $('imgContent').appendChild(imgContentA);
    }

    //debug(maxW + '/' + maxH);
    var resizerW = maxW / img.width;
    var resizerH = maxH / img.height;
    if (resizerH < resizerW) var resizer = resizerH;
    else var resizer = resizerW;
    img.height = (img.height * resizer);
    img.width = (img.width * resizer);

    //var percWidth = 1;
    var trimmmedArr = [];
    //if (maxW < maxH) {maxH = maxW; } else { maxW = maxH; }

    for (var i = 0; i <= arr.length - 2; i++) {
        if (img.height > img.width) {
            trimmmedArr[i] = ['image.aspx?f=' + arr[i] + '&mh=' + ($('imgContent').style.pixelHeight * 0.666) + '&mw=' + (maxW*0.6)];
            maxW = maxW;
            maxH = maxH;
        }
        else {
            trimmmedArr[i] = ['image.aspx?f=' + arr[i] + '&mh=' + (maxH*0.7) + '&mw=' + (0.666 * maxW)];
            maxW = maxW;
            maxH = maxH;
        }
        //debug('h:' + maxH + ' w:' + maxW);
    }

//debug('h:' + img.height + ' w:' + img.width);

    var mygallery = new fadeSlideShow({
        wrapperid: "imgContentA", //ID of blank DIV on page to house Slideshow
        dimensions: [maxW, maxH], //width/height of gallery in pixels. Should reflect dimensions of largest image
        imagearray: trimmmedArr,
        displaymode: { type: 'auto', pause: 2500, cycles: 0, wraparound: false },
        persist: false, //remember last viewed slide and recall within same session?
        fadeduration: 500, //transition duration (milliseconds)
        descreveal: "none",
        togglerid: ""
    })
    //$('imgContentA').style.display = "block";

}

function setupAnim3(arr) {
    var el = $('imgContent');
    $('imgContent').innerHTML = '';

    if ($('playPauseBar') || $('imgNavBar')) {
        off =  190;
    }

    var maxH = $('imgContent').offsetHeight - off;
    var maxW = $('imgContent').offsetWidth - 20;

    if ($('imgContentA') == null) {
        var imgContentA = document.createElement("div");
        imgContentA.setAttribute('id', 'imgContentA');
        imgContentA.style.top = '0px';
        imgContentA.style.left = '0px';
        imgContentA.style.left.position = 'absolute';
        $('imgContent').appendChild(imgContentA);
    }

    var sizeImage = new Image();

    sizeImage.onload = function () {
        //alert('h:' + sizeImage.height + ' w:' + sizeImage.width);
        var trimmmedArr = [];
        for (var i = 0; i <= arr.length - 2; i++) {
            trimmmedArr[i] = ['image.aspx?f=' + arr[i] + '&mh=' + (maxH) + '&mw=' + (maxW * 0.75)];
            debug('h:' + maxH + ' w:' + maxW);
        }



        var mygallery = new fadeSlideShow({
            wrapperid: "imgContentA", //ID of blank DIV on page to house Slideshow
            dimensions: [sizeImage.width, sizeImage.height], //width/height of gallery in pixels. Should reflect dimensions of largest image
            imagearray: trimmmedArr,
            displaymode: { type: 'auto', pause: 2500, cycles: 0, wraparound: false },
            persist: false, //remember last viewed slide and recall within same session?
            fadeduration: 500, //transition duration (milliseconds)
            descreveal: "none",
            togglerid: ""
        })
        //debug('h:' + sizeImage.height + ' w:' + sizeImage.width);
    }
    sizeImage.src = 'image.aspx?f=' + arr[0] + '&mh=' + (maxH) + '&mw=' + (maxW * 0.75);



}

//remove below
function setupAnim(frm) {
   paused = false;
   framesLoaded = 0;
   var el = $(frm);
   prevFrame = el.childNodes.length - 1;
   while (el.firstChild) {
      el.removeChild(el.firstChild);
      }
   for (var i = 0; i < framesArray.length - 1; i++) {
      //var randomnumber=Math.floor(Math.random()*11) //to fix ie cached imaage sizes
      var d = document.createElement('div');
      d.setAttribute('id', 'frameFrame' + i);
      percWidth = 0.6;
      //d.style.width='<%=imageWidth%>px';
      d.style.width = el.offsetWidth;
      d.style.left = '20px';
      d.style.position = 'relative';
      var f = document.createElement('img');
      f.setAttribute('id', 'frameImage' + i);
      f.border = '0';
      //f.style.width='<%=imageWidth%>px';
      //f.style.width = el.offsetWidth+"px";
      //f.style.height = 'auto';
      f.style.position = 'absolute';
      f.style.left = '0px';
      f.setAttribute('onload', " ++framesLoaded; debug(framesLoaded); if(framesLoaded==framesArray.length-1){startFading();}");
      //f.setAttribute('onload', "startFading();");
      f.src = 'image.aspx?f=' + framesArray[i] + '&mh=' + el.offsetHeight + '&mw=' + percWidth * el.offsetWidth;
      setOpacity(f, 100);
      animSize[0] = el.offsetWidth;
      animSize[1] = el.offsetHeight;
      d.style.visibility = 'hidden';
      d.appendChild(f);
      el.appendChild(d);
      }
}

function startFading() {
   animPlaying = true;
   var el = $('imgContent').childNodes[nextFrame];
   if (el) {
      el.style.visibility = 'visible';
      el.style.zIndex = 2;
      setOpacity(el, 0);
      crossFade(el, 0);
      nextFrame = (nextFrame < $('imgContent').childNodes.length - 1) ? nextFrame + 1 : 0;
      currFrame = (nextFrame > 0) ? nextFrame - 1 : $('imgContent').childNodes.length - 1;
      prevFrame = (currFrame > 0) ? currFrame - 1 : $('imgContent').childNodes.length - 1;
      }
}

function crossFade(el, currentOpacity) {
   currentOpacity += 5;
   //frame obacity delta
   var prevEl = el.previousSibling ? el.previousSibling : el.parentNode.lastChild;
   if (currentOpacity > 100) {
      setOpacity(el, 100);
      if(prevEl) prevEl.style.visibility = 'hidden';
      el.style.zIndex = 1;
      if (paused == false) {
         window.setTimeout(startFading, 1000);
         }
      }
   else {
      setOpacity(el, currentOpacity);
      //fade in next image
      //setOpacity(prevEl,50-currentOpacity);//fade out previous image. 200 to stop dip in fade
      if (paused == false) {
         window.setTimeout(function () {
            crossFade(el, currentOpacity); }
         , 20);
         }
      }
}

function fadeDiv(el, currentOpacity) {
   currentOpacity += 5;
   if (currentOpacity > 100) {
      setOpacity(el, 100);
      }
   else {
      setOpacity(el, currentOpacity);
      //fade in
      window.setTimeout(function() {
         fadeDiv(el, currentOpacity); }
      , 10);
      }
}

function fadeOutDiv(el, currentOpacity) {
   currentOpacity -= 5;
   if (currentOpacity < 0) {
      setOpacity(el, 0);
      }
   else {
      setOpacity(el, currentOpacity);
      //fade in
      window.setTimeout(function() {
         fadeOutDiv(el, currentOpacity); }
      , 10);
      }
}

function setOpacity(el, opacity) {
   opacity /= 100;
   el.style.opacity = opacity;
   el.style.MozOpacity = opacity;
   el.style.filter = "alpha(opacity=" + (opacity * 100) + ")";

}

function mouseCoord(e) {
   var xcoord, ycoord;
   var res = new Array();
   if (!e) {
      e = window.event;
      }
   if (!e) {
      return;
      }
   if (typeof (e.pageX) == 'number') {
      xcoord = e.pageX;
      ycoord = e.pageY;
      }
   else if (typeof (e.clientX) == 'number') {
      xcoord = e.clientX;
      ycoord = e.clientY;
      if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
         xcoord -= document.body.scrollLeft;
         ycoord -= document.body.scrollTop;
         }
      else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
         xcoord -= document.documentElement.scrollLeft;
         ycoord -= document.documentElement.scrollTop;
         }
      }
   else {
      return;
      }
   res[0] = xcoord;
   res[1] = ycoord;
   return res;
   // window.alert('Mouse coordinates are (' + xcoord + ',' + ycoord + ')');

}

function elementCoord(obj) {
   var curleft = curtop = 0;
   if (obj.offsetParent) {
      do {
         curleft += obj.offsetLeft;
         curtop += obj.offsetTop;
         }
      while (obj = obj.offsetParent);
      return [curleft, curtop];
      }
}

function sizeTo(divName, iHeight, iWidth, animate, ease) {
   var el = $(divName);
   el.style.pixelHeight = el.offsetHeight;
   el.style.pixelWidth = el.offsetWidth;
   var curWidth = el.style.pixelWidth;
   var curHeight = el.style.pixelHeight;
   if(curWidth < iWidth) {
      var deltaW = iWidth - curWidth;
      }
   else {
      var deltaW = curWidth - iWidth;
      }
   if(curHeight < iHeight) {
      var deltaH = iHeight - curHeight;
      }
   else {
      var deltaH = curHeight - iHeight;
      }
   var dW = Math.floor(deltaW * ease);
   var dH = Math.floor(deltaH * ease);
   //debug(el.style.pixelHeight);
   if (( dW <= 1 ) && ( dH <= 1 )) {
      el.style.pixelHeight = iHeight;
      el.style.pixelWidth = iWidth;
      return null;
      }
   if (!animate) {
      el.style.pixelHeight = iHeight;
      el.style.pixelWidth = iWidth;
      return null;
      }
   if (( dW > 1 ) || ( dH > 1 )) {
      if (curHeight < iHeight) el.style.pixelHeight = curHeight + dH;
      if (curWidth < iWidth) el.style.pixelWidth = curWidth + dW;
      if (curHeight > iHeight) el.style.pixelHeight = curHeight - dH;
      if (curWidth > iWidth) el.style.pixelWidth = curWidth - dW;
      setTimeout('sizeTo("' + divName + '",' + iHeight + ',' + iWidth + ',' + animate + ',' + ease + ')', 10);
      }
}

function slideTo(divName, xPos, yPos, animate, ease) {
   var el = $(divName);
   var curX = eval(el.style.left.replace('px', ''));
   var curY = eval(el.style.top.replace('px', ''));
   if(curX < xPos) {
      var deltaX = xPos - curX;
      }
   else {
      var deltaX = curX - xPos;
      }
   if(curY < yPos) {
      var deltaY = yPos - curY;
      }
   else {
      var deltaY = curY - yPos;
      }
   var dX = Math.floor(deltaX * ease);
   var dY = Math.floor(deltaY * ease);
   if (( dX <= 1 ) && ( dY <= 1 )) {
      el.style.left = xPos + "px";
      el.style.top = yPos + "px";
      //debug('done');
      //if adding to hightlights
      if(addingHighLight) {
         //fadeOutDiv($('hLightText'), 100);
         setOpacity($(divName), 100);
         new Animate($(divName), 'opacity', {
            from: 1,
            to: 0,
            time: 500,
            callback : function () {
               }
            }
         ).start();
         addingHighLight = false;
         getContent('getHighlights.asp?userID=' + userID + '&cnt=1', 'highlights', httpHighlights);
         }
      return null;
      }
   if (!animate) {
      el.style.left = xPos + "px";
      el.style.top = yPos + "px";
      return null;
      }
   if (( dX > 1 ) || ( dY > 1) ) {
      if (curY < yPos) el.style.top = curY + dY + "px";
      if (curX < xPos) el.style.left = curX + dX + "px";
      if (curY > yPos) el.style.top = curY - dY + "px";
      if (curX > xPos) el.style.left = curX - dX + "px";
      setTimeout('slideTo("' + divName + '",' + xPos + ',' + yPos + ',' + animate + ',' + ease + ')', 5);
      }
}

function slideTo2(divName, xPos, yPos, animate, ease) {
   var el = $(divName);
   var curX = eval(el.style.left.replace('px', ''));
   var curY = eval(el.style.top.replace('px', ''));
   var xposMid = curX + (xPos - curX) * ease;
   var yposMid = curY + (yPos - curY) * ease;
   var tempA = Math.abs(curX - xPos);
   tempA = tempA * tempA;
   var tempB = Math.abs(curY - yPos);
   tempB = tempB * tempB;
   var lineLen = Math.sqrt(tempA + tempB);
   //debug(lineLen);

   if (!animate) {
       el.style.left = xPos + "px";
       el.style.top = yPos + "px";
       return null;
   }

   if (lineLen <= 5) {
      el.style.left = xPos + "px";
      el.style.top = yPos + "px";
      //if adding to hightlights
      if (addingHighLight) {
         //fadeOutDiv($(divName), 10);
         setOpacity($(divName), 100);
         new Animate($(divName), 'opacity', {
            from: 1,
            to: 0,
            time: 500,
            callback : function () {
               }
            }
         ).start();
         addingHighLight = false;
         getContent('getHighlights.asp?userID=' + userID + '&cnt=1', 'highlightsSummary', httpHighlights);
         }
      return null;
      }
   else {
      el.style.top = yposMid + "px";
      el.style.left = xposMid + "px";
      setTimeout('slideTo2("' + divName + '",' + xPos + ',' + yPos + ',' + animate + ',' + ease + ')', 5);
      }
}

function loadImage(p,cap) {
   if ($('imgContent')) {
      $('imgContent').innerHTML = "<div align=center><img src='images/wait.gif'></div>";
      var imgContentFrame = $('imgContent');

      //set image caption
      if (cap)
      $('caption').innerHTML = cap;

      //create new image
      var newImg = document.createElement("img");
      //framesArray[0] = document.createElement("img");
      newImg.id = 'imgContentImg';
      newImg.style.zIndex = -999;
      //newImg = imageContent;
      newImg.style.display = 'none';
      //$("imgContent").appendChild(newImg); //append new img to container
      newImg.onload = function () {
          if (loadingImage == newImg.src) {
              //debug('loaded');
              loadingImage = "";
              fitImage(newImg);
              $("imgContent").setAttribute('src', p);
              $("imgContentImg").style.display = 'block';
              $("imgContent").onclick = function () {
                  setupZoom($("imgContent"));
              }
              resize();
          }
      }
      var off = 0;
      if ($('playPauseBar') || $('imgNavBar')) {
         off = 0;
     }
      percWidth = (($('imgContent').offsetWidth) / $('contentTab').offsetWidth);
      newImg.src = p + '&mh=' + $('contentTab').offsetHeight + '&mw=' + percWidth * $('contentTab').offsetWidth;
      loadingImage = newImg.src;
      //newImg.src = imageContent.src;
      // $('contentTab').style.pixelHeight = document.documentElement.clientHeight - (290);
      // if ($('textContent'))
      // $('textContent').style.pixelHeight = document.documentElement.clientHeight - 290;
      }
}

function fitImage(img) {
   if(img) {
      if(img.width || img.height) {
         var off = 0;
         img.style.display = "none";
         if ($('playPauseBar') || $('imgNavBar')) {
            off = 30; //adjusts height of image
            }
         var imgContentFrame = $('imgContent');
         //get image frame width percentage
         percWidth = ((imgContentFrame.offsetWidth) / $('contentTab').offsetWidth);
         var maxH = $('contentTab').offsetHeight - (off);
         var maxW = percWidth * $('contentTab').offsetWidth-40;
         //debug(maxW + '/' + maxH);
         var resizerW = maxW / img.width;
         var resizerH = maxH / img.height;
         if (resizerH < resizerW) var resizer = resizerH;
         else var resizer = resizerW;
         img.height = (img.height * resizer);
         img.width = (img.width * resizer);
         //debug(resizer);
         //remove any existing image
         while (imgContentFrame.hasChildNodes()) {
             imgContentFrame.removeChild(imgContentFrame.childNodes[0])
            }
            $("imgContent").appendChild(img);

         img.style.display = "block";
         }
      }
}

function resize() {
   //resize image
   if ($('imgContent')) {
      if ($('imgContent').childNodes[0] == $('imgContentImg')) {
         fitImage($('imgContentImg'));
         }
 }

   if ($('contentFooterFrame')) {
       var cf = 330;
      }
   else {
      var cf = 220; //affects splash images size
  }

   var off = 0;
   if ($('playPauseBar') || $('imgNavBar')) {
      off = 0;
  }

  //resize frames
  if ($('middleTab') && curSecCode == '') {
      $('middleTab').style.pixelHeight = document.documentElement.clientHeight - 150;
  }
   if ($('contentTab')) {
       $('contentTab').style.pixelHeight = document.documentElement.clientHeight - (cf);
       if ($('imgContent')) {
           $('imgContent').style.pixelHeight = $('contentTab').style.pixelHeight - (off);
       }
      //debug(cf);
       if ($('textContent')) {
           //if ($('imgContent')) { $('imgContent').style.display = 'none'; }
           $('textContent').style.pixelHeight = document.documentElement.clientHeight - cf;
           $('textContent').style.height = document.documentElement.clientHeight - 290 + 'px';
          //debug($('textContent').style.pixelHeight);
          scroller();
          //if ($('imgContent')) { $('imgContent').style.display = 'block'; }
         }
   }


}

function fitAnim() {
   if ($('imgContent')) {
      var off = 0;
      if ($('playPauseBar') || $('imgNavBar')) {
         off = 0;
         }
      var imgContentFrame = $('imgContent');
      //var img = imgContentFrame.firstChild.firstChild;
      //get image frame width percentage
      percWidth = ((imgContentFrame.offsetWidth) / $('contentTab').offsetWidth);
      var maxH = $('contentTab').offsetHeight - (off);
      var maxW = (percWidth * $('contentTab').offsetWidth);
      var resizerW = maxW / animSize[0];
      var resizerH = maxH / animSize[1];
      if (resizerH < resizerW) var resizer = resizerH;
      else var resizer = resizerW;
      //img.height = (img.height * resizer) - 5;
      //img.width = (img.width * resizer) - 5;
      //resize all anim images
      for (i = 0; i < imgContentFrame.childNodes.length; i++) {
         imgContentFrame.childNodes[i].firstChild.height = (imgContentFrame.childNodes[i].firstChild.height * resizer) - 5;
         imgContentFrame.childNodes[i].firstChild.width = (imgContentFrame.childNodes[i].firstChild.width * resizer) - 5;
         }
      $('contentTab').style.pixelHeight = document.documentElement.clientHeight - (290);
      $('imgContent').style.pixelHeight = $('contentTab').style.pixelHeight - (off);
      if ($('textContent')) $('textContent').style.pixelHeight = document.documentElement.clientHeight - 290;
      }
}

function setVisibility(id, vis) {
   $(id).style.visibility = vis;

}

function showHideEdit(e, sh) {
   if(sh) {
      $('edit').style.visibility = 'visible';
      slideTo('edit', elementCoord(e)[0] + e.offsetWidth, elementCoord(e)[1], false, 1);
      //window.setTimeout(function() { showHideEdit(e,false); }, 2000);
      }
   else {
      $('edit').style.visibility = 'hidden';
      slideTo('edit', 0, 0, false, 1);
      }
}


function showHideBookmark(e, sh) {
   if (sh) {
      $('bookmarker').style.display = 'block';
      $('bookmarker').style.visibility = 'visible';
      slideTo2('bookmarker', elementCoord(e)[0] + (e.offsetWidth) - 15, elementCoord(e)[1] + 2, false, 1);
      //window.setTimeout(function() { showHideEdit(e,false); }, 2000);
      }
   else {
      $('bookmarker').style.visibility = 'hidden';
      slideTo2('bookmarker', 0, 0, false, 1);
      }
}

function isString() {
   if (typeof arguments[0] == 'string') {
      return true;
      }
   else {
      return false }
}

function replaceAll(str, r, x) {
   return str.replace(/r/g, x);

}

function trim(str, chars) {
   return ltrim(rtrim(str, chars), chars);

}

function ltrim(str, chars) {
   chars = chars || "\\s";
   return str.replace(new RegExp("^[" + chars + "]+", "g"), "");

}

function rtrim(str, chars) {
   chars = chars || "\\s";
   return str.replace(new RegExp("[" + chars + "]+$", "g"), "");

}

function Left(str, n) {
   if (n <= 0) return "";
   else if (n > String(str).length) return str;
   else return String(str).substring(0, n);

}

function Right(str, n) {
   if (n <= 0) return "";
   else if (n > String(str).length) return str;
   else {
      var iLen = String(str).length;
      return String(str).substring(iLen, iLen - n);
      }
}

function encodeHtml(enc) {
    encodedHtml = escape(enc);
    encodedHtml = encodedHtml.replace(/\//g, "%2F");
    encodedHtml = encodedHtml.replace(/\?/g, "%3F");
    encodedHtml = encodedHtml.replace(/=/g, "%3D");
    encodedHtml = encodedHtml.replace(/&/g, "%26");
    encodedHtml = encodedHtml.replace(/@/g, "%40");
    encodedHtml = encodedHtml.replace(/�/g, "%BA");
    encodedHtml = encodedHtml.replace(/�/g, "%A3");
    encodedHtml = encodedHtml.replace(/�/g, "%B2");
    encodedHtml = encodedHtml.replace(/�/g, "%B3");
    encodedHtml = encodedHtml.replace(/�/g, "%95");
    encodedHtml = encodedHtml.replace(/�/g, "%91");
    encodedHtml = encodedHtml.replace(/�/g, "%92");
    return encodedHtml;
}


   //////////////////////////////// definitions start ///////////////////////////////

function selectedText() {
    var txt = '';
    if (BrowserDetect.browser == 'Firefox') {
        if (window.getSelection().rangeCount>0)
        txt = window.getSelection().getRangeAt(0);
    }
    else {
        if (window.getSelection) {
            txt = window.getSelection();
        }
        else if (document.getSelection) {
            txt = document.getSelection();
        }
        else if (document.selection) {
            txt = document.selection.createRange().text;
        }
    }

   return txt;

}

function addToHighlights() {
   var txt = selectedText();
   var high = txt.toString();
   if (txt.toString().length >= 14) {
      var t = txt.toString().substring(0, 11) + '...';
      }
   else {
      var t = txt;
      }
   //t = txt.toString().replace(' ', '<br>').replace(',', '<br>');
   $('hLightText').innerHTML = t ;
   $('textContent').innerHTML = $('textContent').innerHTML.replace(txt, '<span style="background:#FFFEB9;border:1px dotted black;">' + txt + '</span>');
   //insert highlight
   setContent('sql=INSERT INTO highlights (sectionCode,highlight,sessionID,userID,IP,[time]) VALUES (\'' + curSecCode + '\',\'' + high + '\',\'' + sessionID + '\',' + userID + ',\'' + IP + '\',CURRENT_TIMESTAMP);', 'setData.asp');
   setVisibility('hLightText', 'visible');
   setOpacity($('hLightText'), 100);
   addingHighLight = true;
   //slideTo('hLightText',mouseCoord()[0],mouseCoord()[1],false,1);
   slideTo('hLightText', elementCoord($('pop'))[0], elementCoord($('pop'))[1], false, 1);
   slideTo2('hLightText', elementCoord($('highlightsSummary'))[0], elementCoord($('highlightsSummary'))[1] - 0, true, addToHighlightsSpeed);
   }

function addToBookmarks(){
if(userID!=''){
 setContent('sql=INSERT INTO bookmarks (sectionCode,sessionID,userID,IP,[time]) VALUES (\'' + curSecCode + '\',\'' + sessionID + '\',' + userID + ',\'' + IP + '\',CURRENT_TIMESTAMP);', 'setData.asp');
}
else{
 alert('You must be logged in to creat bookmarks...');
}
}

function remSelText() {
   var txt = selectedText();
   $('textContent').innerHTML = $('textContent').innerText.replace(txt, '<span style="background:#FFFFFF;border:1px dotted black;">' + txt + '</span>');
   //setVisibility('rightClick', 'hidden');

}


function showPop(e,x, y, d) {

   var txt = '';
   if (d != '') {
      txt = d }
   else {
      txt = selectedText();
  }

   var selectPop = $('pop');
   $('definition').innerHTML = '';
   //setVisibility('rightClick', 'hidden');
   setVisibility('pop', 'hidden');

   setVisibility('pop', 'hidden');
   if (txt != '' && selectPop.style.visibility == 'hidden') {
       //if (document.all) {
       //    var e = window.event;
       //}
       //else {
       //    var e = event
       //}

       e = e || window.event;

      var xcoord, ycoord;
      mxcoord = mouseCoord(e)[0];
      mycoord = mouseCoord(e)[1];
      if (x != null) {
         xcoord = x;
         }
      if (y != null) {
         ycoord = y;
         }
      if (mycoord > (document.documentElement.clientHeight - 250)) {
         ycoord = (document.documentElement.clientHeight - 250);
         $('dictPoint').style.top = (mycoord - (document.documentElement.clientHeight - 250)) + "px";
         //debug((mycoord - (document.documentElement.clientHeight - 250)) + "px");
         xcoord = mxcoord;
         }
      else {
         $('dictPoint').style.top = "0px";
         xcoord = mxcoord;
         ycoord = mycoord;
         }
      selectPop.style.left = (xcoord) + "px";
      selectPop.style.top = (ycoord) + "px";
      if (d != '') {
         getDefinition('keyWords.asp?define=' + txt, 'definition', httpDefine);
         }
      else {
         getDefinition('defineWord.asp?words=' + txt, 'definition', httpDefine) }
      setVisibility('pop', 'visible');
      }
   return false;
   }


function showMore(e,x, y, d) {

//   var txt = '';
//   if (d != '') {
//      txt = d }
//   else {
//      txt = selectedText();
//  }

   var selectMore = $('more');
   //$('moreText').innerHTML = '';
   //setVisibility('rightClick', 'hidden');
   //setVisibility('more', 'hidden');

   //setVisibility('more', 'hidden');
   if (selectMore.style.visibility == 'hidden') {
       //if (document.all) {
       //    var e = window.event;
       //}
       //else {
       //    var e = event;
       //}
       e = e || window.event;


      var xcoord, ycoord;
      mxcoord = mouseCoord(e)[0];
      mycoord = mouseCoord(e)[1];

      if (x != null) {
         xcoord = x;
         }
      if (y != null) {
         ycoord = y;
         }
      if (mycoord > (document.documentElement.clientHeight - 500)) {
         ycoord = (document.documentElement.clientHeight - 500);
         $('morePoint').style.top = (mycoord - (document.documentElement.clientHeight - 500)) + "px";
         //debug((mycoord - (document.documentElement.clientHeight - 500)) + "px");
         xcoord = mxcoord;
         }
      else {
         $('morePoint').style.top = "0px";
         xcoord = mxcoord;
         ycoord = mycoord;
         }
      selectMore.style.left = (xcoord) + "px";
      selectMore.style.top = (ycoord) + "px";

      //$('moreText').innerHTML='more content in here!';

        //getDefinition('defineWord.asp?words=' + txt, 'definition', httpMore)
      getContent('more.asp?moreCode='+d, 'moreText', httpMore)
      setVisibility('more', 'visible');

      }
   return false;
   }


//////////////////////////////// definitions end ///////////////////////////////
function notebook() {
    var nbFrame = $('notebookFrame');
    if (nbFrame) {
        if (nbFrame.innerHTML == "") {
            var blankNb = '<!--notebook start-->';
            blankNb += '<div id="notebook" style="z-index:999;background-image: url(\'images/notepadBack.png\');border:0px dotted black;">';
            blankNb += '<table id="notebookTable" cellspacing="0"cellpadding="0"border="0" style="padding:3px;">';
            blankNb += '<tr>';
            blankNb += '<td style="border-bottom:2px solid #939393;width:140px; height:14px;">';
            blankNb += '<b onclick="setupNotebook();">My Notebook</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img id="busy" src="images/wait.gif" style="display:none;"/>';
            blankNb += '</td>';
            blankNb += '<td align="right"style="border-bottom:2px solid #939393;width:110px;padding-right:5px;height:14px;"  onclick="showNotebook = (showNotebook != false ? false : true); notebook();">';
            blankNb += '<img id="nbImg"src="images/notebookDown.png"/>';
            blankNb += '</td>';
            blankNb += '</tr>';
            blankNb += '<tr>';
            blankNb += '<td style="width:340px; height:14px;">';
            blankNb += '<b>Bookmarks</b>';
            blankNb += '<span align="right" onclick="addToBookmarks();">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+Add this page</span></td>';
            blankNb += '<td align="left"style="width:110px;">';
            blankNb += '<div id="bookmarksSummary"></div>';
            blankNb += '</td>';
            blankNb += '</tr>';
            blankNb += '<tr>';
            blankNb += '<td colspan="2" style="border-bottom:1px solid #ffffff">';
            blankNb += '<div id="bookmarks"></div>';
            blankNb += '</td>';
            blankNb += '</tr>';
            blankNb += '<tr>';
            blankNb += '<td style="width:140px; height:14px;">';
            blankNb += '<b>History</b>';
            blankNb += '</td>';
            blankNb += '<td align="left"style="width:110px;">';
            blankNb += '<div id="historySummary"></div>';
            blankNb += '</td>';
            blankNb += '</tr>';
            blankNb += '<tr>';
            blankNb += '<td colspan="2" style="border-bottom:1px solid #ffffff">';
            blankNb += '<div id="history"></div>';
            blankNb += '</td>';
            blankNb += '</tr>';
            blankNb += '<tr>';
            blankNb += '<td style="height:14px;">';
            blankNb += '<b>Highlights</b>';
            blankNb += '</td>';
            blankNb += '<td align="left">';
            blankNb += '<div id="highlightsSummary"></div>';
            blankNb += '</td>';
            blankNb += '</tr>';
            blankNb += '<tr>';
            blankNb += '<td colspan="2"">';
            blankNb += '<div id="highlights"></div>';
            blankNb += '</td>';
            blankNb += '</tr>';
            blankNb += '</table>';
            blankNb += '</div>';
            blankNb += '<!--notebook end-->';
            nbFrame.innerHTML = blankNb;
        }
        //toggle notebook
        var nb = $('notebook');
        var offX = 0;
        var offY = 77;
        //setVisibility('notebook', 'visible');
        //if (document.documentElement) {
        //nb.style.top = nbFrame.offsetTop + offY + 'px';
        //nb.style.left = nbFrame.offsetLeft + offX + 'px';
        ////nb.style.pixelHeight = $('middleTab').offsetHeight - 60;
        ////sizeTo(nb.id, $('middleTab').offsetHeight - 60, 250, true);
        //}
        if (showNotebook) {
          if($('imgContentA')){setVisibility('imgContentA','hidden');}
            $('nbImg').src = "images/notebookUp.png";
            if ($('contentFooterFrame')) {
                var cf = 0;
            }
            else {
                var cf = 66;
            }
            new Animate($('notebook'), 'height', {
                from: 84,
                to: (($('middleTab').offsetHeight + elementCoord($('notebook'))[1]) - 30) + cf,
                time: 500,
                callback: function () {
                    getContent('getBookmarks.asp?userID=' + userID + '&cnt=6', 'bookmarks', httpBookmarks);
                    getContent('getHistory.asp?userID=' + userID + '&cnt=6', 'history', httpHistory);
                    getContent('getHighlights.asp?userID=' + userID + '&list=true', 'highlights', httpHighlights);
                    $('historySummary').innerHTML = '';
                    $('highlightsSummary').innerHTML = '';
                }
            }
      ).start();
        }
        else {

            $('nbImg').src = "images/notebookDown.png";
            //sizeTo('notebook', 87, 250, true, easeSpeed);
            $('history').innerHTML = '';
            $('highlights').innerHTML = '';
            if ($('notebook').offsetHeight > 100) new Animate($('notebook'), 'height', {
                from: ($('middleTab').offsetHeight + 25), to: 84, time: 500, callback: function () {
                  if($('imgContentA')){setVisibility('imgContentA','visible');}
                }
            }
      ).start();
            $('bookmarks').innerHTML = '';
            getContent('getHistory.asp?userID=' + userID + '&cnt=1', 'historySummary', httpHistory);
            getContent('getHighlights.asp?userID=' + userID + '&summary=true', 'highlightsSummary', httpHighlights);
        }
    }
   }
   //////////////////////////////// text scroll start ///////////////////////////////

function scroller() {
   var textObj = $('textContent');
   var scroller = $('scrollbar_track');
   var scrollerHandle = $('scrollbar_handle');
   if (textObj) {
      textObj.style.pixelHeight = document.documentElement.clientHeight - 290;
      if (textObj.scrollHeight > textObj.style.pixelHeight) {
         scroller.style.display = 'block';
         }
      else {
         scroller.style.display = 'none';
         }
      //scale position of scroll handle
      scrollerHandle.style.top = scrollerHandle.getAttribute('pos') * textObj.style.pixelHeight + "px";
      }
}

function scroll(e) {
   var scrollerHandle = $('scrollbar_handle');
   var textObj = $('textContent');
   //if (document.all) {
   //   var e = window.event;
   //   }
   //else {
   //    var e = event
   //}
   e = e || window.event;

   var pos = mouseCoord(e)[1] - 170;
   if (pos <= 0) {
      pos = 0;
      }
   if (pos >= textObj.style.pixelHeight - 20) {
      pos = textObj.style.pixelHeight - 20;
      }
   if (pos) {
      scrollerHandle.style.top = pos + "px";
      }
   if (textObj.scrollHeight >= textObj.style.pixelHeight) {
      var scrollAmount = textObj.scrollHeight - textObj.style.pixelHeight;
      textObj.scrollTop = (((pos / textObj.style.pixelHeight)) * scrollAmount);
      scrollerHandle.setAttribute('pos', Math.floor((pos / textObj.style.pixelHeight)));
      }
}

//////////////////////////////// mouse wheel start ///////////////////////////////

function hookEvent(element, eventName, callback) {
   if(isString(element)) element = $(element);
   if(element == null) return;
   if(element.addEventListener) {
      if(eventName == 'mousewheel') element.addEventListener('DOMMouseScroll', callback, false);
      element.addEventListener(eventName, callback, false);
      }
   else if(element.attachEvent) element.attachEvent("on" + eventName, callback);

}

function unhookEvent(element, eventName, callback) {
   if(isString(element)) element = $(element);
   if(element == null) return;
   if(element.removeEventListener) {
      if(eventName == 'mousewheel') element.removeEventListener('DOMMouseScroll', callback, false);
      element.removeEventListener(eventName, callback, false);
      }
   else if(element.detachEvent) element.detachEvent("on" + eventName, callback);

}

function cancelEvent(e) {
   e = e ? e : window.event;
   if(e.stopPropagation) e.stopPropagation();
   if(e.preventDefault) e.preventDefault();
   e.cancelBubble = true;
   e.cancel = true;
   e.returnValue = false;
   return false;

}

function MouseWheel(e) {
   e = e ? e : window.event;
   var wheelData = e.detail ? e.detail * - 1 : e.wheelDelta / 40;
   var textObj = $('textContent');
   if (wheelData != 0) {
      textObj.scrollTop = textObj.scrollTop - wheelData;
      var scrollerHandle = $('scrollbar_handle');
      var scrollAmount = textObj.scrollHeight - textObj.style.pixelHeight;
      var pos = Math.floor((textObj.scrollTop / scrollAmount) * textObj.style.pixelHeight) - 20;
      if (pos) {
         if (pos <= 0) {
            pos = 0;
            }
         if (pos > textObj.style.pixelHeight) {
            pos = textObj.style.pixelHeight - 20;
            }
         scrollerHandle.style.top = pos + "px";
         scrollerHandle.setAttribute('pos', (pos / textObj.style.pixelHeight));
         //debug(pos);
         }
      }
   return cancelEvent(e);

}

//////////////////////////////// mouse wheel end ///////////////////////////////
//////////////////////////////// text scroll end ///////////////////////////////
var BrowserDetect = {
   init : function () {
      this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
      this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
      this.OS = this.searchString(this.dataOS) || "an unknown OS";
      }
   , searchString : function (data) {
      for (var i = 0; i < data.length; i++) {
         var dataString = data[i].string;
         var dataProp = data[i].prop;
         this.versionSearchString = data[i].versionSearch || data[i].identity;
         if (dataString) {
            if (dataString.indexOf(data[i].subString) != - 1) return data[i].identity;
            }
         else if (dataProp) return data[i].identity;
         }
      }
   , searchVersion : function (dataString) {
      var index = dataString.indexOf(this.versionSearchString);
      if (index == - 1) return;
      return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
      }
   , dataBrowser : [ {
      string : navigator.userAgent, subString : "Chrome", identity : "Chrome" }
   , {
      string : navigator.userAgent, subString : "OmniWeb", versionSearch : "OmniWeb/", identity : "OmniWeb" }
   , {
      string : navigator.vendor, subString : "Apple", identity : "Safari", versionSearch : "Version" }
   , {
      prop : window.opera, identity : "Opera" }
   , {
      string : navigator.vendor, subString : "iCab", identity : "iCab" }
   , {
      string : navigator.vendor, subString : "KDE", identity : "Konqueror" }
   , {
      string : navigator.userAgent, subString : "Firefox", identity : "Firefox" }
   , {
      string : navigator.vendor, subString : "Camino", identity : "Camino" }
   , {
      // for newer Netscapes (6+)
      string : navigator.userAgent, subString : "Netscape", identity : "Netscape" }
   , {
      string : navigator.userAgent, subString : "MSIE", identity : "Explorer", versionSearch : "MSIE" }
   , {
      string : navigator.userAgent, subString : "Gecko", identity : "Mozilla", versionSearch : "rv" }
   , {
      // for older Netscapes (4-)
      string : navigator.userAgent, subString : "Mozilla", identity : "Netscape", versionSearch : "Mozilla" }
   ], dataOS : [ {
      string : navigator.platform, subString : "Win", identity : "Windows" }
   , {
      string : navigator.platform, subString : "Mac", identity : "Mac" }
   , {
      string : navigator.userAgent, subString : "iPhone", identity : "iPhone/iPod" }
   , {
      string : navigator.platform, subString : "Linux", identity : "Linux" }
   ]};
/**
* @constructor Animate
* @param {HTMLElement} el the element we want to animate
* @param {String} prop the CSS property we will be animating
* @param {Object} opts a configuration object
* object properties include
* from {Int}
* to {Int}
* time {Int} time in milliseconds
* callback {Function}
*/
function Animate(el, prop, opts) {
   this.el = el;
   this.prop = prop;
   this.from = opts.from;
   this.to = opts.to;
   this.time = opts.time;
   this.callback = opts.callback;
   this.animDiff = this.to - this.from;
   this.ease = opts.ease;
   }
/**
* @private
* @param {String} val the CSS value we will set on the property
*/
Animate.prototype._setStyle = function (val) {
   switch (this.prop) {
      case 'opacity': this.el.style[this.prop] = val;
      this.el.style.filter = 'alpha(opacity=' + val * 100 + ')';
      break;
      default : this.el.style[this.prop] = val + 'px';
      break;
      };
   };
/**
* @private
* this is the tweening function
*/
Animate.prototype._animate = function () {
   var that = this;
   this.now = new Date();
   this.diff = this.now - this.startTime;
   if (this.diff > this.time) {
      this._setStyle(this.to);
      if (this.callback) {
         this.callback.call(this);
         }
      clearInterval(this.timer);
      return;
      }
   this.percentage = (Math.floor((this.diff / this.time) * 100) / 100);
   this.val = (this.animDiff * this.percentage) + this.from;
   this._setStyle(this.val);
   };
/**
* @public
* begins the animation
*/
Animate.prototype.start = function () {
   var that = this;
   this.startTime = new Date();
   this.timer = setInterval(function () {
      that._animate.call(that); }
   , 4);
   };
