/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
 // Supportive Functions



// Internet Explorer Workaounds:
var bIsMSIE;
if (navigator.appName == "Microsoft Internet Explorer") {
	bIsMSIE = true;
}

if (typeof(ie6)=="undefined") var ie6 = false;

var strPageRoot = 'http://www.webli.nl/';

 // Supportive Functions
 
function Map( obj ) {
   var key;
   for (key in obj) {
      this[key] = obj[ key ];   
   }
}

String.prototype.capitalize = function(){
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.slice(1).toLowerCase();
    });
};

String.prototype.capitalize2 = function(){
    return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.slice(1);
    });
};

function parseElem(value) {
   if (typeof value == 'string') {
      return elemById(value);
   }
   if (!isElement(value)) {
      return null;
   }
   return value;
}

function isElement(node) {
   return (typeof node == 'object' && node.nodeType == 1);
}

function addEvent (elem, event, func) {
   if (elem.addEventListener) {
      elem.addEventListener(event,func,false);
   }
   else if (elem.attachEvent) {
      elem.attachEvent('on'+event,func);
   }
   else {
      elem['on' + event] = func;
   }
}

function elementById(id) {
   if (document.getElementById) {
      return document.getElementById(id);
   }
   else if (document.all) {
      return document.all[id];
   }
   else if (document.layers) {
      return document.layers[id];
   }
}

function getSize(part) {
   var mapSize = new Map();
   var x, y, test1, test2;

   switch (part) {
      case 'window':
         //viewport size
         if (self.innerHeight) { 
            // all except Explorer
            x = self.innerWidth;
            y = self.innerHeight;
         }
         else if (document.documentElement && document.documentElement.clientHeight) {
            // Explorer 6 Strict
            x = document.documentElement.clientWidth;
            y = document.documentElement.clientHeight;
         }
         else if (document.body) {
            // other Explorers
            x = document.body.clientWidth;
            y = document.body.clientHeight;
         }
         break;
      case 'scroll':
         // pixels scrolled
         if (self.pageYOffset) {
            // all except Explorer
            x = self.pageXOffset;
            y = self.pageYOffset;
         }
         else if (document.documentElement && document.documentElement.scrollTop) {
            // Explorer 6 Strict
            x = document.documentElement.scrollLeft;
            y = document.documentElement.scrollTop;
         }
         else if (document.body) {
            // all other Explorers
            x = document.body.scrollLeft;
            y = document.body.scrollTop;
         }
         break;
      case 'document':
         //total doc height
         test1 = document.body.scrollHeight;
         test2 = document.body.offsetHeight
         if (test1 > test2) {
            // all but Explorer Mac
            x = document.body.scrollWidth;
            y = document.body.scrollHeight;
         }
         else {
            // Explorer Mac;
            //would also work in Explorer 6 Strict, Mozilla and Safari
            x = document.body.offsetWidth;
            y = document.body.offsetHeight;
         }
         break;
   }

   mapSize.x = x;
   mapSize.y = y;

   return mapSize;
}

function getInnerWidth (objElem) {

   // get Outer Width
   var intOuterWidth = objElem.offsetWidth;
   
   // get current Overflow and width, because it needs a temp change
   var cssOverflow = getStyleValue(objElem, 'overflow');
   var cssWidth = getStyleValue(objElem, 'width');
   
   // temporarily set the css styles to calculate inner width
   objElem.style.overflow = 'hidden';
   objElem.style.width    = '1px'; // 1, for browsers that cannot handle 0
   
   // this is the spacing of the element without it's contents
   var intSpacing = objElem.offsetWidth - 1;
   
   // Reset css styles, as they were.
   objElem.style.overflow = cssOverflow;
   objElem.style.width = cssWidth;
   
   // the inner Width is outerwidth without it's spacing
   return parseInt(intOuterWidth - intSpacing);
}

function getInnerHeight (objElem) {

   // get Outer Height
   var intOuterHeight = objElem.offsetHeight;
   
   // get current Overflow and height, because it needs a temp change
   var cssOverflow = getStyleValue(objElem, 'overflow');
   var cssHeight = getStyleValue(objElem, 'height');
   
   // temporarily set the css styles to calculate inner height
   objElem.style.overflow = 'hidden';
   objElem.style.height    = '1px'; // 1, for browsers that cannot handle 0
   
   // this is the spacing of the element without it's contents
   var intSpacing = objElem.offsetHeight - 1;
   
   // Reset css styles, as they were.
   objElem.style.overflow = cssOverflow;
   objElem.style.height = cssHeight;
   
   // the inner Height is outerheight without it's spacing
   return parseInt(intOuterHeight - intSpacing);
}

function getStyleValue(value, property, boolNoUnit) {
   var elem, styleValue, cssSyntax, jsSyntax = '', i, unitfree;
   elem = parseElem(value);

   if (document.defaultView && document.defaultView.getComputedStyle) {
      //if Moz/Opera/Safari, just get the style:
      styleValue = document.defaultView.getComputedStyle(elem,null).getPropertyValue(property);
   }
   else if (elem.currentStyle) {
      //if IE, rewrite property and get the style.
      while (property.indexOf('-') > -1)
      {
         _index = property.indexOf('-');

         jsSyntax += property.substr(0, _index);
         jsSyntax += property.substr(_index+1, 1).toUpperCase();
         property = property.substr(_index+2);
      }
      jsSyntax += property;

      styleValue = elem.currentStyle[jsSyntax];
   }

   if (boolNoUnit) {
      styleValue = parseFloat(styleValue);
      if (isNaN(styleValue)) {
         return 0;
      }
   }
   return styleValue;
}

function elementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
		if(re.test(els[i].className))a.push(els[i]);
	return a;
}

function elementsByTagName(tagname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	return node.getElementsByTagName(tagname);
}


function browseTo (loc) {
	if (!loc.match("http://")) {
		loc = strPageRoot + loc;
	}
	document.location.href = loc;
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {left:curleft,top:curtop};
}