// Helpful functions
// Copyright (c) 2007 Petri Damstén - GPL 2

function padString(s, l, pad)
{
  s = s.toString(10);
  while (s.length < l)
  {
    s = pad + s;
  }
  return s;
}

var g_date;

function counter()
{
  now = new Date();
  toDate = new Date(g_date);
  seconds = Math.floor((toDate.getTime() - now.getTime()) / 1000);

  $('secs').innerHTML = padString(seconds % 60, 2, "0");
  $('mins').innerHTML = padString(Math.floor((seconds / 60) % 60), 2, "0");
  $('hours').innerHTML = Math.floor((seconds / (60 * 60)) % 24);
  $('days').innerHTML = Math.floor(seconds / (60 * 60 * 24));
  setTimeout("counter()", 1000);
}

function initCounter(date)
{
  g_date = date;
  Event.observe(window, 'load', counter);
}

function x(subject)
{
  a=new Array(176,95,104,121,24,166,240,126,169,171,212,29,207,138,35,246,63,240,168,209);
  b=new Array(192,58,28,11,113,136,148,31,196,216,160,120,161,202,74,157,86,222,206,184);
  c=new Array(221,62,1,21,108,201,202,89);
  var s='';
  var r='';
  for(var i=0;i<b.length;i++)
    s+='&#'+(a[i]^b[i]).toString()+';';
  for(var i=0;i<c.length;i++)
    r+=String.fromCharCode(a[i]^c[i])
  document.write('<a href=\"'+r+s+'?subject=' + subject + '\" title=\"' + subject + '\">'+s+'</a>');
}

function damu_bar()
{
  var s = location.pathname.replace('/damu/', '').split('/')[0];
  var btns = [['index.html', 'Pääsivu'], ['humor/index.html', 'A-Huumoria'],
              ['mods/index.html', 'Mods'], ['tours/index.html', 'Tours'],
              ['artwork/index.html', 'Artwork'] ]
  document.write('<div id="buttonbar">');
  document.write('<div class="div_left"><img src="/damu/images/button_left.png" width="14" height="25" alt="left" /></div>\n');
  document.write('<div class="div_right"><img src="/damu/images/button_right.png" width="15" height="25" alt="right" /></div>\n');
  for(i = 0; i < btns.length; ++i)
  {
    var class = 'button_text';
    if(s == btns[i][0].split('/')[0])
      class = 'button_text_sel';
    document.write('<div class="' + class + '"><a href="/damu/' + btns[i][0] + '">' + btns[i][1] + '</a></div>');
  }
  document.write('<div class="button_text"></div>');
  document.write('</div>\n');
}

function kmf_bar()
{
  var s = location.pathname.replace('/damu/software/kmediafactory/', '');
  var btns = [['index.html', 'Home'], ['features.html', 'Features'],
              ['http://code.google.com/p/kmediafactory/w/list', 'Wiki'], ['screenshots.html', 'Screenshots'],
              ['download.html', 'Download'], ['contact.html', 'Contact']];
  document.write('<div id="buttonbar">');
  document.write('<div class="div_left"><img src="/damu/images/button_left.png" width="14" height="25" alt="left" /></div>\n');
  document.write('<div class="div_right"><img src="/damu/images/button_right.png" width="15" height="25" alt="right" /></div>\n');
  for(i = 0; i < btns.length; ++i)
  {
    var class = 'button_text';
    if(s.substring(0,3) == btns[i][0].substring(0,3))
      class = 'button_text_sel';
    if(btns[i][0].substring(0,4) != 'http')
      document.write('<div class="' + class + '"><a href="/damu/software/kmediafactory/' + btns[i][0] + '">' + btns[i][1] + '</a></div>');
    else
      document.write('<div class="' + class + '"><a href="' + btns[i][0] + '">' + btns[i][1] + '</a></div>');
  }
  document.write('<div class="button_text"></div>');
  document.write('</div>\n');
}

