/******* Text Box Hints START ********/
/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {
	$.fn.hint = function (blurClass) {
	    if (!blurClass) blurClass = 'blur';
	    return this.each(function () {
	        var $input = $(this),
	            title = $input.attr('title'),
	            $form = $(this.form),
	            $win = $(window);
	        function remove() {
	            if (this.value === title && $input.hasClass(blurClass)) {
	                $input.val('').removeClass(blurClass);
	            }
	        }
	        // only apply logic if the element has the attribute
	        if (title) {
	            // on blur, set value to title attr if text is blank
	            $input.blur(function () {
	                if (this.value === '') {
	                    $input.val(title).addClass(blurClass);
	                }
	            }).focus(remove).blur(); // now change all inputs to title
	            // clear the pre-defined text when form is submitted
	            $form.submit(remove);
	            $win.unload(remove); // handles Firefox's autocomplete
	        }
	    });
	};
})(jQuery);

$(function(){
	// elements with class 'blur'
	$('.blur').hint();
});
/******* Text Box Hints END ********/

/******* SMOOTH SCROLLING START ********/
$(document).ready(function(){
	$('#rcTop a[href*=#], #cr_fc a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html, body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
});
/******* SMOOTH SCROLLING END ********/

/******* FORM LIMITATION SCRIPT START *********/
function limitChars(textid, limit, infodiv){

	 var text = $('#'+textid).val(); 
	 var textlength = text.length;
	 
	 if(textlength > limit){
		
		$('#' + infodiv).html('Не можете да пишете повече от '+limit+' символа!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else{
		$('#' + infodiv).html('Имате още '+ (limit - textlength) +' позволени символа');
		return true;
	}

}

// start limitation
$(function(){
	$('#userComment').keyup(function(){
		limitChars('userComment', 2000, 'charlimitinfo');
	})
});


/******* FORM LIMITATION SCRIPT END *********/

/******* ADDING CLASS ON LAST COMMENTS START *********/
$(document).ready(function(){
	$('#commentsContainer > div.readerComments:last').addClass('readerCommentsLast');
});
/******* ADDING CLASS ON LAST COMMENTS END *********/

/******* FORM CHANGE COLOR START *********/
$(function(){
	$('#userComment').click(function(){
		$(this).css('color', '#000');
	})
});

$(function(){
	$('#userComment').blur(function(){
		if($(this).val() == 'Максимум 2000 символа') $(this).css('color', '#999999');
	})
});
/******* FORM CHANGE COLOR END *********/