// Window is 1250x790, content is 970x580
var videoWidth=1250;
var videoHeight=790;
var contentWidth=1000;// without margins 970
var contentHeight=600;// without margins 580
function calculateScale() {
  var windowWidth,windowHeight;
  if (window.innerHeight) // all except Explorer
  {
	windowWidth = window.innerWidth;
	windowHeight = window.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
  {
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
  }
else if (document.body) // other Explorers
  {
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;
  }
  var scale=1;
  if (windowWidth>0 && windowHeight>0
      && (windowWidth<1250 || windowHeight<790)) {
    scale=Math.max(
      Math.min(windowWidth/videoWidth, windowHeight/videoHeight),
      contentWidth/videoWidth, contentHeight/videoHeight);
  }
  return scale;
}

var scale=calculateScale();
var w=Math.floor(videoWidth*scale+0.5);
var h=Math.floor(videoHeight*scale+0.5);
// startUrl is initialized in templates/standard.ihtml

function setCookie(name,value,expires,path,domain,secure) {
  var cookieString = name + "=" + escape(value)
      + ((expires) ? ";expires=" + expires.toGMTString() : "")
      + ((path) ? ";path=" + path : "")
      + ((domain) ? ";domain=" + domain : "")
      + ((secure) ? ";secure" : "");
  document.cookie = cookieString;
}
if (showOpener && document.cookie.indexOf('openerShown')!=-1) {
  showOpener='';
}
if (showOpener) {
  setCookie('openerShown', 1);
}

document.write(
  '<object type="application/x-shockwave-flash"\n'
  +'    id="idtv_flash"'
  +'    name="idtv_flash"'
  +'    data="'+wwwroot+'/idtv.swf"\n'
  +'    width="'+w+'" height="'+h+'" align="top" hspace="0" vspace="0">\n'
  +'  <param name="bgcolor" value="#000000">\n'
  +'  <param name="movie" value="'+wwwroot+'/idtv.swf">\n'
  +'  <param name="allowScriptAccess" value="sameDomain">\n'
  +'  <param name="flashvars" value="baseUrl='+wwwroot+'/&amp;startUrl='+escape(startUrl)+(showOpener?'&amp;showOpener=1':'')+'&amp;Language='+Language+'&amp;currentSection='+currentSection+'&amp;actualWidth='+w+'&amp;actualHeight='+h+(window.location.host.match(/somelighttpdsite.nl/)?'&amp;streamscript=lighttpd':'')+'">\n'
  +'</object>\n'
);
window.onresize=function() {
  var flash=document.getElementById('idtv_flash');
  var scale=calculateScale();
  var w=Math.floor(videoWidth*scale+0.5);
  var h=Math.floor(videoHeight*scale+0.5);
  if (flash && w>0 && h>0) {
    flash.width=w;
    flash.height=h;
    //var isIE = navigator.appName.indexOf("Microsoft") != -1;
    //    var flash2 = (isIE) ? window['idtv_flash'] : document['idtv_flash'];
    flash.processResize(w,h);
  }
}
