/**************************************************
 * appl.js
 * www.applike.ch
 * Allgemeiner Code zur Steuerung von applike.ch
 **************************************************/
 
// Preloads und Initialisierungen "onDomLoad"
var domLoad = new domFunction(function() {
	net.loadHelper("netHome","xml/home.xml","xml/home.xsl",xGetElementById("content"),true);
	net.setCurrentLocation("Home");
	MM_preloadImages('images/laden.gif','images/nav_home.gif','images/nav_home_a.gif','images/nav_techn_tab.gif','images/nav_techn_a.gif','images/nav_demos_tab.gif','images/nav_demos_a.gif','images/nav_ueber_tab.gif','images/nav_ueber_a.gif','images/nav_kontakt_tab.gif','images/nav_kontakt_a.gif','images/nav_home_tab.gif');
	MM_nbGroup('init','group1','nav_home','images/nav_home.gif',1);
});

// Eventhandling
var event_nav = {
	
	// Navigation > Home
	'#nav_home_href' : function(el) {
		el.onclick = function() {
			MM_nbGroup('down','group1','nav_home','images/nav_home_tab.gif',1);
			net.loadHelper("netHome","xml/home.xml","xml/home.xsl",xGetElementById("content"),true);
			net.setCurrentLocation("Home");
		}
		el.onmouseover = function() {
			MM_nbGroup('over','nav_home','images/nav_home_a.gif','images/nav_home_tab.gif',1);
		}	
		el.onmouseout = function() {
			MM_nbGroup('out');
		}			
	},
	
	// Navigation > Technologie
	'#nav_techn_href' : function(el) {
		el.onclick = function() {
			MM_nbGroup('down','group1','nav_techn','images/nav_techn_tab.gif',1);
			net.loadHelper("netTechnologie","xml/technologie.xml","xml/technologie.xsl",xGetElementById("content"),true);
			net.setCurrentLocation("Technologie");
		}
		el.onmouseover = function() {
			MM_nbGroup('over','nav_techn','images/nav_techn_a.gif','images/nav_techn_tab.gif',1);
		}	
		el.onmouseout = function() {
			MM_nbGroup('out');
		}			
	},
	
	// Navigation > Demos
	'#nav_demos_href' : function(el) {
		el.onclick = function() {
			MM_nbGroup('down','group1','nav_demos','images/nav_demos_tab.gif',1);
			net.loadHelper("netDemos","xml/demos.xml","xml/demos.xsl",xGetElementById("content"),true);
			net.setCurrentLocation("Demos");			
		}
		el.onmouseover = function() {
			MM_nbGroup('over','nav_demos','images/nav_demos_a.gif','images/nav_demos_tab.gif',1);
		}	
		el.onmouseout = function() {
			MM_nbGroup('out');
		}			
	},
	
	// Navigation > Über AppLike
	'#nav_ueber_href' : function(el) {
		el.onclick = function() {
			MM_nbGroup('down','group1','nav_ueber','images/nav_ueber_tab.gif',1);
			net.loadHelper("netUeber","xml/ueber.xml","xml/ueber.xsl",xGetElementById("content"),true);
			net.setCurrentLocation("Über uns");			
		}
		el.onmouseover = function() {
			MM_nbGroup('over','nav_ueber','images/nav_ueber_a.gif','images/nav_ueber_tab.gif',1);
		}	
		el.onmouseout = function() {
			MM_nbGroup('out');
		}			
	},
	
	// Navigation > Kontakt
	'#nav_kontakt_href' : function(el) {
		el.onclick = function() {
			MM_nbGroup('down','group1','nav_kontakt','images/nav_kontakt_tab.gif',1);
			net.loadHelper("netKontakt","xml/kontakt.xml","xml/kontakt.xsl",xGetElementById("content"),true);
			net.setCurrentLocation("Kontakt");			
		}
		el.onmouseover = function() {
			MM_nbGroup('over','nav_kontakt','images/nav_kontakt_a.gif','images/nav_kontakt_tab.gif',1);
		}	
		el.onmouseout = function() {
			MM_nbGroup('out');
		}			
	},		
		
	// Navigation > Logo führt zu Home
	'#logo' : function(el) {
		el.onclick = function() {
			MM_nbGroup('down','group1','nav_home','images/nav_home_tab.gif',1);
			net.loadHelper("netHome","xml/home.xml","xml/home.xsl",xGetElementById("content"),true);
			net.setCurrentLocation("Home");
		}
	},
	
	// Current Location > Home
	'#currentlocation a' : function(el) {
		el.onclick = function() {
			MM_nbGroup('down','group1','nav_home','images/nav_home_tab.gif',1);
			net.loadHelper("netHome","xml/home.xml","xml/home.xsl",xGetElementById("content"),true);
			net.setCurrentLocation("Home");
		}
	},
	// Button Mehr Infos > Über AppLike
	'#btn_mehrinfos_ueber' : function(el) {
		el.onclick = function() {
			MM_nbGroup('down','group1','nav_ueber','images/nav_ueber_tab.gif',1);
			net.loadHelper("netUeber","xml/ueber.xml","xml/ueber.xsl",xGetElementById("content"),true);
			net.setCurrentLocation("Über uns");		
		}
	},
	// Button Mehr Infos > Kontakt
	'#btn_mehrinfos_kontakt' : function(el) {
		el.onclick = function() {
			MM_nbGroup('down','group1','nav_techn','images/nav_techn_tab.gif',1);
			net.loadHelper("netKontakt","xml/kontakt.xml","xml/kontakt.xsl",xGetElementById("content"),true);
			net.setCurrentLocation("Kontakt");
		}
	},	
	// Quicklinks Demos > PLZ Abfrage
	'#quicknav_demos_plz' : function(el) {
		el.onclick = function() {
			// Fenster-Objekt existiert bereits, wieder ins DOM einfügen
			if (typeof(objList[0].winDemosPlz)!="undefined") {
				objList[0].winDemosPlz.append();
			}
			// Neues Fenster-Objekt
			else {
				objList[0].winDemosPlz = new Window();
				objList[0].winDemosPlz.windowID = "win_demos_plz";
				objList[0].winDemosPlz.posX = 200;
				objList[0].winDemosPlz.posY = 300;
				objList[0].winDemosPlz.titleText = "Postleitzahlen-Abfrage";
				//winDemosPlz.parentElement = xGetElementById("page");
				objList[0].winDemosPlz.render();
			}
			net.loadHelper("netDemosPlz","select_DemosPlz.php","xml/select_DemosPlz.xsl",xGetElementById("win_demos_plz_content"),false);
			//net.setCurrentLocation("Über uns");		
		}
	}						
};	

var event_buttons = {
	// Buttons Leben einhauchen
	'div.but-new' : function(el) {
		el.onmouseover = function() {
			this.style.backgroundPosition = "left -50px";
			this.firstChild.style.backgroundPosition = "right -50px";
			this.firstChild.firstChild.style.backgroundPosition = "-200px bottom";
			this.firstChild.firstChild.firstChild.style.color = "#605e6b";
		}
		el.onmouseout = function() {
			this.style.backgroundPosition = "left top";
			this.firstChild.style.backgroundPosition = "right top";
			this.firstChild.firstChild.style.backgroundPosition = "left bottom";
			this.firstChild.firstChild.firstChild.style.color = "#817f8e";
			this.firstChild.firstChild.firstChild.style.padding = "8px 12px 8px 12px";
		}
		el.onmousedown = function() {
			this.firstChild.firstChild.firstChild.style.padding = "10px 10px 6px 14px";
		}
		el.onmouseup = function() {
			this.firstChild.firstChild.firstChild.style.padding = "8px 12px 8px 12px";
		}							
	}
};

Behaviour.register(event_nav);
Behaviour.register(event_buttons);


net.loader = function(xmlFile,xslFile,targetEl,addedParams) {
	this.xmlFile = xmlFile;
	this.xslFile = xslFile;
	this.targetEl = targetEl;
	this.targetDoc = "php/xsltparser.php";
	this.method = "POST";
	this.params = [ "xml=" + this.xmlFile, "xsl=" + this.xslFile ];
	this.addedParams = "";
	this.loading = "<img src=\"images/laden.gif\" width=\"45\" height=\"45\" />";
}

net.loader.prototype = {
	fetchData : function() {
		tools.purge(this.targetEl);
		this.targetEl.innerHTML = this.loading;
		var ajaxHelper = new net.ContentLoader(this, this.targetDoc, this.method, this.params);
		ajaxHelper.sendRequest();
	},
	ajaxUpdate : function(r) {
		 this.response = r.responseText;
		 tools.purge(this.targetEl);
		 this.targetEl.innerHTML = this.response;
		 Behaviour.renderButtons();
		 Behaviour.apply();
	},
	handleError : function(e) {
		alert("Fehler! "+e);
	},
	restore : function() {
		tools.purge(this.targetEl);
		this.targetEl.innerHTML = this.response;
		Behaviour.renderButtons();		 
		Behaviour.apply();
	}
}

net.loadHelper = function(handle,xmlFile,xslFile,targetEl,restorePrevious,addedParams) {
	if (restorePrevious) {
		if (objList[0][handle] == null) {
			objList[0][handle] = new net.loader(xmlFile,xslFile,targetEl,addedParams);
			objList[0][handle].fetchData();
		}
		else { objList[0][handle].restore(); }	
	}
	else {
		objList[0][handle] = new net.loader(xmlFile,xslFile,targetEl,addedParams);
		objList[0][handle].fetchData();
	}
}

net.setCurrentLocation = function(currentLocation) {
	if (currentLocation != "Home") {
		xGetElementById("currentlocation").innerHTML = "<a href=\"javascript:;\">Home</a> > "+currentLocation;
	} else {
		xGetElementById("currentlocation").innerHTML = currentLocation;
	}
	Behaviour.apply();
}
