		
animator = new animator_object;
request = new server_request;
data = new server_data;

function init() {

	//request.get("http://localhost/www.lada-design.at/content.json", data);
	//window.setTimeout("server_data()", 2000);
	
	//animator.add_binding(window, "innerWidth", "Mainframe", "width",
			//"html-style", 0.005, 1.414);
	//animator.activate();
	return null;
}

function loadXMLDoc(dname) {
	if (window.XMLHttpRequest) {
		xhttp = new XMLHttpRequest();
	} else {
		xhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xhttp.open("GET", dname, false);
	xhttp.send("");
	return xhttp.responseXML;
}

function expand(target) {
	
	xml = loadXMLDoc("xml/content.xml");
	xsl = loadXMLDoc("xml/xslt/layout.xsl");
	change = $x('./xsl:template[@match="/"]', xsl);
	newLI = document.createElement('<xsl:variable name="target_name">'+target.nodeName+'</xsl:variable>');
	change.appendChild(newLI);
	
	x=xmlDoc.getElementsByTagName("book")[0];
	x.appendChild(newel);
	// code for IE
	if (window.ActiveXObject) {
		ex = xml.transformNode(xsl);
		target.innerHTML = ex;
	}
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument) {
		
		xsltProcessor = new XSLTProcessor();
		xsltProcessor.importStylesheet(xsl);
		resultDocument = xsltProcessor.transformToFragment(xml, document);
		target.appendChild(resultDocument);
		
	}
}

function server_data() {

	this.parse_json = (function(obj) {
		this[this.length] = obj;
		alert(this[this.length]["domain"]);
	});

}

function animator_object() {
	this.data = new Array;
	this.add_binding = (function(source_name, source_attribute, target_name,
			target_attribute, mode, friction, ratio) {

		if (((typeof (source_name) == "object") || (typeof (source_name) == "string"))
				&& (typeof (source_attribute) == "string")
				&& ((typeof (target_name) == "object") || (typeof (target_name) == "string"))
				&& (typeof (target_attribute) == "string")
				&& (typeof (friction) == "number")) {

			this.new_add = new Array;

			if (typeof (source_name) == "object") {
				this.new_add[0] = source_name;
			} else {
				this.new_add[0] = document.getElementById(source_name);
			}

			this.new_add[1] = source_attribute;

			if (typeof (target_name) == "object") {
				this.new_add[2] = target_name;
			} else {
				this.new_add[2] = document.getElementById(target_name);
			}

			this.new_add[3] = target_attribute;
			this.new_add[4] = friction;
			this.new_add[5] = ratio;
			this.new_add[6] = 0;
			this.new_add[7] = mode;

			this.data[this.data.length] = this.new_add;
		}
	});

	this.animate = (function() {

		for ( var i = 0; i < this.data.length; i++) {
			
			if (!this.data[i][6]) {
				this.data[i][6] = this.data[i][2][this.data[i][3]];
			}

			if (this.new_add[7] == "html-html") {
				this.data[i][2][this.data[i][3]] = Number(this.data[i][2][this.data[i][3]])
						+ Number(this.data[i][4])
						* (Number(this.data[i][0][this.data[i][1]])
								/ Number(this.data[i][5]) - Number(this.data[i][6]));
				this.data[i][6] = Number(this.data[i][2][this.data[i][3]]);
			}
			if (this.new_add[7] == "style-style") {
				this.data[i][2].style[this.data[i][3]] = Number(this.data[i][2][style][this.data[i][3]])
						+ Number(this.data[i][4])
						* (Number(this.data[i][0].style[this.data[i][1]])
								/ Number(this.data[i][5]) - Number(this.data[i][6]));
				this.data[i][6] = Number(this.data[i][2].style[this.data[i][3]]);
			}
			if (this.new_add[7] == "style-html") {
				this.data[i][2][this.data[i][3]] = Number(this.data[i][2][this.data[i][3]])
						+ Number(this.data[i][4])
						* (Number(this.data[i][0].style[this.data[i][1]])
								/ Number(this.data[i][5]) - Number(this.data[i][6]));
				this.data[i][6] = Number(this.data[i][2][this.data[i][3]]);
			}
			if (this.new_add[7] == "html-style") {
				this.data[i][2][this.data[i][3]] = Number(this.data[i][2][this.data[i][3]])
						+ Number(this.data[i][4])
						* (Number(this.data[i][0][this.data[i][1]])
								/ Number(this.data[i][5]) - Number(this.data[i][6]));
				this.data[i][6] = Number(this.data[i][2][this.data[i][3]]);
			}
		}
	});

	this.activate = (function() {
		// this.animate();
		window.setInterval("animator.animate()", 1000 / 24);
	});

}

function server_request() {

	this.resultfunc = (function() {
		alert("bla");
		return null;
	});

	if (typeof (this.XMLHttpRequest) == "undefined") {
		this.XMLHttpRequest = (function() {
			try {
				return new ActiveXObject("MSXML3.XMLHTTP");
			} catch (e) {
			}
			try {
				return new ActiveXObject("MSXML2.XMLHTTP.3.0");
			} catch (e) {
			}
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			}
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
			try {
				return new XMLHttpRequest();
			} catch (e) {
			}
			return null;
		});
	}

	this.httpRequest = this.XMLHttpRequest();

	this.httpRequest.onreadystatechange = (function() {

		if (this.readyState == 4 && (this.status == 200)) {

			if (this.responseText == null) {
				// Mozilla failure, local or HTTP
				data = request.json_parse("Fehler");

			} else if (this.responseText.length == 0) {

				if (!this.isLocal) {
					// HTTP failure

					data = request.json_parse("Fehler");
				} else {

					// Local failure--always happens, try
					// using Microsoft.XMLDOM to load
					this.xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					this.xmlDoc.async = false;
					this.xmlDoc.loadXML(this.responseText);

					if (this.xmlDoc.documentElement != null) {

						data = request.json_parse(eval(this.responseText));
					} else {

						data = request.json_parse("Fehler");
					}
				}
			} else {
				eval("data.parse_json((" + this.responseText + "));");

			}
		}

	});

	this.get = (function(path, data) {

		this.httpRequest.open('GET', path, true);
		this.httpRequest.send(null);

	});

}


function $x(p, c) {
	if (document.evaluate) { 
		var i, r = [], x = document.evaluate(p, c || document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
		while(i=x.iterateNext()) r.push(i);
		return r;
	}
	else {  // Internet Explorer
        message = "Your browser does not support the evaluate method!";
    }
}


function setlada(obj, mode) {
	var tcopy;
	var tcopy2;
	
  if (obj.value!="set"&&mode=="set") {
	  
	  
	  obj.value="set";
    tcopy = obj.innerHTML;
    if (obj.innerText) {
    	 tcopy = obj.innerText;
    	 obj.innerText = "";}
	else {
		tcopy = obj.innerHTML;
		obj.innerHTML = "";}
    tcopy2 = tcopy.substring(0, tcopy.length-2);
	obj["temp"] = tcopy;
    end= "| " + tcopy2.substring(tcopy2.length-1, tcopy2.length);
   start=tcopy2.substring(0,tcopy2.length-1);
   
	if (obj.innerText) {div.innerText = start;}
	else {obj.innerHTML = start;}
	
	
	var font = document.createElement("font");
	
	var color = document.createAttribute("color");
	color.nodeValue = "#ec875b";	
	font.setAttributeNode(color);
	if (font.innerText) {font.innerText = end;}
	else {font.innerHTML = end;}
	
	obj.appendChild(font);
	
	
   
   
   //newitem = "<div id='menu' style='float:left'>" + start + "</div><div id='menu_active' style='float:right'>| " + end + "</div>";
   //obj.innerText = newitem;
  }
  
  if (obj.value!="unset"&&mode=="unset") {
	  
	  obj.value="unset";
   	tcopy = obj["temp"];
   
   if (obj.innerText) {obj.innerText = tcopy.substring(0, tcopy.length);}
	else {obj.innerHTML = tcopy.substring(0, tcopy.length);}
  }
}



function change_img(obj, img_link) {
	obj.src = img_link;
	//obj.opacity = 1;
	//animator.add_value(obj);
}



function close_big_img(obj) {
	var Knoten = document.getElementById("bimg");
	verschwunden = document.getElementById("big_img").removeChild(Knoten);
}

function show_big_img(img_link) {
	if (!document.getElementById("bimg")) {
		var div = document.createElement("div");
		var align = document.createAttribute("align");
		align.nodeValue = "center";	
		div.setAttributeNode(align);
		var style = document.createAttribute("style");
		style.nodeValue = "position:relative; top:0px; left:0px; background-color:#000000; vertical-align:top; align:center; z-index:3;  border:0px;";	
		div.setAttributeNode(style);
		var id = document.createAttribute("id");
		id.nodeValue = "bimg";	
		div.setAttributeNode(id);
		
		var img = document.createElement("img");
		var src = document.createAttribute("src");
		src.nodeValue = img_link;	
		img.setAttributeNode(src);
		var style = document.createAttribute("style");
		style.nodeValue = "position:absolute; top:0px; left:-800px; vertical-align:top; align:center; z-index:3;  border:0px;";	
		img.setAttributeNode(style);
		var align = document.createAttribute("align");
		align.nodeValue = "center";
		img.setAttributeNode(align);
		var onclick = document.createAttribute("onclick");
		onclick.nodeValue = "close_big_img();";
		img.setAttributeNode(onclick);
		div.appendChild(img);
		var big_img = document.getElementById("big_img");
		
		big_img.appendChild(div);
	}
}
