jQuery.fn.extend({
	InputDefValue: function(options) {
		return this.each(function() {
			new jQuery.funcInputDefaultValue(this, options);
		});
	}
});


jQuery.funcInputDefaultValue = function(object, options) {

	//#opcje
	var opt			= options || {};
	opt.inputValue	= opt.inputValue || 'Wpisz text...';
	opt.maxText		= opt.maxText || '';		//only 'textarea'
	opt.maxLength   = opt.maxLength || '';	//only 'textarea'
	opt.charLeft  	= opt.charLeft || '';		//only 'textarea'


	var inputName = $(object); //$(object) = $(this)
	var thisValue = opt.inputValue;


	//#wyłączenie contextmenu
  $('form input, form textarea').bind('contextmenu', function(e) {
    return false;
  });


	//#wartosc dla textarea itp -> }).keyup();
	if ( inputName.get(0).tagName.toLowerCase() == 'textarea' ) {
	  if ( opt.maxLength != '' && opt.maxText != '' ) {
			//value dla textarea
	  	thisValue = opt.inputValue + ' ' + opt.maxText.replace('<max>', opt.maxLength);

			//max value + licznik dla textarea
			inputName.keyup(function(evt) {
				//var charCode = (evt.which) ? evt.which : event.keyCode;

				if( $(this).val().length >= opt.maxLength ) {
					$(this).val( $(this).val().substr( 0, opt.maxLength ) );
					$(this).parent().find('.charactersLeft').addClass('ColorRedLight');
				} else {
				  $(this).parent().find('.charactersLeft').removeClass('ColorRedLight');
				}

				$(this).parent().find('.charactersLeft').html( opt.charLeft + ' ' + (opt.maxLength - $(this).val().length) );
			});

			inputName.click(function() {
				$(this).css({ height: '125px', 'overflow-x': 'hidden' });
			});
	  }
	}


  //#zdarzenia myszy
  if ( inputName.val() == '' || inputName.val() == undefined ) {
		inputName.val(thisValue);
  }
	inputName.focus( function() {
		if ( inputName.val() == thisValue ) {
			inputName.val('');
		}
	});
	inputName.blur( function() {
		if ( inputName.val() == '' || inputName.val() == undefined ) {
			inputName.val(thisValue);
		}
	});

}
