var checkField = function(field) {
  if(field.val() == "") {
    if(!field.parent().is("span")) {
      field.wrap("<span></span>");
    }
    field.parent().addClass("error");
    return false;
  } else {
    field.parent().removeClass("error");
    return true;
  }
}

$(function() {
  
  $(".add-comment .required").blur(function() {
    checkField($(this));
  });

  $(".add-comment form").submit(function() {
    var stop = false;
    $(this).find(".required").each(function() {
      if(checkField($(this)) == false) {
        stop = true;
      }
    });
    if(stop == true) {
      return false;
    }
  });
  
  $('a.reply').click(function (){
  	$('#comment_parent').val($(this).attr('href').substr(1));
  	//window.location = '#add-comment';
  	$('#add-comment').text('Reply to Comment ' + $(this).attr('href'));
  	return false;
  });

  /*$(".add-comment input[type=file]").wrap("<span class='file input'></span>").filestyle({ 
      image: "images/design/transparent.png",
      imageheight: 19,
      imagewidth: 20,
      width: 200
  });*/

  //$(".comment:last-child").addClass('last');
  
  var activePage = $('div.input-wrapper input').val();
  
  $('div.input-wrapper input').blur(function (){
  	if(activePage != $(this).val()) {
  		window.location.href = '/page/'+$(this).val();
  	}
  	return false;
  });
  $('#pager a.next, #pager a.back').hover(function (){
  	$(this).addClass('hover');
  }, function (){
  	$(this).removeClass('hover');
  });
  /*$('div.pager form').submit(function (){
  	if(activePage != $('').val()) {
  		window.location.href = '/page/'+$(this).val();
  	}
  	return false;
  });
 
  $('.comments .comment:last').each(function (){
	if(!$(this).hasClass('threaded')) {
		$(this).css('background', '');
	}
  })*/
  
});