
// Kontrollvariable
var crossfadeProgress = false;
var currentPicId = "";
var newPicId = "";
var currentPicName = "";

function switchPic(id,newPic) {
	id.src = newPic;
}

function showGallery() {
	obj = document.getElementById("divMainOverlay");
	gal = document.getElementById("divGallery");
	if(obj.style.display == "none") {
		obj.style.display = "block";
		gal.style.display = "block";
	}
	else {
		obj.style.display = "none";
		gal.style.display = "none";
	}
	toLeft('divGalleryPreview');
}

function placeGal() {
	winW = document.body.clientWidth;
	winH = document.body.clientHeight;
	docH = document.getElementById("docBody").scrollHeight;
	
	if(winW > 1000) {
		var xpos = (document.getElementById('divCatNav').offsetLeft + ((winW - 1000) / 2));
		xpos = parseInt(xpos);
	}
	
	else {
		var xpos = document.getElementById('divCatNav').offsetLeft;
	}
	
	if(docH > winH) winH = docH;
	if(winH < 814) winH = 814;
	if(winW < 1000) winW = 1000;
		
	document.getElementById('divGallery').style.left = xpos;
	document.getElementById('divMainOverlay').style.width = winW;
	document.getElementById('divMainOverlay').style.height = winH;
}

function crossfade(newImg,width,height,top,headName,headText,bodyName,bodyText) {
	if(crossfadeProgress == false && newImg != currentPicName) {
		crossfadeProgress = true;
		currentPicName = newImg;
		
		newImg = "files/" + newImg;
		if(currentPicId == "") {
			currentPicId = "galleryImg";
			newPicId = "galleryImg2";
			currentDivId = "divGalleryPic";
			newDivId = "divGalleryPic2";
		}
		img = document.getElementById(newPicId);
		document.getElementById(newPicId).src = newImg;
		changeOpac(0,newPicId);
		opacity(currentPicId,100,0,800);
		opacity(newPicId,0,100,800);
		
		setTimeout("document.getElementById(currentDivId).style.zIndex = 1014",1000);
		setTimeout("document.getElementById(newDivId).style.zIndex = 1015",1000);
		
		img.style.width = width;
		img.style.height= height;
		img.style.marginTop = top;
		
		temp = currentPicId;
		currentPicId = newPicId;
		newPicId = temp;
		
		temp = currentDivId;
		currentDivId = newDivId;
		newDivId = temp;
	
		setTimeout("crossfadeProgress = false;",1200);
		if(headName != false) {
			changeText(headName,headText);
			changeText(bodyName,bodyText); 
		}
	} 
}

function changeText(id,text){
	document.getElementById(id).innerHTML = text;
}

// Div-Scrolling
timer = "";

function toLeft(id) {
  document.getElementById(id).scrollLeft = 0;
}

function scrollDiv(id,dir,speed) {
	stopMe();
	switch(dir) {
		case "left":
		document.getElementById(id).scrollLeft += parseInt(speed);
		break;
		case "right":
		document.getElementById(id).scrollLeft -= parseInt(speed);
		break;
	}
	timer = setTimeout("scrollDiv('"+id+"','"+dir+"','"+speed+"')",10);
}
function stopMe(){
  clearTimeout(timer);
}

function stretchStart(art_id) {
	if(art_id == 1) {
		winH = document.body.clientHeight;
		if(winH < 500) winH = 500;
		document.getElementById('divStartseite').style.height = winH;
	}
}

// -----

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function doFocus(elm) {
	elm.style.backgroundColor = "#ECF3FC";
	elm.style.border = "1px solid #000000";
}

function doBlur(elm) {
	elm.style.backgroundColor = "#FFFFFF";
	elm.style.border = "1px solid #999999";
}

var oldPosition = false;

function pageScroll(saveOldPosition) {
	if(saveOldPosition == true && oldPosition == false) {
		oldPosition = document.body.scrollTop;
	}
	if(document.body.scrollTop > 0) {
    	window.scrollBy(0,-50);
    	scrolldelay = setTimeout('pageScroll()',5);
	}
	else {
		stopScroll();	
	}
}

function pageScrollBack() {
	// anti-ruckeln
	if(Math.abs(oldPosition - document.body.scrollTop) > 25) {
		// nach unten
		if(oldPosition > document.body.scrollTop) {
			window.scrollBy(0,50);
			scrolldelay = setTimeout('pageScrollBack()',5);
		}
		// nach oben
		else {
			window.scrollBy(0,-50);
			scrolldelay = setTimeout('pageScrollBack()',5);
		}
	}
	else {
		stopScroll();
		oldPosition = false;
	}
}

// Scrollt um px, wenn screenHeight kleiner minHeight
function scrollDownBy(px) {
	var minHeight = 960;
	if(navigator.appName=='Microsoft Internet Explorer') {
		var screenHeight = screen.height;
	}
	else {
		var screenHeight = window.outerHeight;
	}
	//alert(screenHeight+" "+px);
	if(screenHeight < minHeight) {
		window.scrollBy(0,px);
	}

}

function stopScroll() {
    	clearTimeout(scrolldelay);
}

