var playerConfig = {
  large:   { player:'player.swf',    encode:"f4v", width:540, height:304, beforeWait:1000, afterWait:1000, indication:true,  bgColor:"#000000" },
  flv:     { player:'player.swf',    encode:"flv", width:540, height:304, beforeWait:1000, afterWait:1000, indication:true,  bgColor:"#000000" },
  large43: { player:'player4-3.swf', encode:"flv", width:540, height:360, beforeWait:1000, afterWait:1000, indication:true,  bgColor:"#000000" },
  small:   { player:'player_s.swf',  encode:"f4v", width:96,  height:156, beforeWait:0,    afterWait:0,    indication:false, bgColor:"#FFFFFF" }
}

function movie(coverSrc,configName){
  var id = resolveId(coverSrc);
  if (! configName) configName = 'large';
  var conf = playerConfig[configName];

  var src = "<div id=\"swfOBJ" + id + "\"><\/div>";
  document.getElementById('photoID' + id).innerHTML = src;
  if (conf.indication) {
    setIndication("Stop", "javascript:photo('"+ coverSrc +"', '" + configName + "');", id);
  }
  var so = new SWFObject(media_host + "/catalogue/" + conf.player, "mymovie", conf.width, conf.height, "8", conf.bgColor);
  so.addParam("bgcolor", conf.bgColor);
  so.addParam("quality", "high");
  so.addParam("allowScriptAccess", "always");
  so.addVariable("movieUri", media_host + "/catalogue/" + season_id + "/video/" + id + "." + conf.encode);
  so.addVariable("movieEndUri", "javascript:photo(&quot;" + coverSrc + "&quot;, &quot;" + configName + "&quot;)");  
  so.addVariable("cacheKey", "1");
  so.addVariable("preloadRate", "0.4");
  so.addVariable("beforeWait", conf.beforeWait);
  so.addVariable("afterWait", conf.afterWait);
  so.write("swfOBJ" + id);
}

function photo(coverSrc, configName){
  var id = resolveId(coverSrc);
  if (! configName) configName = 'large';
  var conf = playerConfig[configName];
  var src = "<a href=\"javascript:movie('"+coverSrc+"', '"+configName+"');\">"
            + "<img src=\"" + media_host + "/catalogue/" + season_id + "/" + coverSrc +"\" width=\"" + conf.width + "\" height=\"" + conf.height + "\" \/>"
            + "</a>";
  document.getElementById('photoID' + id).innerHTML = src;
  if (conf.indication) {
    setIndication("Video", "javascript:movie('"+ coverSrc +"', '" + configName + "');", id);
  }
}

function setIndication(label, link, id) {
	var indication = document.getElementById('controlID' + id);
	indication.innerHTML = "<a href=\"" + link + "\">" + label + "</a>";
}

function resolveId(str) {
  return str.substring(str.lastIndexOf("/") + 1, str.indexOf("-"));
}