document.getElementsByClassName = function(className, parentElement) {
  var children = ($(parentElement) || document.body).getElementsByTagName('*');
  return $A(children).inject([], function(elements, child) {
    if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
      elements.push(child);
    return elements;
  });
}

// sId - unique Id of the div element
// It swaps the visibillity of the div element by changing it's css style 
function SwapVisibility(sId){
    var oDiv = null;

    oDiv = document.getElementById(sId);
    if(!oDiv)return;
    
    if (oDiv.style.visibility == 'hidden')
        oDiv.style.visibility = 'visible';
    else 
        oDiv.style.visibility = 'hidden';
}


// Shorthand function for document.getElementById
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 getViewportSize(){
    var size = [0,0];

    if (typeof window.innerWidth != "undefined"){
        size = [
            window.innerWidth,
            window.innerHeight 
        ];
    }else if (typeof document.documentElement != "undefined" &&
              typeof document.documentElement.clientWidth != 'undefined' &&
              typeof document.documentElement.clientWidth != 0){
            size = [
                document.documentElement.clientWidth,
                document.documentElement.clientHeight
            ];
    }else{
        size = [
            document.getElementsByTagName['body'][0].clientWidth,
            document.getElementsByTagName['body'][0].clientHeight
        ];
    }

    return size;
}

function getPageDimensions(){
    var body = document.getElementsByTagName("body")[0];
    var bodyOffsetWidth = 0;
    var bodyOffsetHeight = 0;
    var bodyScrollWidth = 0;
    var bodyScrollHeight = 0;
    var pageDimensions = [0, 0];

    if (typeof document.documentElement != "undefined" &&
        typeof document.documentElement.scrollWidth != "undefined")
    {
        pageDimensions[0] = document.documentElement.scrollWidth;
        pageDimensions[1] = document.documentElement.scrollHeight;
    }

    bodyOffsetWidth = body.offsetWidth;
    bodyOffsetHeight = body.offsetHeight;
    bodyScrollWidth = body.scrollWidth;
    bodyScrollHeight = body.scrollHeight;

    if (bodyOffsetWidth > pageDimensions[0]){
        pageDimensions[0] = bodyOffsetWidth;
    }

    if (bodyOffsetHeight > pageDimensions[1]){
        pageDimensions[1] = bodyOffsetHeight;
    }

    if (bodyScrollWidth > pageDimensions[0]){
        pageDimensions[0] = bodyScrollWidth;
    }

    if (bodyScrollHeight > pageDimensions[1]){
        pageDimensions[1] = bodyScrollHeight;
    }

    return pageDimensions;
}


function getScrollingPosition(){
  //array for X and Y scroll position
  var position = [0, 0];

  //if the window.pageYOffset property is supported
  if (typeof window.pageYOffset != 'undefined')
  {
    //store position values
    position = [
        window.pageXOffset,
        window.pageYOffset
    ];
  }

  //if the documentElement.scrollTop property is supported
  //and the value is greater than zero
  if (typeof document.documentElement.scrollTop != 'undefined'
      && document.documentElement.scrollTop > 0)
  {
    //store position values
    position = [
        document.documentElement.scrollLeft,
        document.documentElement.scrollTop
    ];
  }

  //if the body.scrollTop property is supported
  else if(typeof document.body.scrollTop != 'undefined')
  {
    //store position values
    position = [
        document.body.scrollLeft,
        document.body.scrollTop
    ];
  }

  //return the array
  return position;
}


// cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko by Scott Andrew
// By Scott Andrew
function addEvent(elm, evType, fn, useCapture){
    if (elm.addEventListener){
        elm.addEventListener(evType, fn, useCapture);
        return true;
    } else if (elm.attachEvent){
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    } else {
        elm['on' + evType] = fn;
    }
}


// method borrowed from DOMtab Version 3.1415927 (Christian Heilmann - http://www.wait-till-i.com)
function CSSJS(a,o,c1,c2){
    switch (a){
            case 'swap':
                o.className=!CSSJS('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
            break;
            case 'add':
                if(!CSSJS('check',o,c1)){o.className+=o.className?' '+c1:c1;}
            break;
            case 'remove':
                var rep=o.className.match(' '+c1)?' '+c1:c1;
                o.className=o.className.replace(rep,'');
            break;
            case 'check':
                var found=false;
                var temparray=o.className.split(' ');
                for(var i=0;i<temparray.length;i++){
                    if(temparray[i]==c1){found=true;}
                }
                return found;
            break;
    }
}
