$(document).ready(function(){
  $('#infobox').animate({opacity: 1.0}, 10000);
  $('#infobox').slideUp('slow');
  $(function(){
    $('input').keydown(function(e){
      if (e.keyCode == 13) {
        $(this).parents('form').submit();
        return false;
      }
    });
  });
  


 
	$(".olddays").hover(function(){
		$(this).fadeTo("slow", 1.0);
		},function(){
		$(this).fadeTo("slow", 0.6);
	});

	$(".olddays").hover(function(){
		$(this).animate({ color: "#999999" }, 500 );
		},function(){
		$(this).animate({ color: "#1d1d1d" }, 1000 );
    $(this).dequeue();
	});
	
	$(".watched").click(function(){
	    if ($(this).children().attr('src') == '/images/tick.png') {
            $(this).children().attr('src','/images/ticked.png');
            $(this).children().attr('alt','Mark as unwatched');
        }
        else {
            $(this).children().attr('src','/images/tick.png');
            $(this).children().attr('alt','Mark as watched');
        }
        $.get($(this).attr('href'));
        return false;
	});

  
  // Registration validation
	if ( $("#register").length > 0 ) {
  	$("#register").validate({
			success: function(label) { 
          label.html(" ").addClass("valid");
          label.parent().children().eq(2).addClass("valid");
      },
      error: function(element) {
				element.removeClass().addClass("error");
      },
		  errorPlacement: function(error, element) {
		  	error.appendTo( element.parent() );
		  	error.removeClass().addClass("error");
			},
  		rules: {
  			reg_username: "required",
  			reg_password: "required",
  			reg_username: {
  				required: true,
  				remote: "/canipickthis/",
  				minLength: 3,
  				maxLength: 20
  			},
  			reg_password: {
  				required: true,
  				minLength: 4
  			},
  			reg_verifypassword: {
  				required: true,
  				minLength: 4,
  				equalTo: "#reg_password"
  			},
  			reg_email: {
  				email: true
  			}
  		},
  		messages: {
  			reg_username: {
  				required: "Please enter a username",
  				minLength: "Your username must be between 3 and 20 characters long.",
  				remote: "The username is already in use"
  			},
  			reg_password: {
  				required: "Please provide a password",
  				minLength: "Your password must be at least 4 characters long."
  			},
  			reg_verifypassword: {
  				required: "Please provide a password",
  				minLength: "Your password must be at least 4 characters long.",
  				equalTo: "Please enter the same password as above."
  			},
  			email: "Please enter a valid email address"
  		}
  	});
  }

	if ( $("#reset").length > 0 ) {
    $("#reset").validate({
  		rules: {
  			res_password: "required",
  			res_password: {
  				required: true,
  				minLength: 4
  			},
  			res_verifypassword: {
  				required: true,
  				minLength: 4,
  				equalTo: "#res_password"
  			}
  		},
  		messages: {
  			res_password: {
  				required: "Please provide a password",
  				minLength: "Your password must be at least 4 characters long."
  			},
  			res_verifypassword: {
  				required: "Please provide a password",
  				minLength: "Your password must be at least 4 characters long.",
  				equalTo: "Please enter the same password as above."
  			}
  		}
  	});
	}


})
