var requiredVersion = 5;
var useRedirect = false;

var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var flash8Installed = false;
var flash9Installed = false;
var flash10Installed = false;

var maxVersion = 10;
var actualVersion = 0;
var hasRightVersion = false;
var jsVersion = 1.0;

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;   // true if we're on ie
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // true if we're on windows

if(isIE && isWin){ // don't write vbscript tags on anything but ie win
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
  document.write('flash10Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.10"))) \n');
  document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}

jsVersion = 1.1;
detectFlash = function(){
  if (navigator.plugins) {  // does navigator.plugins exist?
    if (navigator.plugins["Shockwave Flash 2.0"]
  || navigator.plugins["Shockwave Flash"]){

    var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
    var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
    var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

    flash2Installed = flashVersion == 2;
    flash3Installed = flashVersion == 3;
    flash4Installed = flashVersion == 4;
    flash5Installed = flashVersion == 5;
    flash6Installed = flashVersion == 6;
    flash7Installed = flashVersion == 7;
    flash8Installed = flashVersion == 8;
    flash9Installed = flashVersion == 9;
    flash10Installed = flashVersion == 0;
    }
  }

  for (var i = 2; i <= maxVersion; i++) {
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }

  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 2;

  if (actualVersion >= requiredVersion) {
    hasRightVersion = true;
    if (useRedirect) {
      if(jsVersion > 1.0) {
        window.location.replace(flashPage);
      } else {
        window.location = flashPage;
      }
    }
  } else {
    if (useRedirect) {
      if(jsVersion > 1.0) {
        window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
      } else {
        window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
      }
    }
  }
}

writeFlash = function(s,w,h,a,l) {

  var loop = l;
  if (loop == '') {
  	loop = 'false';
  }

  var alternateContent = a;
  if (alternateContent == '') {
    alternateContent = 'Voor deze site heeft u <a target="_blank" href="http://www.microsoft.com/download/">Microsoft Internet Explorer</a> versie 5.5 (of hoger) en de <a target="_blank" href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&P5_Language=English">Macromedia Flash plugin</a> versie ' + requiredVersion + ' (of hoger) nodig.'
  }

  var flashContent = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="'+w+'" HEIGHT="'+h+'" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
  + '<PARAM NAME="MOVIE" VALUE="'+s+'">'
  + '<PARAM NAME="PLAY" VALUE="true">'
  + '<PARAM NAME="LOOP" VALUE="'+loop+'">'
  + '<PARAM NAME="QUALITY" VALUE="high">'
  + '<PARAM NAME="MENU" VALUE="false">'
  + '<PARAM NAME="WMODE" VALUE="transparent">'
  + '<EMBED SRC="'+s+'" WIDTH="'+w+'" HEIGHT="'+h+'" PLAY="true" LOOP="'+loop+'" QUALITY="high" MENU="false" WMODE="transparent" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>'
  + '<NOEMBED>' + alternateContent + '</NOEMBED></OBJECT>';

  if (hasRightVersion) {
    document.write(flashContent);
  } else {
    document.write(alternateContent);
  }
}

function ButtonOver(id){
	var id;
	document.getElementById('button'+id).style.backgroundPosition="right -21px";
	document.getElementById('buttonSpan'+id).style.backgroundPosition="left -21px";
}
function ButtonOut(id){
	var id;
	document.getElementById('button'+id).style.backgroundPosition="right top";
	document.getElementById('buttonSpan'+id).style.backgroundPosition="";
}
function ButtonOverB(id){
	var id;
	document.getElementById('button'+id).style.backgroundPosition="right -20px";
	document.getElementById('buttonSpan'+id).style.backgroundPosition="left -21px";
}
function ButtonOutB(id){
	var id;
	document.getElementById('button'+id).style.backgroundPosition="right +1px";
	document.getElementById('buttonSpan'+id).style.backgroundPosition="";
}

function expand(id,rootId){
	var id;
	document.getElementById(rootId).style.display='none';
	document.getElementById(id).style.display='block';
}

function fold(id,rootId){
	var id;
	document.getElementById(rootId).style.display='block';
	document.getElementById(id).style.display='none';
}

function selecttabA(id){
	var id,now;
	now=parseInt(document.getElementById('ArivalActive').value);
   	document.getElementById('tab'+now).style.display='none';
   	document.getElementById('tab'+id).style.display='block';
 	document.getElementById('ArivalActive').value=id;
  	if(id==1) {
  		document.getElementById('tabS'+now).className="departures ";
  		document.getElementById('tabS'+id).className="arrivals selected arrivals-selected arrivals-hover";
	} else if(id==2) {
		document.getElementById('tabS'+now).className="arrivals ";
      	document.getElementById('tabS'+id).className="departures selected departures-selected ";
	}
}

function switchTab(tabRoot,tabItem) {
	var tabRoot,tabItem,tabList;
	tabList = document.getElementById(tabRoot);
	tabItem = 'li' + tabItem;
	if (tabList != null && tabList != '') {
		for (var i in tabList.childNodes) {
			node = tabList.childNodes[i];
			if (node.nodeName == 'LI') {
				tabContent = 'content' + node.id;
				if (node.className.indexOf('selected') != -1 && node.id != tabItem) {
					node.className = '';
					tabContent = document.getElementById(tabContent);

					if (tabContent != null) {
						tabContent.style.display = "none";
					}
				} else if (node.id == tabItem) {
					node.className = 'selected';
					tabContent = document.getElementById(tabContent);
					if (tabContent != null) {
						tabContent.style.display = "block";
					}
				}
			}
		}
	}
}

function getLastVisited() {
	var cookieName = 'lastvisited';
	var value = getCookieValue(cookieName);
	if (value == null || value == '') {
		return '';
	}

	value = unescape(value);
	return value.split(';');

}

function addLastVisited(url, title) {
	// http://nu.nl|Nu;http://www.feyenoord.nl|Feyenoord
	if (isAlreadyInVisited(title)) {
		return;
	}
	var cookieName = 'lastvisited';
	var value = getCookieValue(cookieName);
	if (value == null) {
		value = '';
	}

	var visitedUrl = url + '|' + title + ';';
	var lastVisitedUrls = value.split(';');
	lastVisitedUrls.push(visitedUrl);
	// Remove the first element of the array when their are more then 6 elements
	if (lastVisitedUrls.length > 6) {
		lastVisitedUrls.shift();
	}
	var lastVisitedCookieValue = lastVisitedUrls.join(';');
	placeCookie(cookieName, lastVisitedCookieValue);
}

function isAlreadyInVisited(title) {
	var cookieName = 'lastvisited';
	var value = getCookieValue(cookieName);
	if (value == null) {
		return false;
	}

	var lastVisitedUrls = value.split(';');
	for (i=0;i<lastVisitedUrls.length;i++) {
		lastVisitedUrl = lastVisitedUrls[i];
		lastVisited = lastVisitedUrl.split('|');
		if (lastVisited != null) {
			urlTitle = lastVisited[1];
			if (title == urlTitle) {
				return true;
			}
		}
	}
	return false;

}

function placeCookie(cookiename, value) {
	var name = cookiename;
	var expire = '3650';
	var expires = new Date();
    expires.setTime(expires.getTime() + (expire*24*60*60*1000));
	document.cookie = name + '=' + escape(value) + ((expire == null) ? '' : ('; expires=' + expires.toGMTString())) + '; path=/';
}

function getCookieValue(cookiename) {
	var cookie = getCookie(cookiename);

	var value = '';
	if (cookie == null || cookie == '') {
		value = ''
	} else {
		value = unescape(cookie);
	}

	return value;
}

function saveTabCookie(tab) {
	placeCookie('savedtabposition', tab);
}

function getSavedTabPosition() {
	var savedTab = getCookieValue('savedtabposition');
	var tabEl, tab;
	if (savedTab != null && savedTab != '') {
		tabEl = savedTab.slice(0,savedTab.indexOf('|'));
		tab = savedTab.slice(savedTab.indexOf('|')+1);
		switchTab(tabEl,tab);
	}
}

// datepicker
$(function(){
	if ($('.date-pick')[0] && $('.date-pick')[0].name != 'df') {
		var dayAfterTomorrow = new Date();
		var endDate = new Date();
		dayAfterTomorrow.setDate(dayAfterTomorrow.getDate() + 2);
		endDate.setDate(endDate.getDate() + 320);
		$('.date-pick').datePicker();
		$('.date-pick').dpSetStartDate(dayAfterTomorrow.asString());
		$('.date-pick').dpSetEndDate(endDate.asString());
		$('.date-pick').dpSetOffset(20, -160);
		$('.date-pick:first').bind(
		'dpClosed',
			function(e, selectedDates)
			{
				var d = selectedDates[0];
				if (d) {
					d = new Date(d);
					$('.date-pick:last').dpSetStartDate(d.addDays(1).asString());
					$('.date-pick:last').dpSetSelected(d.asString());
				}
			}
		);
	} else {
		var startDate = new Date();
		var endDate = new Date();
		startDate.setDate(startDate.getDate() - 356);
		$('.date-pick').datePicker();
		$('.date-pick').dpSetStartDate(startDate.asString());
		$('.date-pick').dpSetEndDate(endDate.asString());
		$('.date-pick').dpSetOffset(20, -160);
	}
});


/* shadowbox conflict sitestat fix */
function openShadowBox(url, type, title, height, width){
	Shadowbox.open({
	    content:    "" + url + "",
	    player:	"" + type + "",
	    title:      "" + title + "",
	    height:     "" + height + "",
	    width:      "" + width + ""
	});
};