/* JS für */
function bgdebug(txt) {
	console.log(txt);
return;
if(document.debugF) { if(!txt || txt=='') { document.debugF.debug.value=''; } else { document.debugF.debug.value=document.debugF.debug.value+"\n"+txt; } }
else { if(document.getElementById('debug')) {
document.getElementById('debug').innerHTML=txt+"<br/>"+document.getElementById('debug').innerHTML;
//document.getElementById('debug').innerHTML=txt;
}}
}

var UA=navigator.userAgent.toLowerCase();var drh_valid=true;
// SAFARI
var saf,safV,safN="safari";
if(UA.indexOf(safN)>-1) saf=true;
if(saf) { safV=UA.replace(/.+safari\//i,'');safV=safV.split(" ",safV);safV=safV[0];if(isNaN(safV)) safV=parseFloat(safV);if(safV<=100) { drh_valid=false; }}
// IE
var ie6=false;var ie=false;
if(UA.indexOf('msie')>-1) { var tmp=UA.substring(UA.indexOf('msie')+5,UA.length);var ieV=tmp.substring(0,tmp.indexOf(";"));if(ieV<7) { ie6=true; } ie=true; }

var drh_baseColor='#4e322c';
var drh_imgPosCur=0;

var drh_timer=false;
function drh_chgImg(id,url,timer) {
	var pic=new Image();
	pic.src=url;
	document.getElementById(id).src=pic.src;
}

function drh_chgImgBN(dir) {
	var oldid=drh_imgPosCur;
bgdebug("old POS:"+drh_imgPosCur);

	drh_chgImgAbg(0,drh_imgPosCur,document.getElementById('drh_galimglink'+drh_imgPosCur));

	var src='';
	if(dir=='next') {
		if(parseInt(parseInt(drh_imgPosCur)+1) >= drh_galimgs.length) {
			drh_imgPosCur=0;
		}
		else {
			drh_imgPosCur++;
		}
	}
	if(dir=='back') {
		if(parseInt(parseInt(drh_imgPosCur)-1)<0) {
			drh_imgPosCur=(drh_galimgs.length-1);
		}
		else {
			drh_imgPosCur-=1;
		}
	}

bgdebug("NEW POS:"+drh_imgPosCur);
	
	drh_chgImgAbg(0,oldid,document.getElementById('drh_galimglink'+oldid));
	drh_chgImgAbg(1,drh_imgPosCur,document.getElementById('drh_galimglink'+drh_imgPosCur));

	drh_replaceImg(drh_imgPosCur);
}

function drh_replaceImg(id) {
	var src=drh_galimgs[id];
	
	var pic=new Image();
	pic.src=src;

	var img=document.createElement('img');
	var attr=document.createAttribute('width');
	attr.nodeValue=drh_galimgsWidth[id];
	img.setAttributeNode(attr);
	attr=document.createAttribute('id');
	attr.nodeValue='drh_galimg';
	img.setAttributeNode(attr);
	attr=document.createAttribute('src');
	attr.nodeValue=src;
	img.setAttributeNode(attr);

	var pobj=document.getElementById('drh_galimg').parentNode;
	var height=document.getElementById('drh_galimg').parentNode.offsetHeight;
	if(height) pobj.style.height=height+"px";
	pobj.replaceChild(img,document.getElementById('drh_galimg'));
	document.getElementById('drh_imgcaption').innerHTML=drh_galimgsCaption[id];
	if(document.getElementById('drh_imgcaption2')) {
		document.getElementById('drh_imgcaption2').innerHTML=drh_galimgsCaption2[id];
		if(typeof sIFR == "function"){
			sIFR.replaceElement(named({sSelector:"DIV.tx-drhprojects-pi10-caption H3", sFlashSrc:"fileadmin/media/zineslab20.swf", sColor:"#4e322c", sLinkColor:"#4e322c", sHoverColor:"#4e322c", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0", sWmode:"transparent"}));
			sIFR.replaceElement(named({sSelector:"P.tx-drhprojects-pi10-subheader", sFlashSrc:"fileadmin/media/zineslab14.swf", sColor:"#4e322c", sLinkColor:"#4e322c", sHoverColor:"#4e322c", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0", sWmode:"transparent"}));
		}
		if(sIFR) {
			sIFR.replace(zineSlab, {
				selector:"DIV.tx-drhprojects-pi10-caption > H3",
				css: ['.sIFR-root { color: #4e322c; }',
				'.sIFR-root a { color: #4e322c; text-decoration: none; }',
				'.sIFR-root a:visited { color: #4e322c; text-decoration: none; }',
				'.sIFR-root a:hover { color: #4e322c; }'],
				wmode:"transparent",
				fixWrap: 1,
				forceSingleLine: "true"
			});
			sIFR.replace(zineSlab, {
				selector:"P.tx-drhprojects-pi10-subheader",
				css: ['.sIFR-root { color: #4e322c; }',
				'.sIFR-root a { color: #4e322c; text-decoration: none; }',
				'.sIFR-root a:visited { color: #4e322c; text-decoration: none; }',
				'.sIFR-root a:hover { color: #4e322c; }'],
				wmode:"transparent",
				fixWrap: 1,
				forceSingleLine: "true"
			});			
		}
	}
}

function drh_chgImgState(id,obj) {
	var span=false;


bgdebug("OLD CURPOS:"+drh_imgPosCur);
	if(document.getElementById('drh_galimglink'+drh_imgPosCur) && id!=drh_imgPosCur) {
		if(document.getElementById('drh_imgcaption2')) {
			var spans=document.getElementById('drh_galimglink'+drh_imgPosCur).getElementsByTagName('SPAN');
			if(spans.length>0) {
				for(var i=0;i<spans.length;i++) {
					if(spans[i].className=='bg') {
						span=spans[i];
						span.style.height=obj.offsetHeight+'px';
						span.style.width=obj.offsetWidth+'px';
						span.style.visibility='hidden';
						break;
					}
				}
			}
		}
		document.getElementById('drh_galimglink'+drh_imgPosCur).style.backgroundColor='#e9e9e7';
	}
	drh_imgPosCur=id;
bgdebug("NEW CURPOS:"+drh_imgPosCur);
	if(obj) {
		obj.style.backgroundColor=drh_baseColor;
	}
}
function drh_chgImgAbg(state,id,obj) {
	if(obj) {
		var span=false;
		if(document.getElementById('drh_imgcaption2')) {
			var spans=obj.getElementsByTagName('SPAN');
			if(spans.length>0) {
				for(var i=0;i<spans.length;i++) {
					if(spans[i].className=='bg') {
						span=spans[i];
						span.style.height=obj.offsetHeight+'px';
						span.style.width=obj.offsetWidth+'px';
						break;
					}
				}
			}
		}
		if(state>0) {
			if(id==drh_imgPosCur) {
				obj.style.backgroundColor=drh_baseColor;
				if(span) {
					span.style.visibility='visible';
				}
			}
			else {
				obj.style.backgroundColor=drh_baseColor;//'#4e322c';
				if(span) {
					span.style.visibility='visible';
				}
			}
		}
		else {
			if(id!=drh_imgPosCur) {
				obj.style.backgroundColor='#e9e9e7'; 
				if(span) {
					span.style.visibility='hidden';
				}
			}
		}
	}
	
}

function drh_showImgNav(id) {
	if(!ie) return;

	if(id=='back') {
		var lid='drh_imgnavBack';
		var altid='drh_imgnavNext';
	}
	else {
		var lid='drh_imgnavNext';
		var altid='drh_imgnavBack';		
	}
	document.getElementById(lid).style.visibility='visible';
	document.getElementById(altid).style.visibility='hidden';
}
function drh_initImgSinglePos() {
	var obj=document.getElementById('drh_galimglink');
	
}


function drh_chgTd(state,obj) {
	if(!ie6) return;
	var bgcolor=(state>0?'#737373':'#dbdbd7');
	var color=(state>0?'white':'#4e322c');

	var tr=obj.parentNode;
	var tds=tr.getElementsByTagName('TD');
	if(tds.length>0) {
		for(var i=0;i<tds.length;i++) {
			var className=tds[i].className;
//bgdebug(i+" "+className);			
			if(className.lastIndexOf('ACT')!='-1') {
//bgdebug(i+" chgColor ...");			
				bgcolor=(state<1?'#e9e9e7':'#737373');
				color=(state<1?'#404040':'white');
			}
			else {
				bgcolor=(state>0?'#737373':'#dbdbd7');
				color=(state>0?'white':'#4e322c');
			}
			tds[i].style.backgroundColor=bgcolor;
			tds[i].style.color=color;
			var as=tds[i].getElementsByTagName('A');
			if(as.length>0) {
				for(j=0;j<as.length;j++) {
					as[j].style.backgroundColor=bgcolor;
					as[j].style.color=color;
				}
			}
		}
	}
}
function drh_chgTh(state,obj) {
	if(!ie6) return;
	var bgcolor=(state>0?'#b38b81':'#4e322c');
	var color=(state>0?'#4e222c':'white');
	var bgimage=(state>0?'fileadmin/images/bg_nav.gif':'fileadmin/images/bg_nav2.gif');

	var className=obj.className;
//bgdebug(i+" "+className);			
	if(className.lastIndexOf('ACT')!='-1') {
//bgdebug(i+" chgColor ...");			
		bgcolor=(state>0?'#b38b81':'#b38b81');
		color=(state>0?'#4e222c':'#4e222c');
		bgimage=(state>0?'fileadmin/images/bg_nav6.gif':'fileadmin/images/bg_nav6.gif');
	}
	else {
		bgcolor=(state>0?'#b38b81':'#4e322c');
		color=(state>0?'#4e222c':'white');
		bgimage=(state>0?'fileadmin/images/bg_nav.gif':'fileadmin/images/bg_nav2.gif');
	}
	obj.style.backgroundColor=bgcolor;
	obj.style.color=color;
	var as=obj.getElementsByTagName('A');
	if(as.length>0) {
		for(j=0;j<as.length;j++) {
			as[j].style.backgroundColor=bgcolor;
			as[j].style.color=color;
			as[j].style.backgroundImage='url('+bgimage+')';
		}
	}
}
function drh_linkTd(obj) {
	var a=obj.getElementsByTagName('A');
	if(a.length>0) {
		if(a[0].href) window.location.href=a[0].href;
	}
}

var drh_scroller=false;
var drh_proCode='';
var drh_liH=0;
var drh_timerDefault=3000;
var drh_steps=1;

function drh_scrollPro(id,mode) {
bgdebug("init:"+id);
	var frame=document.getElementById(id);
	var tmp;
	
	if(mode=='START') {
		drh_proCode=frame.cloneNode(true);

		var i=0;
		var ths=frame.getElementsByTagName('TH');
		var thsW=new Array();
		var topPos=0;
		if(ths.length>0) {
			for(i=0;i<ths.length;i++) {
				var tmpL=12;
				var tmpR=24;
				if(ths[i].className.lastIndexOf('tdcol1')>=0) { tmpR=12; }
				thsW.push(ths[i].offsetWidth-(tmpL+tmpR));
//bgdebug('WIDTH COL'+i+' = '+(ths[i].offsetWidth-(tmpL+tmpR)));				
			}
		}
		var thead=frame.getElementsByTagName('THEAD');
		if(thead.length<1) return false;
		var topPos=thead[0].offsetHeight;
		
		var tbody=frame.getElementsByTagName('TBODY');
		if(tbody.length<1) return false;
		
		var initHeight=0;
		var baseHeight=0;

		var trs=tbody[0].getElementsByTagName('TR');
		for(i=0;i<trs.length;i++) {
			initHeight+=trs[i].offsetHeight;
			if(i>2) {
				trs[i].style.display='none';
			}
			else {
				if(drh_liH<1) {
					drh_liH=trs[i].offsetHeight-(ie6?1:0);
				}
				baseHeight+=trs[i].offsetHeight;
			}
		}
		for(i=0;i<ths.length;i++) {
			ths[i].style.width=thsW[i]+"px";
		}
		

		var div=document.createElement('div');
		var tagattr=document.createAttribute('class');
		tagattr.nodeValue='tdframe';
		div.setAttributeNode(tagattr);
		tagattr=document.createAttribute('id');
		tagattr.nodeValue="frame"+parseInt(100000*Math.random());
		div.setAttributeNode(tagattr);
		div.style.top=(topPos)+'px';
		div.style.width=frame.offsetWidth+"px";
		div.style.height=(baseHeight-1)+"px";
		div.appendChild(drh_proCode);

		trs=div.getElementsByTagName('TR');
		if(trs.length>0) {
			for(i=0;i<trs.length;i++) {
				tds=trs[i].getElementsByTagName('TD');
				if(tds.length>0) {
					for(j=0;j<tds.length;j++) {
						tds[j].style.width=thsW[j]+'px';
					}
				}
			}
		}

		div.innerHTML='<div>'+div.innerHTML+'</div>';
		drh_proCode=div.firstChild.innerHTML;
//alert(drh_proCode);		
		frame.parentNode.parentNode.insertBefore(div,frame.parentNode);

		var obj=div.firstChild;

		obj.style.position='absolute';
		obj.style.top='0px';
		obj.curPos=0;
		obj.initHeight=initHeight;
		obj.maxHeight=initHeight;
		obj.baseHeight=baseHeight;
		obj.style.width=obj.parentNode.offsetWidth+"px";
		
		drh_steps=drh_liH;
		if(ie6) {
			drh_steps+=1;
		}

		drh_scroller=window.setTimeout('drh_scrolling("'+div.id+'")',drh_timerDefault);

	}
	else {

		var obj=frame.getElementsByTagName('DIV');
		if(obj.length>0) {
			obj=obj[0];
		}
		else { return false; }
	
	//alert(drh_proCode);	
		var baseHeight=frame.offsetHeight;
		var baseWidth=frame.offsetWidth;
		obj.style.width=baseWidth+"px";
bgdebug("ORG HEIGHT:"+baseHeight);
		//if(ie6) { baseHeight-=23; }
		frame.style.height=baseHeight+"px";
	
		var lis=obj.getElementsByTagName('LI');
		if(lis.length>0) {
			for(var i=0;i<lis.length;i++) {
				lis[i].style.display='block';
				if(drh_liH<1) {
					drh_liH=(lis[i].offsetHeight)-(ie6?1:0);
				}
			}
		}
		drh_proCode=obj.innerHTML;
	
		obj.style.position='absolute';
		obj.style.top='0px';
		obj.curPos=0;
		obj.initHeight=obj.offsetHeight;
		obj.maxHeight=obj.offsetHeight;
		obj.baseHeight=baseHeight;
		obj.style.width=baseWidth+"px";
bgdebug("REAL HEIGHT:"+obj.offsetHeight);
		
		drh_scroller=window.setTimeout('drh_scrolling("'+id+'")',drh_timerDefault);
	}
	return true;
}

var drh_stopPos=0;
var drh_insertCounter=0;
function drh_scrolling(id) {
	var frame=document.getElementById(id);

	var obj=frame.getElementsByTagName('DIV');
	if(obj.length>0) {
		obj=obj[0];
	}
	else { return; }

	obj.style.top=(obj.curPos-drh_steps)+"px";
	obj.curPos=obj.curPos-drh_steps;
	drh_stopPos+=drh_steps;
	//obj.style.top=(obj.curPos-drh_liH)+"px";
	//obj.curPos=obj.curPos-drh_liH;
	//drh_stopPos+=drh_liH;

	var timer=20;
	if(drh_stopPos>=(drh_liH+(ie6?1:0))) {
		timer=drh_timerDefault;
		drh_stopPos=0;
	}
	drh_scroller=window.setTimeout('drh_scrolling("'+id+'")',timer);

	if(obj.curPos<(0-(obj.maxHeight-obj.baseHeight))) {
		drh_insertCounter++;
		if(drh_insertCounter>2) {
			var tmpH=obj.firstChild.offsetHeight;
			if(!tmpH) { tmpH=obj.initHeight; }
bgdebug("FISRT CHILD HEIGHT:"+tmpH+" / "+obj.tagName);			
			obj.removeChild(obj.firstChild);
			//if(ie) {
				obj.innerHTML='<div style="height:'+(tmpH)+'px;display:block;clear:both;">&nbsp;</div>'+obj.innerHTML;
			//}
		}
		obj.innerHTML=obj.innerHTML+drh_proCode;
		obj.maxHeight=obj.offsetHeight;

bgdebug("NEW MAX HEIGHT:"+obj.maxHeight);
	}
	return;
}

function drh_stopScroll() {
	window.clearTimeout(drh_scroller);
}



function drh_searchHover(state,obj) {
	var pic=new Image;
	if(state>0) { pic.src=drh_baseDir+'fileadmin/images/submit1.gif'; }
	else { pic.src=drh_baseDir+'fileadmin/images/submit.gif'; }
	obj.src = pic.src;
}
var drh_searchSelected=false;
function drh_searchSelect(obj) {
	if(!drh_searchSelected) {
		obj.value = '';
		drh_searchSelected=true;
	}
	obj.select();
}
function drh_fieldFocusSelect(obj) {
	obj.value = '';
	obj.select();
}

function drh_menuHOver(obj,state) {
	var pobj=obj.parentNode.parentNode.parentNode;
	if(state==1) {
		jQuery(pobj).addClass('ACT');
	}
	else {
		jQuery(pobj).removeClass('ACT');
	}
}

drh_loadGal=false;

function getParentObj(obj,classname) {
	if(!obj) return false;
	var o=false;
	var tmp=obj;
	while(!o) {
//console.log('check Obj: '+tmp.tagName+' / class = '+tmp.className);	
		if(tmp.tagName.toLowerCase()=='body') {
			break;
		}
		if(tmp.className.lastIndexOf(classname)>=0) {
//console.log('found Parent Obj: '+tmp.tagName+' / class = '+tmp.className);
			o=true;
			break;
		}
		else {
			tmp=tmp.parentNode;
//console.log('check Parent Obj: '+tmp.tagName+' / class = '+tmp.className);			
		}
	}
	return tmp;
}

function drh_SIFRMenu(obj,state) {
//console.log(state);
	drh_menuHOver(document.getElementById(obj.id).parentNode,state);
	var pObj=getParentObj(document.getElementById(obj.id),'csc-menu-1-f1');
	//console.log(pObj.className);
}


jQuery.noConflict();

var mouseX = 0;
var mouseY = 0;
jQuery(document).mousemove( function(e) {
    mouseX = e.pageX;
    mouseY = e.pageY;
});

jQuery(document).ready(function() {
	if(typeof sIFR == "function"){
		jQuery('span.csc-menu-1-link').each(function(index) {
			var p=this.parentNode;
			var width=jQuery(this).width();
			p.style.width = width+'px';
			var o=this;
			o.style.position = 'absolute';
			o.style.width = (width)+'px';
			o.style.height = '30px';
			if(ie6) {
				var li=this.parentNode.parentNode.parentNode;
//alert(width);				
				//li.style.width  = (width)+'px';
			}			
		});
	}
	jQuery('span.csc-menu-1-link').bind('mouseover',function() {
		//drh_menuHOver(this,1);
	});
	jQuery('span.csc-menu-1-link').bind('mouseout',function() {
		//drh_menuHOver(this,0);
	});
	
	if(drh_loadGal) {
		tx_drhmedia_pi1_hoverInit();
	}
});

