function resizeStuff() {
	if((navigator.userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == "Apple Computer, Inc.") || ((navigator.userAgent.indexOf('rv:1.8') > -1))&&(navigator.userAgent.indexOf('Gecko') > -1)) {
		document.getElementById("innercontent").style.width = "437px";
		//document.write('<style type="text/css"> #innercontent { width:437px; } </style>');
	}
}

function fixScroll() {
    s = document.getElementById('innercontent').scrollTop;
    document.getElementById('dummyscrollanchor').focus()
    document.getElementById('innercontent').scrollTop = s;
}

function popNewsletter(inout) {
	address = document.forms["optinout"].email.value;
	firstname = document.forms["optinout"].firstname.value;
	lastname = document.forms["optinout"].lastname.value;
	company = document.forms["optinout"].company.value;
	
	if(document.forms["optinout"].title[0].checked) {
		title = "Herr";
	}
	else if(document.forms["optinout"].title[1].checked) {
		title="Frau";
	}
	else {
		title="";
	}
	
	if(address && (address!="Ihre eMail-Adresse")) {
		var url = "http://letters.popletter.com/popup/optinout.php?inOut="+inout+"&address="+address+"&fnm="+firstname+"&lnm="+lastname+"&cmp="+company+"&ttl="+title;
		window.open(url,"optWin","width=250,height=250,top=50,left=100,scrollbars=no");
	}
	else {
		alert("Bitte geben Sie eine Adresse ein.");
	}
}

function openMovie(url) {
    movieWindow = window.open(url,"movieWin","width=330,height=285,top=50,left=100,scrollbars=no");
    movieWindow.focus();
}

function openScreenshot(url,w,h) {
	screenH = screen.height;
	screenW = screen.width;		
	
	//alert(screenH+"x"+screenW);
	
	if(screenH > (h+60)) {
		winH = h+20;
	}
	else {
		winH = screenH - 60;
	}
	
	if(screenW > w+60) {
		winW = w+40;
	}
	else {
		winW = screenW - 10;
	}
	
    screenshotWindow = window.open(url,"movieWin","width="+winW+",height="+winH+",top=0,left=0,scrollbars=yes");
    screenshotWindow.focus();
}

function openPage(url,w,h) {
    newWindow = window.open(url,"newWin","width="+w+",height="+h+",top=0,left=0,scrollbars=yes,location=yes,toolbar=yes,resizable=yes");
    newWindow.focus();    
}

function textareaPop(newSrc) {
	var links = document.getElementsByTagName('a');
	for(var i = 0; tag = links[i]; ++i) {
		if(tag.className == 'poplink') {
			tag.target = 'popwindow';
			tag.onclick = openPopwin;
	  	}  	     
	}		
}

function openPopwin() {
	var pwin = window.open(this.href, 'popwindow', 'width=975,height=650, top=25, left=25, scrollbars=yes, resizable=yes');
	try { pwin.focus(); } catch(e) {}
	return false;
}



function extractAnchor() {
    var thisUrl = window.location.href;
    urlArray = thisUrl.split("#");
    
    arrayLength = urlArray.length - 1;   
    var thisAnchor = urlArray[arrayLength];
    
    return(thisAnchor);
}

function newScroll(anchor) {
	thisAnchor = anchor;
		
	/*if(thisAnchor && (overviewFrame.document.getElementsByName(thisAnchor)[0])) {       
	   
		anchorY = overviewFrame.document.getElementsByName(thisAnchor)[0].offsetTop;       
	   
		anchorParentObject = overviewFrame.document.getElementsByName(thisAnchor)[0].offsetParent;
	
		for(i=0;i<2;i++) {
			anchorY += anchorParentObject.offsetTop;
			anchorParentObject = anchorParentObject.offsetParent;
		}
	   
		anchorY -= 15;
		overviewFrame.scrollTo(0,anchorY);               
	}*/
	
	if(thisAnchor && (document.getElementsByName(thisAnchor)[0])) {       
	   
		anchorY = document.getElementsByName(thisAnchor)[0].offsetTop;       	   	   
		
		anchorParentObject = document.getElementsByName(thisAnchor)[0].offsetParent;
	
		//for(i=0;i<1;i++) {
			anchorY += anchorParentObject.offsetTop;
			anchorParentObject = anchorParentObject.offsetParent;
		//}
	   
		anchorY -= 15;
		
		//alert(anchorY);
		document.getElementById("iframecontainer").scrollTop = anchorY;               
	}
}

function swapPhoto(imgName,imgIndex) {
	document.getElementById("contentfoto").src = "img/portfolio/"+imgName+"_foto"+imgIndex+".jpg";
	
	for(i=1;i<10;i++) {
		theLink = "fotolink"+i;
		if(document.getElementById(theLink)) {
			document.getElementById(theLink).className="contentlink";
		}
		else {
			break;
		}		
	}
	
	document.getElementById("fotolink"+imgIndex).className="boldlink";
}

//blaetter
function flickPhoto(where) {
	imgPath = document.getElementById("contentfoto").src;
	
	imgPath = imgPath.split("_foto");
	imgPathPart = imgPath[1].split(".jpg") ;
	imgIndex = imgPathPart[0];
	
	if(where == "next") {
		imgIndex++;
	}
	else {
		imgIndex--;
	}
	
	if(document.getElementById("fotolink"+imgIndex)) {	
		document.getElementById("contentfoto").src = imgPath[0]+"_foto"+imgIndex+".jpg";
		
		for(i=1;i<10;i++) {
			theLink = "fotolink"+i;
			if(document.getElementById(theLink)) {
				document.getElementById(theLink).className="contentlink";
			}
			else {
				break;
			}		
		}
		
		document.getElementById("fotolink"+imgIndex).className="boldlink";
	}
}


var imgwin;

function enlargeMe(theFoto,theWidth,theHeight) {
	if(typeof(theWidth)=="undefined") theWidth = 900;

	if(typeof(theHeight)=="undefined") theHeight = 900;

	littleFoto = theFoto.src;
	bigFoto = littleFoto.replace(/.jpg/g, "_big.jpg");
	
	imgwin = window.open(bigFoto, 'imgwindow', 'width='+theWidth+',height='+theHeight+', top=25, left=25');
	imgwin.focus();	
	setTimeout("checkAndResize()",750);
}

function checkAndResize() {
	if(imgwin.document.images[0]) {
		hoehe = imgwin.document.images[0].height + 20;
		breite = imgwin.document.images[0].width + 20;
			
		hoehe2 = hoehe+90;
	    breite2 = breite+30;
		
		if (window.innerHeight) {
			imgwin.resizeTo(breite2,hoehe2);    //fuer opera
			imgwin.innerWidth = breite;     //mozilla
			imgwin.innerHeight = hoehe;
		}
		else {
			imgwin.resizeTo(breite2,hoehe2); //ie
		}				
	}
	else {
		setTimeout("checkAndResize()",500);
	}
}


/***** NewsBox *****/

var newsInterval;

function initNews() {	
	swapNews();
	newsInterval = setInterval("swapNews()", 8000);
}

function recursiveFadeIn(q, theObject) {	
	if(q == 0) {
		setOpacity(0,theObject);
		theObject.style.display = "block";
	}

	if(q < 20) {
		q++;
		setOpacity(q, theObject);
		//setTimeout(function() { recursiveFadeIn(q, theObject); }, 9*q);			
		setTimeout(function() { recursiveFadeIn(q, theObject); }, 75);			
	}	
}

function recursiveFadeOut(q, theObject) {	
	if(q > 0) {
		q--;
		setOpacity(q, theObject);
		//setTimeout(function() { recursiveFadeOut(q, theObject); }, 6*q);			
		setTimeout(function() { recursiveFadeOut(q, theObject); }, 65);			
	}
	else {
		theObject.style.display = "none";
	}
}

function swapNews() {
	newsCount = 0;
	newsElementsArray = new Array();
	var newsElements = document.getElementsByTagName('div');
	for(var i = 0; theDiv = newsElements[i]; ++i) {
		if(theDiv.className == 'newselement') {
			newsElementsArray.push(i);
			if(newsElements[i].style.display == "block") {
				recursiveFadeOut(20, newsElements[i]);			
			}
	  	}  	     
	}
		
	elementIndex = Math.random() * (newsElementsArray.length - 0.5);
	elementIndex = Math.round(elementIndex);
	
	if(document.cookie) {
		dCookie = document.cookie;
		oldElementIndex = dCookie.substr(dCookie.search('oldIndex=')+9,2);
		oldElementIndex = oldElementIndex.replace(';');		// bis 99 newseintraege
	
		if(elementIndex == oldElementIndex) {					// wenn zufaellig gewaehltes element gerade vorher angezeigt wurde
			if(elementIndex < newsElementsArray.length) {
				elementIndex++;
			}
			else {
				elementIndex = 0;
			}
		}
	}
	
	// letztes angezeigtes element im cookie speichern
	var ablauf = new Date();
	var morgen = ablauf.getTime() + (24 * 60 * 60 * 1000);
	ablauf.setTime(morgen);
	document.cookie = "oldIndex="+elementIndex+"; expires=" + ablauf.toGMTString();

	theObject = newsElements[newsElementsArray[elementIndex]];
	
	if(newsElements[newsElementsArray[elementIndex]]) {
		setTimeout(function() { recursiveFadeIn(0, theObject); }, 1500);			
	}
	else {
		newsElements[newsElementsArray[0]].style.display = "block";
	}
}

function stopNews() {
	window.clearInterval(newsInterval);
}

function startNews() {
	newsInterval = setInterval("swapNews()", 11000);
}

function setOpacity(theValue,theElement) {
	var object = theElement.style; 
	object.opacity = (theValue / 20);
	object.MozOpacity = (theValue / 20);
	object.KhtmlOpacity = (theValue / 20);
	object.filter = "alpha(opacity=" + (100*theValue/20) + ")";	
}


// startseite:
function initWelcomeNews() {
	document.getElementById("newsbody").style.height = "442px";
	welcomeNews();
	newsInterval = setInterval("welcomeNews()", 15500);
}

function welcomeNews() {
	newsElementsArray = new Array();
	var newsElements = document.getElementsByTagName('div');
	for(var i = 0; theDiv = newsElements[i]; ++i) {
		// drei zufŠllige einblenden
		if(theDiv.className == 'newselement') {
			newsElementsArray.push(i);
			if(newsElements[i].style.display == "block") {
				recursiveFadeOut(20, newsElements[i]);			
			}
	  	}  	     
	}
	
	elementIndex2 = Math.random() * (newsElementsArray.length - 0.5);
	elementIndex2 = Math.round(elementIndex2);
	//alert(elementIndex2);
	if((elementIndex2+1) < newsElementsArray.length) {
		elementIndex3 = elementIndex2+1;
	}
	else {
		elementIndex3 = 0;
	}
	
	if(elementIndex2 > 0) {
		elementIndex1 = elementIndex2-1;
	}
	else {
		elementIndex1 = newsElementsArray.length - 1;
	}
	
	setTimeout(function() { 
			recursiveFadeIn(0, newsElements[newsElementsArray[elementIndex1]]);
			recursiveFadeIn(0, newsElements[newsElementsArray[elementIndex2]]);
			recursiveFadeIn(0, newsElements[newsElementsArray[elementIndex3]]);
		}, 1500);
/*	recursiveFadeIn(0, newsElements[newsElementsArray[elementIndex1]]);
	recursiveFadeIn(0, newsElements[newsElementsArray[elementIndex2]]);
	recursiveFadeIn(0, newsElements[newsElementsArray[elementIndex3]]);*/
}