	(function($){   

 $.fn.paintWidget = function(options) {   

  var defaults = {   
   length: 300,   
   minTrail: 20,   
   moreText: "more",   
   lessText: "less",   
   ellipsisText: "..."  

  };   

  var options = $.extend(defaults, options);   

  return this.each(function() {   

	 	obj = $(this);
		var widgetHTML = "";

   		var body = obj.html(); 
   		var color = "white";
   
		widgetHTML='<div class="profile">';

      //   Display first array response.
		var wiyR = WIYResponse[0];
		wiyR.EntrySummary=wiyR.EntrySummary.replace(/\[\]/g,"");
		wiyR.EntryLongSummary=wiyR.EntryLongSummary.replace(/\[\]/g,"");
	   
		var thedateString = new Date();
		var thedateString = wiyR.EntryDate;

		var maxwordlength = 22;
		var url_match = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])/g;
		
		friendlyDate = thedateString.substring(5,7) + "/" + thedateString.substring(8,10) + "/" + thedateString.substring(0,4);

		if (wiyR.EntryAuthorIMG != 'http://blogs.intel.com/mt-static4' || '')
			{
			widgetHTML+= "<div class='image'><a href='" + wiyR.BlogURL + wiyR.EntryPermalink + "' target='_blank'><img class='author' src='" + wiyR.EntryAuthorIMG + "'  width='59' height='59' alt='" + wiyR.EntryAuthor + "' title='" + wiyR.EntryAuthor + "' /></a></div>";
			}
		else
			{
			widgetHTML+= "<div class='image'><img class='author' src='/consumer/wimax/img/trans_placehldr.gif' width='59' height='59' alt='' title='' /></div>";
			}
			widgetHTML+= "<div class='left'><h4><a href='" + wiyR.BlogURL + wiyR.EntryPermalink + "' target='_blank'>" + wiyR.EntryTitle + "</a></h4>";

		//summary = default 1 for short
		if (summaryType == 1)
			{
				var url_match_array = wiyR.EntrySummary.match(url_match);
				if(url_match_array != null)
				{
					for(var i=0;i<url_match_array.length;i++)
					{
						var matched_url = url_match_array[i];
						if(matched_url != null)
						{
							var shortenedURL = matched_url.substring(0, maxwordlength - 3) + "...";
							wiyR.EntrySummary = wiyR.EntrySummary.replace(matched_url,'<a target="_blank" href="'+matched_url+'">'+shortenedURL+'</a>');
						}
					}
				}
				widgetHTML+= "<p>" + wiyR.EntrySummary + "</p>";
			}
		else
			{
				var url_match_array = wiyR.EntryLongSummary.match(url_match);
				if(url_match_array != null)
				{
					for(var i=0;i<url_match_array.length;i++)
					{
						var matched_url = url_match_array[i];
						if(matched_url != null)
						{
							var shortenedURL = matched_url.substring(0, maxwordlength - 3) + "...";
							wiyR.EntryLongSummary = wiyR.EntryLongSummary.replace(matched_url,'<a target="_blank" href="'+matched_url+'">'+shortenedURL+'</a>');
						}
					}
				}
				widgetHTML+= "<p>" + wiyR.EntryLongSummary + "</p>";
			}
			widgetHTML+= "<p>By ";
		if (wiyR.EntryAuthorURL)
			{
			widgetHTML+= "<a href='" + wiyR.EntryAuthorURL + "' target='_blank'>" + wiyR.EntryAuthor + "</a> on " + friendlyDate + "</p>";
			widgetHTML+= "<p><a target='_blank' href='" + wiyR.BlogURL + wiyR.EntryPermalink + "'>Learn more</a><img src='http://www.intel.com/en_US/Assets/Image/icons/gbl-link-plus.gif' /></p></div>";
			}
		else 
			{
			widgetHTML+= wiyR.EntryAuthor + " on " + friendlyDate + "</p>";
			widgetHTML+= "<p><a target='_blank' href='" + wiyR.BlogURL + wiyR.EntryPermalink + "'>Learn more</a><img src='http://www.intel.com/en_US/Assets/Image/icons/gbl-link-plus.gif' /></p></div>";
			}	
							
		//loop for additional responses
		var i;
 		for(i = 1; i < WIYResponse.length; i++) 
		{
       	
		wiyR = WIYResponse[i];
		wiyR.EntrySummary=wiyR.EntrySummary.replace(/\[\]/g,"");
		wiyR.EntryLongSummary=wiyR.EntryLongSummary.replace(/\[\]/g,"");
			
		//keep responses with multiple keywords from repeating
		if (WIYResponse[i].EntryTitle != WIYResponse[i-1].EntryTitle)
			{			
			if (wiyR.EntryAuthorIMG != null || '')
				{
				widgetHTML+= "<div class='image'><a href='" + wiyR.BlogURL + wiyR.EntryPermalink + "' target='_blank'><img src='" + wiyR.EntryAuthorIMG + "'  width='59' height='59' alt='" + wiyR.EntryAuthor + "' title='" + wiyR.EntryAuthor + "' /></a></div>";
				}
			else
				{
				widgetHTML+= "<div class='image'><img src='/consumer/wimax/img/trans_placehldr.gif' width='59' height='59' alt='' title='' /></div>";
				}
				widgetHTML+= "<div class='left'><h4><a href='" + wiyR.BlogURL + wiyR.EntryPermalink + "' target='_blank'>" + wiyR.EntryTitle + "</a></h4>";

				//summary = 1 for short
			if (summaryType == 1)
				{
					var url_match_array = wiyR.EntrySummary.match(url_match);
					if(url_match_array != null)
					{
						for(var j=0;j<url_match_array.length;j++)
						{
							var matched_url = url_match_array[j];
							if(matched_url != null)
							{
								var shortenedURL = matched_url.substring(0, maxwordlength - 3) + "...";
								wiyR.EntrySummary = wiyR.EntrySummary.replace(matched_url,'<a target="_blank" href="'+matched_url+'">'+shortenedURL+'</a>');
							}
						}
					}
					widgetHTML+= "<p>" + wiyR.EntrySummary + "</p>";
				}
			else
				{
					var url_match_array = wiyR.EntryLongSummary.match(url_match);
					if(url_match_array != null)
					{
						for(var i=0;i<url_match_array.length;i++)
						{
							var matched_url = url_match_array[j];
							if(matched_url != null)
							{
								var shortenedURL = matched_url.substring(0, maxwordlength - 3) + "...";
								wiyR.EntryLongSummary = wiyR.EntryLongSummary.replace(matched_url,'<a target="_blank" href="'+matched_url+'">'+shortenedURL+'</a>');
							}
						}
					}
					widgetHTML+= "<p>" + wiyR.EntryLongSummary + "</p>";
				}
				widgetHTML+= "<p>By ";
			if (wiyR.EntryAuthorURL)
				{
				widgetHTML+= "<a href='" + wiyR.EntryAuthorURL + "' target='_blank'>" + wiyR.EntryAuthor + "</a> on " + friendlyDate + "</p>";
				widgetHTML+= "<p class='learn-more'><a target='_blank' href='" + wiyR.BlogURL + wiyR.EntryPermalink + "'>Learn more</a><img src='http://www.intel.com/en_US/Assets/Image/icons/gbl-link-plus.gif' /></p></div>";
				}
			else 
				{
				widgetHTML+= wiyR.EntryAuthor + " on " + friendlyDate + "</p>";
				widgetHTML+= "<p class='learn-more'><a target='_blank' href='" + wiyR.BlogURL + wiyR.EntryPermalink + "'>Learn more</a><img src='http://www.intel.com/en_US/Assets/Image/icons/gbl-link-plus.gif' /></p></div>";
				}
			}
		}
		widgetHTML+='</div>';

      	obj.append(widgetHTML);
   
       });   

      };   

})(jQuery);



