$(document).ready(function()
{
  slide_menu("#navigation", 20, 10, 150);
  image_slide("#splash-viewer");
  var prefill_fields = $('#query, #comment_comment');
  prefill_fields.each(prefill_field);
  prefill_fields.bind('blur.prefilled_field', prefill_field);
  prefill_fields.bind('focus.prefilled_field', function() {
    if($(this).val() == $(this).attr('title')) {
       $(this).removeClass('prefilled').val('');
    }
  });
  map_init("#map-places");
});

function slide_menu(navigation_id, pad_out, pad_in, time)
{
  // creates the target paths
  var list_elements = navigation_id + " li";
  var link_elements = list_elements + " a";

  // creates the hover-slide effect for all link elements
  $(link_elements).each(function(i)
  {
    $(this).hover(
    function()
    {
      $(this).animate({ paddingTop: pad_out }, time);
    },
    function()
    {
      $(this).animate({ paddingTop: pad_in }, time);
    });
  });
}

function image_slide(block_id)
{
  $(block_id).prepend(
    "<div class='splash-navigation'>\n" +
    "<a href='' class='prev'>Prev</a>\n" +
    "<span class='currentOf'>&nbsp;</span>" +
    "<a href='' class='next'>Next</a>\n" +
    "</div>\n");

  $(block_id).jCarouselLite({
    btnNext: ".splash-navigation .next",
    btnPrev: ".splash-navigation .prev",
    divCurrentOf: ".splash-navigation .currentOf",
//    mouseWheel: false,
    auto: 30000,
    speed: 500,
    random: true,
//    vertical: true,
    circular: true,
    visible: 1,
//    start: 0,
//    scroll: 1,
    current_of_size: true,
    beforeStart: null,
    afterEnd: null
  });
}

function prefill_field() {
  var me = $(this);
  if (me.val() == '') {
    me.addClass("prefilled").val(me.attr('title'));
  }
}

function map_init(block_id)
{
  var infoWidth = 200;
  var fadeSpeed = 500;
  var padding_x = 10;
  $(block_id).prepend("<div id='map-info'></div>");
  var info = $("#map-info", block_id);
  info.hide();
  info.css({width: infoWidth + "px"});

  $("a", block_id).each(function() {
    $(this).removeAttr("alt");
    $(this).removeAttr("title");
    $(this).hover(function() {
      info.stop(true, true);

      var x = $(this).position().left - (infoWidth / 2) + ($(this).width() / 2);
      var y = $(this).position().top + $(this).height();

      info.html($(this).html());
      info.wrapInner("<p></p>");
      $("p", info).css({margin: "0px", padding: "20px " + padding_x + "px 5px " + padding_x + "px"});
      info.append("<div id='map-info-foot'>&nbsp;</div>");
      info.css({left: x, top: y});
      info.fadeIn(fadeSpeed);
    }, function() {
      info.fadeOut(fadeSpeed);
    });

    $(this).click(function() {
      return false
    });
  });
}