// JavaScript Core
// Copyright by johannes.wedenigg@linea7.com © 2007

//*************************************
// lineacore Namespace 
// alle hier definierten funktionen sind über lineacore.funktionsname ansprechbar
//*************************************


function L7Namespace() {
	
	/*	Globale Eigenschaften in lineacore       */
	
	
	
	/* 	Test Funktion zum Testen der korrekten Namespace Adressierung
		Diese Funktion öffnet einfach eine Messagebox und gibt den Test "nachricht" aus    */
		
	this.gibLaut = function(nachricht) {
		window.alert(nachricht);
	}
	
	/* Funktion zum einfachen austauschen von Bildern über "src" */
	
	this.changeImgSrc = function(element,newsrc) {
		element = $(element);
		element.src = newsrc;
	}
	
	/* fading von Elementen erreichen */
	this.toggleBlindElement = function(element) {
		blind_target = $(element);
		
		if (blind_target.style.display) {
			new Effect.BlindDown(blind_target, {duration:0.25});
		} else {
			new Effect.BlindUp(blind_target, {duration:0.25});
		}
	}
	
	
	
	
	
	
	
	
	
	
	/* Startseite - Intro-Fulltext ein und ausblenden */
	
	
	this.showFulltextBox = function() {
		box = $("intro-fulltext-box");
		
		if (box.style.display == "none") { 
			new Effect.BlindDown(box, {duration:0.50});
		}
		
	}
	
	
	this.hideFulltextBox = function() {
		box = $("intro-fulltext-box");
		
		new Effect.BlindUp(box, {duration:0.50});
	}

	
	
	
	
	
	/* Suchseiten - Suchbox ein-/ausblenden */
	
	this.showSearchBox = function() {
		box = $("search-container");
		show_button = $("bt-show-search");
		hide_button = $("bt-hide-search");
		
		new Effect.BlindDown(box, {duration:0.50});
		show_button.style.display = "none";
		hide_button.style.display = "block";
	}
	
	
	this.hideSearchBox = function() {
		box = $("search-container");
		show_button = $("bt-show-search");
		hide_button = $("bt-hide-search");
		
		new Effect.BlindUp(box, {duration:0.50});
		show_button.style.display = "block";
		hide_button.style.display = "none";
	}

		
		
	
	
	/* Ergebnis wechseln zwischen Freie Objekte und alle Objekte */
	
	
	this.showAllObjects = function() {
		button_alle = $("bt-alle-objekte");
		button_freie = $("bt-freie-objekte");
		
		results_alle = $("result-box-alle");
		results_freie = $("result-box-freie");
		
		if (results_alle.style.display = "none") {
			button_alle.className = "image-replacement alle-objekte-aktiv";
			button_freie.className = "image-replacement freie-objekte-inaktiv";
			results_alle.style.display = "block";
			results_freie.style.display = "none";
		}
	}
	
	this.showFreeObjects = function() {
		button_alle = $("bt-alle-objekte");
		button_freie = $("bt-freie-objekte");
		
		results_alle = $("result-box-alle");
		results_freie = $("result-box-freie");
		
		if (results_freie.style.display = "none") {
			button_alle.className = "image-replacement alle-objekte-inaktiv";
			button_freie.className = "image-replacement freie-objekte-aktiv";
			results_alle.style.display = "none";
			results_freie.style.display = "block";
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	this.changeBoxStatus = function(element) {
		op_target = $(element);
		
		if(op_target) {
			if (op_target.style.display != "none") {
				new Effect.BlindUp(op_target, {duration:0.25});
			}
		}
	}
	
	
	this.blindUp = function(element) {
		blind_target = $(element);
		
		if (blind_target.style.display != "none") {
			new Effect.BlindUp(blind_target, {duration:0.25});
		}
	}
	
	this.blindDown = function(element) {
		blind_target = $(element);
		
		if (blind_target.style.display != "block") {
			new Effect.BlindDown(blind_target, {duration:0.25});
		}
	}
	
	
	
	
	
	this.showTab = function(tab) {
		var panel = $(tab);
		panel.style.display = "block";
	}

	this.hideTab = function(tab) {
		var panel = $(tab);
		panel.style.display = "none";
	}
	
	
	
	
	
	
	
	
	
	// direktes Veränderen von InnerHTML
	
	this.updateInnerHTML = function(elementID,neuerInhalt) {
		$(elementID).innerHTML = neuerInhalt;
	}
	
	// direktes Erweitern eines Attributs, neuer Inhalt wird angehängt
	
	this.appendToAttribute = function(elementID,attributName,neuerInhalt) {
		$(elementID).attributName = $(elementID).attributName + neuerInhalt;
	}
	
	// direktes Einblenden eines Elements (div)
	this.showElement = function(elementID) {
		$(elementID).style.display = "block";
	}
	
	//direktes Ausblenden eines Elements (div)
	this.hideElement = function(elementID) {
		$(elementID).style.display = "none";
	}
	
			
}  // Ende des Namespace Objekts ----> Diese Klammer NICHT ENTFERNEN!!!!


//*************************************
// Ende des lineacore Namespace
// Initialisieren des Namespace Objekts

var lineacore = new L7Namespace;

// Jetzt können alle Methoden und Eigenschaften von algCoreNamespace über lineacore.blblbla angesprochen werden

// Es folgen weitere Funktionen die noch in den lineacore Namespace überführt werden müssen
//*************************************







//*************************************
// Skripte zum Verändern der Layer-Größen, Einblenden/Ausblenden der Station etc.
//*************************************



function resizeContainer(div_id, div_height)
{
 var div = document.getElementById(div_id);

 if(div.offsetHeight < div_height) {
 
	  var h = div.offsetHeight + 15;
	  
	  if (h < div_height) {	  
		  div.style.height = h+'px';
		  window.setTimeout("resizeContainer('" + div_id +"'," + div_height + ");", 5);
		} else {
	  	  div.style.height = div_height+'px';
	  }
	  
 } else if(div.offsetHeight > div_height) {
 
	  var h = div.offsetHeight - 15;
	  
	  if (h > div_height) {	  
		  div.style.height = h+'px';
		  window.setTimeout("resizeContainer('" + div_id +"'," + div_height + ");", 5);
		} else {
	  	  div.style.height = div_height+'px';
		}
 }
}






//*************************************
// Skripte für Popup Overlay
//*************************************

function hide_popup() {
	
	var popup_box = document.getElementById("popup_box");
	var popup_background = document.getElementById("popup_background");
	
	popup_box.style.display = "none";
	popup_background.style.display = "none";
	
	popup_box.style.top = "0px";
	popup_box.style.left = "0px";
	
	popup_background.style.top = "0px";
	popup_background.style.left = "0px";
	
	popup_box.style.width = "0px";
	popup_box.style.height = "0px";
		
	popup_background.style.width = "0px";
	popup_background.style.height = "0px";
	
	window.onscroll = "";
	window.onresize = "";
}



function show_popup(url,width,height) {
	
	var popup_box = document.getElementById("popup_box");
	var popup_background = document.getElementById("popup_background");
	
	popup_box.style.width = width+"px";
	popup_box.style.height = height+"px";
	
	var screen_size = new getPageSize();
	
	popup_background.style.width = screen_size.width+"px";
	popup_background.style.height = screen_size.height+"px";
	
	popup_background.style.opacity = ".2";
	popup_background.style.filter = 'alpha(opacity=' + '20' + ')';
	
	popup_box.style.display = "block";
	popup_background.style.display = "block";
	
	maintPos();
	
	docClickLoader.loadInto(url, 'popup_content');
	
	window.onscroll = maintPos;
	window.onresize = maintPos;
}

posToCenter = function(elem) {
	var scrollPos = new getScrollPos();
	var pageSize = new getPageSize();
	var emSize = new getElementSize(elem);
	var x = Math.round(pageSize.width/2) - (emSize.width /2) + scrollPos.scrollX;
	var y = Math.round(pageSize.height/2) - (emSize.height /2) + scrollPos.scrollY;	
	elem.style.left = x+'px';
	elem.style.top = y+'px';	
}

getScrollPos = function() {
	var docElem = document.documentElement;
	this.scrollX = self.pageXOffset || (docElem&&docElem.scrollLeft) || document.body.scrollLeft;
	this.scrollY = self.pageYOffset || (docElem&&docElem.scrollTop) || document.body.scrollTop;
}

getPageSize = function() {
	var docElem = document.documentElement
	this.width = self.innerWidth || (docElem&&docElem.clientWidth) || document.body.clientWidth;
	this.height = self.innerHeight || (docElem&&docElem.clientHeight) || document.body.clientHeight;
}

getElementSize = function(elem) {
	this.width = elem.offsetWidth ||  elem.style.pixelWidth;
	this.height = elem.offsetHeight || elem.style.pixelHeight;
}	

maintPos = function() {
	var popup_box = document.getElementById("popup_box");
	posToCenter(popup_box);
	
	var popup_background = document.getElementById('popup_background');
	var pagesize = new getPageSize();
	var scrollPos = new getScrollPos();
	var ua = navigator.userAgent;

	if(ua.indexOf("MSIE ") != -1) {popup_background.style.width = pagesize.width+'px';} 
	else {popup_background.style.width = pagesize.width+'px';}

	if(ua.indexOf("Opera/9") != -1) {popup_background.style.height = document.body.scrollHeight+'px';}
	else {popup_background.style.height = pagesize.height+scrollPos.scrollY+'px';}

	
}

			

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
