var loaded = 0;

////////////////////////////////////////////////////////////////////////////////////////////

function getObject(id, parent) {
  var obj = (
    document.getElementById 
      ? document.getElementById(id)
      : document.all 
          ? document.all[id]
          : eval((parent ? 'parent.' : '') + 'document.' + id)
  );
  if (!obj.style) obj.style = obj;

  return obj;
}

function getImage(id, parent) {
  var obj = 
    document.getElementById 
      ? document.getElementById(id)
      : document.all 
          ? document.all[id] : obj;

  if (!obj) {
    if (parent) { parent = getObject(parent); }
    obj = eval((parent ? 'parent.' : '') + 'document.' + id);
  }
  if (!obj.style) obj.style = obj;

  return obj;
}

////////////////////////////////////////////////////////////////////////////////////////////

var precontent, content, contentscrolling = 0, contentpos=0, contentmaxpos, precontentheight, contentpgsize, scrolltimer = 0;
var arrup, arrdn, arrfup, arrfdn;

function showhidearrows() {
    arrfup.style.visibility = arrup.style.visibility = contentpos > -precontentheight ? 'visible' : 'hidden';
    arrfdn.style.visibility = arrdn.style.visibility = contentpos < contentmaxpos ? 'visible' : 'hidden';
}

function contentscroll() {
  scrolltimer = 0;
  if (contentscrolling != 0) {
    contentpos += contentscrolling;
    if (contentpos < -precontentheight) {contentpos = -precontentheight; }
    if (contentpos > contentmaxpos) {contentpos = contentmaxpos; }
    precontent.style.top = -precontentheight-contentpos;
    content.style.top = -contentpos;
    showhidearrows();
    scrolltimer = setTimeout('contentscroll()', 50);
  }  
}

function getHeight(obj) {
  return obj.offsetHeight ? obj.offsetHeight : obj.clip.height;
}

function contentinitscrolling() {
  arrup = getObject('arrowup');
  arrfup = getObject('arrowfastup');
  arrdn = getObject('arrowdown');
  arrfdn = getObject('arrowfastdown');
  var contentsbound = getObject('contentbound');
  precontent = getObject('precontent', contentsbound);
  precontentheight = getHeight(precontent);
  if (precontentheight < 8) precontentheight = 0;
  content = getObject('content', contentsbound);
  contentpgsize = getHeight(contentsbound);
  contentmaxpos = getHeight(content) - getHeight(contentsbound);
  if (contentmaxpos < -precontentheight) contentmaxpos = -precontentheight;
  if (contentpos > contentmaxpos) {contentpos = contentmaxpos; }
  precontent.style.top = -precontentheight-contentpos;
  content.style.top = -contentpos;
  precontent.style.visibility = 'visible';
  showhidearrows();
}

function contentscrollup() {
  if (!loaded) return;
  contentscrolling = -8;
  if (! scrolltimer) contentscroll();
}
function contentscrolldown() {
  if (!loaded) return;
  contentscrolling = 8;
  if (! scrolltimer) contentscroll();
}
function contentstopscrolling() {
  if (!loaded) return;
  contentscrolling = 0;
  if (scrolltimer) {
    clearTimeout(scrolltimer);
    scrolltimer = 0;
  }
}
function contentpgup() {
  if (!loaded) return;
  contentstopscrolling();
  contentscrolling = -(contentpgsize-20);
  contentscroll();
  contentstopscrolling();
}
function contentpgdn() {
  if (!loaded) return;
  contentstopscrolling();
  contentscrolling = contentpgsize-20;
  contentscroll();
  contentstopscrolling();
}

var menuiem, menuTimer = 0;

function menu_init() {
  menuitem = new Array;

  for(i=1; i<=8; i++) {
    imginit('menuimg' + String(i), 'images/menu' + String(i) + '_over.gif');
    menuitem[i] = getObject('menu' + String(i));
    if (!menuitem[i].style) { menuitem[i].style = menuitem[i]; }
    menuitem[i].savedVisibility = menuitem[i].style.visibility;
  }
}

function menu_enter(idx) {
  if (!loaded) return;
  mouseover('menuimg' + String(idx));
  if (menuTimer) {
    clearTimeout(menuTimer);
    menuTimer = 0;
  }
  for(i = 1; i<menuitem.length; i++) {
    menuitem[i].style.visibility = (i == idx ? 'visible':'hidden');
  }
}

function menu_restore() {
  for(i = 1; i<menuitem.length; i++) {
    menuitem[i].style.visibility = menuitem[i].savedVisibility;
  }
}

function menu_exit(idx) {
  if (!loaded) return;
  mouseout('menuimg' + String(idx));
  if (menuTimer) {
    clearTimeout(menuTimer);
  }
  menuTimer = setTimeout(menu_restore, 1000);
}

function mouseover(img, parent) {
  if (!loaded) return;
  img = getImage(img, parent);
  img.src = img.imgOver.src;
}

function mouseout(img, parent) {
  if (!loaded) return;
  img = getImage(img, parent);
  img.src = img.savedImg;
}

function imginit(img, over, parent) {
  img = getImage(img, parent);
  img.imgOver = new Image();
  img.imgOver.src = over;
  img.savedImg = img.src;
}

function load() {
  imginit('koule1', 'images/ball-over.gif');
  imginit('koule2', 'images/ball-over.gif');
  imginit('koule3', 'images/ball-over.gif');
  imginit('foot1', 'images/foot-dnes-over.gif');
  imginit('foot2', 'images/foot-zitra-over.gif');
  imginit('foot3', 'images/foot-tentotyden-over.gif');
  
  menu_init();
  contentinitscrolling();
  loaded = 1;
}

////////////////////////////////////////////////////////////////////////////////////////////

function detail(channel, title_id) {
  window.open(
    'detail.epl?c='+channel+'&i=' + title_id,
    '',
    'width=670,height=400,scrollbars,resizable');
}

function message(message_id) {
  window.open(
    'message.epl?i=' + message_id,
    '',
    'width=670,height=400,scrollbars,resizable');
}

function popup(url) {
  window.open(
    url,
    '',
    'width=680,height=520,scrollbars,resizable');
}

