﻿// JScript File
var soundID;
var soundUrl;
var isIe=false;  // 'ie' is set to 1 if the current browser is Internet Explorer
var timeoutId;
var setOpValues=false;
var isLocked = false;

function initialize(){
    
    isIe=browserIsIE();
    
    centerOuterDiv();    

    /** Assign source of the main picture: */
    if(document.getElementById('mainPicture2')!=null){
		document.getElementById('mainPicture2').src="images/blank.gif";
    }
	/** Perform fade-in effect of the main picture: */
    fadeIn(0);
    
	setTimeout("hideWelcomeOverlay()", 20);

	initializeOpacityValues('div', 'clickableItem');
	
	path = "MainPagePics";
	
    nextPicture();
    
}

function initializeOpacityValues(tagname, name){
	
	if(!isIe){
		var elements = document.getElementsByName(name);
	
		for(var i=0; i < elements.length; i++){
			elements[i].style.opacity='0.7';
		}
	}
	else{	
		var elements = document.getElementsByTagName(tagname);
		for(var i = 0; i < elements.length; i++){
			if (elements[i].name == name) {
				elements[i].style.filter='alpha(opacity=70)';
			}
		}
	}
}

function hideWelcomeOverlay(){
	
	if(document.getElementById('soundmanager-debug-toggle')!=null)
	{
		document.getElementById('soundmanager-debug-toggle').style.visibility = "hidden";
	}
	if(document.getElementById('soundOn')!=null)
	{
		document.getElementById('soundOn').style.visibility = "hidden";
	}
	if(document.getElementById('eqLoop')!=null)
	{
		document.getElementById('eqLoop').style.visibility = "hidden";
	}
	fadeWelcomeOut(100);
}

function fadeWelcomeOut(step){
	
	if(document.getElementById('welcomeOverlay')!=null){
		if(step==24){
			document.getElementById('welcomeOverlay').style.visibility = "hidden";
		}
		if(step>25){
	        step = step-2;
	        var opacity = 0.01*step;
	        
	            if(isIe){
	                document.getElementById('welcomeOverlay').style.filter ='alpha(opacity='+step+')'; //OK!
	            }
	            else{
	                document.getElementById('welcomeOverlay').style.opacity=opacity;
	            }
	            
	        setTimeout("fadeWelcomeOut("+step+")",10);    
	    }	
	}
}

function mouseOver(owner){
	if(isIe){
		owner.style.filter='alpha(opacity=100)';
	}
	else {
		owner.style.opacity='1.0';
	}
}

function mouseOut(owner){
	if(isIe){
		owner.style.filter='alpha(opacity=70)';
	}
	else {
		owner.style.opacity='0.7';
	}
}

function startSound(){
	
	document.getElementById("loop").src = "Music/eqloop.gif";
	document.getElementById("soundOn").innerText = "Sound off";
	playSound();
}

function centerOuterDiv(){

	if (screen.height < 800) {
		document.getElementById('divOutest').style.left = "83px";
		document.getElementById('divOutest').style.top = "0px";
		document.getElementById('logoPanel').style.bottom = "-12px";
		document.getElementById('divMain').style.height = "558px";
	}
	if ((screen.height > 800) && (screen.height < 1040)) {
		document.getElementById('divOutest').style.left = "200px";
		document.getElementById('divOutest').style.top = "100px";
	}
}

//Function works for IE as well as Mozilla
function fadeIn(step){
    if(step<100 && (document.getElementById('mainPicture')!=null)&&!isLocked){
        step = step+1;
        var opacity = 0.01*step;
        
            if(isIe){
                document.getElementById('mainPicture').style.filter ='alpha(opacity='+step+')'; //OK!
            }
            else{
                document.getElementById('mainPicture').style.opacity=opacity;
            }
            
        setTimeout("fadeIn("+step+")",25);    
    }
	isLocked = false;
}

function fadeOut(step){
    
	if(step>0 && (document.getElementById('mainPicture')!=null)&&!isLocked){
        step = step-1;
        var opacity = 0.01*step;
        
            if(isIe){
                document.getElementById('mainPicture').style.filter ='alpha(opacity='+step+')'; //OK!
            }
            else{
                document.getElementById('mainPicture').style.opacity=opacity;
            }
        setTimeout("fadeOut("+step+")",25);    
    }
	isLocked = false;
}

/* Determine whether the current browser is IE or not
   Returns 1 if Browser is iE and 0 else */
function browserIsIE(){
    //var retVal=0;
    var isIE = false;
	
    var browser=navigator.appName;
    var b_version=navigator.appVersion;
    var version=parseFloat(b_version);
    
    if((browser=='Microsoft Internet Explorer') && (version >= 4)){
        isIE=true;
    }
    
    return isIE;
    
}

function playSound(){
   
	soundManager.onload = function(){
        soundUrl = 'Music/octavarium.mp3';
		soundID = 'intro';
        mysound = soundManager.createSound(soundID, soundUrl);
        soundManager.defaultOptions.volume = 0; // set global default volume
        soundManager.debugMode = false;          // enable debugging output (div#soundmanager-debug, OR console..)
        soundManager.useConsole = false;         // use firebug/safari console.log()-type debug console if available
        soundManager.consoleOnly = true;         // if console is being used, do not create/write to #soundmanager-debug
        document.getElementById('soundmanager-debug').style.visibility="hidden";
		document.getElementById('soundmanager-debug-toggle').style.visibility="hidden";
		mysound.play();
		
    }
	
	//fadeVolumeIn(soundID);
}

function getMap(href, location)
{
	mapWindow = window.open(href, "Plan " + location);
	//mapWindow.open();
}

var n = 0;
function fadeVolumeIn(soundID){
	
	/*var vol = document.createTextNode(n);
    document.getElementById('divBottomBeam').appendChild(vol);
	*/
	if(n<=100){
		soundManager.sounds[soundID].setVolume(n);
		n += 1;	
	}

	setTimeout("fadeVolumeIn("+soundID+")", 200);
	
}

function nextPicture(){
	getNextPicture();
	timeoutId=setTimeout("nextPicture()", 8000);	
}
//never hidden!
function getVisibleMainPicture(){
	if (document.getElementById('mainPicture').style.visibility == "hidden") {
		p1Visible = false;
	}
	else{
		p1Visible = true;
	}
}

function toggleAndFade(isFadeIn)
{
	isLocked = false;
	if(isFadeIn)
	{
		document.getElementById('umbauAfter').style.visibility = "hidden";
		document.getElementById('umbauBefore').style.visibility = "visible";
		fadeIn(0);
	}
	else
	{
		document.getElementById('umbauAfter').style.visibility = "visible";
		document.getElementById('umbauBefore').style.visibility = "hidden";
		fadeOut(100);
	}
}

function setOpacity()
{
	if(isIe){
        document.getElementById('mainPicture').style.filter ='alpha(opacity=100)'; //OK!
    }
    else{
        document.getElementById('mainPicture').style.opacity=1.0;
    }
	
}

