/*

COPYRIGHT 2009 - 2010
CONTENT BY KOKEN-OP-DE-BOOT.BE
SOURCE CODE BY KLAAS BELLEMANS, YAKI.BE
ALL RIGHTS RESERVED 

*/

if (window.addEventListener){window.addEventListener("load", init, false);}
else if (window.attachEvent){window.attachEvent("onload", init);}

window.onunload=function(){if(document.getElementById('map_canvas')){GUnload();}}

function init(){
	if(getElementsByClassName(document.getElementById('container'), 'div', 'fotoalbum')[0]){
		if(document.getElementById('slideshow')){
		}else{
			var slideshowcontainer=document.createElement('div');
			slideshowcontainer.id="slideshow";
			document.getElementById('container').appendChild(slideshowcontainer);
		}
		document.getElementById('slideshow').innerHTML=getElementsByClassName(document.getElementById('container'), 'div', 'fotoalbum')[0].innerHTML;
	}
	if(getElementsByClassName(document.getElementById('container'), 'a', 'blink')[0]){
		underlineOnOff(getElementsByClassName(document.getElementById('container'), 'a', 'blink')[0]);
	}
	if(document.getElementById('slideshow')){startviewer();}
	if(getElementsByClassName(document.getElementById('container'), 'ul', 'fotos')[0]){initViewer();}
	if(document.getElementById('map_canvas')){googleMaps();}
	if(getElementsByClassName(document.getElementById('container'), 'div', 'buttonmenu')[0]){initButtonMenu();}
	if(document.getElementsByTagName('body')[0].id=="home"){
		if(document.getElementById('teaser-joric')){
			document.getElementById('teaser-joric').getElementsByTagName('em')[0].innerHTML="Welkom bij koken op de boot; ik ben Joric en chef kok van dienst...";
			setTimeout("document.getElementById('teaser-joric').getElementsByTagName('em')[0].style.display='block';",500);
			setTimeout("document.getElementById('teaser-joric').getElementsByTagName('em')[0].style.display='none';",5000);
			document.getElementById('teaser-joric').onmouseover=function(){this.getElementsByTagName('em')[0].style.display='block';}
			document.getElementById('teaser-joric').onmouseout=function(){this.getElementsByTagName('em')[0].style.display='none';}
		}
	}
}

function initButtonMenu(){
	var buttonmenu=getElementsByClassName(document.getElementById('container'), 'div', 'buttonmenu')[0];
	var buttons=buttonmenu.getElementsByTagName('li');
	for(var i=0;i<buttons.length;i++){
		buttons[i].onmouseover=function(){this.className="hover";}
		buttons[i].onmouseout=function(){this.className="";}
		buttons[i].onclick=function(){window.location=this.getElementsByTagName('a')[0].href;}
	}
}

function blinkOnOff(obj){
	if(obj.style.color=="white"){
		obj.style.color="#f8422b";
	}else{
		obj.style.color="white";
	}
	setTimeout(function(){blinkOnOff(obj);},550);
}

function underlineOnOff(obj){
	if(obj.style.textDecoration=="underline"){
		obj.style.textDecoration="none";
	}else{
		obj.style.textDecoration="underline";
	}
	setTimeout(function(){underlineOnOff(obj);},750);
}

var colorarray=new Array('#F8422B','#F95843','#FA6E5C','#FB8474','#FB9A8D','#FCB0A6','#FDC6BF','#FEDCD7','#FFF2F0');//,'#FFFFFF');
var cnter=0;
function blinkIt(obj){setInterval (function(){changecolor(obj);},100);}

function changecolor(obj) {
	var x=obj;
	if (x){
		x.style.color = colorarray[cnter];
		if (cnter==8){ 
			cnter=0;
			colorarray = colorarray.reverse();
		}
	}
	cnter++;
}

var slides = new Array();
var waitsomemore = false;
var stop = false;
var tov;

function slideshow(i){
	var theviewer = document.getElementById('slideshow');
	var theimages =slides;
	var interval = 4000; //milliseconds
	if (stop != true){
   	if (waitsomemore == true){
   		interval = interval + 4000;
   		waitsomemore = false;
	   	}
	  	theviewer.style.backgroundImage = "url('" + theimages[i].src + "')";
	  	clearSelection(theviewer.getElementsByTagName('ul')[0]);
	  	theviewer.getElementsByTagName('ul')[0].getElementsByTagName('a')[i].style.backgroundColor="#f8422b";
	   	j = i + 1;
	   	if (j > (theimages.length-1)){
	   		j=0;
	   	//	stop=true;
	   	}
	   	if (stop != true){
	   		tov=setTimeout('slideshow(j)', interval);
	   	}
	}
}

function startviewer(){
	/*preload images*/
	var theviewer = document.getElementById('slideshow');
	var theimages = theviewer.getElementsByTagName('ul')[0].getElementsByTagName('a');
	for(var i=0; i < theimages.length; i++ ){
	slides[i]= new Image();
	slides[i].src = theimages[i].href;
	}
	/*start slideshow*/
	slideshow(0);
   	/*set default image: lijst in omgekeerde volgorde !*/
	theviewer.style.backgroundImage = "url('" + theimages[0].href + "')";
	for( var i=0; i < theimages.length; i++ ){
		/*mouseover bij list-links */
		theimages[i].onmouseover = function(){
			//window.clearTimeout(tov);
			waitsomemore = true;
			stop = false; /* beter ???? */
          	theviewer.style.backgroundImage = "url('" + this.href + "')";
		  	clearSelection(theviewer.getElementsByTagName('ul')[0]);
		  	this.style.backgroundColor = "#f8422b";
		};   
		/* idem bij geval onclick + disable link + stop slideshow */
   		theimages[i].onclick = function(){
   			waitsomemore = true;
   			stop = false;
  			theviewer.style.backgroundImage = "url('" + this.href + "')";
  			clearSelection(theviewer.getElementsByTagName('ul')[0]);
  			this.style.backgroundColor = "#f8422b";
  			return false;
		};  
  	}//end for
}

function clearSelection(obj){
var items=obj.getElementsByTagName('a');
for(var i=0;i<items.length;i++){
items[i].style.backgroundColor="silver";
}
}


function googleMaps() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    //map.setMapType(G_PHYSICAL_MAP);
    
    var point1 = new GLatLng(51.2289, 4.4023);
    //var point2 = new GLatLng(51.2290, 4.4041);
    
    var infoWindowContent1 = "<p style='position:relative;padding:0px;margin:0px;line-height:1.7em;font-size:85%;'><b>'de Scheldewacht'</b><br />Bonaparte-dok<br />Rijnkaai<br />2000 Antwerpen<br /><em style='padding-top:10px;width:100%;display:block;line-height:1.4em;'><small>De kaai is het verlengde van de Noorderlaan;<br />de boot ligt evenwijdig met de hoofdbaan en de Schelde...<br />U herkent onze boot aan het spandoek. <img src='fotos/contact/boot-thumb.jpg' alt='boot Scheldewacht aan Rijnkaai' style='position:absolute;top:0px;right:0px;height:80px;width:80px;' /></small></em></p>";
    //var infoWindowContent2 = "<p style='position:relative;padding:0px;margin:0px;line-height:1.7em;font-size:85%;'><b>'MAS'</b><br />(toekomstige locatie)<br />Nieuwpoortkaai<br />2000 Antwerpen<br /><em style='padding-top:10px;width:100%;display:block;line-height:1.4em;'><small>Binnenkort verplaatst de boot naar de overkant:<br /> op de kaai naast het vernieuwde MAS...<img src='contact/MAS-thumb2.jpg' alt='MAS in aanbouw' style='position:absolute;top:0px;right:0px;height:80px;width:80px;' /></small></em></p>";
    
		
	var icon = new GIcon();
	icon.image = "styles/mapsicon2.gif";
	icon.iconSize = new GSize(35, 35);
	icon.iconAnchor = new GPoint(17,35);
	icon.infoWindowAnchor = new GPoint(20, 0);

	/*
	var icon = new GIcon();
	icon.image = "styles/mapsicon2.gif";
	icon.iconSize = new GSize(35, 35);
	icon.iconAnchor = new GPoint(17,35);
	icon.infoWindowAnchor = new GPoint(20, 0);
	*/
	
	var marker1=new GMarker(point1,icon);
	//var marker2=new GMarker(point2,icon);
	
    map.addOverlay(marker1);
    //map.addOverlay(marker2);
	
	GEvent.addListener(marker1, "click", function() {
		marker1.openInfoWindowHtml(infoWindowContent1);
	});
	
	/*GEvent.addListener(marker2, "click", function() {
		marker2.openInfoWindowHtml(infoWindowContent2);
	});*/
	
	map.setCenter(new GLatLng(51.2289, 4.4023), 17);
	marker1.openInfoWindowHtml(infoWindowContent1);
	
    map.setUIToDefault();
  }
}


/* 
copyright 2008 
klaas bellemans, yaki.be 
*/

var timeout;
var selectedid="photo_-1";


function initViewer(){
	var body=document.getElementsByTagName('body')[0];
	/*half transparant canvas*/
	var canvas=document.createElement('div');
	canvas.id="canvas";
	body.appendChild(canvas);
	/*add imageviewer met controls*/
	var imageviewer=document.createElement('div');
	imageviewer.id="imageviewer";
	imageviewer.title="klik om de viewer te sluiten";
	imageviewer.innerHTML='<table class="center"><tr><td class="center"><div id="imgview"><div><p><a id="vorige" href="#" title="vorige foto"><i>vorige foto</i></a><span> | </span><a id="volgende" href="#" title="volgende foto"><i>volgende foto</i></a></p></div></div></td></tr></table>';
	body.appendChild(imageviewer);
	imageviewer.onclick=function(){
		this.style.display="none";
		document.getElementById('canvas').style.display="none";
		this.style.backgroundImage="url('')";//clear image
	}
	initImageLinks();

	document.getElementById('vorige').onclick=function(e){
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		document.getElementById('volgende').style.display="block";
		var fotolist=getElementsByClassName(document.getElementById('container'), 'ul', 'fotos')[0];
		var photolinks=fotolist.getElementsByTagName('img');
		var numberPhotos=photolinks.length-1;
		var cleanid = selectedid.replace('photo_','');
		cleanid=parseFloat(cleanid)-1;	
		if(cleanid==0){this.style.display="none";}
		if(cleanid>=0){document.getElementById('imageviewer').style.backgroundImage="url("+document.getElementById("photo_"+cleanid).src+")";}
		else{
			var imgviewer=document.getElementById('imageviewer');
			imgviewer.style.display="none";
			document.getElementById('canvas').style.display="none";
			imgviewer.style.backgroundImage="url('')";//clear image
		//document.getElementById('imageviewer').style.backgroundImage="url("+document.getElementById("photo_"+numberPhotos).href+")";
		//cleanid=numberPhotos;
		}
		selectedid="photo_"+cleanid;
		//alert(selectedid);
		return false;
	};
	document.getElementById('vorige').onmouseover=function(){this.className="high";}
	document.getElementById('vorige').onmouseout=function(){this.className="";}
	document.getElementById('volgende').onmouseover=function(){this.className="high";}
	document.getElementById('volgende').onmouseout=function(){this.className="";}
	document.getElementById('volgende').onclick=function(e){
		if (!e) var e = window.event;
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		document.getElementById('vorige').style.display="block";
		var fotolist=getElementsByClassName(document.getElementById('container'), 'ul', 'fotos')[0];
		var photolinks=fotolist.getElementsByTagName('img');
		var numberPhotos=photolinks.length-1;
		var cleanid = selectedid.replace('photo_','');
		cleanid=parseFloat(cleanid)+1;
		if(cleanid==numberPhotos){this.style.display="none";}
		if(cleanid<=numberPhotos){document.getElementById('imageviewer').style.backgroundImage="url("+document.getElementById("photo_"+cleanid).src+")";}
		else{
			var imgviewer=document.getElementById('imageviewer');
			imgviewer.style.display="none";
			document.getElementById('canvas').style.display="none";
			imgviewer.style.backgroundImage="url('')";//clear image
			//document.getElementById('imageviewer').style.backgroundImage="url("+document.getElementById("photo_0").href+")";
			cleanid=0;
			}
		selectedid="photo_"+cleanid;
		//alert(selectedid);
		return false;
	};
}



function initImageLinks(){
	var thelist=getElementsByClassName(document.getElementById('container'), 'ul', 'fotos')[0];
	var theitems=thelist.getElementsByTagName('img');
	for(var i=0;i<theitems.length;i++){
		theitems[i].id="photo_"+i;
		/*theitems[i].onmouseover=function(){
			this.title="*click*";
		};
		theitems[i].onmouseout=function(){
		};*/
		theitems[i].onclick=function(){
			document.getElementById('volgende').style.display="block";
			document.getElementById('vorige').style.display="block";
			document.getElementById('canvas').style.display="block";
			document.getElementById('imageviewer').style.display="block";
			document.getElementById('imageviewer').style.backgroundImage="url("+this.src+")";
			selectedid=this.id;
			var fotolist=getElementsByClassName(document.getElementById('container'), 'ul', 'fotos')[0];
			var photolinks=fotolist.getElementsByTagName('img');
			var numberPhotos=photolinks.length-1;
			var cleanid = selectedid.replace('photo_','');
			cleanid=parseFloat(cleanid)+1;
			if(cleanid==numberPhotos+1){document.getElementById('volgende').style.display="none";}
			if(cleanid==1){document.getElementById('vorige').style.display="none";}
			return false;
		};
	}
}


/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/


function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}


