/*******************************************************/
/* EOLAS Object Embedding Hack: External write methods */
/*******************************************************/

function print(s) {
	document.write(s);
}

function println(s) {
	document.writeln(s);
}



/****************************************/
/* Cross Browser Compatibility Wrappers */
/****************************************/

function getHTTPObject() {
    if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
    return false;
}

function getNodeByID(id) {
	if(document.all) {
		obj = document.all[id];
	} else {
		obj = document.getElementById(id);
	}
	return obj;
}

function getKeycode(key) {
	if (document.all) {
		keycode = window.event.keyCode;
	} else {
		keycode = key.which;
	}
	return keycode;
}

function getScrollPos() {
	if(window.pageYOffset) return window.pageYOffset;
	if(document.documentElement.scrollTop) return document.documentElement.scrollTop;
	if(document.body.scrollTop) return document.body.scrollTop;
	return -1;
}

function getWindowWidth() {
	if(window.innerWidth) return window.innerWidth;
	if(document.documentElement.clientWidth) return document.documentElement.clientWidth;
	if(document.body.clientWidth) return document.body.clientWidth;
	return -1;
}

function getWindowHeight() {
	if(window.innerHeight) return window.innerHeight;
	if(document.documentElement.clientHeight) return document.documentElement.clientHeight;
	if(document.body.clientHeight) return document.body.clientHeight;
	return -1;
}

function getDocHeight() {
	var cbdy = getNodeByID('center_body');
	h =  cbdy.clientHeight + 20;
	w = getWindowHeight();
	if(w > h) return w;
	return h;
}



/*************************/
/* Document Blend In/Out */
/*************************/

function disableDoc() {
	var bdy = getNodeByID("cover_body");
	bdy.style.height = getDocHeight() + 'px';
	bdy.style.display = "block";
}

function enableDoc() {
	var bdy = getNodeByID("cover_body");
	bdy.style.display = "none";	
}



/***************/
/* Media Frame */
/***************/

// Nodes
var nodeMediaFrame = null;
var nodeMediaFrame1 = null;
var nodeMediaFrame2 = null;
var nodeMediaFrameHeadline = null;
var nodeMediaFrameComment = null;
var nodeMediaFrameClose = null;
var nodeMediaFrameCompare = null;

// Constants
var mediaFrameMargin = 4;
var mediaFrameBackgroundColor = '152121';
var mediaFrameHeadlineHeight = 18;
var mediaFrameControlsHeight = 16;
var mediaFramePlayerControlsWidth = 200;
var mediaFramePlayerControlsHeight = 24;
var mediaFrameDefaultMP3Image = '/kk/images/mp3default.jpg';
var mediaFrameDefaultMP3ImageWidth = 200;
var mediaFrameDefaultMP3ImageHeight = 100;

// Clipboard / Buffer variable for timer actions
var mediaFrameClipboard = "";

// Basic Methods

function setMediaFrameNodes() {
	nodeMediaFrame = getNodeByID("media_frame");
	nodeMediaFrame1 = getNodeByID("media_frame1");
	nodeMediaFrame2 = getNodeByID("media_frame2");
	nodeMediaFrameHeadline = getNodeByID("media_frame_headline");
	nodeMediaFrameComment = getNodeByID("media_frame_comment");
	nodeMediaFrameClose = getNodeByID("media_frame_close");
	nodeMediaFrameCompare = getNodeByID("media_frame_compare");
}

function openMediaFrame(w,h) {
	setMediaFrameNodes();
	closeMediaFrame();
	disableDoc();
	nodeMediaFrame.style.left = getWindowWidth()/2 - (w + mediaFrameMargin*2)/2 + 'px';
	nodeMediaFrame.style.top = getScrollPos() + getWindowHeight()/2 - (h + mediaFrameMargin*2 + mediaFrameControlsHeight)/2 + 'px';
	nodeMediaFrame.style.width = w + mediaFrameMargin*2 + 'px';
	nodeMediaFrame.style.height = h + mediaFrameMargin*2 + mediaFrameControlsHeight + 'px';
	nodeMediaFrame.style.display = "block";
}

function closeMediaFrame() {
	nodeMediaFrame1.style.backgroundImage = '';
	nodeMediaFrame2.style.backgroundImage = '';
	nodeMediaFrame1.innerHTML = '';
	nodeMediaFrame2.innerHTML = '';
	nodeMediaFrameComment.innerHTML = '';
	nodeMediaFrameHeadline.innerHTML = '';
	nodeMediaFrameCompare.style.display = "none";	
	nodeMediaFrameClose.style.display = "none";	
	nodeMediaFrameComment.style.display = "none";	
	nodeMediaFrameHeadline.style.display = "none";	
	nodeMediaFrame2.style.display = "none";	
	nodeMediaFrame1.style.display = "none";	
	nodeMediaFrame.style.display = "none";	
	mouseClicked = false;
	enableDoc();
	document.onkeypress = "";
	nodeMediaFrame1.onmousemove = "";
	nodeMediaFrame2.onmousemove = "";
	nodeMediaFrame1.onclick = "";
	nodeMediaFrame2.onclick = "";
}

function openMediaFrameHeadline(w,text) {
	nodeMediaFrameHeadline.style.top = '0px';
	nodeMediaFrameHeadline.style.left = '0px';
	nodeMediaFrameHeadline.style.width = w + mediaFrameMargin*2 + 'px';
	nodeMediaFrameHeadline.style.height = mediaFrameHeadlineHeight + 'px';
	nodeMediaFrameHeadline.style.display = "block";	
	nodeMediaFrameHeadline.innerHTML = text;
}

function openMediaFrameComment(w,h,text) {
	nodeMediaFrameComment.style.top = h + mediaFrameMargin*2 + 'px';
	nodeMediaFrameComment.style.left = mediaFrameMargin  + 'px';
	nodeMediaFrameComment.style.width = w - 20 + 'px';
	nodeMediaFrameComment.style.height = mediaFrameControlsHeight + 'px';
	nodeMediaFrameComment.style.display = "block";	
	nodeMediaFrameComment.innerHTML = text;
}

function openMediaFrameClose(w,h) {
	nodeMediaFrameClose.style.top = h + mediaFrameMargin*2 - 2 + 'px';
	nodeMediaFrameClose.style.left = w + mediaFrameMargin - 20 + 'px';
	nodeMediaFrameClose.style.width = '20px';
	nodeMediaFrameClose.style.height = mediaFrameControlsHeight + 'px';
	nodeMediaFrameClose.style.display = "block";	
}

function openMediaFrameCompare(w,h) {
	nodeMediaFrameCompare.style.top = h + mediaFrameMargin*2 - 2 + 'px';
	nodeMediaFrameCompare.style.left = w + mediaFrameMargin - 100 + 'px';
	nodeMediaFrameCompare.style.width = '70px';
	nodeMediaFrameCompare.style.height = mediaFrameControlsHeight + 'px';
	nodeMediaFrameCompare.style.display = "block";
}

function openMediaFrameImage1(w,h,url) {
	nodeMediaFrame1.style.backgroundImage = 'url("' + url + '")';
	nodeMediaFrame1.style.left = mediaFrameMargin  + 'px';
	nodeMediaFrame1.style.top = mediaFrameMargin  + 'px';
	nodeMediaFrame1.style.width = w + 'px';
	nodeMediaFrame1.style.height = h + 'px';
	nodeMediaFrame1.style.display = "block";
}

function openMediaFrameImage2(w,h,url) {
	nodeMediaFrame2.style.backgroundImage = 'url("' + url + '")';
	nodeMediaFrame2.style.left = mediaFrameMargin  + 'px';
	nodeMediaFrame2.style.top = mediaFrameMargin  + 'px';
	nodeMediaFrame2.style.width = (w/2) + 'px';
	nodeMediaFrame2.style.height = h + 'px';
	nodeMediaFrame2.style.display = "block";
}

function openMediaFrameVideo(w,h,url) {
	mediaFrameClipboard = "<embed src='" + url + "' autostart='true' width='" + w + "' height='" + h + "' bgcolor='#" + mediaFrameBackgroundColor + "'></embed>";
	nodeMediaFrame1.style.left = mediaFrameMargin  + 'px';
	nodeMediaFrame1.style.top = mediaFrameMargin  + 'px';
	nodeMediaFrame1.style.width = w + 'px';
	nodeMediaFrame1.style.height = h + 'px';
	nodeMediaFrame1.style.display = "block";
	window.setTimeout("setMediaFrame1Content()",500);
}

function openMediaFrameFlash(w,h,url) {
	mediaFrameClipboard = "<object width='"+ w + "' height='" + h + "'><param name='movie' value='" + url + "'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='" + url + "' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='" + w + "' height='" + h + "'></embed></object>";
	nodeMediaFrame1.style.left = mediaFrameMargin  + 'px';
	nodeMediaFrame1.style.top = mediaFrameMargin  + 'px';
	nodeMediaFrame1.style.width = w + 'px';
	nodeMediaFrame1.style.height = h + 'px';
	nodeMediaFrame1.style.display = "block";
	window.setTimeout("setMediaFrame1Content()",500);
}

function openMediaFrameMP3(w,h,url1,url2) {
	wt = mediaFramePlayerControlsWidth;
	if(w > wt) wt = w;
	mediaFrameClipboard = "<embed src='" + url1 + "' autostart='true' width='" + wt + "' height='" + mediaFramePlayerControlsHeight + "' bgcolor='#" + mediaFrameBackgroundColor + "'></embed>";
	nodeMediaFrame1.style.left = mediaFrameMargin  + 'px';
	nodeMediaFrame1.style.top = mediaFrameMargin + h + mediaFrameMargin + 'px';
	nodeMediaFrame1.style.width = wt + 'px';
	nodeMediaFrame1.style.height = mediaFramePlayerControlsHeight + 'px';
	nodeMediaFrame1.style.display = "block";
	nodeMediaFrame2.style.backgroundImage = 'url("' + url2 + '")';
	nodeMediaFrame2.style.left = mediaFrameMargin + (wt-w)/2 + 'px';
	nodeMediaFrame2.style.top = mediaFrameMargin + 'px';
	nodeMediaFrame2.style.width = w + 'px';
	nodeMediaFrame2.style.height = h + 'px';
	nodeMediaFrame2.style.display = "block";
	window.setTimeout("setMediaFrame1Content()",500);

}

function setMediaFrame1Content() {
	nodeMediaFrame1.innerHTML = mediaFrameClipboard;
}

function openMediaFramePMVR(w,h,script) {
	var buffer = '<applet name="pmvr" codebase="http://www.doreen-und-rainer.de/java/" archive="pmvr.jar" code="pmvr.class" width="' + w + '" height="' + h + '" mayscript="mayscript" >';
	buffer += '<param name="script" value="' + script + '" />';
	buffer += '<param name="background" value="' + mediaFrameBackgroundColor + '" />';
	buffer += '<param name="cHelp" value="ffcc00" />';
	buffer += '<param name="cArrow" value="ffcc00" />';
	buffer += '<param name="cZoom" value="ffcc00" />';
	buffer += '<param name="cHot" value="ffcc00" />';
	buffer += '<param name="cSlider" value="CCCC80,404040,FFCC00" />';
	buffer += '<param name="hover" value="yes" />';
	buffer += '</applet>';
	nodeMediaFrame1.style.left = mediaFrameMargin  + 'px';
	nodeMediaFrame1.style.top = mediaFrameMargin + mediaFrameHeadlineHeight + 'px';
	nodeMediaFrame1.style.width = w + 'px';
	nodeMediaFrame1.style.height = h + 'px';
	nodeMediaFrame1.style.display = "block";
	nodeMediaFrame1.innerHTML = buffer;
}

function openMediaFrameFloorPlan(w,h,xoffset) {
	var buffer = '<applet name="FloorPlan" codebase="http://www.doreen-und-rainer.de/java/" archive="pmvr.jar" code="FloorPlan.class" width="' + w + '" height="' + h + '" mayscript="mayscript">';
	buffer += '<param name="background" value="' + mediaFrameBackgroundColor + '" />';
	buffer += '<param name="cLine" value="00ba00" />';
	buffer += '<param name="cDot" value="ff0000" />';
	buffer += '<param name="cHot" value="ff0000" />';
	buffer += '<param name="gray" value="30" />';
	buffer += '<param name="cGray" value="000000" />';
	buffer += '<param name="hover" value="yes" />';
	buffer += '</applet>';
	nodeMediaFrame2.style.left = mediaFrameMargin + xoffset + 'px';
	nodeMediaFrame2.style.top = mediaFrameMargin + mediaFrameHeadlineHeight + 'px';
	nodeMediaFrame2.style.width = w + 'px';
	nodeMediaFrame2.style.height = h + 'px';
	nodeMediaFrame2.style.display = "block";
	nodeMediaFrame2.innerHTML = buffer;
}

function openMediaFrameLabel(w,yoffset) {
	var buffer = '<applet name="Label" codebase="http://www.doreen-und-rainer.de/java/" archive="pmvr.jar" code="Label.class" width="' + w + '" height="' + mediaFrameControlsHeight + '" mayscript="mayscript">';
	buffer += '<param name="background" value="' + mediaFrameBackgroundColor + '" />';
	buffer += '<param name="foreground" value="cccc80" />';
	buffer += '<param name="align" value="left" />';
	buffer += '<param name="text" value="Lade...">';
	buffer += '</applet>';
	nodeMediaFrameComment.style.left = mediaFrameMargin  + 'px';
	nodeMediaFrameComment.style.top = mediaFrameMargin + yoffset + 'px';
	nodeMediaFrameComment.style.width = w + 'px';
	nodeMediaFrameComment.style.display = "block";
	nodeMediaFrameComment.innerHTML = buffer;
}


function keyHandlerClose(key) {
	if(getKeycode(key)==27) closeMediaFrame();
}

function keyHandlerCompare(key) {
	if(getKeycode(key)==27) closeMediaFrame();
	if(getKeycode(key)==37) splitPic(-10);
	if(getKeycode(key)==40) splitPic(0);
	if(getKeycode(key)==39) splitPic(10);
}

function mouseHandlerCompareSplitMove(e) {
	if(!e) e = window.event;
	if(e.button && e.button > 0) {
		mouseHandlerCompareSplitClick();
		return;
	}
}

function mouseHandlerCompareSplitClick(e) {
	if(!e) e = window.event;
	new_w = 0;
	if(e.offsetX) {
		new_w = e.offsetX;
	} else {
		if(e.layerX) {
			new_w = e.layerX;
		}
	}
	if(new_w < 0) {
		new_w = 0;
	}
	if(new_w > nodeMediaFrame1.style.width) {
		new_w = nodeMediaFrame1.style.width;
	}
	nodeMediaFrame2.style.width = new_w + 'px';
}

// Interface Methods

function openPic(url,text,w,h) {
	openMediaFrame(w,h);
	openMediaFrameComment(w,h,text)
	openMediaFrameClose(w,h);
	openMediaFrameImage1(w,h,url);
	document.onkeyup = keyHandlerClose;
}

function comparePic(url1,url2,text,w,h) {
	openMediaFrame(w,h);
	openMediaFrameComment(w,h,text)
	openMediaFrameClose(w,h);
	openMediaFrameCompare(w,h);
	openMediaFrameImage1(w,h,url1);
	openMediaFrameImage2(w,h,url2);
	document.onkeyup = keyHandlerCompare;
	nodeMediaFrame1.onmousemove = mouseHandlerCompareSplitMove;
	nodeMediaFrame2.onmousemove = mouseHandlerCompareSplitMove;
	nodeMediaFrame1.onclick = mouseHandlerCompareSplitClick;
	nodeMediaFrame2.onclick = mouseHandlerCompareSplitClick;
}

function splitPic(offset) {
	w1 = parseInt(nodeMediaFrame1.style.width);
	w2 = parseInt(nodeMediaFrame2.style.width);
	if(offset == 0) {
		nodeMediaFrame2.style.width = (w1/2) + 'px';	
	} else {
		w2 = w2 + offset;
		if(w2 < 0) w2 = 0;
		if(w2 > w1) w2 = w1;
		nodeMediaFrame2.style.width = w2 + 'px';	
	}
}

function openVideo(url,text) {
	openVideoSized(url,text,352,288);
}

function openVideoSized(url,text,w,h) {
	h = h + mediaFramePlayerControlsHeight;
	openMediaFrame(w,h);
	openMediaFrameComment(w,h,text)
	openMediaFrameClose(w,h);
	openMediaFrameVideo(w,h,url);
	document.onkeyup = keyHandlerClose;
}

function openFlash(url,text,w,h) {
	h = h + mediaFramePlayerControlsHeight;
	openMediaFrame(w,h);
	openMediaFrameComment(w,h,text)
	openMediaFrameClose(w,h);
	openMediaFrameFlash(w,h,url);
	document.onkeyup = keyHandlerClose;
}

function openMP3(url,text) {
	openMP3Pic(url,mediaFrameDefaultMP3Image,text,mediaFrameDefaultMP3ImageWidth,mediaFrameDefaultMP3ImageHeight);
}

function openMP3Pic(url1,url2,text,w,h) {
	ht = h + mediaFramePlayerControlsHeight + mediaFrameMargin;
	wt = mediaFramePlayerControlsWidth;
	if(w > wt) wt = w;
	openMediaFrame(wt,ht);
	openMediaFrameComment(wt,ht,text)
	openMediaFrameClose(wt,ht);
	openMediaFrameMP3(w,h,url1,url2);
	document.onkeyup = keyHandlerClose;
}

function openPanoramaCenter(script) {
	openPanoramaScript(script,400,250,200,250);
}

function openPanoramaScript(script,wp,hp,wr,hr) {
	var wt = wp + wr + mediaFrameMargin;
	var ht = hp + mediaFrameHeadlineHeight;
	if(hr > hp) ht = hr + mediaFrameHeadlineHeight;
	openMediaFrame(wt,ht);
	openMediaFrameHeadline(wt-2,"Panorama Center");
	openMediaFrameClose(wt,-5);
	openMediaFramePMVR(wp,hp,script)
	openMediaFrameFloorPlan(wr,hr,wp + mediaFrameMargin)
	openMediaFrameLabel(wp,ht)
	document.onkeyup = keyHandlerClose;
}

function clearMediaFrameComment() {
	nodeMediaFrameComment.innerHTML = '';
}
