(function ($) {

/**
 * Front_Comments_Post
 * @constructor jQuery
 * 
 */
$.widget('ui.Front_Comments_Post', $.extend({}, $.ui.Component.prototype, {
	type: 'Front_Comments_Post',
	_init: function () {

		$.ui.Component.prototype._init.call(this); // chain parent constructor
		var self = this
		var fo = Front_Comments_Online
		var name = self.element.find('#name')
		var comment = self.element.find('#comment')

		fo.name_p_border = name.css("border")
		fo.comment_p_border = comment.css("border")
		name.focus(function (){
			if($(this).val() == fo.name){
				$(this).val('');
			}
		})
		comment.focus(function (){
			if($(this).val() == fo.comment){
				$(this).val('');
			}
		})

		name.change(function (){
			$(this).css("border", fo.name_p_border)
		})
		comment.change(function (){
			$(this).css("border", fo.comment_p_border)
		})

		name.blur(function (){
			if($(this).val() == ''){
				$(this).val(fo.name);
			}
		})
		comment.blur(function (){
			if($(this).val() == ''){
				$(this).val(fo.comment);
			}
		})

		fo.chack_val = function (){
			if(name.val() == fo.name || name.val() == ''){
				fo.name_p_border = name.css('border')
				name.css('border', '#C33 solid 1px')
				return false
			}else if(comment.val() == fo.comment || comment.val() == ''){
				fo.comment_p_border = comment.css('border')
				comment.css('border', '#C33 solid 1px')
				return false
			}
			return true
		}

		name.keypress(function(ev){
			if (ev.keyCode == 13) {
				ev.preventDefault()
				if(ev.metaKey == true && fo.chack_val()){
					self.reload({
						name: name.val(),
						comment: comment.val(),
						c_r: $('#c_r').val()})
				}
			}
		})
		comment.keypress(function(ev){
			if (ev.keyCode == 13) {
				ev.preventDefault()
				if(ev.metaKey == true && fo.chack_val()){
					self.reload({
						name: name.val(),
						comment: comment.val(),
						c_r: $('#c_r').val()})
				}
			}
		})
		$('#post_btn').click(function (ev){
			ev.preventDefault()
			if(fo.chack_val()){
				self.reload({
					name: name.val(),
					comment: comment.val(),
					c_r: $('#c_r').val()})
			}
		})
	}
}));

}).require('Component')(jQuery);