var ZoomWin = null;
var nltijd; //for clock
var surtijd; //for clock
var hotnumb = ""; //Hot TopiC 
var photo = ""; //photo in top-left box
var phototxt = ""; // txt in photo poppupwindow
var photoindex = ""; //arrayindex for rotating photos in top-left box
var rotating = null; //set true by do_rotatephoto

//create poppup onClick in picturebox
//Max picturesize in poppup = 500x500px!

//select random photo/hottopic if non supplied, arrayindex > 9 used for random selection
function selectrand (arrayname)
	{
	return (Math.floor(Math.random() * (arrayname.length - 10) + 10)); 
	}

// Funtions that put all elements on the screen
function do_everything(usephoto, usehotnumb)
{
	//reset rotating photo if running
	if (rotating)
		{
		clearTimeout(rotateID);
		rotating = false;
		}
	//if usephoto/usehotnumb is not supplied by page.html, use random one & init do_rotation
	if (usephoto && usephoto != null && usephoto != "") { photoindex = usephoto; }
	else { photoindex = selectrand(photodata[0]); var rotatephoto = true;}
	if (usehotnumb && usehotnumb != null && usehotnumb != "") { hotnumb = (hottopics[(usehotnumb)]); }
	else { hotnumb = hottopics[selectrand(hottopics)]; }
	do_picturebox(rotatephoto);
	do_topboxtxt(hotnumb);
	do_clock();
	do_menubox();
	do_sponsorbox();
	do_linkline();
	if (rotatephoto) {do_rotatephoto();}
} 
		
function do_rotatephoto()
{
	photo = (photodata[0][(photoindex)]);
	phototxt = (photodata[1][(photoindex)]);
	document.images.photoboximg.src=("photos/" + photo);
	if (photoindex == (photodata[0].length -1)) {photoindex = 10;}
	else {photoindex++;}
	//preload the next one
	if (!nextphoto) {var nextphoto = new Image();}
	nextphoto.src = (photodata[0][(photoindex)]);
	rotateID = setTimeout("do_rotatephoto()",20000);
	rotating = true;
}

function do_picturebox(rotatecheck)
{
	photo = (photodata[0][(photoindex)]);
	phototxt = (photodata[1][(photoindex)]);
 	document.write ('<div id="photobox"><a onClick="poppup(\'' + photo + '\');">');
	document.write ('<img name="photoboximg" src="photos/' + photo + '" alt="Een klikkie hiero voor een groot formaat"></a></div>');
	//photoindex++ for poppup() if rotation is off
	if (!rotatecheck) {photoindex++;}
}

function do_topboxtxt(hotnumb)
{
	document.write ('<div id="topbox"><div id="topboxinside"><h5>HoT TopiC:</h5>');
	document.write ('<p class="topboxtxt">' + hotnumb + '</p>');
	document.write ('</div></div>');
}

function do_menubox()
{
	document.write ('<div id="menubox">');
	document.write ('<a class="menuitem" href="nieuws.html">Nieuws</a> ');
	document.write ('<div id="smbox">');
	document.write ('<a class="smbhead" href="stichting.html">De stichting</a>');
	document.write ('<div id="smbinside">');
	document.write ('&middot; <a class="smbitem" href="ontstaan.html">Ontstaan </a><br>');
	document.write ('&middot; <a class="smbitem" href="activiteiten.html">Activiteiten</a><br>');
	document.write ('&middot; <a class="smbitem" href="steunstichtingrb.html">Sponsors</a><br>');
	document.write ('&middot; <a class="smbitem" href="video.html">Video</a><br>');
	document.write ('</div></div>');
	document.write ('<a class="menuitem" href="ruthbotland.html">Ruth Botland</a> ');
	document.write ('<a class="menuitem" href="reageer.html">Reageer</a></div> '); 
} 

function do_sponsorbox()
{
	document.write ('<div id="sponsorbox">');
	document.write ('<p class="subnewsheader white" style="text-align: center;">Sponsors:</p>');
	document.write ('<a href="http://www.ravensbergenbv.nl"><img src="images/ravensbergen.gif"></a>');
	document.write ('</div>');
}

function do_linkline()
{
        document.write ('<div id="linkline"> ');
        document.write ('<a class="white" href="index.html">home</a> | ');
        document.write ('<a class="white" href="contact.html">contact</a> | ');
	document.write ('<a class="white" href="mailto:' + (unescape(OutStringWebMas)) + '">mail webchef</a> | ');
        document.write ('<a class="white" href="http://www.mozilla.org/products/firefox/">bezoek deze website met Firefox</a> | </div>');
}

// Clock functions
function do_clock()
{
	//stop clock if running from previous page
	//if (tijdloopt == true) clearTimeout(tijdID);
	//tijdloopt = false;
	//create clockform
	document.write ('<form name="clockform"><textarea name="clock" class="clock">');
	document.write ('parsing time...');
	document.write ('</textarea></form>'); 
	update_clock();
}

function update_clock()
{	
	var now = new Date();
	var nluren = now.getUTCHours() + 2;
	var sururen = now.getUTCHours() - 3;
	var minuten = now.getMinutes();
	//nltijd & surtijd are global to be able to use them elsewhere
	nltijd = nluren + ((minuten <10) ? ":0" : ":") + minuten;
	surtijd = sururen + ((minuten <10) ? ":0" : ":") + minuten;;
	document.clockform.clock.value = 'Nederland '+ nltijd + ' || ' + surtijd + ' Suriname';
	tijdID = setTimeout("update_clock()",1000);
	tijdloopt = true;
}

//Function for creatin the poppup onClick
function poppup(photo)
{
	//if window exists, focus window
	if (ZoomWin && !ZoomWin.closed) { ZoomWin.focus(); }
	else
	{
	//decide about the src of the large photo
	if (photoindex == 10) { var largephoto = (pictdata[0][((pictdata[0].length) -1)]); }
	else { var largephoto = (photodata[0][(photoindex -1 )]); }
	var photo_large = (largephoto.substring(0, (largephoto.length - 4)) + "_large." + largephoto.substring((largephoto.length -3), largephoto.length));
	//create window and build page
        ZoomWin = window.open('', 'nieuw_venster', 'directories=no,location=no,resizable=yes,\
		menubar=no,scrollbars=no,toolbar=no,status=yes,width=520,height=610,left=30,top=30');
	ZoomWin.document.open();
	ZoomWin.document.write ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
	ZoomWin.document.write ('<html><head><title>Pop-ups are nice :-)</title>');
	ZoomWin.document.write ('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
	ZoomWin.document.write ('<link rel="stylesheet" type="text/css" href="poppup.css"></head>');
	ZoomWin.document.write ('<body><img src="photos/' + photo_large + '" class="picturebox1">');
	ZoomWin.document.write ('<p class="contentbox1"> <span class="grmbl">' + phototxt + ' </span></p>');
	ZoomWin.document.write ('<p> <a class="white" href="#" class="grmbl" ');
	ZoomWin.document.write ('onClick="window.close();"');
	ZoomWin.document.write ('onMouseOver="status = \'Sluit dit venster.\'; return true;"');
	ZoomWin.document.write ('onMouseOut="status = \'\'; return true;">'); 
	ZoomWin.document.write ('<strong>Sluit venster</strong></a> </body></html>');
	ZoomWin.document.close();
	}
}



