 
/**
 * AUDI JavaScript library: core
 * 
 * @projectDescription	Provides core functionalities
 * @namespace			AUDI
 *
 * @author 				$Author: hhoettecke $
 * @version				$Revision: 6416 $
 * @copyright			NEUE DIGITALE GmbH, Berlin
 * 
* @jslint: 2008-10-31
 * 
 * @file:				audi_ngw.core.js
 * $URL: https://svn.pvtool.org/svn/day_audi_ngw/trunk/ngw_base/frontend/js/audi/audi.core.js $
 * 
 */
 




/**
 * Initialize global AUDI object 
 */
if (typeof audi_ngw === 'undefined') {
	audi_ngw = {};
}

/*
// extract docroot from shortcut icon path
jQuery(function(){
  // get relative path to root folder
  if( 'undefined' == typeof audi_ngw.docroot ) {
    audi_ngw.docroot = jQuery('head link[rel="shortcut icon"]').attr('href').split('img/')[0];
  }
  
  // prepend docroot to sIFR paths
  audi_ngw.FlashSrcBreadcrumb = audi_ngw.docroot + audi_ngw.FlashSrcBreadcrumb;
  audi_ngw.FlashSrcHeadlines = audi_ngw.docroot + audi_ngw.FlashSrcHeadlines;
  
});
*/

/**
 * Creates additional namespaces 
 * @param {Object} _oBase: Global Object
 * @param {String} sNamespace: Space to create
 * @example audi_ngw.namespace(audi_ngw,'example.namespace');
 */
audi_ngw.namespace = function(_oBase,_sNamespace) {
	var _col = _sNamespace.split('.');
	
	for (var _i = 0; _i < _col.length; _i++) {
		// don't have currend obj
		if (typeof(_oBase[_col[_i]]) === 'undefined') {
		// add obj
			_oBase[_col[_i]] = {};
		}
		_oBase= _oBase[_col[_i]];
	}
	return _oBase;
};

/**
 * Force id on elemente
 * @param {Object} element
 * @return {String} Element's id 
 * @deprecated 2008-07-07
 * @see audi_ngw.dom.identify()
 */
//audi_ngw.identify = function (element) {
//	 // op & msie gets id as string "null"
//	var _sId = jQuery(element).attr('id');
//	if (!_sId  || _sId  === null || _sId  == 'null') {
//		jQuery(element).attr('id', (('audi_generic_' + new Date().getTime() + '' + Math.floor(Math.random() * 10000)).toString()));
//	}
//	return jQuery(element).attr('id');
//}

/**
 * Clears timers
 * @method _clearTimer
 * @param {Object} Timer
 * @return {Null}
 */
audi_ngw.clearTimer = function(_timer){
	if (!_timer) {
		return;
	}
	window.clearTimeout(_timer);
	window.clearInterval(_timer);
	return null;
};

/**
 * returns random number between 0 and iMax
 * @method getRandomNumber
 * @param {iMax} integer
 * @return {iRandom}
 */
audi_ngw.getRandomNumber = function (iMax) {
	var iRandom = Math.floor(Math.random() * iMax);
	return iRandom;
};

audi_ngw.html_entidiy_decode = function (_str) {
	var _oTable = {
		'&gt;':'>',
		'&lt;':'<',
		'&auml;' : 'Ã¤',
		'&Auml;' : 'Ã„',
		'&ouml;' : 'Ã¶',
		'&Ouml;' : 'Ã–',
		'&uuml;' : 'Ã¼',
		'&Uuml;' : 'Ãœ'
	};
	for (var _key in _oTable) {
		if (_oTable.hasOwnProperty(_key)) {
			_str = _str.split(_key).join(_oTable[_key]);
		}
	}
	
	return _str;
};

/**
 * Internal logging function. Writes a message into the Firebug console.
 * @param {String} msg
 * @return boolean
 */
/*
if( 'undefined' == typeof(console) ) {
	console = {};
	console.log = function(msg) {
		audi_ngw.log(msg, 'log');
		return true;
	}
}
*/
audi_ngw.logCount = 0;
audi_ngw.log = function(msg, type){
	

	if(audi_ngw.debug){
		if( 'undefined' == typeof(type) ) {
			type = 'log';
		}
		try {
			if( 'error' == type) {console.error(msg);}
			else if( 'warn' == type ) {console.warn(msg);}
			else {console.log(msg);}
			return true;
		} catch(e) {
			if( audi_ngw.ieDebug ) {
				if( 0 === jQuery('#debug').size() ) {
					jQuery('<div id="debug"></div>').appendTo('body').css({border: '1px solid #fff', overflow: 'auto', display: 'block', position: 'absolute', left: '5px', top: '5px', width: '200px', height: '300px'});
				}
				audi_ngw.logCount++;
				jQuery('#debug').prepend('<p>' + audi_ngw.logCount + ': ' + msg + '<hr /></p>');
			}
			return true;
		}
	}
};

jQuery(window).bind('unload', function() { 
	jQuery('*').add(window).add(document).unbind(); 
});

 

/**
 * remove an item from an array 
 * @param {Array} array
 * @param {String|Int} index
 * @return 
 */
audi_ngw.arrayRemove = function(varArray, key) {
	
	var pos;
	if( !key ) {
		return;
	}
	
	if( isNaN(key) ) {
		pos = 0;
		for ( var i = 0, length = varArray.length; i < length; i++ ) {
			if( key == varArray[i] ) {
				pos = i;
			}
		}
	} else {
		pos = key;
	}
	
	
	varArray.splice(pos, 1);
	return varArray;
};
