/* (C) 2006-2008 Veselchak U */

/* utilities */

// common library
var lib =
{
	getRef: function (id)
	{
		return (typeof(id) == 'string') ? document.getElementById(id) : id;
	},

	getStyleProp: function (id, propName)
	{
		var ref = this.getRef(id);

		if (ref.style.posLeft)
		{
			if (propName == 'left')
				propName = 'posLeft';
			else if(propName == 'top')
				propName = 'posTop';
		}
		return ref.style[propName] ? ref.style[propName] : undefined;
	},

	setStyleProp: function (id, propName, value)
	{
		var ref = this.getRef(id);

		if (ref.style.posLeft)
		{
			if (propName == 'left')
				propName = 'posLeft';
			else if(propName == 'top')
				propName = 'posTop';
		}
		if (ref.style[propName]) ref.style[propName] = value;
	},

	__next_uid: 0,

	makeUID: function (prefix, postfix)
	{
		return prefix + (++lib.__next_uid) + postfix;
	},

	setClass: function (ref, cls)
	{
	    ref.className = cls;
	}
};

// position lib
var libPos =
{
	getWidth: function (id)
	{
		var ref  = lib.getRef(id);
		return ref ? ref.offsetWidth : 0;
	},

	getHeight: function (id)
	{
		var ref  = lib.getRef(id);
		return ref ? ref.offsetHeight : 0;
	},

	getXPos: function (id)
	{
		var ref = lib.getRef(id);
		return ref ? ref.offsetLeft : 0;
	},

	getYPos: function (id)
	{
		var ref  = lib.getRef(id);
		return ref ? ref.offsetTop : 0;
	},

	getZPos: function (id)
	{
		var ref  = lib.getRef(id);
		return ref ? (0 + ref.style.zIndex) : 0;
	},

	setWidth: function (id, w)
	{
		lib.setStyleProp(id, 'width', w);
	},

	setHeight: function (id, h)
	{
		lib.setStyleProp(id, 'height', h);
	},

	setXPos: function (id, x)
	{
		lib.setStyleProp(id, 'left', x + 'px');
	},

	setYPos: function (id, y)
	{
		lib.setStyleProp(id, 'top', y + 'px');
	},

	setZPos: function (id, z)
	{
		lib.setStyleProp(id, 'zIndex', z);
	}
};

