Cufon.replace('.menuBox li, .navBox li', {hover: true} );
Cufon.replace( '#headerCntr p, .listBox p, .listBox li, .infoBox h3, .newsBox h2, .searchBox h1' );

$(function() {

  $('div.yearNews, div.newsGroup, div.downloadGroup').hide();
  $('h3.yearNewsToggle').bind( 'click', function() {
    $('#news-' + $(this).attr( 'id' ) ).slideToggle();
  });
  
  $('h2.newsGroupToggle').bind( 'click', function() {
    if($.browser.msie ) $('#news_' + $(this).attr( 'id' ) ).toggle();  
    else $('#news_' + $(this).attr( 'id' ) ).slideToggle();        
  });
  
  $('h2.downloadToggle').bind( 'click', function() {
    if($.browser.msie ) $('#downloads_' + $(this).attr( 'id' ) ).toggle();  
    else $('#downloads_' + $(this).attr( 'id' ) ).slideToggle();        
  });  

  $('.newsBox li a').click( function() {
    
    clearTimeout( n_timer );
    news_slider( ($(this).attr( 'rel' ).replace( /slide/, '' ) - 1) );
    return false;
  });
  
  $('.newsBox div.slide').css( {height: '0px'} );
  news_slider();
  
  /**
   * FAQ's
   */
  $( 'div.faq h3' ).css( 'text-decoration', 'underline' );
  $( 'div.faq h3' ).css( 'cursor', 'pointer' );
  $( 'div.faq p' ).hide();
  $( 'div.faq h3' ).bind( 'click', function() { 
    $(this).nextAll().each(function() {
      if ($(this).is('h3')) {
        return false;
      }
      $(this).slideToggle( "fast" );
    });
  });       
  
  
  /**
   * tools floater
   **/
  sh = screen.height; topOffset = 520; fy = $('#footerCntr').offset().top; ny = $(document).height(); bottomOffset = 230 + $('#footerCntr').height();
  $('#tools').css( {top: (sh - topOffset) + 'px'} );
  menuYloc = (sh - topOffset); 
  
  $(window).scroll(function () {
    var offset = menuYloc + $(document).scrollTop();
    if( offset > ( fy - bottomOffset ) ) offset = ( fy - bottomOffset );    
    $('#tools').animate({top: offset + 'px'},{duration:100,queue:false}); 
  });  
  
});

var c_speed = 10000;
var c_timer;
var c_items;

var n_timer;

function news_slider( to ) {
  if( arguments.length == 0 )
    to = 0;
  
  $('.newsBox div.slide').hide();
  $('.newsBox li').removeClass( 'active' );
  
  if( $('.newsBox div.slide:eq(' + to + ')').length == 0 ) {
    to = 0;
  }
  $('.newsBox div.slide:eq(' + to + ')').show();
  $('.newsBox li:eq(' + to + ')').addClass( 'active' );
    
  n_timer = window.setTimeout( 'news_slider(' + ( to + 1 ) + ')', 10000 );
}


function carrousel_start() {
  if( arguments.length == 1 )
    c_speed = arguments[0];
    
  c_items = $('.newsBox li').length;
  
  if( !($.browser.msie) || ($.browser.msie && $.browser.version != 6 ) )
    c_timer = window.setTimeout( carrousel_ride, c_speed, 1 );
}

function carrousel_ride( to ) {
  if( arguments.length == 0 )
    to = 1;
  
  window.clearTimeout( c_timer );
  
  if( to == 0 ) {//to beginning, expand all
    //$( '.newsBox div.slide').animate( { height: '175px'}, 500, function() { $(this).show() });
    $('.newsBox div.slide:eq(0)').show();
    
    //$( '#carrousel li').animate( { height: '187px'}, 500, function() {$(this).show()});
    //$( '#carrousel li h3').show();
  } else {
    
    //collapse all before 'to'
    $( '.newsBox div.slide:lt( ' + to + ')').animate( { height: '0px'}, 500, function() { $(this).hide() });
    //$( '#carrousel li:lt(' + to + ') h3').hide();
    //$( '#carrousel li:lt(' + to + ')').animate( { height: '0px'}, 500, function() { $(this).hide() });
    
    //expand all before en including to
    $( '.newsBox div.slide:gt( ' + (to-1) + ')' ).animate( {height: '175px;'}, 500, function() { $(this).show(); });
    
    //$( '#carrousel li:gt(' + (to-1) + ')').animate( { height: '187px'}, 500, function() { $(this).show() });    
  }
  
  $('.newsBox li').removeClass( 'active' );
  if( $('.newsBox div.slide').eq( to ).length > 0 ) {
      
  }
  /*
  $('#latest-news div.left div.headline div').removeClass( 'activeHeadline' );
  if( $( '#carrousel li').eq(to).length > 0 ) {
    var id = $( '#carrousel li').eq(to).attr( 'id' ).replace( 'preview-', '' );
    $('#headline-' + id ).addClass( 'activeHeadline' );       
  }
  */
  var nextTo = (to+1);
  if( nextTo == c_items )
    nextTo = 0;
  
  if( !($.browser.msie) || ($.browser.msie && $.browser.version != 6 ) ) {
    c_timer = window.setTimeout( 'carrousel_ride(' + nextTo + ')', c_speed );
  }
}
