$(function()
{
	if(pWhat!='')
	{
		var justOneWord = true;

		if($('#any').attr("checked") || $('#all').attr("checked"))
		{
			var allWords = new Array;

			allWords = pWhat.split(" ");
			justOneWord = allWords.length ==1 ? true : false;

			if(!justOneWord)
			{
				for(i=0; i<allWords.length; i++)
				{
					if( allWords[i].length > 2 )
					{
						var pat = "("+allWords[i]+")";

						$('div.title a.title').each(function()
						{
							var th = $(this).html();
							var re = new RegExp(pat, "gi");

							if(re.test(th))
							{
								th = th.replace(re, '<span class="highlight">$1</span>');
								$(this).html(th);
							}
						});

						$('div.description').each(function()
						{
							var th = $(this).html();
							var re = "/<\/?\w+[^>]*>/gi";
							var tmp = th.split(re);

							var re2 = new RegExp(pat, "mgi");

							for(var i=0; i<tmp.length;i++)
							{
								var n =	tmp[i];

								if(re2.test(n))
								{
									var s = n.replace(re2, '<span class="highlight">$1</span>');
									th = th.replace(n, s);
								}
							}

							$(this).html(th);
						});
					}
				}
			}
		}

		if($('#exact').attr("checked") || justOneWord)
		{
			pWhat = "("+pWhat+")";

			$('div.title a.title').each(function()
			{
				var th = $(this).html();
				var re = new RegExp(pWhat,"gi");

				if(re.test(th))
				{
					th = th.replace(re, '<span class="highlight">$1</span>');
					$(this).html(th);
				}
			});

			$('div.description').each(function()
			{
				var th = $(this).html();
				var re = /<\/?\w+[^>]*>/gi;
				var tmp = th.split(re);

				var re2 = new RegExp(pWhat,"mgi");

				for(var i=0; i<tmp.length;i++)
				{
					var n =	tmp[i];
					var s = n.replace(re2, '<span class="highlight">$1</span>');
					th = th.replace(n,s);
				}

				$(this).html(th);
			});
		}
	}
});
