﻿var navXML;
var navArray = new Array();
var linksArray = new Array();
//init_nav();
function init_nav(n1,n2){
	var request = createXMLHttpRequest();

	request.open('GET', 'js/nav_data.xml', true);
	request.onreadystatechange = function() {
	    if (request.readyState == 4) {
	        navXML = request.responseXML; 
	    		parse_nav(n1,n2); 
	    }
	}
	request.send(null);
}


function parse_nav(n1,n2){
	var root = navXML.getElementsByTagName('navigation')[0];
	for(i=0;i<root.getElementsByTagName('item').length;i++){
		var daLinks = new Array();
		var item = root.getElementsByTagName('item')[i];
		var item_lable =  item.getElementsByTagName('lable')[0].childNodes[0].nodeValue;
		daLinks[0] = item.getElementsByTagName('lable')[0].getAttribute("href");
		var subs = new Array();
		if(item.getElementsByTagName('sub').length > 0){
			for(n=0;n<item.getElementsByTagName('sub').length;n++){
				subs[n] = item.getElementsByTagName('sub')[n].childNodes[0].nodeValue;
				daLinks[n+1] = item.getElementsByTagName('sub')[n].getAttribute("href");
			}
		}
		navArray[i] = new Array(item_lable,subs);
		linksArray[i] = daLinks;
	}
	render_nav(n1,n2);
}

function render_nav(num1,num2){
	var out = new String();
//	for(i=0;i<navArray.length;i++){
//		if(navArray[i][0] == "SPACE"){
//			out += '<img src="images/blank.gif" alt="" height="25" width="246" border="0" />';
//		}
//		else{
//			if(num1 == i){
//				if(navArray[i][1][0] == undefined){
//					out += '<table width="246" id="' + i + '_0" border="0" cellspacing="0" cellpadding="0" class="nav_table" onmouseover="nav_mouse(this,\'over\')" onmouseout="nav_mouse(this,\'out\')" onclick="nav_mouse(this,\'click\')"><tr><td align="right" class="nav_lab_active">' + navArray[i][0] + '</td><td width="27" style="padding-left:5px"><img src="images/nav_arrow_left.gif" alt="" height="13" width="13" border="0" /></td></tr></table>';
//					//out += '<div class="nav_hline" style="margin-bottom: 0"><!-- --></div>'
//				}
//				else{
//					out += '<table width="246" id="' + i + '_0" border="0" cellspacing="0" cellpadding="0" class="nav_table" onmouseover="nav_mouse(this,\'over\')" onmouseout="nav_mouse(this,\'out\')" onclick="nav_mouse(this,\'click\')"><tr><td align="right" class="nav_lab_normal">' + navArray[i][0] + '</td><td width="27" style="padding-left:5px"><img src="images/nav_arrow_down_blue.gif" alt="" height="13" width="13" border="0" /></td></tr></table>';
//					out += '<div class="nav_hline" style="margin-bottom: 20px"><!-- --></div>'
//					for(n=1;n<navArray[i][1].length+1;n++){
//						if(num2 == n){
//						out += '<table width="246" id="' + i + '_' + n + '" border="0" cellspacing="0" cellpadding="0" class="nav_table" onmouseover="nav_mouse(this,\'over\')" onmouseout="nav_mouse(this,\'out\')" onclick="nav_mouse(this,\'click\')"><tr><td align="right" class="nav_lab_active">' + navArray[i][1][n-1] + '</td><td width="27" style="padding-left:5px"><img src="images/nav_arrow_left.gif" alt="" height="13" width="13" border="0" /></td></tr></table>';
//						}
//						else{
//							out += '<table width="246" id="' + i + '_' + n + '" border="0" cellspacing="0" cellpadding="0" class="nav_table" onmouseover="nav_mouse(this,\'over\')" onmouseout="nav_mouse(this,\'out\')" onclick="nav_mouse(this,\'click\')"><tr><td align="right" class="nav_lab_sub">' + navArray[i][1][n-1] + '</td><td width="27" style="padding-left:5px"><img src="images/blank.gif" alt="" height="13" width="13" border="0" /></td></tr></table>';
//						}
//					}
//					out += '<div class="nav_hline" style="margin-top: 20px; margin-bottom: 5px"><!-- --></div>';
//				}
//			}
//			else{
//				out += '<table width="246"  id="' + i + '_0"border="0" cellspacing="0" cellpadding="0" class="nav_table" onmouseover="nav_mouse(this,\'over\')" onmouseout="nav_mouse(this,\'out\')" onclick="nav_mouse(this,\'click\')"><tr><td align="right" class="nav_lab_normal">' + navArray[i][0] + '</td><td width="27" style="padding-left:5px"><img src="images/blank.gif" alt="" height="13" width="13" border="0" /></td></tr></table>';
//			}
//		}
//	}
	
	var ftemp = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="246" height="850" align="top" name="flashnav" id="flashnav"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="nav.swf" /><param name="quality" value="best" /><param name="scale" value="noscale" /><param name="wmode" value="transparent" />';
	ftemp += '<param name="flashvars" value="nav=' + num1 + ',' + num2 + '" />';
	ftemp += '<embed align="top" width="246" height="850" name="flashnav" pluginspage="http://www.macromedia.com/go/getflashplayer" src="nav.swf" FlashVars="nav='+ num1 + ',' + num2 + '" quality="best" scale="noscale" wmode="transparent" bgcolor="#ffffff" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" /></object>';
	document.getElementById('nav').innerHTML = ftemp;
}

function setHead(){
	var n = Math.round((Math.random()*10))+1;
	document.getElementById('main_table').className = "logo_" + n;
}

function nav_mouse(obj,s){
	if(s == 'over'){
		document.body.style.cursor = 'pointer';
		obj.style.backgroundColor = '#EFEFEF';
	}
	if(s == 'out'){
		document.body.style.cursor = 'auto';
		obj.style.backgroundColor = '';
	}
	if(s == 'click'){
		var n1 = obj.id.split('_')[0];
		var n2 = obj.id.split('_')[1];
		if(linksArray[n1][n2] != undefined){
			document.location.href = linksArray[n1][n2]; // + '?n1=' + n1 + '&n2=' + n2;
		}
		else{
			document.location.href = 'nix.html?n1=' + n1 + '&n2=' + n2;
		}
		//document.getElementById('out').innerHTML = linksArray[n1][n2];
		//alert(obj.getElementsByTagName('td')[0].innerHTML);
	}
}

function gallery_mouse(obj,s,c,id,id2){
	switch (s) {
		case 'over' :
			document.body.style.cursor = 'pointer';
			obj.style.backgroundColor = '#EFEFEF';
			break;
		case 'out' :
			document.body.style.cursor = 'auto';
			obj.style.backgroundColor = '';
			break;
		case 'click' :
			switch (c) {
				case 'start' :
					document.location.href = 'start_media_gallery.php?id='+id;
					break;
				case 'werkstatt' :
					document.location.href = 'werkstatt_media_gallery.php?id='+id;
					break;
				case 'intern' :
					document.location.href = 'intern_media_gallery.php?id='+id;
					break;
				case 'internwdg' :
					document.location.href = 'intern_werkstatt_gallery.php?id='+id;
					break;
				case 'class' :
					document.location.href = 'intern_media_gallery_class.php?id='+id+'&cid='+id2;
					break;
			}
			break;
	}
}

// Tools
// ###################################################################################

function createXMLHttpRequest() {
    if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
    } else if (typeof ActiveXObject != 'undefined') {
        return new ActiveXObject('Microsoft.XMLHTTP');
    } else {
        throw new Error('XMLHttpRequest not supported');
    }
}

function feedback(s){
	alert(s);
}


function getUrlVars() {
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	 
	for(var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

function print_test(url,w,h,win_name){
	var win= null;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	settings = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=no,toolbar=no';
	win=window.open(url,win_name,settings)
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function login() {
	nameo = document.getElementById('name').value;
	passo = document.getElementById('pass').value;

	createCookie('username_fe',nameo,7);
	createCookie('password_fe',MD5(passo),7);
	document.location.href='intern_termine.php';
}

