/*
	sxFramework 2.1
	by Tobias Jacksteit
*/

/* Detect browser */
var browser = 'unknown';
var browser_version = -1;
if( navigator.userAgent.indexOf( 'Firefox' ) != -1 ) {
	browser_version = parseFloat( navigator.userAgent.replace(/^.*Firefox\/(\d\.\d+).*$/i, '$1' ) );
	browser = 'firefox';
} else if( navigator.userAgent.indexOf( 'Opera' ) != -1 ) {
	browser_version = parseFloat( navigator.userAgent.replace(/^Opera\/(\d\.\d+) .*$/i, '$1' ) );
	browser = 'opera';
} else if( navigator.userAgent.indexOf( 'Safari' ) != -1 ) {
	browser_version = parseFloat( navigator.userAgent.replace(/^.*Version\/(\d\.\d+) .*$/i, '$1' ) );
	browser = 'safari';
} else if( navigator.userAgent.indexOf( 'Konqueror' ) != -1 ) {
	browser = 'konqueror';
} else if( navigator.userAgent.indexOf( 'MSIE' ) != -1 ) {
	browser_version = parseFloat( navigator.userAgent.replace(/^.*MSIE (\d\.\d+);.*$/, '$1') );
	browser = 'ie';
}

/* Add events via JavaScript */
function sx_addEvent( eventObject, eventType, eventFunction, eventPhase ) { 
	if( eventPhase == undefined ) {
		eventPhase = false;
	}
	if( eventObject.addEventListener ) { 
		eventObject.addEventListener( eventType, eventFunction, eventPhase ); 
		return true; 
	} else if( eventObject.attachEvent ) { 
		var r = eventObject.attachEvent( "on" + eventType, eventFunction ); 
		return r; 
	} else { 
		return false; 
	}
}

/* Absolute position of an element */
function sx_absoluteLeft( obj ) {
	if( obj != undefined ) {
		posLeft = obj.offsetLeft;
		while( ( obj = obj.offsetParent ) != null ) {
			posLeft += obj.offsetLeft;
		}
		return( posLeft );
	} else {
		return( 0 );
	}
}

function sx_absoluteTop( obj ) {
	if( obj != undefined ) {
		posTop = obj.offsetTop;
		while( ( obj = obj.offsetParent ) != null ) {
			posTop += obj.offsetTop;
		}
		return( posTop );
	} else {
		return( 0 );
	}
}

/* Loading functions */
var loadFunctions = new Array();
function sx_addLoad( eventFunction ) {
	loadFunctions.push( eventFunction );
}

function sx_onLoad() {
	for( i = 0; i < loadFunctions.length; i++ ) {
		loadFunctions[ i ]();
	}
}

if( window.addEventListener ) {
	window.addEventListener( "load", sx_onLoad, false );
} else if( window.attachEvent ) {
	window.attachEvent( "onload", sx_onLoad );
} else { 
	if( typeof window.onload == 'function' ) {
		var prevLoad = window.onload;
		window.onload = function() {
			prevLoad();
			sx_onLoad();
		}
	} else {
		window.onload = sx_onLoad;
	}
}
