// JavaScript Document

var t_projectDetailsCounter = 0;
var t_projectDetailsCounter_last = -1;

function showProjectDetails(obj, p_op) {
	
	
	switch(p_op) {
		case 'check_and_refresh':
			// make sure that we don't fall over the edges
			if(t_projectDetailsCounter < 0) {
				t_projectDetailsCounter = 0;
			}
			// count down until filled image-tag is found or the counter is at 0
			while(t_projectDetailsCounter > 0 && (obj.parentNode.childNodes[t_projectDetailsCounter].getAttribute("src") == "" || obj.parentNode.childNodes[t_projectDetailsCounter].className != "projekt_img" || obj.parentNode.childNodes[t_projectDetailsCounter].complete == false)) {
				t_projectDetailsCounter--;
			}
			// display / hide the prev and next buttons
			if(t_projectDetailsCounter == 0) {
				obj.parentNode.lastChild.previousSibling.style.display = "none";
			}
			else {
				obj.parentNode.lastChild.previousSibling.style.display = "block";
			}
			if(obj.parentNode.childNodes[t_projectDetailsCounter+1].className != "projekt_img" || obj.parentNode.childNodes[t_projectDetailsCounter+1].getAttribute("src") == "" || obj.parentNode.childNodes[t_projectDetailsCounter+1].complete == false) {
				obj.parentNode.lastChild.style.display = "none";
			}
			else {
				obj.parentNode.lastChild.style.display = "block";
			}
			if(obj.parentNode.lastChild.previousSibling.style.display == "none" && obj.parentNode.lastChild.style.display == "none") {
				obj.parentNode.lastChild.previousSibling.previousSibling.style.display = "none";
			}
			else {
				obj.parentNode.lastChild.previousSibling.previousSibling.style.display = "block";
			}
			if(t_projectDetailsCounter_last != t_projectDetailsCounter) {
				var t_projectDetailsCounter_temp = 0;
				while(obj.parentNode.childNodes[t_projectDetailsCounter_temp].className == "projekt_img") {
					obj.parentNode.childNodes[t_projectDetailsCounter_temp].style.display = "none";
					t_projectDetailsCounter_temp++;
				}
				if(obj.parentNode.childNodes[t_projectDetailsCounter].className == "projekt_img")
					obj.parentNode.childNodes[t_projectDetailsCounter].style.display = "block";
				t_projectDetailsCounter_last = t_projectDetailsCounter;
			}
			break;
		case 'nav_prev':
			t_projectDetailsCounter_last = t_projectDetailsCounter;
			t_projectDetailsCounter--;
			showProjectDetails(obj,'check_and_refresh');
			break;
		case 'nav_next':
			t_projectDetailsCounter_last = t_projectDetailsCounter;
			t_projectDetailsCounter++;
			showProjectDetails(obj,'check_and_refresh');
			break;
		default:
			//obj.parentNode.nextSibling.style.display='inline';
			//obj.parentNode.nextSibling.nextSibling.style.display='inline'; // IE
		
			
			var tabs = getElementsByClass('projekt_image'); //vorher alle löschen
			for(i=0; i<tabs.length; i++)
				tabs[i].style.display = 'none';
				
			var tabs = getElementsByClass('projekt_headline'); //vorher alle löschen
			for(i=0; i<tabs.length; i++)
				tabs[i].style.display = 'none';
		
			var tabs = getElementsByClass('projekt_text'); //vorher alle löschen
			for(i=0; i<tabs.length; i++)
				tabs[i].style.display = 'none';
			
			
			var tabs = getElementsByClass('thumbnail_image'); //vorher alle löschen
			for(i=0; i<tabs.length; i++) {
				tabs[i].style.filter = "gray()";
				tabs[i].style.MozOpacity=0.5;
				tabs[i].style.opacity = 0.5
			}
			
			// zähler für bilder-slideshow zurücksetzen
			t_projectDetailsCounter = 0;
			t_projectDetailsCounter_last = -1;
			showProjectDetails(getNextSibling(obj.parentNode).firstChild, 'check_and_refresh');
			
			getNextSibling(obj.parentNode).style.display='inline'; //statt getNextSibling (geht im FF nicht)
			getNextSibling(getNextSibling(obj.parentNode)).style.display='inline';
			getNextSibling(getNextSibling(getNextSibling(obj.parentNode))).style.display='inline';
			
			
			// Enfärbung (wird über css gemacht)
			//obj.firstChild.filters.gray.enabled=false;
			//obj.firstChild.style.display='none';
			obj.firstChild.style.filter = "none";
			obj.firstChild.style.MozOpacity=1.0;
			obj.firstChild.style.opacity = 1.0
	}
}


function getNextSibling(element){ 
    if(element.nextSibling){
        sibling=element.nextSibling;
        while(sibling.nodeType!=1){ 
            sibling = sibling.nextSibling;
            if(!sibling){ return false; }
        }
        return sibling;
    }else{
        return false;
    }   
}


function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}
