/*
 * McRAY Javascript
 * 
 * --------
 * Copyright (c) 2008 flughafen grafix
 *
 */

/*@cc_on _d=document;eval('var document=_d')@*/

var areaIsDown = true;
var flashObject;
var getInterval;

function addEvent(elm, evType, func, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, func, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, func);
		return r;
	} else {
		elm['on' + evType] = func;
	}
}

function removeEvent(elm, evType, listener, useCapture) {
	if (elm.removeEventListener) {
		elm.removeEventListener(evType, listener, useCapture);
		return true;
	} else if (elm.detachEvent) {
		var r = elm.detachEvent('on' + evType, listener);
		return r;
	} else {
		elm['on' + evType] = {};
	}
}

function setFlashObject() {
	clearInterval(getInterval);
	flashObject = document.all? window['external_flashcontent'] : document['external_flashcontent'];
}

function getFlashObject() {
	if(!flashObject) flashObject = document.all? window['external_flashcontent'] : document['external_flashcontent'];
	return flashObject;
}

function baseFloatPosition() {
		var windowHeight = document.all? document.body.clientHeight : document.documentElement.clientHeight;
		document.getElementById("contentFrame").height = (windowHeight - 80);
		document.getElementById("contentFrame").style.height = (windowHeight - 80) + "px";
		document.getElementById("flashcontent_external").style.top = -(windowHeight - 80) + "px";
}

function baseIframeHeight() {
	var windowHeight = document.all? document.body.clientHeight : document.documentElement.clientHeight;
	document.getElementById("contentFrame").height = (windowHeight - 80);
	document.getElementById("contentFrame").style.height = (windowHeight - 80) + "px";
}

function changeURL(url){
	if(!url) return;
	
	if (areaIsDown) {
		document.getElementById("contentFrame").src = url;
		flashAreaUp();
	} else {
		document.getElementById("contentFrame").src = url;
	}
	getInterval = setInterval('setFlashObject()', 2000);
}

function flashAreaUp(){
	if(!areaIsDown) return;
	
	var windowHeight = document.all? document.body.clientHeight : document.documentElement.clientHeight;
	
	document.getElementById("htmlArea").style.visibility = "visible";
	JSTweener.addTween(document.getElementById("flashcontent_external").style, {
				time: 0.7
				,delay: 1
				,onComplete: function() {
					baseFloatPosition();
					addEvent(window, 'resize', baseFloatPosition, false);
					areaIsDown = false;
				}
				,top: {to:-(windowHeight - 80),unit:'px'}
			});
}

function flashAreaDown(){
	if(areaIsDown) return;
	
	JSTweener.addTween(document.getElementById("flashcontent_external").style, {
				time: 0.5
				,onComplete: function() {
					document.getElementById("htmlArea").style.visibility = "hidden";
					areaIsDown = true;
					removeEvent(window, 'resize', baseFloatPosition, false);
				}
				,top: {to:0,unit:'px'} 
			});
}

function initWindow(){
	baseIframeHeight();
	getInterval = setInterval('setFlashObject()', 2000);
}

function windowStatusChange(){	
	if(document.getElementById("contentFrame").readyState=="complete"){
		if(document.getElementById("contentFrame").document.getElementById("mcray")){
			document.getElementById("contentFrame").document.initLocalWindow();
		}
	}
}

addEvent(window, 'load', initWindow, false);
