/*
 * setup the jquery carousel widget
 */
$(document).ready(function() {
  $('ul.carousel').jcarousel({
    auto: 2,
    scroll: 1,
    wrap: 'last',
    initCallback: mycarousel_initCallback
  });

  $('ul.carousel2').jcarousel({
    auto: 5,
    scroll: 1,
    wrap: 'last',
    initCallback: mycarousel_initCallback
  });

  $('ul.carousel3').jcarousel({
    auto: 3,
    scroll: 1,
    wrap: 'last'
  });
});

function mycarousel_initCallback(carousel) {
  // Disable autoscrolling if the user clicks the prev or next button.
  carousel.buttonNext.bind('click', function() {
    carousel.startAuto(0);
  });

  carousel.buttonPrev.bind('click', function() {
    carousel.startAuto(0);
  });

  // Pause autoscrolling if the user moves with the cursor over the clip.
  carousel.clip.hover(function() {
    carousel.stopAuto();
  }, function() {
    carousel.startAuto();
  });
}


// Initialisierung von allen Elementen auf der Seite
$(document).ready(function() {
  //Verhalten
  $('a.mail').each(function() {
    var html = $(this).html().replace(/\(at\)/, '@');
    $(this).html(html);
    $(this).attr("href", 'mailto:' + html);
  });

  //Image-Helper für den IE
  $('img[align=left]').addClass('left');
  $('img[align=right]').addClass('right');

  $('input, textarea').focus(function () {
    $(this).addClass("focus");
  })
  $('input, textarea').blur(function () {
    $(this).removeClass("focus");
  })
  $('input[type=radio]').addClass('radio');
  $('input[type=checkbox]').addClass('checkbox');

  //Clearing-Funktionen für Input-Felder
  $('input.clear').focus(function () {
    if (this.value == this.defaultValue) this.value = '';
    $(this).removeClass('clear');
    return false;
  });
  $('input.clear').blur(function () {
    if (this.value == '') this.value = this.defaultValue;
    $(this).addClass('clear');
    return false;
  });

  //Logo-Klick
  $('#logo').css("cursor", "pointer");
  $('#logo').click(function () {
    location.href = $("#menu li:first a").attr("href");
  });

  //Teaser-Klick
  $('div.teaser').each(function () {
    if ($(this).find("h1 a").length > 0)
    {
      $(this).css("cursor", "pointer");
      $(this).click(function () {
        location.href = $(this).find("h1 a").attr("href");
      });
    }
  });

  //Box-Klick
  $('div.box').each(function () {
    if ($(this).find("a.title").length > 0)
    {
      $(this).css("cursor", "pointer");
      $(this).click(function () {
        location.href = $(this).find("a.title").attr("href");
      });
    }
  });

  //News-Bilder
  /*
   $('ul.news li').each(function () {
   if ($(this).find("a.arrow").length > 0)
   {
   $(this).find("img").css("cursor", "pointer");
   $(this).find("img").click(function () {
   location.href = $(this).find("a.arrow").attr("href");
   });
   }
   });
   */

  //Tabellenzeilen auszeichnen
  $('table').each(function(element) {
    var trs = $('tr', element);
    for (i = 0; i < trs.length; i++)
    {
      if (i % 2 == 0)
      {
        $(trs[i]).addClass('even');
      }
      else
      {
        $(trs[i]).addClass('odd');
      }

      if (i == 0)
      {
        $(trs[i]).addClass('first');
      }
      if (i == (trs.length - 1))
      {
        $(trs[i]).addClass('last');
      }

      markCellType = function (cellType, row) {
        var cells = $(cellType, row);
        for (j = 0; j < cells.length; j++)
        {
          cells[j].column = j + 1;
          $(cells[j]).addClass('column' + (j + 1));

          if (j % 2 == 0)
          {
            $(cells[j]).addClass('even');
          }
          else
          {
            $(cells[j]).addClass('odd');
          }
        }
      }

      markCellType('td', trs[i]);
      markCellType('th', trs[i]);
    }
  });
});