﻿// Avoid framing
if(top!=self) top.location=self.location;

// Decode email
function DecodeMailto(x) {
	var n=0;
	var r="";
	for(var i=0; i<x.length; i++) { 
		n = x.charCodeAt(i); 
		if(n>=8364) n=128;
		r += String.fromCharCode(n-1); 
	}
	return r;
}
function OpenMailClient(x)	{
	var x="nbjmup;"+x;
	location.href=DecodeMailto(x);
}
	
function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

// Slide effect (MooTools)
function sbgClass() {
	var myScroll;
	var imgIntro;
	var imageWidth = 750;
	var stagediv;
  var menudiv;
	var content;
	var from = 0;

	if ((document.location).toString().indexOf('/news') > 0) from = 1;
	if ((document.location).toString().indexOf('/standorte') > 0) from = 2;
	if ((document.location).toString().indexOf('/born-to-board') > 0) from = 3;
	if ((document.location).toString().indexOf('/shop') > 0) from = 4;
	if ((document.location).toString().indexOf('/angebot') > 0) from = 5;
	if ((document.location).toString().indexOf('/ueber-uns') > 0) from = 6;

	this.afterLoad = function(){
		stagediv = document.getElementById('largestage');
		content = document.getElementById('content');
		imageWidth = imgIntro.width;
		stagediv.style.background = 'url('+imgIntro.src+') #ffffff no-repeat';
		stagediv.style.width = (imageWidth + 1500).toString()+'px';
		content.style.marginLeft = imageWidth.toString()+'px';

		myScroll = new Fx.Scroll('stage', {wait: true, duration: ((imageWidth / 2) + 500)});
		myScroll.scrollTo(imageWidth,0);
		
	}

	window.addEvent('load', function(){
	  if (querySt('from')==undefined) {
        var logoScroll;
        var logoElem = document.getElementById('logo-wrap');
        logoElem.style.zIndex = 10;
        logoScroll = new Fx.Style('logo','margin-left', {wait: true, duration: 1000});
        logoScroll.addEvent('onComplete', function() { afterIntro2(1); });
        var width = window.document.body.clientWidth;
        logoScroll.start((width + 211),width / 2 - 520);
    }
    else
    {
      var logo = document.getElementById('logo');
      var width = window.document.body.clientWidth;
      logo.style.marginLeft = (width / 2 - 519).toString() + 'px';
      afterIntro2(0);
		}
	}); 
  
	window.addEvent('resize', function(){
    var logo = document.getElementById('logo');
    var width = window.document.body.clientWidth;
    logo.style.marginLeft = width / 2 - 518;
	}); 

  this.scrollOut = function(newSite){
    myScroll.addEvent('onComplete', function() { 
      window.location.href=newSite+'?from='+from;			
    });
    myScroll.options.duration = 500;
    myScroll.scrollTo((imageWidth + 1500),0);
  }

  this.afterIntro = function(intro){
    var menuDiv = document.getElementById('menu');
    if (intro==1) {
      var logoElem = document.getElementById('logo-wrap');
      logoElem.style.zIndex = 6;
      
      for (i = 0; i < menuDiv.firstChild.childNodes.length; i++) {
        var menuCol = menuDiv.firstChild.childNodes[i];
        var imgBut = menuCol.firstChild.firstChild;
        var imgText = menuCol.firstChild.nextSibling.firstChild; // .firstChild;
        var origImg = imgBut.src;
        // imgBut.src = 'assets/templates/sbg/images/menu/but_intro_'+(i+1).toString()+'.gif';
        imgBut.src = 'assets/templates/sbg/images/menu/but_spacer.gif';
        
        switch (i) {
          case 0: var delay = 2000; break;
          case 1: var delay = 1000; break;
          case 2: var delay = 0; break;
          case 3: var delay = 1500; break;
          case 4: var delay = 2500; break;
          default: var delay = 500; break;
        }
        var menuTimer = setTimeout('var menuFade = new Fx.Style("'+imgText.id+'","margin-top", {wait: false, duration: 150}); animationStart('+i.toString()+',"'+imgBut.id+'",1); menuFade.start(-30,0); ',delay);
        var menuTimerB = setTimeout('animationStop('+i.toString()+'); document.getElementById("'+imgBut.id+'").src="'+origImg+'"; ', (delay+500));
      }
      setTimeout('document.getElementById("menu").style.visibility = "visible";',200);
    } 
    else
    {
      for (i = 0; i < menuDiv.firstChild.childNodes.length; i++) {
        var menuCol = menuDiv.firstChild.childNodes[i];
        var imgText = menuCol.firstChild.nextSibling.firstChild; // .firstChild;
        imgText.style.marginTop = '0px';
      }
      document.getElementById("menu").style.visibility = 'visible';
    }
                        
		if (querySt('from') != from) {
      imgIntro = new Image();
      imgIntro.onload = function() { slideIn(); };
      imgIntro.src = 'assets/templates/sbg/images/intro_'+from+'.jpg';
    }	
    else
    {
			stagediv = document.getElementById('largestage');
			stagediv.style.width = '2250px';
			content = document.getElementById('content');
			content.style.marginLeft = '750px';
			myScroll = new Fx.Scroll('stage', {wait: true, duration: 500});
			myScroll.scrollTo(750,0);
		}
	}
}

sbgObject = new sbgClass();

function afterIntro2(intro) {
	sbgObject.afterIntro(intro);
}

function slideIn() {
	sbgObject.afterLoad();
}

function slideOut(newSite) {
	sbgObject.scrollOut(newSite);
}

// Menu image mouseover effect
function mo(e, over_out,pageid,wrap) {
  if(wrap.className != "on") {
    var image = document.getElementById("menu"+pageid);
	  var src = image.src, ext = src.substring(src.lastIndexOf('.'),src.length);
	  image.src= (over_out == 1 ? src.replace(ext,'_on' + ext) : src.replace('_on' + ext,ext));

	  var butimage = document.getElementById("but"+pageid);
		if (butimage!=null) {
		  //var butsrc = butimage.src, ext = butsrc.substring(butsrc.lastIndexOf('.'),butsrc.length);
		  //butimage.src= (over_out == 1 ? butsrc.replace(ext,'_on' + ext) : butsrc.replace('_on' + ext,ext));
		  if (over_out == 1)
		    animationStart(pageid,butimage,0)
		  else 
		    animationStop(pageid);
		}
	}
	return;
}

var menuTimer;
var openMenus = new Array();
var currentMenuIndex;

// Menu image mouseover effect
function moc(e, over_out,pageid,wrap) {
  if (!e) var e = window.event;
	var target = e.relatedTarget || e.toElement || false;
	var source = e.srcElement || e.target || false;
	//e.cancelBubble = true;
  //if (e.stopPropagation) e.stopPropagation();
  
  var elem = wrap;
  while (elem.className != 'event level1')
		elem.parentNode;

  if(elem.className != "on") {
    if (over_out == 1) {
      for (ci = 0; ci < elem.childNodes.length; ci++) {
        if (elem.childNodes[ci].className == 'event submenu-wrap') {
          var subMenu = elem.childNodes[ci];
		     	if (subMenu.style.visibility != "visible") {
            for(i = 0; i < openMenus.length; i++) {
              openMenus[i].style.visibility = 'hidden';
            }
            if (menuTimer) clearTimeout(menuTimer);
		    
            var arrChilds = subMenu.childNodes;
	          var nChildHeight = subMenu.firstChild.clientHeight;
            subMenu.style.height = (arrChilds.length*nChildHeight+14).toString()+"px"; 
    
            if ((arrChilds.length*nChildHeight+14+51) > 145) {
              var menuDiv = document.getElementById("menu");
              menuDiv.style.height = (arrChilds.length*nChildHeight+14+51).toString()+'px';
            }
          
 		        for(i = 0; i < arrChilds.length; i++) {
  	          arrChilds[i].style.marginTop = "-"+nChildHeight.toString()+"px";
		        }
		    
 		        subMenu.style.visibility = "visible";
 		          
            for(i = 0; i < arrChilds.length; i++) {
  	          menuSlide = new Fx.Style(arrChilds[i],'margin-top', {wait: false, duration: 100+(50*i)});
              menuSlide.start(nChildHeight*(-1),(nChildHeight*i+14));
    	      }
          
            openMenus.push(subMenu);
		      
            currentMenuIndex = openMenus.length;
            menuTimer = setTimeout('hideMenu('+currentMenuIndex+')',5000);
		      }
		      else
		      {
		        if (menuTimer) {
		          clearTimeout(menuTimer);
		          menuTimer = setTimeout('hideMenu('+currentMenuIndex+')',5000);
		        }
		      }
		    }
 		  }
 	  }
	}
	return;
}

function hideMenu(index) {
  if (openMenus) {
    animationStop();
    openMenus[index-1].style.visibility = 'hidden';
    openMenus.pop();
  }
}

// Gallery mouseover effect
function galleryZoom(wo) {
	if(wo.firstChild.src) {
		var image = wo.firstChild;
		var src = image.src, ext = src.substring(src.lastIndexOf('.'),src.length);
		document.getElementById("zoom").src = src.replace('_small' + ext,ext);
	}
}

//	Manipulate links
window.addEvent('load', function(){
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for(var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		/*anchor.tabindex = i;*/
		if (anchor.getAttribute("href")) {
			anchor.onfocus = function() {
				this.blur();
			}
			if (anchor.getAttribute("rel") == "ext") {
				anchor.target = "_blank";
				if (document.getElementsByTagName("html")[0].lang == "en") {
					if (!anchor.title) anchor.title = "open in new window"
					else anchor.title += " (new window)";					
				}else {
					if (!anchor.title) anchor.title = "in neuem Fenster öffnen"
					else anchor.title += " (neues Fenster)";
				}
			}
		}
	}
});

// Animation Buttons

var timeoutValue = 23;
var numOfImages = 6;
var currentAnimationIndex = 0;
var imageIndex = new Array();
var timeoutID = new Array();
var animationType = new Array();
var animationImage = new Array();

imgIntro = new Array(6);
for(var i=1; i<=numOfImages; i++) {
  imgIntro[i] = new Image();
  imgIntro[i].src = "assets/templates/sbg/images/menu/intro/"+i.toString()+".gif";
}
imgActive = new Array(6);
for(var i=1; i<=numOfImages; i++) {
  imgActive[i] = new Image();
  imgActive[i].src = "assets/templates/sbg/images/menu/active/"+i.toString()+".gif";
}

function animation(index) {
  if (imageIndex[index] < numOfImages)
	  imageIndex[index]++
  else
    imageIndex[index] = 1;

  if (animationType[index] == 0)
	  animationImage[index].src = imgActive[imageIndex[index]].src
	else
    animationImage[index].src = imgIntro[imageIndex[index]].src;
	  
	timeoutID[index] = setTimeout("animation("+index.toString()+")", timeoutValue);
}

function animationStart(index,imageElem,type) {
  imageIndex[index] = 1;
  animationType[index] = type;
  animationImage[index] = null;
  timeoutID[index] = 0;
  animationType[index] = type;
  if (typeof(imageElem) == "string")
    animationImage[index] = document.getElementById(imageElem)
  else
    animationImage[index] = imageElem;
  
  animation(index);
}

function animationStop(index) {
  if (animationImage[index])
    animationImage[index].src = "assets/templates/sbg/images/menu/but.gif";
	clearTimeout(timeoutID[index]);
}
