var bookmarkurl="http://www.kijktvonline.nl/";
var bookmarktitel="Kijk TV Online.nl";

function favorieten()
{
  if (document.all)
  window.external.AddFavorite(bookmarkurl,bookmarktitel)
}

function ScreenWidth()
{
// Eerst ff kijken hoe breed je scherm is
  if( typeof( window.innerWidth ) == 'number' ) {
  //Non-IE
    return window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  //IE 6+ in 'standards compliant mode'
    return document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  //IE 4 compatible
    return document.body.clientWidth;
} }

function resizeTV()
{
  var myWidth = ScreenWidth();
  if(horizontalSlider)
  {
    YY = horizontalSlider.getValue();
  }else{
    YY = 0;
  }

  if(YY < 0) {
    x = Math.floor( 320  + (YY * (320/100)) );
  }else{
    x = Math.floor( 320  + (YY * 3 * (320/100)) );
  }

  XX = Math.ceil(myWidth * 0.9);
  if(XX < MinWidth) {
    XX = MinWidth;
  }else if(XX > MaxWidth) {
    XX = MaxWidth;
  }

  if(x > (XX - 320)) {
    x = (XX - 320);
  }
  document.getElementById('TV').style.width  = x+"px";
  document.getElementById('TV').style.height = Math.round(270/320 * x)+"px";
  document.getElementById('TV_comment').style.width = x+"px";
  
  if(document.getElementById('FlashPlayer1'))
  {
    document.getElementById('FlashPlayer1').style.width = x+"px";
    document.getElementById('FlashPlayer1').style.height = Math.round(270/320 * x)+"px";
  }
  if(document.getElementById('FlashPlayer2'))
  {
    document.getElementById('FlashPlayer2').style.width = x+"px";
    document.getElementById('FlashPlayer2').style.height = Math.round(270/320 * x)+"px";
  }
};


// Deze functie zorgt ervoor dat het resizen van de content niet de gehele tijd gebuurt als de browser groter of kleiner wordt. Dit zorgt ervoor dat er minder cpu nogig is voor de browser.
var wait_now = 1;
function Wait_time( id )
{
  if(wait_now == 1)
  {
    div_maxwidth( id );
    wait_now = 0;
  }
  setTimeout('Wait_time("'+ id +'")', 1000);
}


// Standaard waardes...
var MinWidth = 970; // in "px".
var MaxWidth = 1500; // in "px".
var Width_   = 970;
var ProcentBolletjes = 60; // in "%".
var TVbreed = 90; // in "%".
var TVwidth = 320; // in "%".
var contents = 0; // aantal contents die aanwezig zijn.
var ContentMinWidth = 225 // in "px".
var ContentMaxWidth = 450 // in "px".
var contentdiv_ = 0;
var TV = 0;
function div_maxwidth(id1)
{
  var myWidth = ScreenWidth();

  if(TV == 1)
  {
    resizeTV();
  }

  object1 = document.getElementById( id1 );
  Width_ = Math.ceil(myWidth * 0.9);
  if(Width_ < MinWidth)
  {
    Width_ = MinWidth;
  }else if(Width_ > MaxWidth)
  {
    Width_ = MaxWidth;
  }
  object1.style.width = Width_+'px';

// De header goed maken
  BolletjesBreed = Math.floor( ( (myWidth - Width_) / 2 ) * (ProcentBolletjes / 100));
  if( BolletjesBreed <= 0 ) { BolletjesBreed = 1; }

  object2 = document.getElementById( 'headLeft');
  object3 = document.getElementById( 'headRight');

  object2.style.width = BolletjesBreed+'px';
  object3.style.width = BolletjesBreed+'px';

// De content goed maken...
  innerhtml_ = (Width_ - 316);
  innerhtml = Math.floor( innerhtml_ / ContentMinWidth );

// De breedte van de TV goed zetten als de pagina groter/kleiner wordt... (alleen ff onChange functie aanroepen!)
// Tabel breedtes instellen
 if(contents)
 {
  maintable_1 = document.getElementById('MainTable_1');
  maintable_2 = document.getElementById('MainTable_2');
  maintable_3 = document.getElementById('MainTable_3');
  maintable_4 = document.getElementById('MainTable_4');
  maintable_5 = document.getElementById('MainTable_5');
  contentdiv = document.getElementById('ContentDiv');
  spacer_1 = document.getElementById('Spacer_1');
  spacer_2 = document.getElementById('Spacer_2');
  spacer_3 = document.getElementById('Spacer_3');
  spacer_4 = document.getElementById('Spacer_4');

  maintable_1.style.width = '0px';
  maintable_2.style.width = '0px';
  maintable_3.style.width = '0px';
  maintable_4.style.width = '0px';
  maintable_5.style.width = '0px';

  spacer_1.innerHTML = '';
  spacer_2.innerHTML = '';
  spacer_3.innerHTML = '';
  spacer_4.innerHTML = '';
  if(innerhtml == 1) {
    maintable_1.style.width = Math.floor( innerhtml_ / 1 ) + 'px';
    contentdiv.style.width = Math.floor( innerhtml_ / 1 ) + 'px';
  }else if(innerhtml == 2) {
    maintable_1.style.width = ( Math.floor( innerhtml_ / 2 ) - 6 ) + 'px';
    maintable_2.style.width = ( Math.floor( innerhtml_ / 2 ) - 6 ) + 'px';
    spacer_1.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    contentdiv.style.width = (Math.floor( innerhtml_ / 2 ) * 2) + 'px';
  }else if(innerhtml == 3) {
    maintable_1.style.width = ( Math.floor( innerhtml_ / 3 ) - 8 ) + 'px';
    maintable_2.style.width = ( Math.floor( innerhtml_ / 3 ) - 8 ) + 'px';
    maintable_3.style.width = ( Math.floor( innerhtml_ / 3 ) - 8 ) + 'px';
    spacer_1.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    spacer_2.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    contentdiv.style.width = (Math.floor( innerhtml_ / 3 ) * 3) + 'px';
  }else if(innerhtml == 4) {
    maintable_1.style.width = ( Math.floor( innerhtml_ / 4 ) - 9 ) + 'px';
    maintable_2.style.width = ( Math.floor( innerhtml_ / 4 ) - 9 ) + 'px';
    maintable_3.style.width = ( Math.floor( innerhtml_ / 4 ) - 9 ) + 'px';
    maintable_4.style.width = ( Math.floor( innerhtml_ / 4 ) - 9 ) + 'px';
    spacer_1.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    spacer_2.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    spacer_3.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    contentdiv.style.width = (Math.floor( innerhtml_ / 4 ) * 4) + 'px';
  }else if(innerhtml == 5) {
    maintable_1.style.width = ( Math.floor( innerhtml_ / 5 ) - 10 ) + 'px';
    maintable_2.style.width = ( Math.floor( innerhtml_ / 5 ) - 9 ) + 'px';
    maintable_3.style.width = ( Math.floor( innerhtml_ / 5 ) - 10 ) + 'px';
    maintable_4.style.width = ( Math.floor( innerhtml_ / 5 ) - 9 ) + 'px';
    maintable_5.style.width = ( Math.floor( innerhtml_ / 5 ) - 10 ) + 'px';
    spacer_1.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    spacer_2.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    spacer_3.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    spacer_4.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    contentdiv.style.width = (Math.floor( innerhtml_ / 5 ) * 5) + 'px';
  }else{
    maintable_1.style.width = ( Math.floor( innerhtml_ / 2 ) - 6 ) + 'px';
    maintable_2.style.width = ( Math.floor( innerhtml_ / 2 ) - 6 ) + 'px';
    spacer_1.innerHTML = '<img src="images/content/spacer-9x9.png" height="9" width="12" alt="" border="0" />';
    contentdiv.style.width = (Math.floor( innerhtml_ / 2 ) * 2) + 'px';
    innerhtml = 2;
  }

  maintable_1.innerHTML = '';
  maintable_2.innerHTML = '';
  maintable_3.innerHTML = '';
  maintable_4.innerHTML = '';
  maintable_5.innerHTML = '';

  var z = 1;
  for (var i = 1; contents >= i; i++)
  {
    source = document.getElementById('container_'+i).innerHTML;
    if(z == 1) { maintable_1.innerHTML = maintable_1.innerHTML + '<br />' + source; }
    if(z == 2) { maintable_2.innerHTML = maintable_2.innerHTML + '<br />' + source; }
    if(z == 3) { maintable_3.innerHTML = maintable_3.innerHTML + '<br />' + source; }
    if(z == 4) { maintable_4.innerHTML = maintable_4.innerHTML + '<br />' + source; }
    if(z == 5) { maintable_5.innerHTML = maintable_5.innerHTML + '<br />' + source; }

    z++;
    if( z > innerhtml ) { z = 1; }
  }

  }else if(contentdiv_){
    contentdiv = document.getElementById('ContentDiv');
  if(innerhtml_ > ContentMaxWidth)
  {
    contentdiv.style.width = ContentMaxWidth + 'px';
  }else{
    contentdiv.style.width = innerhtml_ + 'px';
}}}
