var tickerdiv = null;
var popupbox = null;
var popupbox_image = null;
var contentMinHeight = 370;

var news = new Array("Niemand kann Ihnen Ihren Selbstwert nehmen, wenn Sie ihn nicht hergeben",
                     "Str&auml;uben Sie sich nicht gegen die F&uuml;hrung Ihrer Seele. Sie wei&szlig; am besten, was Sie gl&uuml;cklich und erfolgreich macht",
                     "Selbstsicher dr&uuml;cken Sie Ihre Einzigartigkeit auf die beste Weise aus",
                     "Jede positive Ver&auml;nderung hat ihren Preis. Sind Sie bereit, ihn zu zahlen?",
                     "Es gibt keine Abk&uuml;rzung auf dem Weg zur Kompetenz",
                     "Ihre Angst verschwindet, wenn Sie tun, wovor Sie Angst haben",
                     "Dankbarkeit lenkt den Focus auf F&uuml;lle, Neid auf Mangel",
                     "Nur wenn Sie eine T&auml;tigkeit lieben, sind Sie darin wirklich gut",
                     "Zwei Kriterien zeigen, wo Ihr Talent liegt: Was Sie tun, f&auml;llt Ihnen leicht und macht Ihnen Freude");
var ticker_count = 0;
var newsmessage = null;
var animation_count = 0;
function startTicker() {
  if(tickerdiv) {
    newsmessage = news[ticker_count%news.length]; //loop
    //newsmessage = news[Math.floor(Math.random()*news.length)]; //random
    ++ticker_count;
    animation_count = 0;
    tickerdiv.innerHTML = "„ " + newsmessage + " “";
//tickerdiv.firstChild.data = newsmessage;
    tickeranimation2();

  }
}

function tickeranimation2() {
  if(animation_count > 100) window.setTimeout(startTicker, 8000);
  else {
    var opacity = animation_count/100;
    animation_count += 5;
    if(tickerdiv.style.opacity != undefined){
      tickerdiv.style.opacity = opacity;
    } else if( tickerdiv.style.MozOpacity != undefined){
      tickerdiv.style.MozOpacity = opacity;
    } else if ( tickerdiv.style.filter != undefined){
      tickerdiv.style.filter="alpha(opacity=" + Math.round(opacity * 100) + ")";
    }
    window.setTimeout(tickeranimation2, 50);
  }
}

var centerizeNodeToParent = function(t, p, s) {
  var offsetPosition = getElementPosition(p)
  if(!s || s=='h') t.style.left = ((p.offsetWidth - t.offsetWidth) / 2) + 'px';
  if(!s || s=='v') t.style.top = ((p.offsetHeight - t.offsetHeight) / 2) + 'px';
}

function getEpochTime(includeMiliseconds) {
  var d = new Date();
  return (includeMiliseconds)?d.getTime():((d.getTime()-d.getMilliseconds())/1000);
}

function getTime() {
  var d = new Date();
  return toSt2(d.getHours()) + ':' +
         toSt2(d.getMinutes()) + ':' +
         toSt2(d.getSeconds());
}

var getElementsByClassName = function(className, base) {
  if(!base) base = document;
  var nodeList = [];
  var e = base.getElementsByTagName('*');
  var r = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
  for(var i = 0; i < e.length; i++) {
    var classes = e[i].className.split(' ');
    for(var q = 0; q < classes.length; q++) {
      if(r.test(superTrim(classes[q]))) {
        nodeList.push(e[i]);
      }
    }
  }
  return nodeList;
}

var superTrim = function(s) {
  return(s.replace(/\s+/g," ").replace(/\s+$/,"").replace(/^\s+/,""));
}

//including current node (descendant)
var getAncestorByClassName = function(descendant, className) {
  var limit = 5; //only upper 5 nodes
  do {
    if(containsClass(descendant, className)) return descendant;
    else if(descendant.parentNode) descendant = descendant.parentNode;
  } while(limit-- || descendant);
}

function setClass(node,className) {
    node.setAttribute("class", className);
    node.className = className;
}

function appendClass(node, className) {
  if(containsClass(node, className)) return;
  node.className = node.className + " " + className;
}

function removeClass(node, className) {
  if(!containsClass(node, className)) return;
  node.className = node.className.replace(className, "");
}

var containsClass = function(node, className) {
  var classNames = node.className.split(' ');
  for(var i = 0; i < classNames.length; i++) {
    if(superTrim(classNames[i]) == className) return true;
  }
  return false;
}

function setId(node,name) {
    node.setAttribute("id", name);
    node.id = name;
}

function setCookie(name, value, expires) {
  document.cookie = name + "=" + escape(value) + "; path=/" +
                    ((expires == null)?"":"; expires=" + expires.toGMTString());
}

function getCookie (name) {
    var dc = document.cookie;
    var cname = name + "=";

    if (dc.length > 0) {
      var begin = dc.indexOf(cname);
      if (begin != -1) {
        begin += cname.length;
        var end = dc.indexOf(";", begin);
        if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
        }
      }
    return null;
}


function delCookie(name) {
  document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
} 

var getElementPosition = function(e) {
  var x = 0, y = 0;
  do {
    x += e.offsetLeft;
    y += e.offsetTop;
    e = e.offsetParent;
  } while(e);
  return {x : x, y : y};
}

function oeffneInterview () {
	var fenster = window.open("/files/video/mdr.html", "Interview", "width=640, height=480, left=400, top=10, menubar=no, status=yes, scrollbars=no, resizable=no");
	fenster.focus();
}

function oeffneVideoBensheim () {
	var fenster = window.open("/php/fragmente/bensheim_video.html", "Vortragsausschnitt", "width=400, height=300, left=400, top=10, menubar=no, status=yes, scrollbars=no, resizable=no");
	fenster.focus();
}

function oeffneScreenshot (url) {
	var fenster = window.open(url, "Screenshot", "width=340, height=520, left=400, top=10, menubar=no, status=yes, scrollbars=no, resizable=no");
	fenster.focus();
}

function initGalleryImages() {

  var clickEvent = function(event) {
    var event = (event) ? event : window.event;
    var target = (event.target) ? event.target : event.srcElement;
    popupbox_image.src = target.src.replace(/_small/i,"_big");
    displaypopbox(true);
  }
  
  var cimages = getElementsByClassName("clickimage");
  
  popupbox.onclick = function() {
    displaypopbox(false);
  }
  
  for(var i = 0; i < cimages.length; i++) {
    cimages[i].onclick = clickEvent;
  }
}
    

function displaypopbox(yes) {  
  if(yes) {
    popupbox.style.display = "block";
  } else {
    popupbox_image.src = "";
    popupbox.style.display = "none";
  }
}

//calls init function of site-js
window.onload = function() {
  var content = document.getElementById("content");
  var bottom = document.getElementById("bottom");
  
  tickerdiv = document.getElementById("ticker");
  popupbox = document.getElementById("popupbox_wrapper");
  popupbox_image = popupbox.getElementsByTagName("img")[0];
  
  var pos = getElementPosition(bottom);
  startTicker();
  initGalleryImages();
  var extrabottomspace = 15;
  var minHeight = 13 + 145 + (1 + 6 + 21 + 1) + contentMinHeight + 13;
  window.onresize = function() {
    var windowHeight = document.documentElement.clientHeight;
    content.style.height = ((windowHeight>minHeight)?windowHeight-minHeight-extrabottomspace+contentMinHeight:contentMinHeight) + "px";
  }
  window.onresize();
  if(typeof init == 'function') init(); //this function might be defined in site specific scripts to init these.
}

/* Google */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2163882-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

