// browser sniffer
function Browser(){
  this.uA = navigator.userAgent.toLowerCase();
  this.aN = navigator.appName.toLowerCase();
  this.iE = this.aN.indexOf('microsoft') != -1 ? 1 : 0;
  this.mac =  this.uA.indexOf('mac') != -1 ? 1 : 0;
  this.win = this.uA.indexOf('windows') != -1 ? 1 : 0;
  this.safari =  this.uA.indexOf('webkit') != -1 ? 1 : 0;
  this.opera =  this.uA.indexOf('opera') != -1 ? 1 : 0;    
  this.mozilla = this.aN.indexOf('netscape') != -1 && !this.safari ? 1 : 0;
  this.winMozilla = this.mozilla && this.win ? 1 : 0;
  this.winIE = this.iE && this.win && !this.opera ? 1 : 0;
  this.winIE6Down = this.winIE && parseInt(this.uA.split('msie ')[1].substring(0,1)) <= 6 ? 1: 0;
  this.macIE = this.iE && this.mac ? 1 : 0;
};

var browser = new Browser();

// getElementById wrapper
if (typeof document.getElementById != 'undefined'){
  var getEl = function(id){
    var el = document.getElementById(id);
    if (!el){
      //error('elById: element width id "' + id + '" not found in DOM');
      return false;
    }
    return(el);
  };
}
else {
  error('document.getElementById not supported');
}


// array for DOMContentLoaded events
var DOMCLEvents = [];
var executeDOMCLEvents = function(){
  if(DOMCLEvents.preventExecution){
    return;
  }
  DOMCLEvents.preventExecution = true;
  for (var i = 0; i < DOMCLEvents.length; i++){
    DOMCLEvents[i]();
  }
};

//event listening
if (window.addEventListener){
  var addEvent = function(obj, eventType, functionName){
    if (eventType == 'DOMContentLoaded'){
      DOMCLEvents[DOMCLEvents.length] = functionName;
    }
    obj.addEventListener(eventType, functionName, false);
    return true;
  };
  if (/WebKit/i.test(navigator.userAgent)){ //for safari
    var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
    clearInterval(_timer); executeDOMCLEvents();}}, 10);
  };
  addEvent(window,'load',executeDOMCLEvents); //for opera < 9, ..
  addEvent(window,'DOMContentLoaded',function(){DOMCLEvents.preventExecution = true;}); //not for firefox
}
else if(window.attachEvent && Function.apply){ //for ie 5.5+
  var addEvent = function(obj, eventType, functionName){
    if (eventType == 'DOMContentLoaded'){
      DOMCLEvents[DOMCLEvents.length] = functionName;
      return true;
    }
    var r = obj.attachEvent("on"+eventType, function() { functionName.apply(obj); });
    return r;
  };
  document.write('<script type="text/javascript" id="__ie_onload" defer="defer" src="javascript:void(0);"><\/script>');
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      executeDOMCLEvents();
    }
  }
}
else {
  error("event handling not supported");
}


function setScrollTop(y){
	//can't get proper discriminating object detection
	if (browser.safari){
		document.body.scrollTop = y;
	}
	else if (document.documentElement && typeof document.documentElement.scrollTop != "undefined"){
		document.documentElement.scrollTop = y;
	}
};

function getScrollTop(){
	//can't get proper discriminating object detection
	if (browser.safari){
		return document.body.scrollTop;
	}
	if (document.documentElement && typeof document.documentElement.scrollTop != "undefined"){
		return document.documentElement.scrollTop;
	}
  return 0;
};



//power animator dev 1.2, mDI, march 2006, adds partial clipping
var animTimer = [];
animate = function (oArg){
  clearTimeout(animTimer[oArg.timerName]);
  var cD,cS,pS,pD
  cD = !oArg.currDist ? 0 : oArg.currDist;
  cS = !oArg.currSpeed ? 0 : oArg.currSpeed;
  cS = !oArg.currSpeed && !oArg.easeIn ? oArg.speed : cS;
  pS = !oArg.peakSpeed ? oArg.speed : oArg.peakSpeed;
  if (oArg.peakDist){
    pD = oArg.peakDist;
  }
  else { 
    pD = oArg.easeIn && oArg.easeOut ? parseInt((oArg.dist)/(oArg.easeIn+oArg.easeOut)*oArg.easeIn) : 0;
  }
  if (cD >= pD && oArg.easeOut){
    cS = parseInt(((oArg.dist-cD)+((oArg.speed-cS)/2))/(oArg.easeOut+0.5)+1);
    if (cS > pS){
      cS = pS;
    }
  }
  else if (oArg.easeIn){
    cS = parseInt((cD+((oArg.speed-cS)/2))/(oArg.easeIn-0.5)+1);
    if (cS > oArg.speed){
      cS = oArg.speed;
    }
  }
  if (cD+cS > oArg.dist){
    cS = oArg.dist-cD;
  }
  cD += cS;
  for (var i in oArg.elements){
    var o = oArg.elements[i];
    var currPosition = o.negMove ? o.startPos-cD : o.startPos+cD;
    if (o.style == 'clip'){
      if (o.clipType == 'vertFromCenter'){
        var d = 'rect(' + (o.maxHeight - currPosition) + 'px, ' + o.clipRight + 'px, ' + currPosition + 'px, 0)' ;
        getEl(o.id).style[o.style] = d;
      }
    }
    else {
      getEl(o.id).style[o.style] = currPosition + 'px';
    }
  }
  if (cD < oArg.dist){
    oArg.currDist = cD;
    oArg.currSpeed = cS;
    oArg.peakDist = pD;
    oArg.peakSpeed = pS;
    animTimer[oArg.timerName] = setTimeout(function(){animate(oArg)},25);
    return;
  }
  if (oArg.callBack != ''){
    if (!oArg.obj){
      oArg.obj = 'window';
    }    
    animTimer[oArg.timerName] = setTimeout(oArg.obj + '.' + oArg.callBack,0);
  }  
}


//get window height
function getWindowHeight(){
  if (document.documentElement.clientHeight){
    return document.documentElement.clientHeight;
  }
  if(document.body.clientHeight){
    return document.body.clientHeight;
  }
  return 0;
}

//get window width
function getWindowWidth(){
  if (document.documentElement.clientWidth){
    return document.documentElement.clientWidth;
  }
  if(document.body.clientWidth){
    return document.body.clientWidth;
  }
  return 0;
}

//thanx PPK
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


// flashObject 1.3, Mark Dibbets, Fabrique, update mei 2006


// setClassName
function setClassName(el,className){
  if (!className){
    return;
  }
  if (el.getAttribute('className') != null){
    el.setAttribute('class',className);
  }
  else {
    el.setAttribute('class',className);
  }
};

// add stylesheet
var styleSheetFromScript = false;
function addStyle(selector,properties){
  if (document.styleSheets) {
    if (!styleSheetFromScript){
      styleSheetFromScript = document.createElement('style');
      styleSheetFromScript.setAttribute('type','text/css');
      document.getElementsByTagName('HEAD')[0].appendChild(styleSheetFromScript);
    }
    var lastSheet = document.styleSheets[document.styleSheets.length - 1];
    if(lastSheet && typeof lastSheet.addRule == 'object'){
      lastSheet.addRule(selector, properties);
    }
    else {
      styleSheetFromScript.appendChild(document.createTextNode(selector + ' { ' + properties + ' }'));
    }
 }
};

// check if the proper version is installed
function hasMinFlashVersion(versionNumber){
	if (window.ActiveXObject){
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + versionNumber);
			return 1;
		}
		catch(e){
			return 0;
		}
	}
	else {
		if(navigator.plugins.length){
			for (var i=0; i < navigator.plugins.length; i++){
				var pluginIdent = navigator.plugins[i].description.split(" ");
				if(pluginIdent[0] == "Shockwave" && pluginIdent[1] == "Flash"){
					var versionArray = pluginIdent[2].split(".");
					return versionArray[0] >= versionNumber;
				}
			}
		}
	}
	return 0;
};


// Class FlashObject
flashObjects = [];
function FlashObject(oArg){
  
  FlashObject.QUALITY = {'BEST':'best','HIGH':'high'};
  
  this.id = oArg.id;
  this.parentId = oArg.parentId;
  this.uri = oArg.uri;
  this.width = oArg.width ? oArg.width : false;
  this.height = oArg.height ? oArg.height : false;
  this.hasRequiredVersion = hasMinFlashVersion(oArg.requiredVersion);
  this.className = oArg.className ? oArg.className : '';
  this.params = oArg.params || {};
  this.flashVars = oArg.flashVars || null;
  this.noFocus = oArg.noFocus;
  
  this.quality = oArg.quality || FlashObject.QUALITY.BEST;
  if (!browser.winIE) {
    this.params.quality = this.quality;
  }
  
  flashObjects[this.id] = this;
  this.obj = null;
  
  if (this.hasRequiredVersion){
    addStyle('#' + oArg.parentId + ' .alternate-content','display:none !important;');
  }

  // create the object
  this.create = function(){
    if ((!this.hasRequiredVersion) || (!getEl(this.parentId))){
      return;
    }
    
    var obj = document.createElement('object');
    obj.setAttribute('type','application/x-shockwave-flash');
    if (this.id){
      obj.setAttribute('id',this.id);
    }
    obj.setAttribute('data',this.uri);
    obj.setAttribute('src',this.uri);
    
    if (this.width){
      obj.setAttribute('width',this.width);
    }
    if (this.height){
      obj.setAttribute('height',this.height);
    }
    if (this.noFocus){
      obj.setAttribute('tabIndex',-1);
    }
    setClassName(obj,this.className);
    
    if(this.flashVars){
      var delimiter = '';
      var strFlashVars = '';
      for (var i in this.flashVars){
        strFlashVars += delimiter + i + '=' + this.flashVars[i];
        delimiter = '&';
      }
      this.params['FlashVars'] = strFlashVars;
      //alert(strFlashVars);
    }
    
    for (var i in this.params){
      var param = this.params[i];
      var paramEl = document.createElement('param');
      paramEl.setAttribute('name',i);
      paramEl.setAttribute('value',this.params[i]);
      obj.appendChild(paramEl);
      obj.setAttribute(i,this.params[i]);
    }
    getEl(this.parentId).appendChild(obj);
    this.obj = obj;
    
    try {
      obj.loadMovie(0,this.uri);
    }
    catch (e){
    }

    if (browser.winIE) {//Yikes: no proper object detection possible
      this.setQualityWinIE();
    }
  }

  /* 
  * FIXME: UGLY Fix
  */
  this.setQualityWinIE = function(){
    this.obj.SetVariable('_quality',this.quality);
    try {
      this.obj.GetVariable('_quality');
    }
    catch(e){
      setTimeout('flashObjects["' + this.id + '"].setQualityWinIE()',100);
    }
  }

};

// make a flash object
function createFlashObject(oArg){
  flashObjects[oArg.id] = new FlashObject(oArg);
};

// create all the flash objects (onload)
function createFlashObjects(){
  for (var i in flashObjects){
    flashObjects[i].create();
  }
};



// ajax functions, mdi
var xmlDoc = [];

function loadXMLDoc(oArg){
  if (window.XMLHttpRequest){
    xmlDoc[oArg.documentName] = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlDoc[oArg.documentName] = new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlDoc[oArg.documentName]){
      return;
    }
  }
  xmlDoc[oArg.documentName].onreadystatechange = function(){xmlhttpChange(oArg);}
  xmlDoc[oArg.documentName].open("GET",oArg.documentPath,true);
  xmlDoc[oArg.documentName].send(null);
};

function xmlhttpChange(oArg){
  if (xmlDoc[oArg.documentName].readyState==4){
    if (xmlDoc[oArg.documentName].status==200){
        setTimeout(oArg.callBack,0);
    }
    else{
      alert("Problem retrieving XML data");
    }
  }
};




/*LL2007 specific */

function ProgrammeActs(){

  this.defaultActId = null;
  this.selectedActId = null;
  this.programme = null;
  this.selectedElement = null;
  this.originalContentHeight = null;


  // instance hash
  if (!ProgrammeActs.prototype.instances){
    ProgrammeActs.prototype.instances = [];
  }
  this.instance = ProgrammeActs.prototype.instances.length;
  ProgrammeActs.prototype.instances[this.instance] = this;

  this.setup = function(){
    this.programme = getEl('programme-list');
    if (!this.programme){
      return;
    }
    var list = this.programme.getElementsByTagName('a');
    for (var i = 0; i < list.length; i++){
      if (list[i].className != 'artist_name'){
        continue;
      }
      var aEl = list[i];
      var actId = aEl.getAttribute('href').split('act.php?id=')[1];
      if (!actId){
        continue;
      }
      aEl.setAttribute('actId',actId);
      
      aEl.setAttribute('id','act' + actId);
      aEl.setAttribute('href','javascript:void(0);');
      aEl.setAttribute('progInstance',this.instance);
      aEl.onclick = function(){
        var actId = this.getAttribute('actId');
        var instance = ProgrammeActs.prototype.instances[this.getAttribute('progInstance')];
        instance.getNewAct(actId,this);
      }
    }
    
    //save default height
    this.originalContentHeight = getEl('content-framework').offsetHeight;
    
    if (this.defaultActId) {
    	aEl =	getEl('act' + this.defaultActId);
      if (aEl){
        if ((!getEl('block-mail-a-friend')) || getEl('block-mail-a-friend').offsetTop != 200){
          setScrollTop(aEl.offsetTop  - 50);
        }
      	aEl.onclick();
      }
    }
  }

	this.setDefaultAct = function(actId) {
		this.defaultActId = actId;
	}

  this.openActPage = function(){
    location = 'programme.php?act=' + this.selectedActId + '&mailafriend=1';
  }
  
  // get a new act in XML-format
  this.getNewAct = function(actId,aEl){
    this.selectedActId = actId;
    if (this.selectedElement){
      this.selectedElement.className = 'artist_name';
    }
    aEl.className = 'artist_name active';
    this.selectedElement = aEl;
    if (getEl('act-visual')){
      //alert('sdds');
    }
    getEl('secondary-content').innerHTML = '';
    //alert(act.php?id)
    loadXMLDoc({
      documentPath:'programme-act-blockschedule.php?id='+actId,
      documentName:'progAct',
      callBack:'ProgrammeActs.prototype.instances[' + this.instance + '].onActLoaded()'
    });
  };

  this.onActLoaded = function(){
    var xmlText = xmlDoc['progAct'].responseText;
    var parentEl = getEl('secondary-content');
    parentEl.style.display = 'block';
    parentEl.innerHTML = xmlText;
    linkTop = getScrollTop();
    if (linkTop < 210){
      linkTop = 210;
    }
    parentEl.style.marginTop = linkTop + 'px';

    var actVisualSrc = getEl('act-visual-img').getAttribute('src');
    var actVisual = new FlashObject({
      parentId:'act-visual-container',
      id:'act-visual',
      uri:'_swf/act_visual.swf?imgSrc=' + actVisualSrc,
      className:'flashObject',
      params:{'wmode':'transparent'},
      requiredVersion:8
    });
    
    actVisual.create();
    
    
    var actId = this.selectedElement.getAttribute('actId');
        
    var actMugshot = new FlashObject({
      parentId:'llowlife-visit-container',
      id:'act-mugshot',
      uri:'_swf/act_mugshot.swf?xmlSrc=programme-act-favorites.php?id=' + actId,
      className:'flashObject',
      params:{},
      requiredVersion:8
    });
    actMugshot.create();
        
  }
}







/* picture arroussel*/
function Carroussel(oArg){

  this.rootId = oArg.rootId;
  this.buttonPreviousId = oArg.buttonPreviousId;
  this.buttonNextId = oArg.buttonNextId;
  this.buttonPlayPauseId = oArg.buttonPlayPauseId;
  this.currentPic = 0;
  this.profileId = null;
  this.numPictures = 0;
  this.autoPlay = true;

  // instance hash
  if (!Carroussel.prototype.instances){
    Carroussel.prototype.instances = [];
  }
  this.instance = Carroussel.prototype.instances.length;
  Carroussel.prototype.instances[this.instance] = this;

  this.setup = function(){

    this.root = getEl(this.rootId);
    if (!this.root){
      return;
    }

    this.buttonPrevious = getEl(this.buttonPreviousId);
    this.buttonPrevious.setAttribute('carrId',this.instance);
    this.buttonPrevious.setAttribute('href','javascript:void(0)');
    addEvent(this.buttonPrevious,'click',
      function(){
        Carroussel.prototype.instances[this.getAttribute('carrId')].previous();
      }
    );

    this.buttonNext = getEl(this.buttonNextId);
    this.buttonNext.setAttribute('carrId',this.instance);
    this.buttonNext.setAttribute('href','javascript:void(0)');
    addEvent(this.buttonNext,'click',
      function(){
        Carroussel.prototype.instances[this.getAttribute('carrId')].next();
      }
    );


    //TODO play, pause
    this.buttonPlayPause = getEl(this.buttonPlayPauseId);
    this.buttonPlayPause.setAttribute('carrId',this.instance);
    this.buttonPlayPause.setAttribute('href','javascript:void(0)');
    addEvent(this.buttonPlayPause,'click',
      function(){
        Carroussel.prototype.instances[this.getAttribute('carrId')].playPause(this);
      }
    );

    this.animTimer = setTimeout('Carroussel.prototype.instances[' + this.instance + '].next()',6000);

  }

  this.setNumPictures = function(numPictures){
    this.numPictures = numPictures;
  }

  this.setProfileId = function(id){
    this.profileId = id;
  }

  this.next = function(){
    //alert('');
    this.currentPic++;
    if(this.currentPic > this.numPictures){
      this.currentPic = 1;
    }
    this.getPicture();
  }

  this.previous = function(){
    this.currentPic--;
    if(this.currentPic < 1){
      this.currentPic = this.numPictures;
    }
    this.getPicture();
  }

  this.playPause = function(el){
    if (this.autoPlay){
      this.autoPlay = false;
      el.innerHTML = 'Speel af';
      el.className = 'play';
      clearTimeout(this.animTimer);
    }
    else {
      this.autoPlay = true;
      el.innerHTML = 'Pauze';
      el.className = '';
      this.next();
    }
  }

  // get a new pic in XML-format
  this.getPicture = function(){
    clearTimeout(this.animTimer);
    var reqUrl = 'community-picture.php?picture=' + this.currentPic + (this.profileId ? "&profileid=" + this.profileId : "");
    loadXMLDoc({
      documentPath: reqUrl,
      documentName:'carroussel' + this.instance,
      callBack:'Carroussel.prototype.instances[' + this.instance + '].onPictureLoaded()'
    });
    //urchinTracker(reqUrl);
  };

  this.onPictureLoaded = function(){
    var xmlText = xmlDoc['carroussel' + this.instance].responseText;
    this.root.innerHTML = xmlText;
    if (this.autoPlay){
      this.animTimer = setTimeout('Carroussel.prototype.instances[' + this.instance + '].next()',6000);
    }
    //status = this.currentPic;
  }
}




/* Lowmap */


function PlaneHover(map) {
  this.map=map;
  this.visible = false;
}

try{
  PlaneHover.prototype = new GOverlay();
}
catch(e){

}


PlaneHover.prototype.initialize = function(map) {
  var element = document.createElement("div");
  element.style.position = "absolute";
  map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(element);
  this.element = element;

  // internal hash
  if (!PlaneHover.prototype.instances){
    PlaneHover.prototype.instances = [];
  }
  this.instance = PlaneHover.prototype.instances.length;
  PlaneHover.prototype.instances[this.instance] = this;

  this.element.setAttribute('instance',this.instance);
  this.element.onmouseout = function(){
    PlaneHover.prototype.instances[this.getAttribute('instance')].hide();
  }
}

PlaneHover.prototype.openOnMap = function(point, html) {
  this.offset = new GPoint(0,0);
  this.point = point;
  this.element.innerHTML = html;
  var z = GOverlay.getZIndex(this.point.latitude);
  this.element.style.zIndex = z;
  this.visible = true;
  this.show();
  this.redraw(true);
}

PlaneHover.prototype.openOnMarker = function(marker,html) {
  var vx = marker.getIcon().iconAnchor.x - marker.getIcon().iconAnchor.x;
  var vy = marker.getIcon().iconAnchor.y - marker.getIcon().iconAnchor.y;
  this.openOnMap(marker.getPoint(), html, new GPoint(vx,vy));
}

PlaneHover.prototype.setHideCallBack = function(callBack){
  this.hideCallBack = callBack;
};

PlaneHover.prototype.redraw = function(force) {
  if (!this.visible) {return;}
  var p = this.map.fromLatLngToDivPixel(this.point);
  this.element.style.left  = (p.x -20) + "px";
  this.element.style.top = (p.y -50) + "px";
}

PlaneHover.prototype.remove = function() {
  this.element.parentNode.removeChild(this.element);
  this.visible = false;
}

PlaneHover.prototype.copy = function() {
  return new PlaneHover(this.map);
}

PlaneHover.prototype.show = function() {
  this.element.style.display="";
  this.visible = true;
}

PlaneHover.prototype.hide = function() {
  if (this.hideCallBack){
    setTimeout(this.hideCallBack,0);
  }
  this.element.style.display="none";
  this.visible = false;
}




var LowMap = new function(){
  this.planes = [];
  this.planeIcons = [];
  this.activePlaneNum = null;

  this.create = function(oArg){
    this.latitude = oArg.latitude;
    this.longitude = oArg.longitude;
    addEvent(window,'load',function(){LowMap.render()});
  }

  this.addPlane = function(oArg){
    for (var i = 0; i < this.planes.length;i++){
      if (this.planes[i].planeId == oArg.planeId){
        return;
      }
    }
    this.planes[this.planes.length] = oArg;
  }

  this.createIcons = function(){

    // white plane
    this.planeIcons['planewhite'] = new GIcon();
    this.planeIcons['planewhite'].image = "images/lowmap/maps_plane_white.png";
    this.planeIcons['planewhite'].iconSize = new GSize(23, 23);
    this.planeIcons['planewhite'].iconAnchor = new GPoint(6, 20);
    this.planeIcons['planewhite'].infoWindowAnchor = new GPoint(5, 1);
    this.planeIcons['planewhite'].hasHoverState = true;

    // blue plane
    this.planeIcons['planeblue'] = new GIcon();
    this.planeIcons['planeblue'].image = "images/lowmap/maps_plane_blue.png";
    this.planeIcons['planeblue'].iconSize = new GSize(23, 23);
    this.planeIcons['planeblue'].iconAnchor = new GPoint(6, 20);
    this.planeIcons['planeblue'].infoWindowAnchor = new GPoint(5, 1);
    this.planeIcons['planeblue'].hasHoverState = true;
    
    // draggable plane
    this.planeIcons['planedraggable'] = new GIcon();
    this.planeIcons['planedraggable'].image = "images/lowmap/maps_plane_draggable.png";
    this.planeIcons['planedraggable'].iconSize = new GSize(71, 75);
    this.planeIcons['planedraggable'].iconAnchor = new GPoint(6, 20);
    this.planeIcons['planedraggable'].infoWindowAnchor = new GPoint(5, 1);
    this.planeIcons['planedraggable'].draggable = true;
    this.planeIcons['planedraggable'].hasHoverState = false;
  }

  this.render = function(){
    //status = ('he');
    if (!GBrowserIsCompatible()) {
      //not compatible
      return;
    }

    this.map = new GMap2(document.getElementById("map"));
    this.createIcons();

    this.centerLatitude = this.latitude;
    this.centerLongitude = this.longitude;
    for (var i = 0; i < this.planes.length; i++){
      if (this.planes[i].activePlane == 1){
        this.activePlaneNum = i;
        if(this.planes[i].setCenter){
          this.centerLatitude = this.planes[i].latitude;
          this.centerLongitude = this.planes[i].longitude;
        }
        break;
      }
    }

    this.map.setCenter(new GLatLng(this.centerLatitude, this.centerLongitude), 15,G_SATELLITE_MAP);
    this.planeHover = new PlaneHover(this.map);
    this.map.addOverlay(this.planeHover);
    this.currentPlaneNum = 0;

    if (this.activePlaneNum !== null){
      this.landPlane(this.planes[this.activePlaneNum]);
      this.planeHover.setHideCallBack('LowMap.hover(LowMap.planes[' + this.activePlaneNum + '])');
      this.hover(this.planes[this.activePlaneNum]);
    }

    if (this.mapControl) {
      this.showMapControl();
    }

    if (this.legendaFriends) {
      this.showLegendaFriends();
    }

    this.animTimer = setTimeout('LowMap.sequentialLanding()',10);

    //window.onunload = GUnload;
  }

  this.sequentialLanding = function(){
    for (var i = this.currentPlaneNum; i < this.currentPlaneNum + 10; i++){
      if (i === this.activePlaneNum){ //active plane already made the first landing
        continue;
      }
      if (this.planes.length <= i){
        return;
      }
      this.landPlane(this.planes[i]);
    }
    this.currentPlaneNum += 10;
    this.animTimer = setTimeout('LowMap.sequentialLanding()',5);
  }

  this.landPlane = function(plane){
    plane.marker = new GMarker(new GLatLng(plane.latitude,plane.longitude),{icon:this.planeIcons[plane.planeType],title:plane.planeTitle,draggable:this.planeIcons[plane.planeType].draggable});
    GEvent.addListener(plane.marker, "mouseover", function(){LowMap.hover(plane);});
    this.map.addOverlay(plane.marker);
  }

  this.hoverById = function(id){
    for (var i = 0; i < this.planes.length; i++){
      if (this.planes[i].planeId == id){
        this.hover(this.planes[i]);
        break;
      }
    }
  }
  
  this.getActivePlaneCoords = function(){
    if (this.activePlaneNum === null){
      return;
    }
    return this.planes[this.activePlaneNum].marker.getPoint();
  }
  
  this.getCenterLatitude = function(){
    return this.centerLatitude;
  }
  
  this.getCenterLongitude = function(){
    return this.centerLongitude;
  }
  
  this.hover = function(plane){
    if (!this.planeIcons[plane.planeType].hasHoverState){
      return;
    }
      var w = '';
      w += '<a href="' + plane.url + '" class="maps-' + plane.planeType + '-hover">';
      w += '<div class="overlay-ie"><!-- --></div>';
      w += '<div class="overlay"><!-- --></div>';
      w += '<div class="pic"><img style="" src="' + plane.picture + '" /><!-- --></div>';
      w += '<div class="banner" style="">' + plane.planeTitle + '</div></a>';
      LowMap.planeHover.openOnMarker(plane.marker,w);
  }

  this.setActivePlane = function(planeId){
    //this.activePlaneId = planeId;
  }

  this.addLegendaFriends = function(){
    this.legendaFriends = true;
  }

  this.showLegendaFriends = function(){

    //friendsDiv
    var friendsDiv = document.createElement("div");
    friendsDiv.setAttribute('id','maps-friends');
    this.map.getContainer().appendChild(friendsDiv);

    var friendliesDiv = document.createElement("div");
    friendliesDiv.setAttribute('id','maps-friendlies');
    this.map.getContainer().appendChild(friendliesDiv);

  }

  this.addMapControl = function(){
    this.mapControl = true;
  }

  this.showMapControl = function(){

    //north
    var northDiv = document.createElement("div");
    northDiv.className = 'maps-control';
    northDiv.setAttribute('id','maps-control-north');
    GEvent.addDomListener(northDiv, "click", function() {
      LowMap.map.panDirection(0,1);
    });
    this.map.getContainer().appendChild(northDiv);

    //east
    var eastDiv = document.createElement("div");
    eastDiv.className = 'maps-control';
    eastDiv.setAttribute('id','maps-control-east');
    GEvent.addDomListener(eastDiv, "click", function() {
      LowMap.map.panDirection(-1,0);
    });
    this.map.getContainer().appendChild(eastDiv);

    //south
    var southDiv = document.createElement("div");
    southDiv.className = 'maps-control';
    southDiv.setAttribute('id','maps-control-south');
    GEvent.addDomListener(southDiv, "click", function() {
      LowMap.map.panDirection(0,-1);
    });
    this.map.getContainer().appendChild(southDiv);

    //west
    var westDiv = document.createElement("div");
    westDiv.className = 'maps-control';
    westDiv.setAttribute('id','maps-control-west');
    GEvent.addDomListener(westDiv, "click", function() {
      LowMap.map.panDirection(1,0);
    });
    this.map.getContainer().appendChild(westDiv);

    //zoom in
    var zoominDiv = document.createElement("div");
    zoominDiv.className = 'maps-control';
    zoominDiv.setAttribute('id','maps-control-zoomin');
    GEvent.addDomListener(zoominDiv, "click", function() {
      LowMap.map.zoomIn();
    });
    this.map.getContainer().appendChild(zoominDiv);

    //zoom out
    var zoomoutDiv = document.createElement("div");
    zoomoutDiv.className = 'maps-control';
    zoomoutDiv.setAttribute('id','maps-control-zoomout');
    GEvent.addDomListener(zoomoutDiv, "click", function() {
      LowMap.map.zoomOut();
    });
    this.map.getContainer().appendChild(zoomoutDiv);

  }

  this.showPlaneHover = function(planeId){
    for (var i = 0; i < this.planes.length;i++){
      if (this.planes[i].planeId == planeId){
        this.hover(this.planes[i]);
        break;
      }
    }
  }

  this.hidePlaneHover = function(){
    try {
      this.planeHover.hide();
    }
    catch(e){
    
    }
    return;
  }

}


function setupMapsHoverFromList(){
  var parentEl = getEl('videolist');
  var pageEl = getEl('page-community_videos');
  if (!parentEl){
    parentEl = getEl('pictureslist');
    pageEl = getEl('page-community_pictures')
    if (!parentEl){
      parentEl = getEl('gamepictureslist');
      pageEl = getEl('page-community_gamepictures')
    }
  }
  if (!parentEl || !pageEl){
    return;
  }
  var list = parentEl.getElementsByTagName('a');
  for (var i = 0; i < list.length;i++){
    addEvent(list[i],'mouseover',
    function(){
       var parentId = this.parentNode.parentNode.getAttribute('id');
       var profId = parentId.split('_prof_')[1];
       try {
        LowMap.hoverById(profId);
       }
       catch(e){
       } 
    });

    addEvent(list[i],'mouseout',
    function(){
       LowMap.hidePlaneHover();
    });

  }
}

function setupRegisterLowMap(){
  var formEl = getEl('register2');
  var mode = 'new';
  if (!formEl){
    var formEl = getEl('edit_map');
    mode = 'edit';
    if (!formEl){
      return;
    }
  }
  //alert(formEl);
  formEl.onsubmit = function(){
    try {
      var planeCoords = LowMap.getActivePlaneCoords();
      var centerLatitude = LowMap.getCenterLatitude();
      var centerLongitude = LowMap.getCenterLongitude();
    }
    catch(e){
      alert('gmap problem')
      return false;
    }
    
    getEl('map_latitude').value = planeCoords.lat();
    if ((planeCoords.lat() != centerLatitude && planeCoords.lng() != centerLongitude) || mode == 'edit'){
      getEl('map_longitude').value = planeCoords.lng();
    }
    else {
      getEl('map_longitude').value = '';
    }
  }
}


/* login popup */
function setFrameworkHeight(){
  if (getEl('page-home')){
    return;
  }
  var wH = getWindowHeight();
  var cH = getEl('content-framework').offsetHeight;
  //alert(wH + cH);
  if (wH > cH){
    getEl('content-framework').style.height = (wH -167) + 'px';
  }
}



function setupUserPopup(){
  var elUserPopup = getEl('block-user-popup');
  var elCF  = getEl('framework');
  if (!elUserPopup || !elCF){
    return;
  }
  
  addEvent(getEl('user-popup-close'),'click',hideLoginPopup);
  
  var list = elCF.getElementsByTagName('a');
  for (var i = 0; i < list.length; i++){
    if (list[i].getAttribute('href').indexOf('#block-user-popup') == -1){
      continue;
    }
    
    list[i].setAttribute('href','javascript:void(0)');
    addEvent(list[i],'click',showLoginPopup);
  }

  var list = elUserPopup.getElementsByTagName('span');
  for (var i = 0; i < list.length; i++){
    if (list[i].className == 'error-message'){
      showLoginPopup();
      return;
    }
  }
  var list = elUserPopup.getElementsByTagName('p');
  for (var i = 0; i < list.length; i++){
    if (list[i].className == 'error-message'){
      showLoginPopup();
      return;
    }
  }  
}

function showLoginPopup(){
  getEl('block-user-popup').style.top = '90px';
}

function hideLoginPopup(){
  getEl('block-user-popup').style.top = '-1000px';
}
/*end login popup*/

/* invite popup */
function setupInvitePopup(){
  var elInvitePopup = getEl('block-invite-friends');
  //elInvitePopup.style.height = '1%';
  
  var elCF  = getEl('framework');
  var elLink = getEl('link-invite-friends');
  var elClose = getEl('invite-close');
  
  if (!elInvitePopup || !elCF || !elLink || !elClose){
    return;
  }
  elLink.setAttribute('href','javascript:void(0);');
  addEvent(elLink,'click',showInvitePopup);
    
  addEvent(elClose,'click',
    function(){
      getEl('block-invite-friends').style.top = '-1000px';
    }
  );
  
  //set state
  var list = elInvitePopup.getElementsByTagName('span');
  for (var i = 0; i < list.length; i++){
    if (list[i].className == 'error-message'){
      showInvitePopup();
      return;
    }
  } 
  if (getEl('invite-sent')){
    showInvitePopup();
  } 
}

function showInvitePopup(){
  getEl('block-invite-friends').style.top = '200px';
}

/* end invite popup */


/* mail a friend popup */
function setupMailaFriendPopup(){
  var elMailPopup = getEl('block-mail-a-friend');
  //elInvitePopup.style.height = '1%';
  
  var elCF  = getEl('framework');
  var elLink = getEl('link-mail-a-friend');
  var elClose = getEl('mail-a-friend-close');
  
  if (!elMailPopup || !elCF || !elClose){
    
    return;
  }
  addEvent(elClose,'click',
    function(){
      getEl('block-mail-a-friend').style.top = '-1000px';
    }
  );

  //set state
  var list = elMailPopup.getElementsByTagName('span');
  for (var i = 0; i < list.length; i++){
    if (list[i].className == 'error-message'){
      getEl('block-mail-a-friend').style.top = '200px';
      break;
    }
  } 
  if (getEl('mail-a-friend-succes')){
    getEl('block-mail-a-friend').style.top = '200px';
  }
  //hack
  if (location.href.toString().indexOf('mailafriend') != -1){
    getEl('block-mail-a-friend').style.top = '200px';
  }
  
  if (!elLink){
    return;
  }
  elLink.setAttribute('href','javascript:void(0);');
  addEvent(elLink,'click',showMailaFriendPopup);
  
}

function showMailaFriendPopup(){
  getEl('block-mail-a-friend').style.top = (findPos(getEl('link-mail-a-friend'))[1] - 300) + 'px';
}

/* end a friend popup */

/* new questions  popup */
function setupNewQuestionsPopup(){
  var elClose = getEl('block-new-questions-close');
  if (!elClose){
    return;
  }
  addEvent(elClose,'click',
    function(){
      getEl('block-new-questions').style.top = '-1000px';
    }
  );
}
/* end new questions  popup */





function createHomeNewsHovers(){
  var pageHome = getEl('page-home');
  if (!pageHome){
    return;
  }
  var list = getEl('news').getElementsByTagName('a');
  for (var i = 0; i < list.length; i++){
    if (i == 0){
      list[i].className = 'active';
    }
    list[i].onmouseover = function(){
      getEl('news').getElementsByTagName('a')[0].className = '';
      this.className = 'active';
    }
    list[i].onmouseout = function(){
      this.className = '';
      getEl('news').getElementsByTagName('a')[0].className = 'active';
    }
  }
}

/* tbv audio popup */

// add event 

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  }
  else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, function() { fn.apply(obj); });
    return r;
  }
  else {
    alert("Handler could not be attached");
  }
};

function setCookie(cookieName,cookieValue,nDays) {
  var today = new Date();
  var expire = new Date();
  if (nDays==null || nDays==0) nDays=1;
  expire.setTime(today.getTime() + 3600000*24*nDays);
  document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function getCookie(c_name){
  if (document.cookie.length>0){
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1){ 
      c_start=c_start + c_name.length+1 
      c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end));
      } 
    }
  return null;
}


function setupAudioPopup(){
  var elAudio = getEl('audio-popup');
  if (!elAudio){
    return;
  }
  //elAudio.setAttribute('href','javascript:void(0)');
  elAudio.onclick = function(){
    var pHeight,pWidth;
    if (browser.winIE6Down){
      pHeight = 250;
      pWidth = 200;
    }
    else if (browser.winIE){
      pHeight = 250;
      pWidth = 100;
    }
    else {
      pHeight = 250;
      pWidth = 200;
    }
    var audioPopup = window.open("audio_popup.php","audipopup","height=" + pHeight +",width=" + pWidth +",status=no,toolbar=no,menubar=no,location=no,scrollbars=no, resizable=no");
    //var audioPopup = window.open('http://www.fabrique.nl',"audio_popup", "width=200, height=300, scrollbars=no, resizable=no");
    return false;
  }
}


function setupNewsLetterPopup(){
  var el = getEl('nav-news_newsletter');
  if (!el){
    return;
  }
  var aEl = el.getElementsByTagName('a')[0];
  aEl.onclick = function(){
    var audioPopup = window.open(this.href,"nieuwsbrief","height=480,width=720,status=no,toolbar=no,menubar=no,location=no,scrollbars=no, resizable=no");
    return false;
  }
}


function setupActionCarroussel(){
  var el = getEl('block-action');
  if (!el){
    return;
  }
  var list = el.getElementsByTagName('li');
  if (list.length < 1){
    return;
  }
  setActiveActionButton(list[Math.floor(Math.random() * list.length)]);
  setInterval('switchActiveActionButton()',8000);
}


function switchActiveActionButton(){
  var el = getEl('block-action');
  var list = el.getElementsByTagName('li');
  var activeFound = false;
  for (var i = 0; i < list.length; i++){
    if (list[i].className == 'active'){
      activeFound = true;
      list[i].className = '';
    }
    else if (activeFound){
      setActiveActionButton(list[i]);
      return;
    }
  }
  if (list[0]){
    setActiveActionButton(list[0]);
  }
}

function setActiveActionButton(el){
      el.className = 'active';
      //dirty hack for essent no flowers
      var elAction = el.parentNode.parentNode;
      if(el.id == 'action-essent' || el.id == 'action-grolsch'){
        elAction.className = 'block no-flowers';
      }
      else {
        elAction.className = 'block';
      }
      //end dirty hack for essent
}

function setupProfilesList() {
    if (browser.winIE && getEl('profileslist')) {
        var el = getEl('profileslist');
        var list = el.getElementsByTagName('li');
        var c = 0;
        for (var i = list.length - 1; i >= 0; i--) {
            list[i].style.position = 'relative';
            list[i].style.zIndex = c++ + 1000;
        }
    }
}



/* programme fly and land plane */

function flyPlane(){
  var containerEl = document.getElementById('llowlife-visit-container');
  //document.body.style.overflow = 'hidden';
  var w = getWindowWidth() - getEl('framework').offsetLeft - 704;
  if (w < 121) {
    w = 121;
  }
  containerEl.style.width = w + 'px';
  containerEl.style.height = '731px';
  containerEl.style.top= '-264px';
  setFrameworkHeight();
}
function landPlane(){
  var containerEl = document.getElementById('llowlife-visit-container');
  containerEl.style.width = '121px';
  containerEl.style.height = '131px';
  containerEl.style.top= '36px';
}


/* llov 06 (VBO) */
function setupGallery(){
  var gallery2007 = document.getElementById('page-beeld_fotos');
  if (gallery2007){
    fillGallery(1, 'llow08', 48);
  }
  /*
  var gallery2006 = document.getElementById('page-more-stuff_llov06');
  if (gallery2006){
    fillGallery(1, 'llov06', 50);
  }*/
}

function pad(number,length) {
  var str = '' + number;
  while (str.length < length)
  str = '0' + str;
  return str;
}

function fillGallery(page, folder, totalPics) {
  var pics = 10; // Aantal getoonde afbeeldingen per pagina
  var start = (page - 1) * pics + 1;
  var end = start + (pics - 1);
  var total = totalPics // Totaal aantal afbeeldingen
  var totalPages = total / pics;
  var i = start;
  document.getElementById('gallery').innerHTML = '';

  while (i <= end && i <= total) {
    document.getElementById('gallery').innerHTML += '<li><a onclick="document.getElementById(\'gallery_image\').src = this.href; return false;" href="images/festival/'+folder+'/'+pad(i,3)+'.jpg"><img src="images/festival/'+folder+'/'+pad(i,3)+'_thumb.jpg" /></a></li>';
    i++;
  }

  if (page > 1) {
    var prevPage = page - 1;
    document.getElementById('prevButton').innerHTML = '<a onclick="fillGallery('+prevPage+', \''+folder+'\', '+totalPics+');" href="#">Vorige</a>';
  }else {
    document.getElementById('prevButton').innerHTML = 'Vorige';
  }
  
  if (page < totalPages) {
    var nextPage = page + 1;
    document.getElementById('nextButton').innerHTML = '<a onclick="fillGallery('+nextPage+', \''+folder+'\', '+totalPics+');" href="#">Volgende</a>';
  }else {
    document.getElementById('nextButton').innerHTML = 'Volgende';
  }
  
}
/*end llov 06*/


/*blokkenschema*/

/*remember days in blokkenschema*/
function setBlokkenschemaDay(day){
	setCookie('blokkenschemaDay',day,365);
};

function getBlokkenschemaDay(){
	var day = getCookie('blokkenschemaDay');
	if (!day){
		day = 1;
	}
	return day;
};

/*end blokkenschema*/

function setupGameFormToggler (){
  var fieldsetFoto = getEl('fieldset-foto');
  var fieldsetFilm = getEl('fieldset-film');
  if ((!fieldsetFoto) && (!fieldsetFilm)){
    return;
  }
  if ((!fieldsetFoto)){
    fieldsetFilm.style.display = 'block';
    return;
  }
  if ((!fieldsetFilm)){
    fieldsetFoto.style.display = 'block';
    return;
  }
  var radioFoto = getEl('entry_type_1');
  var radioFilm = getEl('entry_type_2');
  if (radioFoto.checked){
    fieldsetFoto.style.display = 'block';
  }
  else if (radioFilm.checked){
    fieldsetFilm.style.display = 'block';
  }
  radioFoto.onclick = function(){
    getEl('fieldset-foto').style.display = 'block';
    getEl('fieldset-film').style.display = 'none';
  }
  radioFilm.onclick = function(){
    getEl('fieldset-foto').style.display = 'none';
    getEl('fieldset-film').style.display = 'block';
  }
}

/*earlybird popup*/

function setupEarlybirdPopup(lang){
  var popupId = 'block-earlybird-' + lang + '-popup';
  var elPopup = getEl(popupId);
  var elLink = getEl('earlybird-' + lang + '-popup-link');
  if (!(elPopup && elLink)){
    return;
  }
  elLink.setAttribute('earlybirdPopupId',popupId);
  
  elLink.setAttribute('href','javascript:void(0)');
  addEvent(elLink,'click',
    function(){
      var popup = getEl(this.getAttribute('earlybirdPopupId'));
      popup.style.left = '222px';
      var elIFrame = getEl('llowlog-iframe');
      if (elIFrame){ //iframe swf shows through popup
        elIFrame.style.display = 'none';
      }
    }
  );
  
  var elClose = getEl('earlybird-' + lang + '-popup-close');
  addEvent(elClose,'click',
    function(){
      this.parentNode.parentNode.style.left = '-1000px';
      var elIFrame = getEl('llowlog-iframe');
      if (elIFrame){ //iframe swf shows through popup
        elIFrame.style.display = '';
      }
    }
  );
}

/*earlybird popup*/

function setupNavigationHovers(elements){
  for (var i = 0; i < elements.length; i++){
    var el = getEl(elements[i]);
    if (!el){
      continue;
    }
    var list = el.getElementsByTagName('a');
    for (var j = 0; j < list.length; j++){
      if (list[j].parentNode.className.indexOf('active') != -1){
        continue;
      }
      addEvent(list[j],'mouseover',
        function(){
          this.parentNode.className = 'hover';
        }
      );
      addEvent(list[j],'mouseout',
        function(){
          this.parentNode.className = '';
        }
      );
    }
  }
}

function setupRandomSideBarStitches() {
  var el = getEl('secondary-content');
  if (!el){
    return;
  }
  var list = el.getElementsByTagName('p');
  for (var i = 0; i < list.length; i++){
    var elP = list[i];
    elP.className += ' type-' + Math.ceil(Math.random() * 5);
  }
}


var Panic = {

  //vars:
  transAmount: 0,
  transitionSpeed: 3,
  elHeart : null,
  
  //arrays
  /*list : {
    'home':{
      'hide':[
        'block-user-popup',
        'block-logo-animation'
      ],
      'scroll':[
        'block-payoff',
        'navigation',
        'block-audio-popup',
        'block-banner',
        'block-sponsors',
        'column-festival',
        'column-llowlife'
      ]
    },
    'sub':{
      'hide':[
        'block-user-popup',
        'block-logo-animation',
      ],
      'scroll':[
        /*'block-profile',
        'block-payoff',
        'navigation',
        'block-audio-popup',
        'block-banner',
        'block-sponsors',
        'secondary-content',
        'content'
        'framework'
      ]
    }
  },*/
  
  list : {
    'home':{
      'hide':[
        'block-user-popup',
        'block-logo-animation',
        'block-mail-a-friend'
      ],
      'scroll':[
        'framework'
      ]
    },
    'sub':{
      'hide':[
        'block-user-popup',
        'block-logo-animation',
        'block-mail-a-friend'
      ],
      'scroll':[
        'framework'
      ]
    }
  },
  
  //setup
  setup : function(){
    var el = getEl('button-panic');
    if (!el){
      return;
    }
    el.setAttribute('href','javascript:void(0);');
    addEvent(el,'click',Panic.start);
  },
  
  //start it up 
  start : function(){
    
    //define current page
    var current = getEl('page-home') ? 'home' : 'sub';
    
    
    var hideList = getEl('framework').childNodes;
    for (var i = 0; i < hideList.length; i++){
      var el = hideList[i];
      if (el.nodeType != 1){
        continue;
      }
      if (el.getAttribute('id') == 'block-logo'){
        continue;
      }
      el.style.display = 'none';
    }
    
    //prepare animation
    //var elHTML = document.getElementsByTagName('html')[0];
    //elHTML.style.overflow = 'hidden';
    //getEl('content-framework').style.background = 'none';
    //getEl('framework').style.background = 'none';
    setScrollTop(0);
    getEl('block-logo').style.overflow = 'hidden';
    //create heart
    var elHeart = document.createElement('a');
    elHeart.setAttribute('href',window.location.href);
    elHeart.setAttribute('id','panic-heart');
    elHeart.setAttribute('title','We llov you!');
    elHeart.appendChild(document.createTextNode('We llov you!'));
    getEl('framework').style.background = 'none';
    getEl('content-framework').style.background = 'none';
    getEl('framework').appendChild(elHeart);
    Panic.elHeart = elHeart;
    
    //set fade to 0
    //Panic.setOpacity(elHeart,0);
    
    
    //hide it
    /*var hideList = Panic.list[current]['hide'];
    for (var i = 0; i < hideList.length; i++){
      var el = getEl(hideList[i]);
      if (!el){
        continue;
      }
      el.style.display = 'none';
    }*/
    
    
    
    
    //scroll it
    /*var scrollList = Panic.list[current]['scroll'];
    for (var i = 0; i < scrollList.length; i++){
      var el = getEl(scrollList[i]);
      if (!el){
        continue;
      }
      //var callBack = i == scrollList.length - 3 ? 'Panic.onanimFinished()' : '';
      var callBack = 'Panic.onanimFinished()';
      setTimeout('Panic.animate(getEl("' + scrollList[i] + '"),"' + callBack +'")',i * 150);
    }*/
    
  },
  
  //default animation
  animate : function(el,callBack){
    animate({
      timerName:el.id,
      elements:Array(
        {id:el.id,style:'marginTop',startPos:el.offsetTop,negMove:false},
        {id:'block-logo',style:'marginTop',startPos:0,negMove:true}
      ),
      dist:2000,
      speed:27,
      easeIn:5,
      easeOut:15,
      callBack:callBack
    });
  },
  
  onanimFinished : function(el){
    //Panic.fadeIn();
    getEl('block-logo').style.marginTop = '-2000px';
  },
  
  // looping function to fade in
  fadeIn : function(el){
    if (Panic.transAmount > 100){
      Panic.transAmount = 100;
    }
    else {
      Panic.transAmount += Panic.transitionSpeed;
    }
    Panic.setOpacity(Panic.elHeart,this.transAmount);
    if (Panic.transAmount < 100){
      var animTimer = setTimeout('Panic.fadeIn()',40);
    }
  },
  
  // the actual cross browser fading effect
  setOpacity : function(el,opac){
    if (typeof el.filters != 'undefined'){
      //status = 'filters';
      el.filters.alpha.opacity = opac;
    }
    else {
      //status = 'opacity';
      el.style.opacity = opac / 101;
    }
  }
  
}



// set external links
var setExternalLinks = function(){
  var localDomain = (location.href.split('/')[2]);
    
    var localExtensionsInNewWindow = Array('doc','xls','pdf');
    
    for (var a = 0; a < arguments.length; a++){
      var rootNode = getEl(arguments[a]);
      if (!rootNode){
        continue;
      }
      //alert(rootNode);
      var list = document.getElementsByTagName('A');
      for (var i = 0; i < list.length; i++){
        var aEl = list[i];
        var aElHref = aEl.href;
        
        // check for extensions
        var extension = (aElHref.substring(aElHref.length - 4,aElHref.length)).toLowerCase();
        var foundExtension = false;
        for (var j = 0; j < localExtensionsInNewWindow.length; j++){
          if (extension == '.' + localExtensionsInNewWindow[j]){
            foundExtension = true;
            break;
          }
        }
        
        // open in new window if conditions are right
        if ((aElHref.split('/')[2] != localDomain && aElHref.indexOf('mailto:') == -1 && aElHref.indexOf('javascript:') == -1) || foundExtension){
          aEl.onclick = function(){
          window.open(this.href);
          return false;
        }
      }
    }
  }
};


/* faceculture video player */
function createActVideoPop(key){
  
  if (getEl('acts-video-popup')){ //bestaat al
    //alert('nee');
    return;
  }
  getEl('acts-video-container').innerHTML = 
    '<div class="popup" id="acts-video-popup">' +
    '<div class="top"><!-- --></div>' +
    '<div class="content">' +
    '<div class="button-close">' +
    '<a id="acts-video-popup-close" href="javascript:void(0);">Sluit popup</a>' +
    '</div>' +
    '<div id="vs_div_video"></div>' +
    '</div>' +
    '<div class="bottom"><!-- --></div>' +
    '</div>';
    
  getEl('acts-video-popup-close').onclick = 
   function(){
    getEl('acts-video-container').innerHTML = '';
  }
  
  changeVideo(key, "vs_div_video");
}


/* code van filmpstrip, heavily modified: wordt nu niet gebruikt */
var g_play_key = 23939566;

// Set height and width for FaceCulture
var FaceculturePlayerHeight = '283';
var FaceculturePlayerWidth = '352'

function changeVideo(key, elementId, clickToStart){
  var elm = document.getElementById(elementId);
  if (!elm){
    return;
  }
  //default click to start
  if (typeof clickToStart == 'undefined'){
    var clickToStart = 1;
  }
  // create the IFRAME
  elm.innerHTML = '<iframe style="background-color:transparent; overflow:hidden;" id="' + "vs_iframe_video-" + elementId + '" src="faceculture_vids.php?player_width=' + FaceculturePlayerWidth +'&player_height=' + FaceculturePlayerHeight + '&cnti_key=' + key + '&play_key=' + g_play_key + '&click_to_start=' + clickToStart +'" width="' + FaceculturePlayerWidth + '" height="' + FaceculturePlayerHeight + '" ALLOWTRANSPARENCY="true" frameborder="0" scrolling="no"><\/iframe>';
}
/* end code van filmpstrip */
/* end faceculture video player */

/* muziekagenda*/

var muziekAgendaTimer = null;
function setupMuziekAgendaScroller(){
  var el = getEl('muziekagenda-scroller');
  if (!el){
    return;
  }
  muziekAgendaTimer = setTimeout('scrollMuziekAgenda()',1500);
  var list = el.getElementsByTagName('a');
  for (var i = 0; i < list.length; i++){
    setExternalLinks('block-muziekagenda');
    addEvent(list[i],'mouseover',
      function(){
        clearTimeout(muziekAgendaTimer);
      }
    );
     addEvent(list[i],'mouseout',
      function(){
        muziekAgendaTimer = setTimeout('scrollMuziekAgenda()',500);
      }
    );
  }
  
}

function scrollMuziekAgenda(){
  var el = getEl('muziekagenda-scroller');
  var elParent = el.parentNode;
  var top = el.offsetTop;
  var height = el.offsetHeight;
  if (-top + elParent.offsetHeight >= height){
    muziekAgendaTimer = setTimeout(
      'getEl(\'muziekagenda-scroller\').style.marginTop = \'0px\';muziekAgendaTimer = setTimeout("scrollMuziekAgenda()",1500)',
      1500);
    return;
  }
  top -= 5;
  el.style.marginTop = top + 'px';
  muziekAgendaTimer = setTimeout('scrollMuziekAgenda()',150);
}

/* end muziekagenda*/






/***
 * Fabrique, dra, Lowlands 2008 - blokkenschema
 */

 
 
/***
 * Setup printlink
 */
function setupPrint() {
  var el = getEl('print');
  if (!el)
    return false;
  
  addEvent(el, 'click', function() {
    print();
    return false;
  });
}

 
 
/***
 * Setup calendar importfeature
 */
function setupCalDownloads() {
  var anchors = document.getElementsByTagName("A");
  for(var i = 0; i < anchors.length; i++) {
    if(anchors[i].className.indexOf('caltype') !== -1) {
      addEvent(anchors[i], 'click', function() {
        var favOnly = getEl('lineup-favourite');
        var favFlag = '&fav=1';
        var downloadFav = this.href.indexOf(favFlag);
                
        if(favOnly.checked == true) {
          if(downloadFav == -1)
            this.href += favFlag;
        }
        else if(downloadFav !== -1) {
          this.href = this.href.substring(0, downloadFav);
        }
      });
    }
  }
}


function setupToggleSchemeSize(){
  var el = getEl('viewtype-link');
  if (!el){
    return;
  }
  
  addEvent(el, 'click', function() {
    var el = getEl('stages');
    if (!el){
      return;
    }
    var fontSize = el.style.fontSize;
    el.style.fontSize = 
      (!el.style.fontSize) || el.style.fontSize == '90%' ? '130%' : '90%';
  });
}



/*
  mostly (dirty) copied from program acts 
*/

function BlokkenschemaActs(){

  this.defaultActId = null;
  this.selectedActId = null;
  this.programme = null;
  this.selectedElement = null;
  this.originalContentHeight = null;
  this.imagePath = 'images/festival/';


  // instance hash
  if (!BlokkenschemaActs.prototype.instances){
    BlokkenschemaActs.prototype.instances = [];
  }
  this.instance = BlokkenschemaActs.prototype.instances.length;
  BlokkenschemaActs.prototype.instances[this.instance] = this;

  this.setup = function(){
    this.programme = getEl('stages');
    if (!this.programme){
      return;
    }
    var list = this.programme.getElementsByTagName('li');
    for (var i = 0; i < list.length; i++){
      var aEl = list[i];
      if (aEl.className != 'scheme-act'){
        continue;
      }
      var actId = aEl.getAttribute('id').split('act')[1];
      aEl.setAttribute('actId',actId);

      aEl.setAttribute('progInstance',this.instance);
      
      aEl.onclick = function(){
        var actId = this.getAttribute('actId');
        var instance = BlokkenschemaActs.prototype.instances[this.getAttribute('progInstance')];
        instance.getNewAct(actId,this);
        //alert(actId);
      }
    }
  }
  
  // get a new act in XML-format
  this.getNewAct = function(actId,aEl){
    this.selectedActId = actId;
    if (this.selectedElement){
      
    }
    this.selectedElement = aEl;
    loadXMLDoc({
      documentPath:'programme-act-blockschedule.php?id='+actId,
      documentName:'schemaAct',
      callBack:'BlokkenschemaActs.prototype.instances[' + this.instance + '].onActLoaded()'
    });
  };

  this.onActLoaded = function(){
  
    //fill XML (dirty, no time)
    
    //close button
    var xmlText = xmlDoc['schemaAct'].responseText;
    var parentEl = getEl('act-container-content');
    parentEl.innerHTML = '<a href="javascript:void(0)" id="act-container-close">sluit</a>';
    
    // time
    var list = this.selectedElement.getElementsByTagName('span');
    var strTime = '';
    for (var i = 0; i < list.length; i++){
      var cN = list[i].className;
      if (cN == 'dtstart'){
        strTime += list[i].innerHTML;
      }
      else if (cN == 'dtend'){
        strTime += ' - ' + list[i].innerHTML;
        break;
      }
    }
    parentEl.innerHTML += '<div class="act-time">' + strTime + '</div>';
    
    //xml text
    parentEl.innerHTML += xmlText;
    
    //sluit button behaviour
    getEl('act-container-close').onclick = function(){
      this.parentNode.parentNode.style.left = '-1000px';
    }
    
    //positioning
    var positioner = getEl('act-container');
    var pLeft = this.selectedElement.offsetLeft - this.programme.scrollLeft  + 200;
    if (pLeft > this.programme.offsetWidth - 350){
      pLeft = this.programme.offsetWidth - 350;
    }
    positioner.style.left = pLeft + 'px';
    var pTop = findPos(this.selectedElement)[1] - 170;
    if (pTop + parentEl.offsetHeight > this.programme.offsetHeight + 200){
      pTop = 200;
    }
    positioner.style.top = pTop + 'px';
    
    //voeg swf toe
    var actId = this.selectedElement.getAttribute('actId');
    var actMugshot = new FlashObject({
      parentId:'llowlife-visit-container',
      id:'act-mugshot',
      uri:'_swf/act_mugshot.swf?xmlSrc=programme-act-favorites.php?id=' + actId,
      className:'flashObject',
      params:{},
      requiredVersion:8
    });
    actMugshot.create();
    
	var actAnchors = parentEl.getElementsByTagName('a');
	for(var i = 0, len = actAnchors.length; i < len; i++) {
	  if(actAnchors[i].className.indexOf('is-favorite') > -1 || actAnchors[i].className.indexOf('add-favorite') > -1) {
	    actAnchors[i].onclick = function() {
	      addRemoveFavorite(actId, this);
		  return false;
		}
	  }
	  
	  if(actAnchors[i].className.indexOf('show-login') > -1) {
	    actAnchors[i].onclick = function() {
		  showLoginPopup();
		  return false;
		}
	  }
	}
	
    //set act-toggler
    addRemoveFavorite.schemaActsInstance = this.instance;
    addRemoveFavorite.callBack = function(){
      var scheme = BlokkenschemaActs.prototype.instances[addRemoveFavorite.schemaActsInstance];
      var divTheme = scheme.selectedElement.getElementsByTagName('div')[0];
      var classNames = divTheme.className.split(' ');
      var isFav = false;
      var cNString = '';
      var space = '';
      var shimStr = '';
      for (var i = 0; i < classNames.length; i++){
        if (classNames[i] == 'favourite'){
          isFav = true;
          continue;
        }
        if (classNames[i].indexOf('theme') != -1){
          shimStr = classNames[i];
        }
        lastCN = classNames[i];
        cNString += space + classNames[i];
        space = ' ';
      }
      if (!isFav){
        cNString += space + 'favourite';
        shimStr = 'favourite';
      }
      divTheme.className = cNString;
      
      //alert(shimStr);
      //image moet gelijk mee veranderen voor print (zucht)
      var imgShim = scheme.selectedElement.getElementsByTagName('img')[0];
      if (imgShim){
        imgShim.setAttribute('src',scheme.imagePath + 'blok_print_shim_' + shimStr + '.gif');
      }
    }
  }
}


function addRemoveFavorite(actId,element){
  if (!addRemoveFavorite.callBack){
    addRemoveFavorite.callBack = function(){
      return;
    };
  }
  element.className = element.className == '' ? 'is-favorite' : '';
  loadXMLDoc({
    documentPath:'programme-add-fav.php?id='+actId,
    documentName:'programme-add-fav',
    callBack:addRemoveFavorite.callBack
  });
}


/* llowbite intro */

function showBlogIntro(){
  var el = getEl('block-blogpost');
  if (!el){
    return;
  }
  var list = el.getElementsByTagName('div');
  for (var i = 0; i < list.length; i++){
    var elContainer = list[i];
    if (elContainer.className != 'text'){
      continue;
    }
    elContainer.style.display = 'block';
    var text = typeof elContainer.innerText != 'undefined' 
      ? elContainer.innerText : elContainer.textContent;
    
    var blogPost = elContainer.getAttribute('id').split('-')[1];
    elContainer.innerHTML = '<p>' + text.substring(0,200) + '... <a href="community_llowbite.php?blogpost=' + blogPost + '">lees verder</a></p>';
  }
}