(function($) {

  $.fn.charLength = function(options) {     

	var defaults = {  
    limit: 200,  
	message: "[ Read More... ]",   
	color: "red",
	fontSize: 12,
	dialogWidth: 500,
	dialogHeight: 400  
	};  
	var options = $.extend(defaults, options);
 
 return this.each(function() {

	var div = $(this);
	var divID = div.attr("id");
	var newDivID = divID+"CHAR";
	var content = div.html();
	var charLength = div.html().length;
	if (charLength > options.limit) {
	var newcontent = content.slice(0,options.limit)
	div.html(newcontent+"... <a id='"+newDivID+"trigger' class='test' href='#' style='color:"+options.color+";font-size:"+options.fontSize+"px;'>"+options.message+"</a>");		
	$("body").append("<div id='"+newDivID+"'>"+content+"</div>")
	$("#"+newDivID).dialog({autoOpen: false, dialogClass: 'commentWindow', width: options.dialogWidth, height: options.dialogHeight});
	
		$('#'+newDivID+'trigger').click(function() {
		// $("body").append("<div id='"+newDivID+"'>"+content+"</div>")
		// 		$("#"+newDivID).dialog({autoOpen: false, dialogClass: 'commentWindow', width: options.dialogWidth, height: options.dialogHeight});
			$("#"+newDivID).dialog('open');}
			);			

		}//end of if

     });
     };
			
 })(jQuery);

(function($) {

  $.fn.charLengthRenew = function(options) {     

	var defaults = {  
    limit: 200,  
	message: "[ Read More... ]",   
	color: "red",
	fontSize: 10,
	dialogWidth: 500,
	dialogHeight: 400  
	};  
	var options = $.extend(defaults, options);

 return this.each(function() {

	var div = $(this);
	var divID = div.attr("id");
	var newDivID = divID+"CHAR";
	var content = div.html();
	var charLength = div.html().length;
	if (charLength > options.limit) {
	var newcontent = content.slice(0,options.limit)
	div.html(newcontent+"... <a id='"+newDivID+"trigger' class='test' href='#' style='color:"+options.color+";font-size:"+options.fontSize+"px;'>"+options.message+"</a>");
	if ($('#'+newDivID).length) { // implies *not* zero
		$('#'+newDivID).empty();
		$('#'+newDivID).html(content);
		$('#'+newDivID+'trigger').click(function() {
			$("#"+newDivID).dialog('open');}
			);
  }		
	else {
	$("body").append("<div id='"+newDivID+"'>"+content+"</div>")
	$("#"+newDivID).dialog({autoOpen: false, dialogClass: 'commentWindow', width: options.dialogWidth, height: options.dialogHeight});

		$('#'+newDivID+'trigger').click(function() {
			$("#"+newDivID).dialog('open');}
			);			
		}//end of not-prexisting if statement
		}//end of actual char length if statement

     });
     };

 })(jQuery);

