// Gibt das HTTP-Request Objekts zurück
function makeBlink(id,pic1,pic2){
  $(id).css('background-image', $(id).css('background-image').replace(pic1,pic2) );
  setTimeout("makeBlink('"+id+"','"+pic2+"','"+pic1+"')", 700);
}

function moveOnMouseOver(id){
  $(id).css('left',((Number($(id).css('left').replace(/px/g, ""))+2)+'px'));  
  if($(id).css('top'))$(id).css('top',((Number($(id).css('top').replace(/px/g, ""))+2)+'px'));
//  if($(id).css('bottom'))$(id).css('bottom',((Number($(id).css('bottom').replace(/px/g, ""))-2)+'px'));
}

function moveOnMouseOut(id){
  $(id).css('left',((Number($(id).css('left').replace(/px/g, ""))-2)+'px'));
  if($(id).css('top'))$(id).css('top',((Number($(id).css('top').replace(/px/g, ""))-2)+'px'));
//  if($(id).css('bottom'))$(id).css('bottom',((Number($(id).css('bottom').replace(/px/g, ""))+2)+'px'));
}

		function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}
		function setContent() {
			if (document.getElementById) {
				var windowHeight = getWindowHeight();
				if (windowHeight > 0) {
					var contentElement = document.getElementById('verticalCenter');
					var contentHeight = contentElement.offsetHeight;
					if (windowHeight - contentHeight > 0) {
						contentElement.style.position = 'relative';
						contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
					}
					else {
						contentElement.style.position = 'static';
					}
				}
			}
		}




function getXMLHttpRequestObject() {

    var requestObject;

    var browser = navigator.appName;

    if(browser == "Microsoft Internet Explorer") {

        requestObject = new ActiveXObject("Microsoft.XMLHTTP");

    }else{

        requestObject = new XMLHttpRequest();

    }

    return requestObject;

}

function savePage() {   
     Element3DList = document.getElementsByClassName("3DElement");
     paremElement3D = '';
     for(i=0;i<Element3DList.length;i++){
             
             paremElement3D += "&left["+Element3DList[i].id+"]="+Element3DList[i].style.left;
             paremElement3D += "&top["+Element3DList[i].id+"]="+Element3DList[i].style.top;
     }
     
     fixList = document.getElementsByClassName("fixElement");
     paremFix = '';
     for(i=0;i<fixList.length;i++){
             
             paremFix += "&left["+fixList[i].id+"]="+fixList[i].style.left;
             paremFix += "&top["+fixList[i].id+"]="+fixList[i].style.top;
     }
     
     
/*    frontImageLeft = document.getElementById("knall").style.left;
    frontImageBottom = document.getElementById("knall").style.top;
    middleImageLeft = document.getElementById("scen").style.left;
    middleImageBottom = document.getElementById("scen").style.top;
    backImageLeft = document.getElementById("klecks").style.left;
    backImageTop = document.getElementById("klecks").style.top;
    pageId = document.getElementById("pageId").value;     */
  //  alert(paremElement3D);                                                                                                                                                                                               
    param = 'windowHeight='+window.innerHeight+paremElement3D+paremFix; 
    httpRequestObject.open('POST', 'ajaxResponse.php?query=savePage',true);
    httpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    httpRequestObject.setRequestHeader("Content-length", param.length);
    httpRequestObject.setRequestHeader("Connection", "close");


    httpRequestObject.onreadystatechange = savePageResponse;
      
    httpRequestObject.send(param);

}

function getEmbed(id,elementId,query) {
    
    setTimeout("$('#videoplayer').css('display','inline')", 100);
    setTimeout("$('#videoplayer').css('display','none')", 200);
    setTimeout("$('#videoplayer').css('display','inline')", 400);
           
    param = 'id='+id+'&elementId='+elementId+'&query='+query;     
    httpRequestObject.open('POST', 'ajaxResponse.php',true);      
    httpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");      
    httpRequestObject.setRequestHeader("Content-length", param.length);  
    httpRequestObject.setRequestHeader("Connection", "close");  

    httpRequestObject.onreadystatechange = getEmbedResponse;

    httpRequestObject.send(param);

}

function getEmbedResponse() {
      
        // Ajax-Anfrage erfolgreich?

    if(httpRequestObject.readyState == 4){
            
        // Holt die Antwort aus der Anfrage

        var ajaxResponse = httpRequestObject.responseXML;
              
          document.getElementById(ajaxResponse.getElementsByTagName("elementId")[0].firstChild.nodeValue).innerHTML=ajaxResponse.getElementsByTagName("content")[0].firstChild.nodeValue; 
    $('#blackVideo').fadeIn('slow', function() {});
    $("#blackVideo").click(function () {
      
      closeVideo();
     
    });
    $("#closeVideo").click(function () {
      
      closeVideo();
     
    });
    $("#closeVideo").mouseover(function () {
              
      $("#closeVideo").attr('src', $("#closeVideo").attr('src').replace('btn_close.png','btn_close_over.png') );
     
    });
    
    $("#closeVideo").mouseout(function () {
      
      $("#closeVideo").attr('src', $("#closeVideo").attr('src').replace('btn_close_over.png','btn_close.png') );
     
    });   

    }

}

function closeVideo(){
    
    setTimeout("$('#videoplayer').css('display','none')", 100);  
    setTimeout("$('#videoplayer').css('display','inline')", 200);  
    setTimeout("$('#videoplayer').css('display','none')", 400);   
    setTimeout("document.getElementById('videoplayer').innerHTML=''", 600); 
    
    setTimeout("$('#blackVideo').fadeOut('slow', function() {})", 600); 
  
}

function savePageResponse() {

        // Ajax-Anfrage erfolgreich?

    if(httpRequestObject.readyState == 4){

        // Holt die Antwort aus der Anfrage

        var ajaxResponse = httpRequestObject.responseXML;

        // Ändert den Textinhalt, des HTML-Elements mit der ID ajax
        var html = '';
        if(ajaxResponse.getElementsByTagName("error")[0]){
          var errorList = ajaxResponse.getElementsByTagName("error")[0].firstChild.nodeValue;
          
          for(i=0;i<ajaxResponse.getElementsByTagName("error").length;i++){
            html += ajaxResponse.getElementsByTagName("error")[i].firstChild.nodeValue+'<br>';
          }
          document.getElementById('registryError').innerHTML=html;
        }
        else{
          alert('ok');
        }
        

    }

}



function ajaxCall(id,elementId,query) {
           
    param = 'id='+id+'&elementId='+elementId+'&query='+query;     
    httpRequestObject.open('POST', 'ajaxResponse.php',true);      
    httpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");      
    httpRequestObject.setRequestHeader("Content-length", param.length);  
    httpRequestObject.setRequestHeader("Connection", "close");  

    httpRequestObject.onreadystatechange = ajaxCallResponse;

    httpRequestObject.send(param);

}


function getPopupContent(id,elementId,query) {

  $('#black').fadeIn('slow', function() {
});

    document.getElementById('verticalCenter').style.zIndex='300';  
    param = 'id='+id+'&elementId='+elementId+'&query='+query;     
    httpRequestObject.open('POST', 'ajaxResponse.php',true);      
    httpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");      
    httpRequestObject.setRequestHeader("Content-length", param.length);  
    httpRequestObject.setRequestHeader("Connection", "close");  

    httpRequestObject.onreadystatechange = getPopupContentResponse;

    httpRequestObject.send(param);

}

function ajaxCallResponse() {
      
        // Ajax-Anfrage erfolgreich?

    if(httpRequestObject.readyState == 4){
            
        // Holt die Antwort aus der Anfrage

        var ajaxResponse = httpRequestObject.responseXML;
                              
          document.getElementById(ajaxResponse.getElementsByTagName("elementId")[0].firstChild.nodeValue).innerHTML=ajaxResponse.getElementsByTagName("content")[0].firstChild.nodeValue; 





    }

} 

function getPopupContentResponse() {
      
        // Ajax-Anfrage erfolgreich?

    if(httpRequestObject.readyState == 4){
            
        // Holt die Antwort aus der Anfrage

        var ajaxResponse = httpRequestObject.responseXML;
                              
          document.getElementById(ajaxResponse.getElementsByTagName("elementId")[0].firstChild.nodeValue).innerHTML=ajaxResponse.getElementsByTagName("content")[0].firstChild.nodeValue; 

  
$('#go').click(function(){
$(".block").animate({left: '+=597px'}, 500); 
});

$("#back").click(function(){
$(".block").animate({left: '-=597px'}, 500); 
});

$("#anfang").click(function(){
$(".block").animate({left: '80px'}, 500); 
});


setTimeout("$('#sheet1').css('display','inline')", 100);
setTimeout("$('#sheet1').css('display','none')", 300);
setTimeout("$('#sheet1').css('display','inline')", 400);

setTimeout("$('#sheet2').css('display','inline')", 500);
setTimeout("$('#sheet2').css('display','none')", 700);
setTimeout("$('#sheet2').css('display','inline')", 800);
 
setTimeout("$('#sheet3').css('display','inline')", 900);
setTimeout("$('#sheet3').css('display','none')", 1100);
setTimeout("$('#sheet3').css('display','inline')", 1200);

setTimeout("$('#leftHand').css('display','inline')", 1200);
setTimeout("$('#leftHand').css('display','none')", 1400); 
setTimeout("$('#leftHand').css('display','inline')", 1500);
 
setTimeout("$('#rightHand').css('display','inline')", 1200);
setTimeout("$('#rightHand').css('display','none')", 1400);  
setTimeout("$('#rightHand').css('display','inline')", 1500);

setTimeout("$('#3DLevel2').css('display','none')", 300);
setTimeout("$('#3DLevel6').css('display','none')", 300);

setTimeout("$('#slider-wrap').css('display','inline')", 1500);

setTimeout("$('#scroll-pane').css('display','inline')", 1500);
setTimeout("$('#closePopup').css('display','inline')", 1500);
setTimeout("$('#scrollcontent').css('display','inline')", 1500);    
//$('#sheet2').css('display','inline');
//$('#sheet3').css('display','inline');
/*
    $('#3DLevel1').fadeOut('slow', function() { });
    $('#3DLevel2').fadeOut('slow', function() { });
    $('#3DLevel3').fadeOut('slow', function() { });
    $('#sheet1').fadeIn('slow', function() {
      $('#sheet2').fadeIn('slow', function() {
        $('#closePopup').fadeIn('slow', function() {});

        $('#sheet3').fadeIn('slow', function() {
          $('#leftHand').fadeIn('slow', function() {});
          $('#rightHand').fadeIn('slow', function() {});
          $('#videoplayer').fadeIn('slow', function() {}); 
          $('#wrapperPopup').fadeIn('slow', function() {
      //      document.getElementById('scroll').style.height='300px';
        //    TINY.scroller.init('scroll','scrollcontent','scrollbar','scroller','buttonclick');
        //    document.getElementById('scroll').style.height='475px';
  
  }); 
  }); 
  });   
  }); 
 */

    $("#closePopup").click(function () {
      
      closePopupLayer()
     
    });

    $("#black").click(function () {
      
      closePopupLayer()
     
    });
    
    $("#closePopup").mouseover(function () {
         
      $("#closePopup").attr('src', $("#closePopup").attr('src').replace('btn_close.png','btn_close_over.png') );
     
    });
    
    $("#closePopup").mouseout(function () {
      
      $("#closePopup").attr('src', $("#closePopup").attr('src').replace('btn_close_over.png','btn_close.png') );
     
    });
    
    $(function() {
	    $('a.openImage').lightBox(); // Select all links with lightbox class

    });
$(function() {     
//change the main div to overflow-hidden as we can use the slider now
$('#scroll-pane').css('overflow','hidden');

//calculate the height that the scrollbar handle should be
var difference = $('#scrollcontent').height()-$('#scroll-pane').height();//eg it's 200px longer 

if(difference>0)//if the scrollbar is needed, set it up...
{            
   var proportion = difference / $('#scrollcontent').height();//eg 200px/500px
   var handleHeight = 123;//Math.round((1-proportion)*$('#scroll-pane').height());//set the proportional height - round it to make sure everything adds up correctly later on
   handleHeight -= handleHeight%2; 
  
   $("#scroll-pane").after('<\div id="slider-wrap"><\div id="slider-background"><\/div><\div id="slider-vertical"><\/div><\/div>');//append the necessary divs so they're only there if needed
   //$("#slider-wrap").height($("#scroll-pane").height());//set the height of the slider bar to that of the scroll pane
   $("#slider-wrap").height(250);
   $("#scroll-pane").css('margin-right','0px');
  
   //set up the slider 
   $('#slider-vertical').slider({
      orientation: 'vertical',
      range: 'max',
      min: 0,
      max: 100,
      value: 100,
      slide: function(event, ui) {
         var topValue = -((100-ui.value)*difference/100);
         $('#scrollcontent').css({top:topValue});//move the top up (negative value) by the percentage the slider has been moved times the difference in height
      }
   });
    
   //set the handle height and bottom margin so the middle of the handle is in line with the slider
   $(".ui-slider-handle").css({height:handleHeight ,'margin-bottom':-0.5*handleHeight});
	
   var origSliderHeight = $("#slider-vertical").height();//read the original slider height
   var sliderHeight = origSliderHeight - handleHeight ;//the height through which the handle can move needs to be the original height minus the handle height
   var sliderMargin =  (origSliderHeight - sliderHeight)*0.5;//so the slider needs to have both top and bottom margins equal to half the difference
   $(".ui-slider").css({height:sliderHeight,'margin-top':sliderMargin});//set the slider height and margins
	$(".ui-slider-range").css({top:-sliderMargin});//position the slider-range div at the top of the slider container
}//end if
else{
  $("#scroll-pane").css('margin-right','21px');
}
	 
	//additional code for mousewheel
	$("#scroll-pane,#slider-wrap").mousewheel(function(event, delta){
  		var speed = 5;
	    var sliderVal = $("#slider-vertical").slider("value");//read current value of the slider
		
	    sliderVal += (delta*speed);//increment the current value
 
	    $("#slider-vertical").slider("value", sliderVal);//and set the new value of the slider
		
		var topValue = -((100-sliderVal)*difference/100);//calculate the content top from the slider position
		
		if (topValue>0) topValue = 0;//stop the content scrolling down too much
		if (Math.abs(topValue)>difference) topValue = (-1)*difference;//stop the content scrolling up too much
		
		$("#scrollcontent").css({top:topValue});//move the content to the new position
	    event.preventDefault();//stop any default behaviour
 	});
	
	
	
});

  }
    


}


function closePopupLayer(){
 /*       $('#videoplayer').fadeOut('slow', function() {});
        $("#leftHand").fadeOut("slow",function(){});
        $("#rightHand").fadeOut("slow",function(){});
        $("#wrapperPopup").fadeOut("slow",function(){
          $("#closePopup").fadeOut("slow",function(){});
          
          $("#sheet3").fadeOut("slow",function(){
            $("#sheet2").fadeOut("slow",function(){
              $("#sheet1").fadeOut("slow",function(){
                $('#3DLevel1').fadeIn('slow', function() { });
                $('#3DLevel2').fadeIn('slow', function() { });
                $('#3DLevel3').fadeIn('slow', function() { });
                $('#black').fadeOut('slow', function() { });
                document.getElementById('videoplayer').innerHTML='';
                });
            });
          });
        });  */
      //  document.getElementById('verticalCenter').style.display='';

document.getElementById('videoplayer').innerHTML='';
$('#scrollcontent').css('display','none');
$('#videoplayer').css('display','none');
$('#leftHand').css('display','none');
$('#rightHand').css('display','none');      
$('#slider-wrap').remove();       
//$('#black').fadeOut('slow', function() { });
setTimeout("$('#black').fadeOut('slow', function() { })", 700);
setTimeout("$('#sheet1').css('display','none')", 600);

setTimeout("$('#sheet2').css('display','none')", 400);

setTimeout("$('#sheet3').css('display','none')", 100);  

setTimeout("$('#closePopup').css('display','none')", 10);

setTimeout("$('#3DLevel2').css('display','inline')", 700);
setTimeout("$('#3DLevel2').css('display','none')", 800);
setTimeout("$('#3DLevel2').css('display','inline')", 1000);
setTimeout("$('#3DLevel6').css('display','inline')", 1100);
setTimeout("$('#3DLevel6').css('display','none')", 1200);
setTimeout("$('#3DLevel6').css('display','inline')", 1400);
setTimeout("document.getElementById('verticalCenter').style.zIndex='0'", 1400); 
 
$(".ui-slider-handle").css({'bottom':'100%'});
$("#scrollcontent").css({'top':'0'});
  /*

 
setTimeout("$('#scroll-pane').css('display','none')", 100);
setTimeout("$('#closePopup').css('display','none')", 10);  */
     
}


function getVideoPopupContent(){
    document.getElementById('verticalCenter').style.zIndex='300';
    setTimeout("$('#videoplayer').css('display','inline')", 100);
    setTimeout("$('#videoplayer').css('display','none')", 200);
    setTimeout("$('#videoplayer').css('display','inline')", 400);
    setTimeout("$('#3DLevel2').css('display','none')", 300);
    setTimeout("$('#3DLevel6').css('display','none')", 300);
    param = 'query=getLatestVideo';
    httpRequestObject.open('POST', 'ajaxResponse.php',true);
    httpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    httpRequestObject.setRequestHeader("Content-length", param.length);
    httpRequestObject.setRequestHeader("Connection", "close");

    httpRequestObject.onreadystatechange = getVideoPopupContentResponse;
    
    httpRequestObject.send(param); 
}

function getVideoPopupContentResponse(){
    if(httpRequestObject.readyState == 4){
          
        // Holt die Antwort aus der Anfrage
        
        var ajaxResponse = httpRequestObject.responseXML;
             
          document.getElementById(ajaxResponse.getElementsByTagName("elementId")[0].firstChild.nodeValue).innerHTML=ajaxResponse.getElementsByTagName("content")[0].firstChild.nodeValue; 
           
    $('#blackVideo').fadeIn('slow', function() {});   
    $("#blackVideo").click(function () {
       
      closeVideo();       
      setTimeout("$('#3DLevel2').css('display','inline')", 700);
      setTimeout("$('#3DLevel2').css('display','none')", 800);
      setTimeout("$('#3DLevel2').css('display','inline')", 1000);
      setTimeout("$('#3DLevel6').css('display','inline')", 1100);
      setTimeout("$('#3DLevel6').css('display','none')", 1200);
      setTimeout("$('#3DLevel6').css('display','inline')", 1400);
      setTimeout("document.getElementById('verticalCenter').style.zIndex='0'", 1400);
     
    });    
    $("#closeVideo").click(function () {
      
      closeVideo();
      setTimeout("$('#3DLevel2').css('display','inline')", 700);
      setTimeout("$('#3DLevel2').css('display','none')", 800);
      setTimeout("$('#3DLevel2').css('display','inline')", 1000);
      setTimeout("$('#3DLevel6').css('display','inline')", 1100);
      setTimeout("$('#3DLevel6').css('display','none')", 1200);
      setTimeout("$('#3DLevel6').css('display','inline')", 1400);
      setTimeout("document.getElementById('verticalCenter').style.zIndex='0'", 1400);
      
     
    });   
    $("#closeVideo").mouseover(function () {
              
      $("#closeVideo").attr('src', $("#closeVideo").attr('src').replace('btn_close.png','btn_close_over.png') );
     
    });    
    
    $("#closeVideo").mouseout(function () {
      
      $("#closeVideo").attr('src', $("#closeVideo").attr('src').replace('btn_close_over.png','btn_close.png') );
     
    });   

    }
}


function setFlowplayer(id){

    setTimeout("$('#videoplayer').css('display','inline')", 100);
    setTimeout("$('#videoplayer').css('display','none')", 200);
    setTimeout("$('#videoplayer').css('display','inline')", 400);

    param = 'id='+id+'&query=getAudio';
    httpRequestObject.open('POST', 'ajaxResponse.php',true);
    httpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    httpRequestObject.setRequestHeader("Content-length", param.length);
    httpRequestObject.setRequestHeader("Connection", "close");

    httpRequestObject.onreadystatechange = setFlowplayerResponse;

    httpRequestObject.send(param); 

}

function setFlowplayerResponse(){
    if(httpRequestObject.readyState == 4){

        // Holt die Antwort aus der Anfrage

        var ajaxResponse = httpRequestObject.responseXML;
                         
          document.getElementById('videoplayer').innerHTML = ajaxResponse.getElementsByTagName("container")[0].firstChild.nodeValue + '<div id="audio" style="display:block;width:450px;height:30px;" href="'+ajaxResponse.getElementsByTagName("content")[0].firstChild.nodeValue+'"></div>'; 
    
flowplayer("audio", "http://localhost/kanllinger/swf/flowplayer-3.2.5.swf", {

	// fullscreen button not needed here
	plugins: {
		controls: {
			fullscreen: false,
			height: 30,
			autoHide: false
		}
	},

	clip: {
		autoPlay: false,

		// optional: when playback starts close the first audio playback
		onBeforeBegin: function() {
			$f("player").close();
		}
	}

});
    
    $('#blackVideo').fadeIn('slow', function() {});
    $("#blackVideo").click(function () {
      
      closeVideo();
     
    });
    $("#closeVideo").click(function () {
      
      closeVideo();
     
    });
    $("#closeVideo").mouseover(function () {
              
      $("#closeVideo").attr('src', $("#closeVideo").attr('src').replace('btn_close.png','btn_close_over.png') );
     
    });
    
    $("#closeVideo").mouseout(function () {
      
      $("#closeVideo").attr('src', $("#closeVideo").attr('src').replace('btn_close_over.png','btn_close.png') );
     
    }); 

    
    }
}


function setStat(type) {

  
    param = 'type='+type+'&query=setStatistic';     
    httpRequestObject.open('POST', 'ajaxResponse.php',true);      
    httpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");      
    httpRequestObject.setRequestHeader("Content-length", param.length);  
    httpRequestObject.setRequestHeader("Connection", "close");  

    httpRequestObject.onreadystatechange = setStatResponse;

    httpRequestObject.send(param);

}

function setStatResponse() {
      
        // Ajax-Anfrage erfolgreich?

    if(httpRequestObject.readyState == 4){
            
        // Holt die Antwort aus der Anfrage


    }

} 




// Holen des HTTP-Request Objekts

var httpRequestObject = getXMLHttpRequestObject();



function openCurtain(){ 
				if ($curtainopen == false){  
             
					$(".rope").stop().animate({top: '0px' }, {queue:false, duration:350, easing:'easeOutBounce'}); 
					$(".leftcurtain").stop().animate({width:'1px'}, 3500 );
					$(".rightcurtain").stop().animate({width:'0px'},3500 );
					$curtainopen = true;    
				}
}	
