// don't load twice
if (window.embedded_player_initialized === undefined) {
	// this is the first time, we are included - we just continue
} else {
	// we were initialized before - don't continue
	exit();
}
// ok - we are not initialized - thus we can continue


// the control panel of the flowplayer takes 35 pixels
player_height = 35;
player_url = "/fileadmin/flashplayer/flowplayer/flowplayer-3.1.0.swf";
player_api = "/fileadmin/flashplayer/flowplayer/flowplayer-3.1.0.min.js";
fs_magic_key = "bV";
fs_magic_value = "yes";
embedded_player_initialized = "yes";

// we need to include the flowplayer javascript file - this is dirty, but allows a Single Point of Truth regarding script locations
document.write('<script type="text/javascript" src="' + player_api + '"></script>');

// Quelle: http://www.barmetler.de/js-tutorial/anwendungsbeispiele/argumente_aus_url.html
function getArg(name) {
  var args = new Object();
  var query = location.search.substring(1);
  var pairs = query.split("&");
  number_of_arguments = pairs.length;
  for (var i=0; i<number_of_arguments; i++){
    var pos = pairs[i].indexOf('=');
    if (pos == -1) continue;
    var argname = pairs[i].substring(0,pos);
    var value = pairs[i].substring(pos+1);
    args[argname] = unescape(value);
  }
  args["NB_OF_ARGS"] = number_of_arguments;
  switch(name){
    case "ALL_ARGS":
      return args;
      break;
    default:
      if (args[name]){
        return args[name];
      }
      else {
        return null;
      }
    break;
  }
}


function showVideo(name, source, width, height, duration, fullscreen) {
	// check if the current query string is empty - use "?foo=bar&" or "?" respectively
	fs_url_prefix = (window.location.search.length > 0) ? window.location.search + "&" : "?";
	// output the "a" block for the video output
	document.write('<p style="text-align:center"><a href="' + source + '" style="display:block;width:' + width + 'px;height:' + (player_height + height) + 'px" id="' + name + '"></a></p>');
	// define arguments for the player
	var args = new Object();
	args.clip = {
		autoPlay: false,
		autoBuffering: true,
		duration: duration,
		scaling: "fit"
	};
	if (fullscreen) {
		// we start immediately in fullscreen mode
		args.clip.autoPlay = true;
	} else {
		// don't start in a small window
		args.clip.autoPlay = false;
		// add a link to the bigger video
		args.canvas = {
			linkUrl: escape(fs_url_prefix + fs_magic_key + "=" + fs_magic_value)
		}
	}
	// start the player
	flowplayer(name, player_url, args);
}


function conditionalSmallVideo(name, source, width, height, duration) {
	if (getArg(fs_magic_key) != fs_magic_value) {
		// start the video in not-fullscreen mode (last parameter)
		showVideo(name, source, width, height, duration, false);
	}		
}


function conditionalBigVideo(name, source, width, height, duration) {
	if (getArg(fs_magic_key) == fs_magic_value) {
		// start the video in fullscreen mode (last parameter)
		showVideo(name, source, width, height, duration, true);
	}		
}


