// --------------------------------------------------
// -- 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 = '';

  //str_html += '<img src="' + img_path + '/' + n_image + '" width="660" height="300" alt="' + n_headline + '" border="0" />';
  //str_html += '<div class="news_date">' + n_date + '</div>';
  
  //str_html += '<div class="item_news" style="background-image: url(' + img_path + '/' + n_image + '); ">';
  
  str_html += '<div class="item_news">';
  str_html += '<img src="' + img_path + '/' + n_image + '" width="658" height="250" alt="' + n_headline + '" border="0" /><br/>';
  str_html += '<div class="item_news_text_area">';
  str_html += '<div class="item_news_headline"><a href="' + n_link + '">' + n_headline + '</a></div>';
  str_html += '<div class="item_news_ingress"><a href="' + n_link + '"><a href="' + n_link + '">' + n_ingress + '</a></div>';
  str_html += '<a href="' + n_link + '"><a href="' + n_link + '"><img src="/templates/saipa/images/front_news_read_more.gif" border="0" style="margin-bottom: 5px;"></a><br/>';
  str_html += '</div>';
  str_html += '</div>';
  
  //<span class="item_news_date">' + n_date + '</span><br />
  
//  str_html += '<div class="item_news_text_area">';
  //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>';
/*  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 += '>';
    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>';
  document.getElementById('news_block').innerHTML = str_html;
}


