function blurInput(obj) { if (obj.value == "") obj.value = obj.defaultValue; } function focusInput(obj) { if (obj.value == obj.defaultValue) obj.value = ""; } function preload(url) { var img = new Image(); img.src = url; } function getBestStyle(obj) { if (window.getComputedStyle != undefined) { return window.getComputedStyle(obj); } else if (obj.currentStyle != undefined) { return obj.currentStyle; } else return obj.style; } function getPixels(s) { if (s == undefined || s.indexOf("px") == -1) { return 0; } else return parseInt(s.replace("px", "")); } function parseColor(s) { var a = Array(); for (var i = 0; i < s.length; i += 2) { var b = s.substring(i, i + 2); a.push(parseInt(b, 16)); } return a; } function colorString(a) { var s = ""; for (var i = 0; i < a.length; i++) { var b = a[i].toString(16); if (b.length == 1) b = "0" + b; s += b; } return s.toUpperCase(); } function interColor(a, b, p) { a = parseColor(a); b = parseColor(b); c = Array(); for (var i = 0; i < a.length; i++) { var x = b[i] - a[i]; x *= p; x += a[i]; x = Math.round(x); c.push(x); } return colorString(c); } function setOpacity(obj, value) { obj.style.opacity = value; obj.style.filter = 'alpha(opacity=' + value * 100.0 + ')'; } function getOffset(obj) { var x = 0; var y = 0; while (obj) { x += obj.offsetLeft || 0; y += obj.offsetTop || 0; obj = obj.offsetParent; } return {left: x, top: y}; } function findChildByClass(obj, cname) { for (var i = 0; i < obj.childNodes.length; i++) { if (obj.childNodes[i].className == cname) { return obj.childNodes[i]; } } return undefined; } function childrenWithClass(parent, className) { var items = Array(); var children = parent.childNodes; for (var i = 0; i < children.length; i++) { var classes = children[i].className != undefined ? children[i].className.split(" ") : Array(); for (var j = 0; j < classes.length; j++) { if (classes[j].toLowerCase() == className.toLowerCase()) { items.push(children[i]); break; } } } return items; } function getMovement(time, speed) { var px = Math.round(speed * time / 1000.0); if (speed < 0) { if (px >= 0) px = -1; } else { if (px <= 0) px = 1; } return px; } function onWindowLoad(handler) { if (window.addEventListener) { window.addEventListener("load", handler, false); } else if (window.attachEvent) { window.attachEvent("onload", handler); } } // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating // requestAnimationFrame polyfill by Erik Möller // fixes from Paul Irish and Tino Zijdel (function () { var lastTime = 0; var vendors = ['ms', 'moz', 'webkit', 'o']; for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame']; } if (!window.requestAnimationFrame) window.requestAnimationFrame = function (callback, element) { var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = window.setTimeout(function () { callback(currTime + timeToCall); }, timeToCall); lastTime = currTime + timeToCall; return id; }; if (!window.cancelAnimationFrame) window.cancelAnimationFrame = function (id) { clearTimeout(id); }; }());