/**
 * This file contains standard functions used throughout the application.
 *
 * @author Herman Bredewoud
 * @version 1.00
 * @name Eventlistener Script
 */
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var m_oEvent				= null;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*	This function will check the browser type used by the client.
*/
function EVENT_browserCheck(){
	var a_sNav_userAgent, a_sBrowser_type;

	a_sNav_userAgent = navigator.userAgent;

	this.isIE    = false;
	this.version = null;

	a_sBrowser_type = "MSIE";
	if ((i = a_sNav_userAgent.indexOf(a_sBrowser_type)) >= 0){
		this.isIE = true;
		this.version = parseFloat(a_sNav_userAgent.substr(i + a_sBrowser_type.length));
		return;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*	This function will create all global event listeners.
*/
function EVENT_event(){
	//Will call the onload function for loading scripts after page has been loaded.
	if(typeof(window.onload) != 'function'){
		window.onload = EVENT_onload;
	}

	//Will check for onmouseover actions to be done.
	if(typeof(document.onmouseover) != 'function'){
		document.onmouseover = EVENT_onmouseover;
	}
	
	//Will check for onclick actions to be done.
	if(typeof(document.onclick) != 'function'){
		document.onclick = EVENT_onclick;
	}
	
	//Will check for onclick actions to be done.
	if(typeof(document.onmousedown) != 'function'){
		document.onmousedown = EVENT_onmousedown;
	}
	
	//Will check for onclick actions to be done.
	if(typeof(document.onmouseup) != 'function'){
		document.onmouseup = EVENT_onmouseup;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*	This function calls function that has te be run after the page has loaded.
*
*	@param object a_oEvent
*/
function EVENT_onload(a_oEvent) {
	//If the browser is Internet Explorer m_oEvent is the window.event.
	if(m_oBrowserType.isIE){
		m_oEvent 	= window.event;
		a_oEvent 	= m_oEvent;
	}

////// Load files used for application plugins./////////////////////////////////////////
	// Load the optional javascripts.
	if (CONF_bIncPNGFix) OBJ_include_js(CONF_getDir('dir_javascripts')+'js_pngfix.js',true);	
	if (CONF_bIncSWFac) OBJ_include_js(CONF_getDir('dir_javascripts')+'js_swf_ac.js',true);
	if (CONF_bIncSWFac) OBJ_include_js(CONF_getDir('dir_javascripts')+'js_flash.js',false);
	
////////////////////////////////////////////////////////////////////////////////////////
	
	// Preload some images.
//	EVENT_preLoadImages(CONF_getDir('dir_img_logos')+'logo.png');
}

/**
*	This function will check if on the mouseover an action needs to be done.
*
*	@param object a_oEvent
*/
function EVENT_onmouseover(a_oEvent){
	if(m_oBrowserType.isIE){
		a_oEvent = m_oEvent;
	}
}

/**
*	This function will check if on the onclick an action needs to be done.
*
*	@param object a_oEvent
*/
function EVENT_onclick(a_oEvent){
	if(m_oBrowserType.isIE){
		a_oEvent = m_oEvent;
	}
}

/**
*	This function will check if on the onmousedown an action needs to be done.
*
*	@param object a_oEvent
*/
function EVENT_onmousedown(a_oEvent){
	if(m_oBrowserType.isIE){
		a_oEvent = m_oEvent;
	}
}

/**
*	This function will check if on the onmouseup an action needs to be done.
*
*	@param object a_oEvent
*/
function EVENT_onmouseup(a_oEvent){
	if(m_oBrowserType.isIE){
		a_oEvent = m_oEvent;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*	This funtion will return the target element on an event.
*
*	@param object a_oEvent
*/
function EVENT_getTargetElement(a_oEvent){
	if(m_oBrowserType.isIE){
		return a_oEvent.srcElement;
	}else{
		return a_oEvent.target;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
*	This function will preload images. Unlimited number of source arguments may be given when calling this function.
*
*	@param string(s)
*/
function EVENT_preLoadImages(){
	if(CONF_bPreloadImage){
		var oDoc = document;
		if (oDoc.images){
			if (!oDoc.aPreloadImages){
				oDoc.aPreloadImages = new Array();
			}
			
			var iPreloadCounter = oDoc.aPreloadImages.length;
			var oImageSrc = EVENT_preLoadImages.arguments;
			
			for (var i=0; i < oImageSrc.length; i++){
				oDoc.aPreloadImages[iPreloadCounter] = new Image;
				oDoc.aPreloadImages[iPreloadCounter++].src = oImageSrc[i];
			}
		}
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var m_oBrowserType = new EVENT_browserCheck();
//Run the event function for creating eventlisteners.
EVENT_event();
