// --------------------------------------------------
// -- saipa.fi news changer script
// --------------------------------------------------

var news_count = -1;
var news_image = new Array();
var news_image_caption = new Array();
var news_date = new Array();
var news_headline = new Array();
var news_ingress = new Array();
var news_link = new Array();

function scroll_news( news_count, max_news, timer, x_stop, img_path )
{
  if ( news_count == 'prev' )
  {
    clearTimeout( t );
    news_count = news_count - 1;
    if ( news_count == -1 )
    {
      news_count = max_news - 1;
    }
    show_news( news_image[ news_count ], news_image_caption[ news_count ], news_date[ news_count ], news_headline[ news_count ], news_ingress[ news_count ], news_link[ news_count ], news_count, max_news, timer, img_path );
  } else if ( news_count == 'next' )
  {
    clearTimeout( t );
    news_count = news_count + 1;
    if ( news_count == max_news )
    {
      news_count = 0;
    }
    show_news( news_image[ news_count ], news_image_caption[ news_count], news_date[ news_count ], news_headline[ news_count ], news_ingress[ news_count ], news_link[ news_count ], news_count, max_news, timer, img_path );
  } else if ( x_stop == 1 )
  {
    clearTimeout( t );
    show_news( news_image[ news_count ], news_image_caption[ news_count], news_date[ news_count ], news_headline[ news_count ], news_ingress[ news_count ], news_link[ news_count ], news_count, max_news, timer, img_path );
  } else {
    news_count = news_count + 1;
    if ( news_count == max_news )
    {
      news_count = 0;
    }
    show_news( news_image[ news_count ], news_image_caption[ news_count], news_date[ news_count ], news_headline[ news_count ], news_ingress[ news_count ], news_link[ news_count ], news_count, max_news, timer, img_path );
    t = setTimeout('scroll_news(' + news_count + ', ' + max_news + ', ' + timer + ', 0, \'' + img_path + '\');', timer * 1000);
  }
}

function show_news( n_image, n_image_caption, n_date, n_headline, n_ingress, n_link, news_count, max_news, timer, img_path )
{
  var str_html = '';

  if ( n_image_caption != "" )
  {
    str_html += '<img src="' + img_path + '/' + n_image + '" width="430" height="213" alt="' + n_headline + '" border="0" />';
    str_html += '<br/><div class="news_image_caption">' + n_image_caption + '</div>';
  }
  else
  {
    str_html += '<img src="' + img_path + '/' + n_image + '" width="295" height="200" alt="' + n_headline + '" border="0" />';
  }

  str_html += '<div class="news_changer_items">';

  for ( x = 0; x < max_news; x++ )
  {
    if ( news_count == x )
    {
      str_class = 'news_changer_item_active';
    }
    else
    {
      str_class = 'news_changer_item';
    }
    str_html += '<div class="' + str_class + '"';
    if ( x < max_news - 1)
    {
      /*str_html += ' style="border-right: solid 1px #000;"';*/
    }
    str_html += '>';
    if ( x != news_count )
    {
      str_html += '<a href="javascript:scroll_news( ' + x + ', ' + max_news + ', ' + timer + ', 1, \'' + img_path + '\' )" title="' + news_headline[ x ] + '">';
    }
    str_html += x + 1;
    if ( x != news_count )
    {
      str_html += '</a>';
    }
    str_html += '</div>';
  }

  str_html += '</div>';
  str_html += '<div style="clear: both;"></div>';

  str_html += '<div class="item_news_headline"><a href="' + n_link + '">' + n_headline + '</a></div>';
  str_html += '<div class="item_news_text_area">';
  str_html += '<div class="news_date">' + n_date + '</div>';
  str_html += '<div class="news_text"><a href="' + n_link + '">' + n_ingress + '</a></div>';
  str_html += '</div>';
  str_html += '<div class="news_text_link"><a href="' + n_link + '">Lue lis&auml;&auml;</a></div>';

  document.getElementById('news_block').innerHTML = str_html;
}

function show_stats( item )
{
  document.getElementById('stats_scoreboard').style.display = 'none'
  document.getElementById('stats_statistics').style.display = 'none'
  document.getElementById( item ).style.display = 'block'
}

