$(function(){
	
	var sk_commentForm = function(){
		this.respond = $('#respond');
		this.label = this.respond.find('label');
		this.input = this.respond.find('input[type="text"]');
		
		this.required = this.respond.find('.required');
		
		this.replyLink = $('#comments').find('.comment-reply-link');
		this.cancelLink = this.respond.find('#cancel-comment-reply-link');
		this.replyTitle = $('#reply-title');
		this.letsTalk = this.replyTitle.find('.large');
		this.speed = 500;
		
		this.name = this.input.eq(0);
		this.nameText = 'Enter Your Name';
		
		this.email = this.input.eq(1);
		this.emailText = 'Enter Your Email';
		
		this.submitButton = $('#commentSubmit');
		
		
		this.init();
	};
	
	sk_commentForm.prototype = {
			
		init: function(){
			//Initial Style Actions
			this.label.hide();
			this.required.hide();
			this.input.css({'margin-bottom':'20px', 'margin-top':'0px'});
			this.email.css({'margin-bottom':'25px'});
			
			//Default Values
			this.setDefaultValues(this.name, this.nameText);
			this.setDefaultValues(this.email, 'Enter Your Email');
			
			//Focus Behavior
			this.setFocusBehavior(this.name, this.nameText);
			this.setFocusBehavior(this.email, this.emailText);
			
			//Check Values on Submit
			this.checkOnFormSubmit(this.submitButton, this.name, this.nameText);
			this.checkOnFormSubmit(this.submitButton, this.email, this.emailText);
			
			//Set Cancel and Reply Link Behavior
			this.setWPReplyLink(this.replyLink, this.cancelLink, this.letsTalk, this.replyTitle);
			this.setWPCanelLink(this.cancelLink, this.letsTalk, this.replyTitle);
		},
		
		
		setDefaultValues : function(input, defaultText){
			//Default Form Values
			if(input.val() == ''){
				input.val(defaultText).css({'color':'#777777'});
			}
		}, //setDefaultValues
		
		
		setFocusBehavior : function(input, defaultText){
			
			
			//Focus In
			input.focusin(function(){
				var value = $(this).val();
				if(value == defaultText){
					$(this).val('');
					$(this).css('color', '#222222');
				}
			});
			
			//Focus Out
			input.focusout(function(){
				var value = $(this).val();
				if(value == ''){
					$(this).val(defaultText);
					$(this).css('color', '#777777');
				}
			});
		}, //setFocusBehavior
		
		
		setWPReplyLink : function(link, cancelLink, letsTalk, replyTitle){
			//Reply Event - modify reply title
			link.click(function(){
				cancelLink.hide();
				letsTalk.fadeOut(this.speed, function(){
					cancelLink.fadeIn(this.speed);
					// need 29px more length (default padding of 5px 0 10px 0)
					replyTitle.css({'padding-top':'19px', 'padding-bottom':'20px'});
					});
			});
		}, //setWPReplyLink
		
		
		setWPCanelLink : function(link, letsTalk, replyTitle){
			//Cancel event = put it back
			link.click(function(){
				letsTalk.fadeIn(speed);
				replyTitle.css({'padding-top':'5px', 'padding-bottom':'10px'});
			});
		},//setWPCancelLink
		
		
		checkOnFormSubmit : function(submitButton, input, defaultText){
			//Dont let Submit Click save dafault vales
			submitButton.click(function(){
				if(input.val() == defaultText){ input.val(''); }
			});
		}//checkFormSubmit
	};
	
	//Run
	new sk_commentForm();
});
