/***
* @author 			Oskar Hasinski ( hasinski@popsit.com )
* @package			ItemtManager
* 
* @created			20.12.2008
* @updated			07.02.2009
* @updateAuthor		Oskar Hasinski
* 
* @copy				Oskar Hasinski, Miet24 GmbH
**/

//String.ucwords( $str )
//{
//	return ($str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
//        return $1.toUpperCase();
//    });
//}

String.prototype.ucwords = function(){
	return this.replace(/\w+/g, function(a){
        return a.charAt(0).toUpperCase() + a.substr(1).toLowerCase();
    });
};


/* jQuery expand */
jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	};
};





jQuery.implode = function( glue,pieces )
{
	return ( ( pieces instanceof Array ) ? pieces.join( glue ) : pieces );

};
jQuery.in_array = function( needle,haystack,argStrict )
{
	var key = '', strict = !!argStrict;
 
	if (strict)
	{
		for (key in haystack)
		{
			if (haystack[key] === needle)
			{
				return true;
			};
		};
	}
	else
	{
		for (key in haystack)
		{
			if (haystack[key] == needle)
			{
				return true;
			};
		};
	};
 
    return false;
};

jQuery.disableKey	= function( $key, $scope )
{
	var $key_code;
	$( $scope ).bind( 'keydown', function( event ){
		if( window.event )
		{
			$key_code	= window.event.keyCode;
		}
		else
		{
			$key_code	= event.which;
		}
		
		if( $key_code == $key )
		{
			event.preventDefault();
		}
	});	
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

jQuery.getUrlVars = function()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	};
	return vars;
};

jQuery.getUrlVar = function( name )
{
	return $.getUrlVars()[name];
};

/**
 * SET class
 * @author 		Oskar Hasinski (hasinski@popsit.com)
 * @created		01.02.2009
 * @updated		07.02.2009
 **/

function _set()
{
	this.data_arr 			= Array();
	this.scope 				= '';
	this.valStatus		= Array();
	
	this.data = function( key,value )
	{
		this.data_arr[key] = value;
	};
	
	this.setScope = function (scope)
	{
		this.scope = '#'+scope+' ';
	};
}
set = new _set();

/**
 * GET class
 * @author 		Oskar Hasinski (hasinski@popsit.com)
 * @created		01.02.2009
 * @updated		06.02.2009
 **/

function _get()
{
	this.data = function ( key )
	{
		return set.data_arr[key];
	};
	
	this.date = function()
	{
		return new Date;
	};
	
	this.charactersPosition = function(pattern, needle)
	{
		var position = Array();
		var arr = 0;
		for(i=0; i<pattern.length; i++)
		{
			if(pattern.charAt(i) == needle)
			{
				position[arr] = i;
				arr++;
			};
		};	
		return arr[0];
	};
};
get = new _get();

_get.prototype.position = function( obj )
{
	var $left	= 0; 
	var $top	= 0;
	if (obj.offsetParent) {
		do {
			$left	+= obj.offsetLeft;
			$top	+= obj.offsetTop;
		} while (obj = obj.offsetParent);
		
		return [$left,$top];
	};
};



/*
 * Startup
 */
$(document).ready(function()
{
	if( typeof( set.tabbed ) !== 'undefined' ) set.tabbed();
	if( typeof( set.dropped ) !== 'undefined' ) set.dropped();
	
});
