/*
*	SubMenu
*/
startNaviFunc = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
  				}
  				node.onmouseout=function() {
 					this.className=this.className.replace(" over", "");
  				}
  			}
  		}
	}

}
//window.onload=startNaviFunc;

/*
*	rewrite inner a-tag
*/
var markChar = unescape("%u203A");
function markThis(callObj){
	var stringIst = callObj.firstChild.data;
	var stringSoll = markChar+stringIst;
	callObj.style.margin = "0px";
	callObj.firstChild.data = stringSoll;
}
function unmarkThis(callObj){
	var stringIst = callObj.firstChild.data;
	var stringSoll = stringIst.replace(markChar, "");
	callObj.style.margin = "6px";
	callObj.firstChild.data = stringSoll;
}

/*
*	Projekte
*/
function xreplace(checkMe,toberep,repwith){
	var temp = checkMe;
	var i = temp.indexOf(toberep);
	while(i > -1){
		temp = temp.replace(toberep, repwith);
		i = temp.indexOf(toberep);
	}
	return temp;
}
function replaceSpecialSigns(string){
	string = xreplace(string, '&auml;', '%E4');
	string = xreplace(string, '&Auml;', '%C4');
	string = xreplace(string, '&ouml;', '%F6');
	string = xreplace(string, '&Ouml;', '%D6');
	string = xreplace(string, '&uuml;', '%FC');
	string = xreplace(string, '&Uuml;', '%DC');
	string = xreplace(string, '&szlig;', '%DF');
	string = xreplace(string, '&quot;', '%22');
	return(string);
}
function inArray(value, array){
	for(var i=0; i<array.length; i++){
		if(array[i] == value){
			return(true);
		}
	}
	return(false);
}
function getPID(callObj){
	//return(callObj.id.replace("projekt_", ""));
	var obj = callObj.src.replace("http://www.sacker-architekten.de/tpl/images/projekte/thumbs/projekt_", ""); 
	//obj = callObj.src.replace("http://www.sacker.de/tpl/images/projekte/thumbs/projekt_", ""); 
	//obj = callObj.src.replace("http://sacker.de/tpl/images/projekte/thumbs/projekt_", "");
	obj = obj.replace("http://sacker-architekten.de/tpl/images/projekte/thumbs/projekt_", ""); 
	obj = obj.replace("http://www.sacker.de/tpl/images/projekte/thumbs/projekt_", ""); 
	obj = obj.replace("http://sacker.de/tpl/images/projekte/thumbs/projekt_", "");

	obj = obj.replace(".jpg", "");
	
	return(obj);
}
function getPKID(callObj){
	return(callObj.id.replace("projektKategorie_", ""));
}
function replaceTitle(callObj){
	var pid = getPID(callObj);
	var string = replaceSpecialSigns(projektTitel[pid]);
	var thisElement = document.getElementsByTagName("h1")[0].firstChild;
	var firstChar = 0;
	var strLength = thisElement.nodeValue.length;
 	thisElement.replaceData(firstChar, strLength, unescape(string));
}


function deleteTitle(){
	var string = selGroupId ? replaceSpecialSigns(projektNamen[selGroupId]) : replaceSpecialSigns(pageTitle);
	var thisElement = document.getElementsByTagName("h1")[0].firstChild;
	var firstChar = 0;
	var strLength = thisElement.nodeValue.length;
 	thisElement.replaceData(firstChar, strLength, unescape(string));
}
function replaceTitleKat(callObj){
	var pkid = getPKID(callObj);
	var string = replaceSpecialSigns(projektNamen[pkid]);
	var thisElement = document.getElementsByTagName("h1")[0].firstChild;
	var firstChar = 0;
	var strLength = thisElement.nodeValue.length;
 	thisElement.replaceData(firstChar, strLength, unescape(string));
}
function replaceImg(callObj, pid, grey){
	if(callObj){
		// image directory
			var dir = grey ? 'thumbs_grey' : 'thumbs';
		// replace
			callObj.src="http://sacker-architekten.de/tpl/images/projekte/"+dir+"/projekt_"+pid+".jpg";
			
	}
}
function unmarkProjects(){
	for(var i=0; i<projektIds.length; i++){
		var pid = projektIds[i];
		var thisElement = document.getElementById("projekt_"+pid);
		replaceImg(thisElement, pid, 1);
	}
}
function clearProjectPositions(){
	for(var i=0; i<=40; i++){
		var thisElement = document.getElementById("pos_"+i);
		var pid = "X"; //empty project
		replaceImg(thisElement, pid, 0);
	}
}

function proFuncInit_(){

	if(selGroupId){
	 // group array
		var groupArray = projektRelations[selGroupId];
	 // fetch group array
		for(var i=0; i<40; i++){
			var pid_pos = projektRelations[selGroupId][i];
			var split_pid_pos = pid_pos.split("->");
			var pos = split_pid_pos[1];
			var pid = split_pid_pos[0];
			var thisElement = document.getElementById("pos_"+pos);
			replaceImg(thisElement, pid, 0);
		}
	}
}


function getSelectedProjectSet(){
	if(selGroupId=="") {
		selGroupId=15;
	}
	if(selGroupId){

	 // group array
		var groupArray = projektRelations[selGroupId];
	 // fetch group array
		for(var i=0; i<groupArray.length; i++){
			var pid_pos = projektRelations[selGroupId][i];
			var split_pid_pos = pid_pos.split("->");
			var pos = split_pid_pos[1];
			var pid = split_pid_pos[0];
			var thisElement = document.getElementById("pos_"+pos);
			replaceImg(thisElement, pid, 0);
		}
	}
}



function proFuncPicOver(callObj){

	if(callObj){
		// pid
			var pid = getPID(callObj);
			//alert(pid);
		// replace image
			//replaceImg(callObj, pid, 0);
		// replace title
			replaceTitle(callObj);
	}
}

function proFuncPicOut(callObj){
	if(callObj){
		var pid = getPID(callObj);
		if(selGroupId){
			// if not from selected group
			if(!inArray(pid, projektRelations[selGroupId])){
				// replace image
				//	replaceImg(callObj, pid, 1);
			}
		}
		else{
			//replaceImg(callObj, pid, 1);
		}
		// delete title
			 deleteTitle();
	}
}

function proFuncKatOver(callObj){

	if(callObj && !selProjId){
		// clar projects
			clearProjectPositions();
		// delete title
			deleteTitle();			
		// group id
			var pkid = getPKID(callObj);
		// group array
			var groupArray = projektRelations[pkid];
		// replace image from this kategorie
			for(var i=0; i<groupArray.length; i++){
				
				var pid_pos = groupArray[i];
								
				
				if(pid_pos!=null) {
					var split_pid_pos = pid_pos.split("->");
					pos = split_pid_pos[1];
					
					pid = split_pid_pos[0];
					thisElement = document.getElementById("pos_"+pos);
					replaceImg(thisElement, pid, 0);

							
				} 
				
				
				//alert(pid);
				//var thisElement = document.getElementById("pos_"+i);
				//replaceImg(thisElement, pid, 0);
			}
		// replace title
			replaceTitleKat(callObj);
	}
}

function proFuncKatOut(callObj){
	if(callObj && !selProjId){

		// unmark projects
			clearProjectPositions();
		// mark projects from selected group
//			proFuncInit();
	getSelectedProjectSet();
		// delete title
			deleteTitle();
	}
}