$(document).ready(function () {

    $.each($('input[type="text"]'), function (index, obj) {
        var initValue = $(this).val();
        $(this).focus(function () {
            if ($(this).val() == initValue) {
                $(this).val('');
            }
//            $(this).val('');
        }).blur(function () {
            if ($(this).val() == '') {
                $(this).val(initValue);
            }
        });
    });

    $(".datepicker").datepicker({
        showOn: "button",
        buttonImage: "/asset/img/calendar.jpg",
        buttonImageOnly: true,
        dateFormat: "dd/mm/yy"
    });

    //$(".scrollers").scrollable({ circular: true}).autoscroll({ interval: 3000});
});


if ($('.scrollContent').height() >= 380) {
    $('.scrollContent').css({ 'height': '380px' });
} else {
    $('.downArrow').hide();
}


var scrollvalue = -200;
$('.upArrow').hide();
$('.downArrow').click(function (evt) {
    evt.preventDefault();
    var lastEl = $(this).parent().find(".scrollContent").children().last();
    var scrollRef = $(this).parent().find(".scrollContent");
    var totalvalue = (400 + (lastEl.position().top + lastEl.height()) * -1);

    scrollRef.stop();
    var currentPos = scrollRef.position().top;
    if ((currentPos) <= totalvalue) {
      $('.downArrow').hide();
    } else {
      currentPos += scrollvalue;
    }

    scrollRef.animate({ top: currentPos }, 600, function () {
      if ((currentPos) < 0) {
        $('.upArrow').show();
      }
      if ((currentPos) <= totalvalue) {
        $('.downArrow').hide();
      }

    });
 });

 $('.upArrow').click(function (evt) {
    evt.preventDefault();
    var lastEl = $(this).parent().find(".scrollContent").children().last();
    var scrollRef = $(this).parent().find(".scrollContent");
    var totalvalue = (400 + (lastEl.position().top + lastEl.height()) * -1);
    scrollRef.stop();
    var currentPos = scrollRef.position().top;
    if ((currentPos) >= 0) {
      $('.upArrow').hide();
    } else {
      currentPos -= scrollvalue;
    }

    scrollRef.animate({ top: ((currentPos > 0) ? 0 : currentPos) }, 600, function () {
      if ((currentPos) < 0) {
        $('.upArrow').show();
      }
      if ((currentPos) == 0) {
        $('.upArrow').hide();
        $('.downArrow').show();
      }
      if ((currentPos) <= totalvalue) {
        $('.downArrow').hide();
      } else {
        $('.downArrow').show();
      }
    });
});
