//

// HEADERBEELD ROTATOR MAIN FUNCTION	
function headerRotator() {
// arguments: image name, rotation speed, (optional) path to images
var rotator1 = new dw_Rotator('headerimage', 10000, "http://www.nihes.nl/site/newhome/headerimages/");
// add the images to rotate into that image object  
rotator1.addImages("HeaderRotterdamErasmusMC.jpg", "HeaderRotterdamWatertaxi.jpg", "HeaderRotterdamZenne.jpg", "HeaderRIVM.jpg", "HeaderNKIAVLBuilding.jpg", "HeaderUvaBuilding.jpg", "HeaderUvaStudents.jpg", "HeaderUvaLogo.jpg", "HeaderUvaCanal.jpg","HeaderRotterdamLecture.jpg");

rotator1.addCredits("Faculty building Erasmus MC, Rotterdam, The Netherlands - Nihes Participating Institute", "Watertaxi on the river Maas at Rotterdam, The Netherlands", "Cruiseship Rotterdam docking in the Port of Rotterdam, The Netherlands", "National Institute for Public Health and the Environment (RIVM), Netherlands - Nihes Participating Institute", "The Netherlands Cancer Institute-Antoni van Leeuwenhoek Hospital, Amsterdam, The Netherlands - Nihes Participating Institute", "University of Amsterdam, The Netherlands - Nihes Participating Institute", "Students at University of Amsterdam, The Netherlands - Nihes Participating Institute", "University of Amsterdam, The Netherlands - Nihes Participating Institute", "Canals in Amsterdam, The Netherlands", "Professor Huibert Pols, Dean Erasmus MC - Nihes Graduation 2008");
rotator1.rotate(); // sometimes may want to call rotate here
dw_Rotator.start();
}

//newsflash();
// Write NEWSflashbox
function newsflash() {
	var s2 = new SWFObject("http://www.nihes.nl/site/webcasts/player.swf","ply","262","205","9","#FFFFFF");
	s2.addParam("allowfullscreen","true");
	s2.addParam("allowscriptaccess","always");
	s2.addParam("flashvars","file=http://www.nihes.nl/site/webcasts/ProfBertHofman.flv&image= http://www.nihes.nl/site/webcasts/ProfBertHofman.jpg");
	s2.write("newsflashbox");
}

// WEBCAST SEQUENCER MAIN FUNCTION
function pickAWebcast() {
	webcasturl = "http://www.nihes.nl/site/webcasts/";
	
	var Headers=new Array(	"Professors about Nihes", 
							"Students about Nihes",
							"Students about Nihes",
							"Students about Nihes",
							"Students about Nihes",
							"Students about Nihes",
							"Students about Nihes",
							"Students about Nihes",
							"Students about Nihes",
							"Students about Nihes",
							"Students about Nihes",
							"Rotterdam Student City",
							"Professors about Nihes"
							);

	var Files=new Array(	"ProfTrichopoulos", 
							"OlujideArije",
							"AfshinAslani",
							"CaraDeJong",
							"DavidKwasiAmankwa",
							"FarizahMohdHairi",
							"GianlucaTrifiro",
							"IwonaLugowska",
							"MarinaStegne",
							"MehlikaToy",
							"TomrisCesuroglu",
							"RSC",
							"ProfJohanvanderLei"
							);

// // Play requested webcast or random. > requested via URL passed variable: webcast=x
// 	var sGet = window.location.search;
// 	if (sGet) {
// 		sGet = sGet.substr(1); // Drop the leading "?"
// 		// Generate a string array of the name value pairs. Each array element will have the form "foo=bar"
// 		var sNVPairs = sGet.split("&");
// 
// 		// Now, for each name-value pair, we need to extract the name and value.
// 		for (var i = 0; i < sNVPairs.length; i++) {
// 			//So, sNVPairs[i] contains the current element... Split it at the equals sign.
// 			var sNV = sNVPairs[i].split("=");
// 			var sName = sNV[0];
// 			var sValue = sNV[1];
// 		}
// 		
// 		if(sName == "webcast") {
// 			nr=sValue;
// 		} else {
// 			if(typeof(nr)!='undefined') {
// 				if(nr>=Files.length-1) {
// 					nr=0;
// 				} else {
// 						nr++;
// 				}
// 			} else {
// 				nr=Math.floor(Math.random()*Headers.length);
// 			}
// 		}
// 	}
	
	
	if(typeof(nr)!='undefined') {
		if(nr>=Files.length-1) {
			nr=0;
		} else {
				nr++;
		}
	} else {
		nr=Math.floor(Math.random()*Headers.length);
	}
	
	// Write flashbox
		var s1 = new SWFObject("http://www.nihes.nl/site/webcasts/player.swf","ply","276","215","9","#FFFFFF");
		s1.addParam("allowfullscreen","true");
		s1.addParam("allowscriptaccess","always");
		s1.addParam("flashvars","file=http://www.nihes.nl/site/webcasts/" + Files[nr] + ".flv&image=http://www.nihes.nl/site/webcasts/" + Files[nr] + ".jpg");
		      s1.write("flashbox");

	// Write texts
	document.getElementById("webcasthead").innerHTML = Headers[nr];
	// document.getElementById("webcasttext").innerHTML = Texts[nr];
}

// HEADERBEELD ROTATOR FUNCTIONS
dw_Rotator.restartDelay = 500; // delay onmouseout before call to rotate
dw_Rotator.col = []; 

// arguments: image name, rotation speed, path to images (optional), 
// target, i.e. name of window to direct url's to onclick (optional)
function dw_Rotator(name, speed, path, tgt) {
    this.name = name; this.speed = speed || 4500; // default speed of rotation
    this.path = path || ""; this.tgt = tgt;
    this.ctr = 0; this.timer = 0; this.imgs = []; this.credits = []; this.actions = [];
    this.index = dw_Rotator.col.length; dw_Rotator.col[this.index] = this;
    this.animString = "dw_Rotator.col[" + this.index + "]";
}

dw_Rotator.prototype.addImages = function() { // preloads images
    var img;
    for (var i=0; arguments[i]; i++) {
        img = new Image();
        img.src = this.path + arguments[i];
        this.imgs[this.imgs.length] = img;
    }
}

dw_Rotator.prototype.addCredits = function() { // preloads images
    var txt;
    for (var i=0; arguments[i]; i++) {
        this.credits[this.credits.length] = arguments[i];
    }
}

dw_Rotator.prototype.addActions = function() {
    var len = arguments.length; // in case an argument's value is null
    for (var i=0; i < len; i++) 
        this.actions[this.actions.length] = arguments[i]; 
}

dw_Rotator.prototype.rotate = function() {
    clearTimeout(this.timer); this.timer = null;
    //if (this.ctr < this.imgs.length-1) this.ctr++;
    //else this.ctr = 0;

	this.ctr=Math.floor(Math.random()*this.imgs.length);
	
	
    var imgObj = document.getElementById('headerimage');
	var imgCrdt = document.getElementById('photocredit');
    if (imgObj) {
		imgObj.style.backgroundImage = "url("+this.imgs[this.ctr].src+")";
		imgCrdt.innerHTML = this.credits[this.ctr];
        // imgObj.src = this.imgs[this.ctr].src;
        this.timer = setTimeout( this.animString + ".rotate()", this.speed);
    }
}

// Start rotation for all instances 
dw_Rotator.start = function() {
    var len = dw_Rotator.col.length, obj;
    for (var i=0; i<len; i++) {
        obj = dw_Rotator.col[i];
        if (obj && obj.name ) // check for empty instance created by dw_random.js
            obj.timer = setTimeout( obj.animString + ".rotate()", obj.speed);
    }
}

// called onclick of images
dw_Rotator.doClick = function(n) {
    var obj = dw_Rotator.col[n]; 
	if ( !document.images || !obj ) return true;
    if ( obj.actions && obj.actions[obj.ctr] ) {
        if ( typeof obj.actions[obj.ctr] == "string" ) { // url
            if ( obj.tgt ) { // open in separate window
                // add features here if you want, i.e., chrome, size, position, ...
                var win = window.open(obj.actions[obj.ctr], obj.tgt);
                if ( win && !win.closed ) win.focus();
            } else {
                window.location = obj.actions[obj.ctr];
            }
        } else { // function pointer 
            obj.actions[obj.ctr](); // execute function
        }
    }
    return false;
}

// for stopping/starting onmouseover/out
dw_Rotator.pause = function(n) {	
    dw_Rotator.clearTimers(n);
}

dw_Rotator.clearTimers = function(n) {
    var obj = dw_Rotator.col[n]; 
    if ( obj ) {
        clearTimeout( obj.timer ); obj.timer = null;
    }
}

dw_Rotator.resume = function(n) {
    dw_Rotator.clearTimers(n);
    var obj = dw_Rotator.col[n]; 
    if ( obj ) {
        obj.timer = setTimeout( obj.animString + ".rotate()", dw_Rotator.restartDelay );
    }
}