﻿// 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];
		}
	}
}

var clientIP = '<!--#echo var="REMOTE_ADDR"-->'; 

// 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('/shop') > 0) from = 2;
	if ((document.location).toString().indexOf('/angebot') > 0) from = 3;
	if ((document.location).toString().indexOf('/ueber-uns') > 0) from = 4;

	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 logoScrollV;
        var logoScrollH;
        var logoScrollL;
        var logoScrollT;
        var logoElem = document.getElementById('logo-intro');
        var logoElemWrap = document.getElementById('logo-intro-wrap');
        var logo = document.getElementById('logo-wrap');
        var green = document.getElementById('green-wrap');
        green.style.top = '0px';
        green.style.left = '0px';
        green.style.width = '100%';
        green.style.height = '100%';
        green.style.zIndex = 10;
        green.style.visibility = 'visible';
        
        //preloading
        imgIntro = new Image();
        imgIntro.src = 'assets/templates/sbg/images/g-unit.gif';
        
        var width = window.document.body.clientWidth;
        var height = window.document.body.clientHeight;
        var targetTop = (logo.offsetTop+0).toString() + 'px'; //444+70
        var targetLeft = (width / 2 - 490+68).toString() + 'px'; //center-422
        logoElemWrap.style.width = '100%';
        logoElemWrap.style.height = '100%';
        logoElemWrap.style.display = 'block';
        logoScrollL = new Fx.Style('logo-intro','left',{wait: false, duration: 1000});
        logoScrollT = new Fx.Style('logo-intro','top',{wait: false, duration: 1000});
        logoScrollV = new Fx.Style('logo-intro','width',{wait: false, duration: 1000});
        logoScrollH = new Fx.Style('logo-intro','height',{wait: true, duration: 1000});
        logoScrollH.addEvent('onComplete', function() { afterIntro2(1); });
         
        logoScrollL.start(targetLeft);
        logoScrollT.start(targetTop);
        logoScrollV.start(88);
        logoScrollH.start(91);
        
        var greenTimer = setTimeout('var green = document.getElementById("green-wrap"); green.style.visibility = "hidden";',500)
        var splashTimer = setTimeout('var logosplashwrap = document.getElementById("logo-splash-wrap"); logosplashwrap.style.visibility = "visible";',900)
        
        // afterIntro2(1);
    }
    else
    {
      var togglerwrap = document.getElementById('toggler-wrap');
      togglerwrap.style.visibility = 'visible';
      
      var menuDiv = document.getElementById("menu");
      for (i = 0; i < menuDiv.firstChild.childNodes.length; i++) {
        var menuCol = menuDiv.firstChild.childNodes[i];
        menuCol.style.visibility = 'visible';
      }
      
      var logosplashwrap = document.getElementById('logo-splash-wrap');
      logosplashwrap.style.visibility = 'visible';
      var logo = document.getElementById('logo');
      var logoSplash = document.getElementById('logo-splash');
      var width = window.document.body.clientWidth;
      logo.style.marginLeft = (width / 2 - 542).toString() + 'px';
      logoSplash.style.marginLeft = (width / 2 - 542).toString() + 'px';

      afterIntro2(0);
		}
	}); 
  
	window.addEvent('resize', function(){
		var logo = document.getElementById('logo');
		var width = window.document.body.clientWidth;
		logo.style.marginLeft = (width / 2 - 542).toString() + 'px';
              var logoSplash = document.getElementById('logo-splash');
              logoSplash.style.marginLeft = (width / 2 - 542).toString() + 'px';
	}); 

  this.scrollOut = function(newSite){
    myScroll.addEvent('onComplete', function() { 
      // preload large images
      
      if (newSite.toString().indexOf('/news') > 0) var toSite = 1;
	    if (newSite.toString().indexOf('/shop') > 0) var toSite = 2;
	    if (newSite.toString().indexOf('/angebot') > 0) var toSite = 3;
	    if (newSite.toString().indexOf('/ueber-uns') > 0) var toSite = 4;
	    if (toSite != from) {
        var preload = new Image();
        preload.src = 'assets/templates/sbg/images/intro_'+toSite+'.jpg';
      }
      
      // now go to the site
      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 logoElemWrap = document.getElementById('logo-intro-wrap');
      logoElemWrap.style.display = 'none';
      
      var menuDiv = document.getElementById("menu");
      for (i = 0; i < menuDiv.firstChild.childNodes.length; i++) {
        switch (i) {
          case 0: var delay = 500; break;
          case 1: var delay = 1000; break;
          case 2: var delay = 1500; break;
          case 3: var delay = 2000; break;
          case 4: var delay = 2500; break;
          default: var delay = 500; break;
        }
        var menuTimer = setTimeout('var menuDiv = document.getElementById("menu"); var menuCol = menuDiv.firstChild.childNodes[' + i.toString() + ']; menuCol.style.visibility = "visible";',delay);
      }
      var menuTimer = setTimeout('var togglerwrap = document.getElementById("toggler-wrap"); togglerwrap.style.visibility = "visible"; ',2500);
      
      // var logosplashwrap = document.getElementById('logo-splash-wrap');
      // logosplashwrap.style.visibility = 'visible';
      var logo = document.getElementById('logo');
      var width = window.document.body.clientWidth;
      logo.style.marginLeft = (width / 2 - 542).toString() + 'px';

      var logoSplash = document.getElementById('logo-splash');
      logoSplash.style.marginLeft = (width / 2 - 542).toString() + 'px';

    } 
    else
    {
      var togglerwrap = document.getElementById('toggler-wrap');
      togglerwrap.style.visibility = 'visible';
      var menuDiv = document.getElementById("menu");
      for (i = 0; i < menuDiv.firstChild.childNodes.length; i++) {
        var menuCol = menuDiv.firstChild.childNodes[i];
        menuCol.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]);
}
