/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
 // Supportive Functions



// Internet Explorer Workaounds:
var bIsMSIE;
if (navigator.appName == "Microsoft Internet Explorer") {
	bIsMSIE = true;
}

var strWebRoot  = 'http://www.rockpalace.com/';
var strPageRoot = 'http://www.rockpalace.com/';

 // Supportive Functions
 
function Map( obj ) {
   var key;
   for (key in obj) {
      this[key] = obj[ key ];   
   }
}

Number.prototype.fix = function (i) {
    var n = String(this);
    while (n.length<i) n='0'+n;
    return n;
};

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);
    });
};

String.prototype.formatDate = function(offset){
	var dt = new Date(this.replace(/^(\w+) (\w+) (\d+) (\d+:\d+:\d+) \+(\d+) (\d+)$/, '$2 $3, $6 $4'));
	var dth = dt.getUTCHours() + parseInt((typeof(offset)=="number" ? offset : 0), 10);
	return dt.getDate().fix(2) + '-' + parseInt(dt.getMonth()).fix(2) + '-' + dt.getUTCFullYear() + ' ' + (dth>23?dth-24:dth).fix(2) + ':' + dt.getUTCMinutes().fix(2) + ':' + dt.getUTCSeconds().fix(2);
};


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 getWindowDims() {
  try {
  return {
  'width' : window.innerWidth ?
            window.innerWidth : //firefox
            ((document.documentElement.clientWidth == 0) ? // are we in quirks mode?
              document.body.clientWidth :  // yes we are, so this is width
              document.documentElement.clientWidth ), // no, so this is width

  'height': window.innerHeight ?
            window.innerHeight : //firefox
            ((document.documentElement.clientHeight == 0) ? // are we in quirks mode?
              document.body.clientHeight:  // yes we are, so this is width
              document.documentElement.clientHeight ), // no, so this is width

  'scrollTop' : window.pageYOffset ?
                window.pageYOffset : // ff
                (document.body.scrollTop != 0 ? //ie
                  document.body.scrollTop :  // quirks mode ie
                  (document.documentElement.scrollTop) ), // strict mode ie

  'scrollLeft': window.pageXOffset ?
                window.pageXOffset :
                (document.body.scrollLeft != 0 ? //ie
                          document.body.scrollLeft : // quirks mode ie
                          document.documentElement.scrollLeft ) // strict mode ie

  };
  } catch (e) {}
}

function getMouse (evt) {
	var dims = getWindowDims();
	if (evt.pageX)
		return {
			x:evt.pageX,
			y:evt.pageY
		}; 
	else if (evt.clientX)
		return {
			x: evt.clientX + dims['scrollLeft'],
			y: evt.clientY + dims['scrollTop']
		};
	else
		return {x:null, y:null};
}

/*function getMouse (evt) {
	
	var tempX, tempY;
   var xny = new Map();
	var IE = document.all?true:false;
	var dims = getWindowDims();
	
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + dims['scrollLeft'];
		tempY = event.clientY + dims['scrollTop'];
	} else {  // grab the x-y pos.s if browser is NS
		if (typeof(e)=='undefined') e = window.event;
		tempX = e.pageX;
		tempY = e.pageY;
	} 
	
	xny.x = tempX;
	xny.y = tempY;
	
	return xny;
	
}*/

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;
}

var getURL;
getURL = function (url) {
	document.location.href = url;
}


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};
}