/**
 * Extending classes function
 */
extend = function( child, parent )
{
	var f = function() {};
	f.prototype = parent.prototype;
	child.prototype = new f();
	child.prototype.constructor = child;
	child.superclass = parent.prototype;
}

/**
 * Copying properties from src object to dst object function
 */
mixin = function ( dst, src )
{
	var tobj = {} 
	for (var x in src)
		if ((typeof(tobj[x]) == "undefined") || (tobj[x] != src[x]))
			dst[x] = src[x];
	
	if (document.all && !document.isOpera)
	{
		var p = src.toString;
		if (typeof(p) == "function" && p != dst.toString && p != tobj.toString &&
			p != "\nfunction toString() {\n    [native code]\n}\n")
		{
			dst.toString = src.toString;
		}
	}
}

/**
 * Returning svg path string part function
 */
svgPathPart = function ()
{
	var res = "";
	for (var i = 0; i < arguments.length; i++)
		res += arguments[i] + " ";
	
	return res;
}

/**
 * Returning translatable group of elements function
 */
Raphael.fn.translateGroup = function ()
{
	// Creating group object
	group = {dx: 0, dy: 0, elems: []};
	
	// Translating group function
	group.translate = function ( dx, dy )
	{
		// Memorizing translation
		this.dx += dx;
		this.dy += dy;
		
		// Translating all existing elements
		for (i in this.elems)
			this.elems[i].translate(dx, dy);
	}
	
	// Adding element to group function
	group.push = function ( elem )
	{
		elem.translate(this.dx, this.dy);
		this.elems[this.elems.length] = elem;
	}
	
	return group;
}

/**
 * Returning number from the begining of the string function
 */
getNumber = function ( str )
{
	var res = "";

	for (i = 0; i < str.length; i++)
	{
		cur = str.charAt(i);
		if (cur >= '0' && cur <= '9')
			res += cur;
		else
			break;
	}

	return res * 1;
}

/**
 * Returning position of element function
 */
getElementPos = function ( el )
{
	var r = {x: el.offsetLeft, y: el.offsetTop};
	
	if (el.offsetParent)
	{
		var tmp = getElementPos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	
	return r;
}

/**
 * Generating JS object from JSON string function
 * @param string str - string with JSON object
 */
jsonMakeObject = function ( str )
{
	return eval("(" + str + ")");
}

/**
 * Deleting space symbols from left function
 */
function ltrim( str )
{
	var ptrn = /\s*((\S+\s*)*)/;
	return str.replace(ptrn, "$1");
}

/**
 * Deleting space symbols from right function
 */
function rtrim( str )
{
	var ptrn = /((\s*\S+)*)\s*/;
	return str.replace(ptrn, "$1");
}

/**
 * Deleting space symbols from left and right function
 */
function trim( str ) {
	return ltrim(rtrim(str));
}
