

/**
 *
 */
function $( id )
{
	if( document.getElementById( id ) )
	{
		return document.getElementById(id);
	}
	else
	{
		if( document.getElementById( 'debug' ) )
		{
			debug('Element "'+id+'" does not exists in the DOM.');
		}
		return false;
	}
}


/************ Bind,  , e *************************/

/**
 *
 */
Function.prototype.bind = function( obj )
{	
	var method = this;
	return function(e)
	{
		return method.call( obj , e );
	};
}

Function.prototype.curry = function()
{	
	var method = this;//function
	var obj = arguments[0];
	var args = new Array();
    for (var i=1, len = arguments.length; i < len; ++i)
	{
        args.push(arguments[i]);
    };
	
	return function()
	{
	    method.apply(obj,args);
    };
} 

Function.prototype.e = function()
{	
	var method = this;//function
	var obj = arguments[0];//obj for scope
	var args = new Array();
  for (var i=2, len = arguments.length; i < len; ++i)
	{
		args.push(arguments[i]);
  };
	return function(e)
	{
		method.apply( obj, args.unshift(e) );
  };
} 

/************* Mouse *************************************************/

mouse = {};
mouse.getPos = function ( e )
{
	var pos = new Array();

	if (!e) var e = window.event;

	if (e.pageX || e.pageY)
	{
		pos['x'] = e.pageX;
		pos['y'] = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		pos['x'] = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		pos['y'] = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	
	return pos;
}

mouse.change_cursor = function( e )
{
	document.body.style.cursor = 'move';
}

mouse.change_cursor2 = function( e )
{
	document.body.style.cursor = '';
}


//_________________________________ Events _____________________________________


/**
 * caters for the differences between Internet Explorer and fully DOM-supporting browsers
 */
function findTarget(e)
{
 var target;

 if (window.event && window.event.srcElement)
   target = window.event.srcElement;
 else if (e && e.target)
   target = e.target;
 if (!target)
   return null;

 return target;
}


/**
 *
 */
addEvent = function( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}


