function zufallszahl( min, max )
{
    return Math.floor(Math.random()*(min + max))
}
function GetRandom( min, max )
{
    // zwischen 1 und 9:
    return Math.floor(Math.random()*100) - 50;
    // -10 10
    // zufall :

        //      -10                                             +10
        return( min + parseInt( Math.floor(Math.random()) * ( max-min+1 ) ) );
}
function swap_ku_navi()
{
  var $active = $('#ku_navi .active');
  var $next = "";
  if($('#ku_navi .active').next().length > 0)
  {
      $next = $('#ku_navi .active').next()
  }
  else
  {
      $next = $('#ku_navi div:first');
  }
  $active.fadeOut(function()
  {
    $active.removeClass('active');
    $next.fadeIn().addClass('active');
    $next.circulate(
                    {
                    speed: 2000+GetRandom( -10, 10 ),
                    height: 1,/*GetRandom( -10, 10 ),*/
                    width: 1,/*GetRandom( -10, 10 ),*/
                    loop: true
                    });
  });
}
function swap_circles()
{
   var id=zufallszahl(1,25);
   $("#c"+id).fadeOut(1000);
   $("#c"+id).fadeIn(1000);

}
function swap_ku_messages()
{
  var max_ku_navis              = 3;
  var active_number             = ($('#ku_navi .active').attr("id")).match(/\d+$/);
  var next_number               = 0;

  if(parseInt(active_number) == parseInt(max_ku_navis))
  {
     next_number = 1;
  }
  else
  {
     next_number = parseInt(active_number)+1;
  }

    //$("#ku_li_"+next_number).hide();    // *

    //$("#ku_li_face_"+next_number).hide();

    $("#ku_li_"+active_number).removeClass("active");       // aktive box de-markieren (z-index change)

    //$("#ku_li_face_"+active_number).removeClass("talk");    // aktives gesicht de-markieren (background change)

    $("#ku_li_face_"+active_number).fadeOut("slow");

    $("#ku_li_face_"+next_number).fadeIn("slow");

    $("#ku_li_mess_"+active_number).removeClass("active");  // aktive box->message de-markieren (background change)

    $("#ku_li_"+next_number).addClass("active");            // nächste box markieren  (z-index change)

    //$("#ku_li_face_"+next_number).addClass("talk");         // nächstes gesicht markieren (background-change)

    //$("#ku_li_face_"+next_number).fadeIn();

    $("#ku_li_mess_"+next_number).addClass("active");       // nächste box->message markieren (background change)

    //$("#ku_li_"+next_number).fadeIn("slow");  // _mess

}
$(document).ready(function()
{
    $(".ku_li_mess").hide();  // alle messages in boxen ausblenden
    $(".circle").hide();  // Kreise ausblenden

    $(".ku_li_face").hide();  // sprechende Kreise ausblenden

    $("#ku_li_face_1").fadeIn("slow");        // ersten sprechenden einblenden

    $(".ku_li_mess").fadeIn("slow");
    //$(".ku_li_face").fadeIn();  // sprechende Kreise ausblenden


    $('.ku_channel').mouseover(function()
    {
        var id = ((this.id).match(/\d+$/));
        $("#ku_li_face_"+id).fadeIn("slow");
    });
    $('.ku_channel').mouseleave(function()
    {
        var id = ((this.id).match(/\d+$/));
        $("#ku_li_face_"+id).fadeOut("slow");
    });



    $("#ku_li_1").circulate(
                {
                speed: 2000+GetRandom( -10, 10 ),
                height: 4,
                width: 4,
                loop: true
                });

    $("#ku_li_2").circulate(
                {
                speed: 2000+GetRandom( -10, 10 ),
                height: -4,
                width: 4,
                loop: true
                });

    $("#ku_li_3").circulate(
                {
                speed: 2000+GetRandom( -10, 10 ),
                height: 4,
                width: 4,
                loop: true
                });
    /*
    $("#ku_li_face_1").circulate(
                    {
                    speed: 2000,
                    height: 10,
                    width: 20,
                    loop: true
                    });

    $("#ku_li_face_2").circulate(
                    {
                    speed: 2000,
                    height: 10,
                    width: 20,
                    loop: true
                    });

    $("#ku_li_face_3").circulate(
                    {
                    speed: 2000,
                    height: 10,
                    width: 20,
                    loop: true
                    });
    */


});


setInterval('swap_ku_messages()', 7000);

// Kreise animieren:
setInterval('swap_circles()', 200);


function fadeIn() {
  $("#ku_li_1").animate({opacity:0},500);
  setTimeout(fadeOut,3500);
}

function fadeOut() {
  $("#ku_li_1").animate({opacity:1},500);
  setTimeout(fadeIn,3500);
}

function startAnim() {
  setTimeout(fadeIn,3000);
}

//startAnim();

$(document).ready(function()
{

    /*
    setInterval(function()
    {
        $("#ku_li_1").fadeOut().delay(1000).fadeIn();
    }, 2000);
    setInterval(function()
    {
        $("#ku_li_2").fadeOut().delay(1000).fadeIn();
    }, 2000);
    */
    /*
    $("#ku_ba").everyTime(3000,function(i)
    {
        $(this).html(i);

        $('#ku_li_1').fadeIn().delay(1000).fadeOut();

        //$("#ku_li_1").delay(2000).fadeIn();
        //$("#ku_li_1").fadeOut();

        //$("#ku_li_1").fadeIn();

        $(this).oneTime(1, "hide", function()
        {
            $("#ku_li_1").fadeIn();
        });
        $(this).oneTime(2, "hide", function()
        {
            $("#ku_li_1").fadeOut();
        });

    });
    */

    //$("#circle").fadeOut();
    /*
    $(".circleX").circulate({

        speed: 1100,                  // Speed of each quarter segment of animation, 1000 = 1 second
        height: 10,                 // Distance vertically to travel
        width: 10,                  // Distance horizontally to travel
        sizeAdjustment: 100,         // Percentage to grow or shrink
        loop: true,                 // Circulate continuously
        zIndexValues: [1, 1, 1, 1]   // Sets z-index value at each stop of animation

    });
    */
    //alert(GetRandom( 0, 1 ));

    /* LATEST:


    $("#circles div").each(function()
    {
        $(this).circulate(
        {
            speed:  1000+GetRandom( -10, 10 ),
            height: GetRandom( -10, 10 ),
            width: GetRandom( -10, 10 ),
            loop: true
        }).click(function()
        {
             alert(this.id);
        })
    });
    */






    /*
    $("#ku_navi div").each(function()
    {
        $(this).circulate({
            speed: 2000+GetRandom( -10, 10 ),
            height: GetRandom( -10, 10 ),
            width: GetRandom( -10, 10 ),
            loop: true
        });
    }).click(function()
    {
        alert(this.id);
    });
    */



});


