/*
Architekturbüro Rau
_______________
Markus Falk
webit! Gesellschaft für neue Medien mbH - www.webit.de
*/

function inform (element) {
	var langebeschreibung = element.getAttribute("alt");
	document.getElementById("beschreibung").innerHTML = langebeschreibung;
	
}

function cleartext () {
	document.getElementById("beschreibung").innerHTML = "";
}


/* Referenzbildleiste */
function ref() {
	if(document.getElementById('referenzbildleiste1')){
		var referenzleiste1 = document.getElementById('referenzbildleiste1');
		var referenzleiste2 = document.getElementById('referenzbildleiste2');
		
		refimg = referenzleiste1.getElementsByTagName('img');
		for(var i = 0; i < refimg.length; i++) {
			refimg[i].setAttribute('id','ri'+i);
			refimg[i].onmouseover = new Function("swapimg("+i+")");
			refimg[i].onmouseout = new Function("swapimg("+i+")");
			/*refimg[i].setAttribute('onmouseover', 'swapimg('+i+')');
			refimg[i].setAttribute('onmouseout','swapimg('+i+')');*/
			}	
			
		
		reflink = referenzleiste2.getElementsByTagName('a');
		for(var i = 0; i < reflink.length; i++) {

			reflink[i].setAttribute('id','rl'+i);
			reflink[i].setAttribute('style','color:#4d494a')
			reflink[i].onmouseover = new Function("swapimg("+i+")");
			reflink[i].onmouseout = new Function("swapimg("+i+")");
			}	
		}
	}

// Entscheidungsvariable: Farbe für Links ändern 
zahl = 0;

function swapimg(id) {

	var refimg = document.getElementById('ri'+id);
	var quelle = refimg.getAttribute("src");
	if(quelle.search(/_sw.+/) != -1) {
		quelle = quelle.replace(/_sw/, '_farbig')
		refimg.setAttribute('src', quelle);
		}
	else {
		quelle = quelle.replace(/_farbig/, '_sw')
		refimg.setAttribute('src', quelle);
		}
		
	
	var reflink = document.getElementById('rl'+id);
	
	//alert("zahl: "+zahl);
	entscheider = zahl%2;
	//alert("Entscheider: "+entscheider);
	
	if( entscheider == 0 ) {
		//reflink.setAttribute('style','color:#8a1014');
		reflink.style.cssText = 'color:#8a1014';
		
	}
	else if ( entscheider != 0 ){
		//reflink.setAttribute('style','color:#4d494a'); 
		reflink.style.cssText = 'color:#4d494a';
	}
	
	zahl++;
	//alert("zahl++: "+zahl);
	
	/**** HINWEIS *************************************************************************
	*	
	*	Die offensichtlichere Herangehensweise per setAttribute funktioniert im IE nicht. 
	*	MS-Musterlösung mit getAttribute(attr,iFlag) oder attributes[ ] funktionieren ebenfalls nicht.
	*	"cssText =" getestet mit FF 2, IE 7,6,5.5, Opera 9, Safari 1.3.2
	*
	*															Markus
	****************************************************************************************/

}


/**_______________________________________________________________________________________
 * following is written by Christian Seifert
 * webit! Gesellschaft für neue Medien mbH - www.webit.de
 * Last Action: 14:43 19.07.2007 UD (Fix IE7)
 * _______________________________________________________________________________________
 */

/**
 * Global Vars
 */
var allA = new Array();
var currentElement = null;
var firstIdx = null;
var first = true;
var isIE_6 = (navigator.userAgent.indexOf("MSIE 6.0") != -1) ? true : false;
var isIE_55 = (navigator.userAgent.indexOf("MSIE 5.5") != -1) ? true : false;
var isIE_7 = (navigator.userAgent.indexOf("MSIE 7.0") != -1) ? true : false;
var lastIdx = 0;
var tooltip_link = null;

//alert(navigator.userAgent);

/**
 * Replace Image
 * @param {int} idx
 * @param {string} href
 */
function changeImage(idx, href) {
	var cur = null, prevA = null;
	var lastImage = document.getElementById('projektBild').src;
	document.getElementById('projektBild').src = href;
	/* Parentnode from clicked Link */
	var parentOfA = allA[idx].parentNode;
	if(!first) {
		cur = document.getElementById('bilder').getElementsByTagName('strong')[0];
		prevA = cur.firstChild;
		parentOfA.insertBefore(prevA, cur);
		parentOfA.removeChild(cur);
	}
	/* the temp-link get the previoues Image */
	allA[idx].setAttribute('href', 'javascript:void(0);');
	/* Create strong-Element */
	var strong = document.createElement('strong');
	/* Append strong-Element the Link with the Prevous Image */
	strong.appendChild(allA[idx]);
	/* Insert Link at the Sourceposition */
	if(idx == firstIdx) {
		parentOfA.insertBefore(strong, parentOfA.firstChild);
		lastIdx = idx;
	} else {
		parentOfA.insertBefore(strong, allA[idx-1].nextSibling);
		lastIdx = idx - 1;
	}
	first = false;
}

/**
 * Find all anchor-Elements,
 * which have the Relation(rel) to 'Gallery'.
 */
function getAllLinks() {
	allA = document.getElementsByTagName('a');
	var isFirst = false;
	for(var i = 0; i < allA.length; i++) {
		if(allA[i].getAttribute('rel') == 'gallery') {
			if(!isFirst) {
				isFirst = true;
				firstIdx = i;
			}
			var h = allA[i].getAttribute('href');
			/**
			 * IE need a extra directive ... ;)
			 */

			if(isIE_6 || isIE_55 || isIE_7) {
				allA[i].onclick = new Function("changeImage(" + i + ", '" + h + "'); return(false);");
			} else {
				allA[i].setAttribute('onclick', "changeImage(" + i + ", '" + h + "'); return(false);");
			}
		}
	}
	/**
	 * Simulate the first Click ...
	 */
	if(firstIdx != null) {
		changeImage(firstIdx, allA[firstIdx].getAttribute('href'));
	}

	/**
	 * Only for IE6 and IE5.5 the Tooltip-Link gets a alternative directive to show the Tooltip
	 */
	/* tooltip wird im moment gar nicht angezeigt
	if((isIE_6 || isIE_55) && (firstIdx != null)) {
		tooltip_link = document.getElementById('tooltip');
		tooltip_link.onmouseover = new Function("ie_tooltip()");
		tooltip_link.onmouseout = new Function("ie_tooltip_out()");
		tooltip_link.alt = "";
		tooltip_link.title = "";
	}*/
}

/**
 * MouseOver for IE only, its the alternative for the CSS-hover.
 * @param {Event} e
 */
function ie_tooltip(e) {
	var fc = tooltip_link.getElementsByTagName('span')[0];
	fc.style.display = "block";
}

/**
 * MouseOut for IE only, to revoke the MouseOver.
 * @param {Event} e
 */
function ie_tooltip_out(e) {
	var fc = tooltip_link.getElementsByTagName('span')[0];
	fc.style.display = "none";
}

window.onload=function() { getAllLinks(); ref(); };
