/*
* Rationed wird gespeichert
*/
function VocableOfTheDay()
{
	this.url = "?ajax=info";
	this.postBack = "index";
	
	this.listContainer = document.getElementById("vocables");
	//this.resultObject = document.getElementById("vocables");
	this.pagingContainer = document.getElementById("paging");
	this.dialogContainer = document.getElementById("popupcontent");
	this.page = 1;

	this.xmlDoc = null;
	this.xslt = new Xslt();
	this.xPath = new XPath();
	this.pos = 1;

	/*
	* Lädt das XSL file und iniziert den XSLTProcessor
	*/
	this.init = function(xslFile)
	{
		try {
			this.listContainer.style.width = this.listContainer.width + "px";
		}
		catch(e) {
			// Kann der IE nicht
		}
		this.xslt.init(xslFile);
	}

	/*
	* Ergebniss des Ajax-Requests wird behandelt
	* Statische Funktion
	*/
	this.update = function()
	{
		if(vocableOfTheDay.xmlHttpReq.readyState == 4)
		{
			if (vocableOfTheDay.xmlHttpReq.responseXML)
			{
				// Info Request
				if (vocableOfTheDay.xmlHttpReq.responseXML.documentElement.nodeName == "ajax")
				{

					if (vocableOfTheDay.xmlHttpReq.responseXML.documentElement.firstChild && vocableOfTheDay.xmlHttpReq.responseXML.documentElement.firstChild.nodeName == "vocablelisting")
					{
						if (vocableOfTheDay.xmlHttpReq.responseXML.documentElement.getAttribute("load") == "true")
						{
							vocableOfTheDay.xmlDoc = vocableOfTheDay.xmlHttpReq.responseXML;
							vocableOfTheDay.renderList();
						}
					}
				}
			}
		}
	}

	/*
	* Bestimmt den zum resultNode gehörenden Node in xmlDoc
	* Funktioniert nur solang Nodes im xmlDoc nur einmal vorkommen
	*/
	this.getXmlNode = function(resultNode)
	{
		this.xPath.evaluate("//"+resultNode.nodeName+"[id"+resultNode.nodeName+"='"+resultNode.firstChild.textContent+"']", this.xmlDoc);
		var xmlNode = this.xPath.iterateNext();
		return xmlNode;
	}

	/*
	* Rendert gesammten Inhalt
	*/
	this.renderList = function() {
		this.xslt.setParameter("side", this.pos);
		this.xslt.setParameter("mode", "default");
		var result = this.xslt.transformToDocument(this.xmlDoc);
		this.xslt.setParameter("mode", "");

		this.listContainer.innerHTML = "";
		appendXSLTResult(this.listContainer, result);
		if (innerWidth > 648) {
			if (innerWidth < 1200) {
				document.getElementById("selector").style.width = (innerWidth - 140) + "px";
			}
		}
		else {
			document.getElementById("selector").style.width = "648px";
		}
	}
	
	/*
	* Rendert die große VCard
	*/
	this.renderCard = function() {
		this.xslt.setParameter("side", this.pos);
		this.xslt.setParameter("mode", "card");
		var result = this.xslt.transformToDocument(this.xmlDoc);
		this.xslt.setParameter("mode", "");

		document.getElementById("mainvcard").innerHTML = "";
		appendXSLTResult(document.getElementById("mainvcard"), result);
	}
	
	/*
	* Die Vokabeln werden geladen
	*/
	this.loadVocables = function() {
		var str = encodeURI("ajax=info&postBack="+this.postBack+"&value[action]=load&value[object]=vocablelisting");
		this.asyncron = true;
		this.startPostRequest(str);
	}
	
	/*
	* Neue Vokabel wird angezeigt
	*/
	this.activate = function(pos, obj) {
		this.pos = pos;
		this.renderCard();
		
		var node = obj.parentNode.firstChild;
		while (node) {
			if (node != obj) {
				if (!is_ie) {
					node.className = "cell";
				}
				else {
					node.className = "";
				}
			}
			else {
				if (!is_ie) {
					node.className = "cell active";
				}
				else {
					node.className = "active";
				}
			}
			node = node.nextSibling;
		}
	}
}
VocableOfTheDay.prototype = new Ajax();
var vocableOfTheDay = new VocableOfTheDay();
vocableOfTheDay.init("Xsl/AJAX/vocableOfTheDay.php");
vocableOfTheDay.loadVocables();