/*
 *
 * ContentLoaded.js
 *
 * Author: Diego Perini (diego.perini at gmail.com)
 * Summary: Cross-browser wrapper for DOMContentLoaded
 * Updated: 05/10/2007
 * License: GPL/CC
 * Version: 1.0
 *
 * http://javascript.nwbox.com/ContentLoaded/
 *
 * Notes:
 *
 *  based on code by Dean Edwards and John Resig
 *  http://dean.edwards.name/weblog/2006/06/again/
 *
 *
 */

/*
 * Example call, in this case:

	Offspring.ContentLoaded(window,
		function () {
			document.body.style.backgroundColor = 'green';
		}
	);
*
*/

// @w	window reference
// @f	function reference
function ContentLoaded(w, fn) {
	var d = w.document,
		u = w.navigator.userAgent.toLowerCase();

	function init(e) {
		if (!arguments.callee.done) {
			arguments.callee.done = true;
			fn(e);
		}
	}

	// konqueror/safari
	if (/khtml|webkit/.test(u)) {

		(function () {
			if (/complete|loaded/.test(d.readyState)) {
				init('poll');
			} else {
				setTimeout(arguments.callee, 10);
			}
		})();

	// internet explorer all versions
	} else if (/msie/.test(u) && !w.opera) {

		(function () {
			try {
				d.documentElement.doScroll('left');
			} catch (e) {
				setTimeout(arguments.callee, 10);
				return;
			}
			init('poll');
		})();
		d.attachEvent('onreadystatechange',
			function (e) {
				if (d.readyState == 'complete') {
					d.detachEvent('on'+e.type, arguments.callee);
					init(e.type);
				}
			}
		);

	// browsers having native DOMContentLoaded
	} else if (d.addEventListener &&
		(/gecko/.test(u) && parseFloat(u.split('rv:')[1]) >= 1.8) ||
		(/opera/.test(u) && parseFloat(u.split('opera ')[1]) > 9)) {

		d.addEventListener('DOMContentLoaded',
			function (e) {
				this.removeEventListener(e.type, arguments.callee, false);
				init(e.type);
			}, false
		);

	// fallback to last resort
	} else {

		// from Simon Willison
		var oldonload = w.onload;
		w.onload = function (e) {
			if (typeof oldonload == 'function') {
				oldonload(e || w.event);
			}
			init((e || w.event).type);
		};

	}
} // end of ContentLoaded


  
function calcElementSize(el) {
  /*
	var oldWidthStyle = el.style.width, oldHeightStyle = el.style.height;
	el.style.width = "200px";
	el.style.height = "200px";
	var offsetWidth = el.offsetWidth;
	var offsetHeight = el.offsetHeight;
	el.style.width = oldWidthStyle;
	el.style.height = oldHeightStyle;
	return [ el.offsetWidth - (offsetWidth - 200), el.offsetHeight - (offsetHeight - 200)];
	*/
	return [ el.clientWidth, el.clientHeight ];
}

function calcElementPaddingBottom(el) {
  var oldPaddingStyle = el.style.paddingBottom;
	var size1 = el.offsetHeight;
	el.style.paddingBottom = 0;
	var size2 = el.offsetHeight;
	el.style.paddingBottom = oldPaddingStyle;
	return size1-size2;
}