/**
* JSAX - JavaScript (Standard) Abstractions for X(HT)ML
*
* written by Florian Sax 20051229 <flosax(at)users.sourceforge.net>
* Copyright (C) 2005 Florian Sax
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
* 
* 
* You can also find the GPL at the following internet adress: <http://www.gnu.org/copyleft/gpl.html>
*
* @version: 20060626
*/
window.JSAX = {
	Version: 20060626,
/**
* JSAX.JSload - include and require for JavaScript ( uses JSAX.HTTP)
*
* @parent JSAX.JSload
*/
JSload: {
	dir: "",
	end: ".js",
/**
* JSAX.JSload.solvPath - This is a helper function for JSAX.JSload.require( fn).
*/
	solvePath: function( file){
		var file = file;
		if( file.indexOf( "?") == -1
		 && ( file.toLowerCase().indexOf( JSAX.JSload.end) == -1
		 || file.toLowerCase().lastIndexOf( JSAX.JSload.end) +JSAX.JSload.end.length != file.length)){
			file += JSAX.JSload.end;
		}
		if( JSAX.JSload.dir){
			if( JSAX.JSload.dir.lastIndexOf( "/") != JSAX.JSload.dir.length -1){
				JSAX.JSload.dir += "/";
			}
		}else{
			JSAX.JSload.dir = "./";
		}
		if( file.indexOf( JSAX.JSload.dir) != 0){
			file = JSAX.JSload.dir+file;
		}
		return file;
	},
/**
* This is a alias to JSAX.HTTP.request
*/
	read: function( file){
		return JSAX.HTTP.request( file, arguments[1], arguments[2], arguments[3]);
	},

/**
* JSAX.JSload.passthrew - Returnes the content of the requested file directly in the document
* NOTE that google is not able to do these actions.
* 
* @param String file - The file which should be pasted into the document
*/
	passthrew: function( file){
		JSAX.HTTP.request( file, "alert( ...); document.write( ...);");
	},

/**
* JSAX.JSload.execute - Execute JavaScript without failure
* 
* @param String code - The code which should be run.
* @param String file - The fileName which will be shown in the alert on a failure
*
* @return Boolean - True on success false on an error.
*/
	execute: function( code, file){
		try{
			eval( code);
		}catch( e){
			var correction = 82; // NOTE this must be set to this lineNumber
			var error = "Error";
			if( e.lineNumber){
				var line = e.lineNumber -correction -1;
				error += " on line "+line;
			}
			alert( error+" in file "+file+": "+e.message+"\n\n"+code);
			return false;
		}
		return true;
	},

/**
* JSAX.JSload.include - Include a JavaScript file.
* 
* @param String file - The path of the .js file (for example: include( "./myLib/myScript.js", "./myLib/myOtherScript.js"))
* @param String [file2] - The name of the 2. file
* @param String [file3] - ...
*
* @return String - The number of files which could be loaded without failure.
*/
	include: function( file){
//		var file = JSAX.JSload.solvePath( file);
		if( arguments.length > 1){
			var succeed = 0;
			for( var i=0; i < arguments.length; i++){
				if( JSAX.JSload.include( arguments[i])){
					succeed++;
				}
			}
			return succeed;
		}

		var code = JSAX.JSload.read( file);
		return JSAX.JSload.execute( code, file);
	},
	
	requiredFiles : [],
/**
* JSAX.JSload.require - Include a JSAX library once. this function has a pathcorrection.
* 
* @param String file - The name of the JSAX object (for example: include( "proto/String"))
* @param String [file2] - The name of the 2. script
* @param String [file3] - ...
*
* @return String - The number of files which could be loaded without failure.
*/
	require: function( file){
		var file = JSAX.JSload.solvePath( file);
			var succeed = 0;
		if( arguments.length == 1 && typeof( arguments[0]) == "object"){
			arguments = arguments[0];
		}
		if( arguments.length > 1){
			for( var i=0; i < arguments.length; i++){
				if( JSAX.JSload.require( arguments[i])){
					succeed++;
				}
			}
			return succeed;
		}

		if( typeof( JSAX.JSload.requiredFiles[file]) != "string"){
			var content = read( file)
			JSAX.JSload.execute( content, file);
			JSAX.JSload.requiredFiles[file] = content;
			return ;
		}
		return true;
	}
},

/**
* JSAX.HTTP - file reading ( works only on the host of the HTML file wich this is on)
* This procedure is called Ajax
*
* @parent JSAX.HTTP
*/
HTTP: {

/**
* JSAX.HTTP - file reading ( works only on the host of the HTML file wich this is on)
* 
* @param String URL - The path to the file (or script)
* @param String [method] - The request method (GET or POST, default=GET) to send the data
* @param Array [data] - The request data ( as a HTMLform)
*
* @return String - The result of your request (file content, script result)



	function ajaxRequest(url, method, param, onSuccess, onFailure){
		var xmlHttpRequest = new XMLHttpRequest();
		xmlHttpRequest.onreadystatechange = function() {
			if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) onSuccess(xmlHttpRequest);
			else if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status != 200) onFailure(xmlHttpRequest);
		};
		xmlHttpRequest.open(method, url, true);
		if (method == 'POST') xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttpRequest.send(param);
	}
*/
	objects: [],
	request: function( URL, eval, method, data){
		if( !method){
			var method = "GET";
		}
		if( !data){
			var data = null;
		}
		var reqObj = JSAX.HTTP.requestObject();
		if( !reqObj){
			return false;
		}
		if( eval){ // asynchron
			reqObj.open( method, URL, true);
//			if( data){
				reqObj.send( data);
//			}
			while( eval.indexOf( "...") != -1){
				eval = eval.replace( "...", "window.JSAX.HTTP.objects[id].responseText");
			}
			reqObj.eval = eval;
			reqObj.URL = URL;
			var id = JSAX.HTTP.objects.length;
			JSAX.HTTP.objects[id] = reqObj;
			reqObj.onreadystatechange = JSAX.HTTP.respond( id);
			return true;
		}else{ // wait
			reqObj.open( method, URL, false);
			reqObj.send( data);
			return reqObj.responseText;
		}
	},
	states: ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'],
	respond: function( id){
		var reqObj = JSAX.HTTP.objects[id];
		if( reqObj.readyState == "1"){
			setTimeout( "JSAX.HTTP.respond( "+id+");", 10);
			return;
		}
//		alert( JSAX.HTTP.states[reqObj.readyState]+" "+reqObj.URL);
		var e = false;
		try{
			eval( reqObj.eval);
		}catch( e){
			alert( e.message);
		}
		if( reqObj.readyState == 0){
			alert( "failed to load URL( "+reqObj.URL+").");
		}
		reqObj.onreadystatechange = null;
		window.JSAX.HTTP.objects[id] = null;
	},
/**
* Internal helper function for JSAX.HTTP.request()
* @return Object - XMLHttpRequest request Object
*/
	requestObject: function(){
		if( typeof( XMLHttpRequest) != "undefined"){
			return new XMLHttpRequest();
		}else{ // M$IE
			var possible = new Array(
				"Microsoft.XMLHTTP",
				"Msxml2.XMLHTTP",
				"MSXML2.XMLHTTP.3.0",
				"MSXML2.XMLHTTP.4.0"
			);
			var reqObj = false;
			var done = false;
			for( var i=0; i < possible.length; i++){
				try{
					reqObj = new ActiveXObject( possible[i]);
					done = true;
				}catch( e){
					reqObj = false;
				}
				if( done){
					return reqObj;
				}
			}
		}
		return false;
	}
	
},
/**
* object handling helpers
* @parent JSAX.object
*/
object: {

/**
* JSAX.object.concat - Makes a new object of any number of objects, the first object is the most dominating. This function does not modify the given objects, it makes a copy.
* @param Object object1
* @param [Object object2]
* @return Object - Combined object of object1 and object2 ... where object2 has priority if a value exists in both objects.
*/
	concat: function( object1, object2){
		var newObj = new Object();
		for( var i = 0; i < arguments.length; i++){
			for( var child in arguments[i]){
				newObj[child] = arguments[i][child];
			}
		}
		return newObj;
	},
/**
* JSAX.object.glue - Makes a new object of any number of objects, the first object is the most dominating. This function does not modify the given objects, it makes a copy. This function is a alias of JSAX.object.concat
* @param Object object1
* @param [Object object2]
* @return Object - Combined object of object1 and object2 ... where object2 has priority if a value exists in both objects.
*/
	glue: function( object1, object2){
		return JSAX.object.concat( object1, object2);
	},
/**
* JSAX.object.attachTo - Assigns attach to target. This function has no return, the target object will be modified.
* @param Object attach - The object you wan to attach to the target (for example your prototype library).
* @param Object target - The target object. CAUTION: the original of this object will be modified.
* @return Object combined object of object1 and object2 where object2 has priority if a value exists in both objects.
*/
	attachTo: function( attach, target){
		for( var child in attach){
			try{
				target[child] = attach[child];
			}catch( e){}
		}
	}
},
/**
* container to gather prototype extensions
* @parent JSAX.proto
*/
proto: {}

};

// assign the main functions to window, so they are easy available
window.include		= JSAX.JSload.include;
window.require		= JSAX.JSload.require;
window.read		= JSAX.HTTP.request;

if( !JSAX.HTTP.requestObject()){
	alert( "Your browser does not support JavaScript HTTP reading!\nPlease download Firefox from 'http://www.mozilla.org/'.");
}


JSAX.JSload.require = function(){};
window.require = function(){};
/**
* JSAX.RQ
* written by Florian Sax 20060131
*
* Assigns the variables in location.search to _GET
* example:
document.location.href == "http://localhost/index.php?var1=test&var2=test2"
_GET["var1"] == "test"
_GET.var2 == "test2"
*
* Copyright (C) 2006 Florian Sax <flosax(at)users.sourceforge.net>
* JSAX.RQ is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*/


if( !window.JSAX){
	JSAX = {};
}

JSAX.RQ = {
	Version: 20060223,
	_GET: {},
	_POST: { "variables":"cannot be recieved from browser"},
	GET: function(){
/*
		if( document.location.href != document.location.protocol+'//'+
			document.location.hostname+
			document.location.port+
			document.location.pathname+
			document.location.search+
			document.location.hash){
			alert( "document.location object is not standard conform!");
		}
*/
		var string = unescape( document.location.search.substr( 1));
		var vars = string.split( "&");
		for( var i=0; i < vars.length; i++){
			var pos = vars[i].indexOf( "=");
			if( pos > 0){
				var key = vars[i].substr( 0, pos);
				JSAX.RQ._GET[key] = vars[i].substr( pos +1);
			}
		}
		// consume this function
		JSAX.RQ.GET = function(){
			return JSAX.RQ._GET;
		}
		return JSAX.RQ._GET;
	}
};
window._GET = JSAX.RQ.GET();



/**
* JSAX JS Reference
* Gathered by Florian Sax under the GPL <http://www.gnu.org/copyleft/gpl.html>
*/

if( !window.JSAX){
	alert( "The reference is not able to work without JavaScript Abstractions for X(HT)ML (objects/JSAX.js).");
}

JSAX.reference = {
	Version: 20060108,

CSS: {
	properties: new Array( "background", "background-attachment", "background-color", "background-image", "background-position", "background-repeat", "border", "border-top", "border-right", "border-bottom", "border-left", "border-collapse", "border-color", "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", "border-spacing", "border-style", "border-top-style", "border-right-style", "border-bottom-style", "border-left-style", "border-width", "border-top-width", "border-right-width", "border-bottom-width", "border-left-width", "bottom", "caption-side", "clear", "clip", "color", "content", "counter-increment", "counter-reset", "cursor", "direction", "display", "empty-cells", "float", "font", "font-family", "font-size", "font-style", "font-variant", "font-weight", "height", "left", "letter-spacing", "line-height", "list-style", "list-style-image", "list-style-position", "list-style-type", "margin", "margin-top", "margin-right", "margin-bottom", "margin-left", "max-height", "max-width", "min-height", "min-width", "orphans", "outline", "outline-color", "outline-style", "outline-width", "overflow", "padding", "padding-top", "padding-right", "padding-bottom", "padding-left", "page-break-after", "page-break-before", "page-break-inside", "position", "quotes", "right", "table-layout", "text-align", "text-decoration", "text-indent", "text-transform", "top", "unicode-bidi", "vertical-align", "visibility", "white-space", "widows", "width", "word-spacing", "z-index")
}

,
DOM: {
},
standaloneFunctions: {
	"parseInt": {},
	"parseFloat": {},
	"parseNumber": {},
	"parseString": {},
	"typeof": {},
	"instanceof": {}
},
Objects: {
	Boolean: {
	},
	Number: {
		"JSAX.proto": JSAX.proto.Number
	},
	Math: {
		
	},
	Array: {
		push: {
			0: "Object" },
		pop: {},
		shift: {},
		unshift: {},
		join: {},
		"JSAX.proto": JSAX.proto.Array
	},
	String: {
		indexOf: {
			0: "indexOf( StringTofind)" },
		lastIndexOf: {
			0: "StringToFind" },
		search: {
			0: "RegExp" },
		substr: {
			0: "intStart, intEnd" },
		substring: {
			0: "intStart, intEnd" },
		fromCharCode: {
			0: "Event.which" },
		"JSAX.proto": JSAX.proto.String
	},
	RegExp: {
		match: {}
	},
	Date: {
	},
	Node: {
	},
	Element: {
		"JSAX.proto": JSAX.proto.Element
	},
	Object: {
		"JSAX.proto": JSAX.proto.Object
	},
	Function: {
	}
},
Events: {
	neededlisteners: {
		mousemove: {},
		mousedown: {},
		mouseup: {},
		keydown: {},
		keyup: {},
		scroll: {},
		submit: {}
		
	},
	listeners: {
		mousemove: {},
		mousedown: {},
		mouseup: {},
		mouseover: {},
		mouseout: {},
		dragstart: {},
		dragend: {},
		click: {},
		contextmenu: {},
		keydown: {},
//		keyup: {},
		keypress: {},
		scroll: {},
		submit: {}
		
	}
}
};
/**
* OutPut.js
* a simple output, usefull instead of alert or as loading message
* written by Florian Sax 20060121
*
* Copyright (C) 2006 Florian Sax <flosax(at)users.sourceforge.net>
* OutPut is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*/

if( !window.JSAX){
	alert( "OutPut is not able to work without JavaScript Abstractions for X(HT)ML (objects/JSAX.js).");
}

require( "DOM", "compat/browser_msie", "Opacity");
JSAX.OutPut = {
	Version: 20071020,
	style: {
		position:	"absolute",
		top:		100,
		left:		200,
		fadetime:	0.1,
		opacity:	100,
		zIndex:		999,
		padding:	"5px",
		border:		"2px solid black",
		background:	"#C0C0C0",
		cursor:		"default",
		color:		"black"},
//		font:		"monospace 12px",
//		textAlign:	"middle"},

	show: function( item){
		var OutPut = byId(  "myOutPut");
		if( !OutPut){
			OutPut		= document.createElement( "div");
			OutPut.id	= "myOutPut";
			OutPut.onclick 	= function( e){
				if( !e){
					var e = window.event;
				}
				JSAX.OutPut.hide();
				if( e.preventAction){
					e.preventAction( e);
				}
				e.cancelBubble = true;
				return false;
			};
			for( var prop in JSAX.OutPut.style){
				OutPut.style[prop] = JSAX.OutPut.style[prop];
			}
			document.body.appendChild( OutPut);
			OutPut		= byId(  "myOutPut");
		}
		OutPut.innerHTML	= item+"<br/>";
		if( JSAX.OutPut.style.align == "middle"){;
			OutPut.style.top	= "-999px";
			OutPut.style.left	= "-999px";
			OutPut.style.display	= "block";
			var posY	= window.innerHeight/2 -OutPut.offsetHeight/2;
			var posX	= window.innerWidth/2 -OutPut.offsetWidth/2;
		}else{
			var posY	= JSAX.OutPut.style.top;
			var posX	= JSAX.OutPut.style.left;
		}
		posX 		+= document.body.scrollLeft;
		posY 		+= document.body.scrollTop;
		OutPut.style.top	= posY+"px";
		OutPut.style.left	= posX+"px";
		OutPut.style.display	= "block";
		if( JSAX.OutPut.style.fadetime && OutPut.style.opacity == 0){
			JSAX.Opacity.fade( "myOutPut", JSAX.OutPut.style.opacity, JSAX.OutPut.style.fadetime);
		}

		if( arguments[1]){
			setTimeout( "JSAX.OutPut.hide();", arguments[1]*1000);
		}
	},

	hide: function(){
		if( JSAX.OutPut.style.fadetime){
			JSAX.Opacity.fade( "myOutPut", 0, JSAX.OutPut.style.fadetime);
		}else{
			OutPut.style.display	= "hidden";
		}
	}
};



/**
* Number prototype library - Number.js
* this is a collection of usefull javascript functions
* written by Florian Sax 20051217
*
* Copyright (C) 2006 Florian Sax <flosax(at)users.sourceforge.net>
* Number.js is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*
if( !window.Number){
	var Number = 7;
}
assignPrototype( Number);

*/


if( !window.JSAX){
	alert( "JSAX.proto.Number needs JavaScript Abstractions for X(HT)ML (objects/JSAX.js) to work.");
}

JSAX.proto.Number = {

	canBeANumber: function(){
		return true;
	},

	dif: function( num){
		if( num > this){
			return num -this;
		}else if( num < this){
			return this -num;
		}else{
			return 0;
		}
	}

}





JSAX.object.attachTo( JSAX.proto.Number, Number.prototype);





if( !window.JSAX){
	alert( "Element.js is not able to work without JavaScript Abstractions for X(HT)ML (objects/JSAX.js).");
}

/**
* Returns boolean true if the element has the class else false
* @param Object elem - The element wich should be checked
* @param String className - The className (for example: <TAG class="kd CLASSNAME">)
* @return boolead true if elem has className else false
*/
window.isClassMember = function( elem, className){
	if( typeof( elem.className) != "string"){
		return false;
	}
	if( elem.className == className
	 || elem.className.indexOf( className+" ") == 0
	 || elem.className.lastIndexOf( " "+className) == elem.className.length -className -1
	 || elem.className.indexOf( " "+className+" ") != -1){
		return true;
	}
	return false;
};

/**
* Element.js
* Element prototype extensions
*
* @parent JSAX.proto.Element
*
* Copyright (C) 2006 Florian Sax <flosax(at)users.sourceforge.net> 20060202
* Element.js is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*
* @version 20060227
*
* @example: require( "proto/Element"); docement.body.insertBefore( document.createElement( "div"), docement.body.childNodes[0])
*/
JSAX.proto.Element = {
	"JSAX.proto.Element Version": 20060227,

/**
* Returns boolean true if the element has the class else false
* @param String className - The className (for example: <TAG class="kd CLASSNAME">)
* @return boolead true if elem has className else false
*/
isClassMember: function( className){
	return window.isClassMember( this, className);
},

/**
* Returns a list of all childNodes that have the given className
* @param String className - The className
* @return Array containing all elements that match the className
*/
getElementsByClassName: function( className){
	var elem = this;
	if( typeof( elem.getElementsByTagName) == "undefined"){
		elem = document;
	}
	if( typeof( elem.getElementsByTagName) == "function"){
		var allElems = elem.getElementsByTagName( "*");
	}else{
		var allElems = document.all;
	}
	var elems = new Array();
	for( var i=0; i < allElems.length; i++){
		if( isClassMember( allElems[i], className)){
			elems.push( allElems[i]);
		}
	}
	return elems;
},

/**
* Returns a list of all childNodes that have attribute with value
* @param String attrubute - The attrubute wich the elements must have.
* @param [Array value] - The value wich the attibute must be set to
* @return Array - All child Elements which matched the condistions of the given parameters
*/
getElementsBy: function( attribute, value){
	if( !value && !attribute){
		return false;
	}
	var elem = this;
	if( typeof( elem.getElementsByTagName) == "undefined"){
		elem = document;
	}
	if( typeof( elem.getElementsByTagName) == "function"){
		var allElems = elem.getElementsByTagName( "*");
	}else{
		var allElems = document.all;
	}
	var elems = new Array();
	for( var i=0; i < allElems.length; i++){
		if( typeof( value) == "undefined"){
			if( typeof( allElems[i][attribute]) != "undefined"){
				elems.push( allElems[i]);
			}
		}else if( allElems[i][attribute] == value){
			elems.push( allElems[i]);
		}
	}
	return elems;
},

/**
* Returns the value if the element has it. if not the innerHTML
* @return String - The content of the Element
*/
returnValue: function(){
	if( typeof( this.value) == "undefined"){
		return this.value;
	}else{
		return this.innerHTML;
	}
},

/**
* Removes the element (it can not be reviewed)
*/
removeNode: function(){
	this.parentNode.removeChild( this);
}



};

// assign getElementsByClassName to document as well
document.getElementsByClassName = JSAX.proto.Element.getElementsByClassName;




// the horrible procedure to pretend beein able to assign it to the Element.prototype in all Browsers
JSAX.proto.ElementPrototype = {
assign: function(){

	// get the a Element with prototype at JSAX.proto.Element.protoElem
	JSAX.proto.ElementPrototype.object = document.createElement( "DIV");
	
	// Mozilla & Opera(w3c)
	if( window.HTMLElement){
	//	alert( "HTMLElement");
		JSAX.proto.ElementPrototype.object = HTMLElement.prototype;
	
	// KHTML
	}else if( window["[[DOMElement.prototype]]"]){
	//	alert( "[[DOMElement.prototype]]");
		JSAX.proto.ElementPrototype.object = window["[[DOMElement.prototype]]"];
	
	// ?? Probably exists as well who knows, i do not know what safari or icab use
	}else if( window.DOMElement){
	//	alert( "DOMElement");
		JSAX.proto.ElementPrototype.object = DOMElement.prototype;
	
	// M$IE does not support element prototyping
	}else{
		JSAX.proto.ElementPrototype.object = false;
	}
	
	
	if( JSAX.proto.ElementPrototype){ // M O K
		JSAX.object.attachTo( JSAX.proto.Element, JSAX.proto.ElementPrototype.object);
	
	// M$IE
	// micro$oft does not support element prototyping at all, not even over objects. that's a shame.
	// so we assign it to all elements one by one and repeat this procedure recursivly after 0.1 sec
	}else{
		JSAX.proto.ElementPrototype.runtime = setInterval( "JSAX.proto.ElementPrototype.assignIE();", 100);
	}
},
assignIE: function(){
	return JSAX.proto.ElementPrototype.assignToAllElements( 'JSAX.proto.Element');
},
assignToAllElements: function( objP){
	var obj = eval( objP);
	var elems = document.getElementsByTagName( "*");
	for( var i=0; i < elems.length; i++){
		JSAX.object.attachTo( obj, elems[i]);
	}
}
};

JSAX.proto.ElementPrototype.assign();


/**
* DOM.js
* written by Florian Sax 20051229
*
* DOM.js is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*/
/*
JSAX.DOM = {
findPrototype: function(){
	if( this.__proto__){
		return this.__proto__;
	}else if( this.constructor.prototype){
		return this.constructor.prototype;
	}
	return this.prototype;
},
assignPrototype: function( object){
	if( typeof( object) == "undefined"){
		object = {};
	}
	if( !object.findPrototype){
		object.findPrototype = JSAX.DOM.findPrototype;
	}
	if( !object.prototype){
		object.findPrototype().prototype = object.findPrototype();
	}
	return true;
}
};
*/


require( "proto/Element");

document.getElementsByClassName = JSAX.proto.Element.getElementsByClassName;
window.getElementsByClassName = JSAX.proto.Element.getElementsByClassName;
document.getElementsBy = JSAX.proto.Element.getElementsBy;
window.getElementsBy = JSAX.proto.Element.getElementsBy;


//Element.prototype.getElementsByClassName = getElementsByClassName;





window.byId = function( id){
	if( !document.getElementById){
		if( document.all){
			var all = document.all;
		}else if( !document.getElementsByTagName){
			var all = document.getElementsByTagName("*");
		}else{
			return false;
		}
		if( all[id]){
				return all[i];
		}
	}
	return document.getElementById( id);
};
document.byId = window.byId;



/**
* eventTools
* some event handling helpers
* eventTools doesn not work without JSAX
* written by Florian Sax 20051229
*
* eventTools is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*/

if( !window.JSAX){
	alert( "eventTools need JavaScript Abstractions for X(HT)ML (objects/JSAX.js) to work.");
}
JSAX.Event = {
	Version: 20071020,

	solv: function( e){
		if( typeof( e) == "undefined"){
			var event = window.event;
		}else{
			var event = e;
			try{
				window.event = event;
			}catch( e){}
		}
		if( !event){
			return null;
		}
		event.preventAction = function( p){
			this.cancelBubble = true;
		}
		if( !event.preventDefault){
			event.preventDefault = function( p){
				this.preventAction( 1);
				return false;
			}
		}else if( !event.stopPropagation){
			event.stopPropagation = function(){
				this.preventAction( 2);
				return false;
			}
		}
		if( event.clientX && !event.screenY){
			event.screenX = event.clientX;
			event.screenY = event.clientY;
		}
		if( event.offsetX && !event.layerX){
			event.layerX = event.offsetX;
			event.layerY = event.offsetY;
		}
		if( !event.target && event.srcElement){
			event.target = event.srcElement;
		}
		if( !event.charCode && event.keyCode){
			try{
				event.charCode = event.keyCode;
			}catch( e){}
		}
		if( !event.charCode && event.which){
			try{
				event.charCode = event.which;
			}catch( e){}
		}
		if( !event.clientX && event.x){
			event.clientX == event.x;
			event.clientY == event.y;
		}
		return event;
	},
	preventAction: function( e){
		var event = JSAX.Event.solv( e);
		if( !event)return null;
		event.preventAction();
		return false;
	},

	listen: function( e){
		var event = JSAX.Event.solv( e);


//		var eventName = JSAX.Event.keyName( event);
		JSAX.Event.history[JSAX.Event.history.length] = event;
		JSAX.Event.history[event.type] = event;

		if( JSAX.CJSED){
			JSAX.CJSED.checkElem( event.target, event);
		}

//		JSAX.Event.history.push( event);
//		JSAX.OutPut.show( "type:"+event.type+" - which:"+event.which+" - charCode:"+event.charCode+" - keyCode:"+event.keyCode+" - name:"+eventName+" - targetTag:"+elem.tagName, 1);
	},

	startListen: function(){
		require( "Reference");
		try{
			JSAX.reference.Events.listeners;
		}catch( e){
			return false;
		}
		for( property in JSAX.reference.Events.listeners){
			document["on"+property] = JSAX.Event.listen;
		}
		return true;
	},

	keyName: function( e){
		if( e ){
			var event = e;
		}
		if( event.which){
			var num = event.which;
		}else{
			var num = event.keyCode;
		}
		if( event.which == 0){
			if( JSAX.Event.keys[event.charCode]){
				var eventName = JSAX.Event.keys[event.keyCode];
			}else{
				var eventName = "UNKNOWN";
			}
		}else if( JSAX.Event.keys[num]){
			var eventName = String.fromCharCode( num);
		}else{
			var eventName = JSAX.Event.keys[num];
		}
		if( typeof( eventName) == "undefined"){
			eventName = "UNKNOWN";
		}
		if( event.shiftKey){
			eventName = "Shift+"+eventName;
		}
		if( event.altKey){
			eventName = "Alt+"+eventName;
		}
		if( event.ctrlKey){
			eventName = "Ctrl+"+eventName;
		}
		if( event.metaKey){
			eventName = "Meta+"+eventName;
		}
		eventName.chopEnd( "+");

		return eventName;
	},

	history: new Array(),


	start: function(){
//		var events = {};
//		for( var eventName in JSAX.Event.events){
//			var num = JSAX.Event.events[eventName];
//			events[num] = eventName;
//		}
//		JSAX.Event.events = JSAX.object.glue( JSAX.Event.events, events);
//		
//		var keys = {};
//		for( var keyName in JSAX.Event.keys){
//			var num = JSAX.Event.keys[keyName];
//			keys[num] = keyName;
//		}
//		JSAX.Event.keys = JSAX.object.glue( JSAX.Event.keys, keys);

		if( JSAX.CJSED){
			JSAX.Event.startListen();
		}
	}

};
JSAX.Event.start();


/**
* browser_msie.js
* this is a collection of usefull javascript functions
* written by Florian Sax 20051219
*
* browser_msie.js is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*/


if( !window.JSAX){
	alert( "browser_msie.js was designed to be run in a package of JavaScript Abstractions for X(HT)ML (objects/JSAX.js).");
}

if( ( navigator.userAgent.toLowerCase().indexOf( "msie") != -1
   || navigator.userAgent.toLowerCase().indexOf( "explorer") != -1)
 && navigator.userAgent.toLowerCase().indexOf( "opera") == -1){
//	alert( "You are still using Microsoft InternetExplorer!?");

}
	require( "compat/png_alpha");
	require( "compat/innerSize");
/**
* compat.png_alpha
* makes alpha transparancy of png's compatibel to M$IE
* written by Florian Sax 20060222
*
* compat.png_alpha is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*/

if( !window.JSAX){
	window.JSAX = {};
}
if( !JSAX.compat){
	JSAX.compat = {};
}

JSAX.compat.PNG_alpha = {
	Version: 20060228,

	replaceImages: function(){
		if( typeof( document.body.runtimeStyle) == "undefined"){
			return false;
		}
		var ae = document.getElementsByTagName( "*");
		if( ae.length < 1){
			ae = document.all;
		}
		var s = 0;
		for( var i = 0; i < ae.length; i++){
			if( ae[i].src && ae[i].src.toLowerCase().indexOf( ".png") > 1){
				JSAX.compat.PNG_alpha.doImage( ae[i]);
				s++;
			}else if( ae[i].style.background && ae[i].style.background.toLowerCase().indexOf( ".png") > 1){
				JSAX.compat.PNG_alpha.doBG( ae[i]);
				s++;
			}
		}
		return s;
	},

	doBG: function( elem){

		if( elem.style.background.toLowerCase().indexOf( "url") != -1){
			var img = elem.style.background.substring(
				elem.style.background.indexOf( "(") +1,
				elem.style.background.indexOf( ")"));
			if( elem.runtimeStyle.filter.indexOf( img) > 1){
				return;
			}

			elem.runtimeStyle.background = "";
			elem.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='crop', src='"+img+"')";
		}
		return;
	},

	cssProperties: ["height", "width", "border", "cursor"],
	doImage: function( elem){

		if( elem.tagName.toLowerCase() == "img"){
			if( elem.parentNode.runtimeStyle.filter.indexOf( elem.src) > 1){
				return;
			}
			if( elem.parentNode.tagName.toLowerCase() != "span"
			 || elem.parentNode.runtimeStyle.filter.toLowerCase().indexOf( ".png") == -1){
				var cont = document.createElement( "span");
				elem.parentNode.insertBefore( cont, elem);
				cont.appendChild( elem);
			}
			if( elem.className)elem.parentNode.className = elem.className;
			for( var i = 0; i < JSAX.compat.PNG_alpha.cssProperties.length; i++){
				var prop = JSAX.compat.PNG_alpha.cssProperties[i];
				if( elem.style[prop]){
					elem.parentNode.runtimeStyle[prop] = elem.style[prop];
				}
			}
			elem.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
			elem.parentNode.runtimeStyle.display = "inline-block";
			elem.parentNode.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='scale', src='"+elem.src+"')";
		}
		return;
	},

	runId: false
};


if( navigator.userAgent.toLowerCase().indexOf( "msie") != -1
 && navigator.userAgent.toLowerCase().indexOf( "opera") == -1){
	JSAX.compat.PNG_alpha.runId = setInterval( "JSAX.compat.PNG_alpha.replaceImages();", 1000);
}



/**
* innerSize.js
* this is a collection of usefull javascript functions
* written by Florian Sax 20051219
*
* innerSize.js is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*/



JSAX.compat.innerSize = {
	onWindowResize: function(){
		if( document.body && document.body.clientHeight){
			window.innerHeight = document.body.clientHeight;
			window.innerWidth  = document.body.clientWidth;
		}else{
			window.innerHeight = 0;
			window.innerWidth  = 0;
		}
	},
	windowCheck: function(){
		if( window.innerHeight != document.body.clientHeight
		 || window.innerWidth != document.body.clientWidth){
			JSAX.compat.innerSize.onWindowResize();
		}
	}
}

if( typeof( window.innerWidth) == "undefined"){ // for M$IE
	JSAX.compat.innerSize.onWindowResize();
	setInterval( "JSAX.compat.innerSize.windowCheck();", 1000);
};
/*
* JSAX.Opacity - transparent HTML Elements
* This lib is compatibel with Mozilla, InternetExplorer and Khtml, but it somehow does not work in Konqueror
* test with:
require( "Opacity"); JSAX.Opacity.fade( "test", 10, 10)
*
* Copyright (C) 2006 Florian Sax <flosax(at)users.sourceforge.net>
* JSAX.Opacity is protected by the GPL <http://www.gnu.org/copyleft/gpl.html>
*/


if( !window.JSAX){
	alert( "JSAX.Opacity is not able to work without JavaScript Abstractions for X(HT)ML (objects/JSAX.js).");
}

require( "proto/Number", "DOM");


JSAX.Opacity = {
	Version: 20060314,

	fadeElemId: 0,
//change the opacity for different browsers
set: function( opacity, id){
	var elem = byId( id);
	if( !elem){
		if( id.tagName){
			elem = id;
		}else{
			return false;
		}
	}
	var opacity = parseInt( opacity);
	if( opacity <= 0){
		opacity = 0;
//		JSAX.Opacity.clearSteps( elem);
	}else if( opacity >= 99){
		opacity = 99;
//		JSAX.Opacity.clearSteps( elem);
	}

	if( opacity == 0){
		elem.style.visibility = "hidden";
		elem.style.display = "none";
	}else{
		elem.style.visibility = "";
		elem.style.display = "";
	}

	elem.myOpacity		= opacity;				// Internal
	elem.style.opacity	= ( opacity /100);			// General
	elem.style.MozOpacity	= ( opacity /100);			// Mozilla
	elem.style.filter	= "alpha( opacity="+opacity+")";	// M$IE
	elem.style.KHTMLOpacity	= ( opacity /100);			// KHTML
	elem.style.KhtmlOpacity	= ( opacity /100);
	elem.style.khtmlOpacity	= ( opacity /100);
	return true;
},

clearSteps: function( elem){
	if( !elem.fadeSteps){
		elem.fadeSteps = [];
	}
	for( var i = 0; i < elem.fadeSteps.length; i++){
		clearTimeout( elem.fadeSteps[i]);
	}
	elem.fadeSteps = [];
},

// <a onclick="JSAX.Opacity.fade( 'testElemById', 100, 0, 0.5)">Hide</a>
fadeFrom: function( id, opacStart, opacEnd, sec){
	var elem = byId( id);
	if( !elem){
		return false;
	}
	JSAX.Opacity.clearSteps( elem);
	
	if( opacStart > 100){
		opacStart = 100;
	}
	if( opacStart < 0){
		opacStart = 0;
	}
	if( opacEnd > 100){
		opacEnd = 100;
	}
	if( opacEnd < 0){
		opacEnd = 0;
	}

	var steps = opacEnd.dif( opacStart);
	if( !steps){
		return;
	}
	var msec = sec *1000;
	var tpp = Math.round( msec /steps);

	JSAX.Opacity.set( opacStart, id);

	for( var i = 1; i <= steps; i++){
		if( opacStart < opacEnd){
			var opac = opacStart +i;
		}else{
			var opac = opacStart -i;
		}
		elem.fadeSteps.push( setTimeout( "JSAX.Opacity.set( "+opac+", '"+id+"');", i *tpp));
	}
},

// <a onclick="JSAX.Opacity.shift( 'testElemById', 1);">show/hide</a>
shift: function( id, sec){
	//if an element is invisible, make it visible, else make it ivisible
	var elem = byId( id);
	if( !elem){
		return false;
	}

	if( typeof( elem.myOpacity) == "undefined"){
		elem.myOpacity = 100;
	}

	if( elem.myOpacity == 0){
		JSAX.Opacity.fadeFrom( id, 0, 100, sec);
	}else{
		JSAX.Opacity.fadeFrom( id, 100, 0, sec);
	}
},

// <a onclick="JSAX.Opacity.fade( 'testElemById', 60, 3);">fade to 60%</a>
fade: function( id, opacEnd, sec){
	var elem = byId( id);
	if( !elem){
		return false;
	}

	if( typeof( elem.myOpacity) == "undefined"){
		elem.myOpacity = 100;
	}

	// fade byId from currentOpac to opacEnd in sec
	JSAX.Opacity.fadeFrom( id, elem.myOpacity, opacEnd, sec);
},

hideOnUnfocus: function( elem, sec){
	if( typeof( elem) == "string"){
		var elem = document.getElementById( elem);
	}
	if( typeof( elem) != "object"){
		return false;
	}
	if( !elem.id){
		elem.id = "fadeElem_"+JSAX.Opacity.fadeElemId++;
	}
	elem.onmousemove = function( e){
		JSAX.Opcaity.clearSteps( this);
		JSAX.Opcaity.set( 100, this.id);
	}
	JSAX.Opacity.fadeFrom( elem.id, 100, 0, sec);
},

// <a onclick="JSAX.Opacity.blendImage( 'blendDiv','blendImage', 'testImage.jpg', 0.2);">Image 1</a>
blendImage: function( divId, imageId, imageFile, sec){
	var msec = sec *1000;
	var divElem = byId( divId);
	if( !divElem){
		return false;
	}
	JSAX.Opacity.clearSteps( divElem);
	var imgElem = byId( imageId);
	if( !imgElem){
		return false;
	}

	var speed = Math.round( msec /100);

	//set the current image as background
	divElem.style.backgroundImage = "url( "+imgElem.src+")";

	//make image transparent
	JSAX.Opacity.set( 0, imageId);

	//make new image
	imgElem.src = imageFile;

	//fade in image
	for( var i = 0; i <= 100; i++){
		divElem.fadeSteps.push( setTimeout( "JSAX.Opacity.set( "+i+", '"+imageId+"');", i *speed));
	}
}
};



window.M$IE = false;
if( navigator.userAgent.indexOf( "MSIE ") != -1){
	window.M$IE = true;
	window.M$IE = navigator.userAgent.split( "MSIE ")[1].split( ";")[0].split( " ")[0];
	window.M$IE = parseFloat( M$IE);
}
window.activateNav = function(){
	var c = document.location.search;
	var nav = document.getElementById( "navigation");
	if( nav){
		window.subnav_activ = null;
		var lis = nav.getElementsByTagName( "li");
		for( var i = 0; i < lis.length; i++){
      lis[i].onmouseover = function( e){
				if( subnav_activ && subnav_activ.id != this.id){
					if( subnav_activ.to)clearTimeout( subnav_activ.to);
					subnav_activ.style.display = 'none';
				}
//	    	if( this.TO)clearTimeout( this.TO);
				this.className += " hover";
			};
			lis[i].removeClass = function( cn){
        this.className = this.className.split( " "+cn).join( "");
				if( this.className == cn)this.className = "";
			};
			lis[i].onmouseout = function( e){
				this.removeClass( "hover");
				subnav_activ = this;
				return;
				this.to = setTimeout( "subnav_activ.cemoveClass( 'hover');", 500);
//				window.overElem = this;
//				var c = 'overElem.className = overElem.className.split( " hover").join( "");'+
//					'if( overElem.className == "hover")overElem.className = "";';
//				window.overElemTO = setTimeout( c, 500);
			};
		}
	}
};
