/*
 * CPP Javascript
 *
 * Copyright (c) 2008 Crystal Park
 *
 * $Date: $
 * $Rev:  $
 */
var Cpp;
if (!Cpp) Cpp = {}; 

if (!Cpp.defaultMovie) Cpp.defaultMovie = 'startup';
if (!Cpp.playerWidth) Cpp.playerWidth = '690';
if (!Cpp.playerHeight) Cpp.playerHeight = '388';
if (!Cpp.playerFilmpjePrefix) Cpp.playerFilmpjePrefix = 'cpmp/cq/';
if (!Cpp.playerFilmpjeSuffix) Cpp.playerFilmpjeSuffix = '.mp4';
if (!Cpp.playerImgPrefix) Cpp.playerImgPrefix = "imgs/";
if (!Cpp.playerImgSuffix) Cpp.playerImgSuffix = '.jpg';
if (!Cpp.selected) Cpp.selected = null;

Cpp.addClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
};

Cpp.removeClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

Cpp.buildFilmpjeUrl = function(filmpje, type) {
	var filmpjeUrl;
	
	if (filmpje == null) {
		fimpje = Cpp.defaultMovie;
	} 
	
	if (filmpje.match("http://") != null || filmpje.match("playlist") != null) {
		filmpjeUrl = filmpje;
	} else if (type != null && type.match("stream") != null) {
		filmpjeUrl = "cpmp=" + filmpje + ".sdp"; 
	} else {
		filmpjeUrl = Cpp.playerFilmpjePrefix + filmpje + Cpp.playerFilmpjeSuffix;
	}
	
	//alert('Filmpje: ' + filmpjeUrl);
	return filmpjeUrl;
}

Cpp.buildImgUrl = function(img) {
	var imgUrl;
	
	if (img.match("http://") != null) {
		imgUrl = img;
	} else {
		imgUrl = Cpp.playerImgPrefix + img + Cpp.playerImgSuffix; 
	}
	
	//alert('Img: ' + imgUrl);
	return imgUrl;
}

Cpp.switchSelected = function(elementId) {
	if (Cpp.selected != null) {
		Cpp.removeClassName(Cpp.selected, "current");
	}
	
	Cpp.selected = document.getElementById(elementId);
	Cpp.addClassName(Cpp.selected, "current");
}

Cpp.switchJWPlayer = function(filmpje, img, autostart, width, height, type) {
	//alert('Filmpje ' + filmpje);
	if (width == null) {
		width = Cpp.playerWidth; 
	}
	
	if (height == null) {
		height = Cpp.playerHeight;
	}
	
	var so = new SWFObject('media/player43.swf','mpl',width,height,'9.0.115.0');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addVariable('file', Cpp.buildFilmpjeUrl(filmpje, type));

	if (type != null && type.match("stream") != null) {
		so.addVariable('streamer','rtmp://fl1.streamzilla.jet-stream.nl/rtplive');
		so.addVariable('displayclick','none');
	} else {
		so.addVariable('streamer','rtmp://fl1.streamzilla.jet-stream.nl/VOD');	
	}

	if (type != null && type.match("image") != null) {
		so.addVariable('displayclick','link');
		so.addVariable('linktarget','_self');
		so.addVariable('link','live.php');
	}

	if (type != null && (type.match("image") != null || type.match("stream") != null )) {
		so.addVariable('controlbar','none');
	} else {
		so.addVariable('displayclick','play');
		so.addVariable('controlbar','over');
	}
	
	so.addVariable('height',height);
	if (img != null) {
		so.addVariable('image', 'imgs/cq.jpg');
	}	
	
	so.addVariable('width',width);
	so.addVariable('stretching','uniform');
	if (autostart != null) {
		so.addVariable('autostart',autostart);
	}		
	so.addVariable('bufferlength','5');
	so.addVariable('repeat', 'list');
	so.write('player16');
}

Cpp.switchSlideshowPlayer = function(filmpje, img, autostart, width, height, type) {
	var so = new SWFObject("media/monoslideshow.swf", "SOmonoSlideshow", width, height, "7", "#ffffff");
	so.addParam('allowscriptaccess','always');
	so.addVariable('dataFile', filmpje);
	so.addVariable("showLogo", "false");
	so.write("player16");
}

Cpp.switchPhotowallPlayer = function(filmpje, img, autostart, width, height, type) {
	// alert('filmpje ' + filmpje);

	var so = new SWFObject(filmpje,'PhotoWall',width,height,'9.0.115.0');
	so.addParam('XMLSource', 'fotowalls/beleidsdag01_portret.xml');
	so.addVariable('XMLSource', 'fotowalls/beleidsdag01_portret.xml');
	so.write('player16');
	//SWFObject.init('fotowalls/beleidsdag01_portret.xml');
}

Cpp.switchPlayer = function(filmpje, img, autostart, width, height, type) {
	if (width == null) {
		width = Cpp.playerWidth; 
	}
	
	if (height == null) {
		height = Cpp.playerHeight;
	}

	//bepalen welk player we gaan laden
	if (type == null || type == "" || type == "image" || type == "stream") {
		Cpp.switchJWPlayer(filmpje, img, autostart, width, height, type);
	} else if (type == "slideshow") {
		Cpp.switchSlideshowPlayer(filmpje, img, autostart, width, height, type);
	} else if (type == 'photowall') {
		Cpp.switchPhotowallPlayer(filmpje, img, autostart, width, height, type);
	}
}

/**
	Zet het juiste panel van de accordion actief en start het juiste filmpje.
	
	@param elementId id van het anchor welke geselecteerd dient te worden, verplicht.
	@param panel id van het panel van de accordion welke geopend dient te worden, 
		   indien niet aangeleverd blijft het huidige panel actief. 
	@param filmpje url van het filmpje welke getoond dient te worden,
	       indien alleen een naam wordt gebruikt wordt er
	       http://dl1.streamzilla.jet-stream.nl/cpmp/cq/ + fimpje + .mp4 van gemaakt,
	       indien deze leeg wordt doorgegeven dan wordt de elementId gebruikt.
	@param width de breedte van de mediaplayer, default 690
	@param height de hoogte van de mediaplayer, default 388  
	@param type Indien stream, wordt de player in stream modus gestart, indien 
		   image wordt de player in image mode gestart, anders wordt het met 
		   een image gestart waarna op play kan worden gedrukt.         
**/
Cpp.doNav = function(elementId, panel, filmpje, img, autostart, type, width, height) {
	//alert('parameters elementId' + elementId + ' panel: ' + panel + ' fimpje: ' + filmpje + ' img: ' + img + ' autostart: ' + autostart + ' width: ' + width + ' height: ' + height);
	
	if (panel != null) {
		acc.openPanel(panel);
	}
	
	if (filmpje == null) {
		filmpje = elementId;
	}
	
	Cpp.switchSelected(elementId);
	Cpp.switchPlayer(filmpje, img, autostart, width, height, type);
};