$(document).ready(function() {
	$('#presentation-screenshots a').fancybox({
		zoomSpeedIn: 1000,
		zoomSpeedOut: 500
	});

  $("#slide-miniatures div").each(function(i) {
    $(this).mouseenter(function () {
      $("#slides").animate({"backgroundPosition": -(640 * i) + 'px 0'});
      $(".slide-legend:visible").hide();
      $("#slide-legend-" + (i + 1)).show();
    });
  });
  
  $('#rank-stars div').each(function(i) {
    $(this).mouseenter(function() {
      $(this).parent().removeClass('rank-big-stars-' + $('#rank-value').val());
      $(this).parent().addClass('rank-big-stars-' + (i + 1));
    });
    $(this).mouseleave(function() {
      $(this).parent().removeClass('rank-big-stars-' + (i + 1));
      $(this).parent().addClass('rank-big-stars-' + $('#rank-value').val());
    });
    $(this).click(function() {
      $.getJSON('../../' + $('#rank-url').val() + (i + 1), function(data) {
        $('#rank-stars').hide();
        $('#post-rank').html(data.message);
        $('#post-rank').fadeIn();
      });
    });  
  });
  
  $('.input-prefilled').each(function () {
    $(this).attr('title', $(this).val());
    $(this).focus(function () {
      if($(this).val() == $(this).attr('title')) {
        $(this).val('');
      }
    });
    $(this).blur(function () {
      if($(this).val() == '') {
        $(this).val($(this).attr('title'));
      }
    });
  });
  
  $('#options-gotogame-select').change(function () {
    document.location.href = $(this).val();
  });
  
  $('.delete-comment').click(function() {
      $.get('../../' + $('#delete-comment-url').val() + $(this).parent().parent().parent().parent().attr('id').substring(8));
      $(this).parent().parent().parent().parent().slideUp("slow");
  });
  
  $('.modify-comment').click(function() {
      $.getJSON('../../' + $('#modify-comment-url').val() + $(this).parent().parent().parent().parent().attr('id').substring(8), function(data) {
        $('#comment-' + data.id).find('.comment-message').html('');
        $('#comment-' + data.id).find('.comment-message').append($('<div class="comment-edit"><form method="get" action=""><textarea id="comment-edit-text" cols="10" rows="3" class="standard-textarea">' + data.message + '</textarea><input type="button" class="standard-submit" id="comment-edit-submit" /></form></div>'));
         $('#comment-edit-submit').click(function () {
          $.post('../../' + $('#modify-comment-url').val() + data.id, {'message': $('#comment-edit-text').val()}, function (data) {
            $('#comment-' + data.id).find('.comment-message').html(data.message);    
          }, 'json');
         });
      });
  });
  
	$('span.tip-active[title]:visible, img.tip-active[title]:visible, a.tip-active[title]:visible, input.tip-active[title]:visible, select.tip-active[title]:visible').tooltip({ 
    track: true, 
    delay: 0, 
    showURL: false,
    fade: 250,
		extraClass: 'minitip' 
	});
});