/*
* Site Library
* @Author: Alexander Gavazov
* @Date: 2007-11-22
*/

function addLoadEvent(func, objectId)
{
	if(!objectId)
	{
		objectId = 'onload';
	}

	var oldonload = window[objectId];

	if(typeof window[objectId] != 'function')
	{
		window[objectId] = func;
	}
	else
	{
		window[objectId] = function()
		{
			if(oldonload)
			{
				oldonload();
			}

			func();
		}
	}
}

function $(elementId)
{
	return document.getElementById(elementId);
}

Function.prototype.bind = function(obj)
{
	var method = this,
	temp = function()
	{
		return method.apply(obj, arguments);
	};

	return temp;
}


function removeNodes(node)
{
	if(!node)
	{
		return;
	}

	while(node.hasChildNodes())
	{
		node.removeChild(node.firstChild);
	}
}


function positivelyInt(integer)
{
	if(integer < 0 || isNaN(integer))
	{
		integer = 0;
	}

	return integer;
}


function getDocumentSize()
{
	size = [];
	size['width'] = (self.innerWidth) ? self.innerWidth : document.documentElement.clientWidth;
	size['height'] = (self.innerHeight) ? self.innerHeight : document.documentElement.clientHeight;
	return size;
}


function getPosition(element)
{
	positions = {
		top: 0,
		left: 0
	};

	if(element.offsetParent)
	{
		positions.top = element.offsetTop;
		positions.left = element.offsetLeft;

		while(element = element.offsetParent)
		{
			positions.top += element.offsetTop
			positions.left += element.offsetLeft
		}
	}

	return positions;
}
