function initResults(pattern) {

   var fullURL = parent.document.URL
   var queryvar = fullURL.substring(fullURL.indexOf('results_per_page=')+17, fullURL.length);
   var resultsPerPage = queryvar.slice(0,queryvar.indexOf('&'));

   $("#resultnum option").each(function (i) {
      if(this.value == resultsPerPage){
         $(this).attr("selected", "selected");
      }
   });

      /* Search term highlight */
   var searchTerm = pattern.split(" ");
   var matchedTerm;
   var count;
   for(i=0;i<searchTerm.length;i++) {
      var patt=new RegExp(searchTerm[i], "gi");
      matchedTerm = "";

    $('.resulttitle').each(function(){
      matchedTerm = $(this).html().match(patt);

	  if(matchedTerm !=null){
      for(j=0;j<matchedTerm.length;j++) {     
	     $(this).html($(this).html().replace(new RegExp(matchedTerm[j],'g'),
           '<span class="highlight">'+matchedTerm[j]+'</span>'));
	     }
	  }
    });
      $('.resultdesc').each(function(){
         matchedTerm = $(this).html().match(patt);
		 if(matchedTerm !=null){
         for(j=0;j<matchedTerm.length;j++) {     
	       $(this).html($(this).html().replace(new RegExp(matchedTerm[j],'g'),
           '<span class="highlight">'+matchedTerm[j]+'</span>'));
	     }
		 }
       }); 
   }


}

 $(document).ready(function(){

/* *************************
   External Links Icon
************************* */

// Content External Links
	$('#content a[href^=http]').each(
		function(){
			if(this.href.indexOf(location.hostname) == -1) {
				$(this).attr('target', '_blank')
					.attr('class', 'external-link')
					.attr('title', 'External link (will open in new window)');
			}

		}
	);




 /* ***********************
   Content tools
*********************** */

   $("#rhstooldiv").prepend('<ul id="rhstools"><li id="text-resize"><p>Text size:</p><a id="text-decrease" class="decrease-text-size" title="Decrease Text Size" href="#">Decrease Text Size</a><a id="text-increase" title="Increase Text Size" href="#" class="increase-text-size">Increase Text Size</a></li><li id="print-version"><a href="#" title="Print friendly version">Print:</a></li></ul>');


  // Increase Font Size
  $(".increase-text-size").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.1;
	if (newFontSize < 24 ) {
       $('html').css('font-size', newFontSize);
	} 
    return false;
  });
  // Decrease Font Size
  $(".decrease-text-size").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*0.9;
	if (newFontSize > 14 ) {
       $('html').css('font-size', newFontSize);
	}
    return false;
  });


	/* *
	 * Print Page
	 *
	 * Print this page stylesheet switcher
	 *
	 */

	// Insert print button
	var printSheet = $("link[title='print preview']");
	var screenSheet = $("link[media='screen']");
	var printButton = $("li#print-version a");

	// Print Preview
	printButton.click( function() {
		// Switch to print
		$("body").fadeOut("fast", function() {
			screenSheet.each(function() {
				this.disabled = true;
			});
			printSheet.each(function() {
				this.disabled = true;
				this.disabled = false;
			});
			$(this).fadeIn("slow");

			$('html, body').animate({scrollTop:0}, 'fast');

			// Create Print Preview Heading
			$("body").prepend('<div id="preview-message"><h3>Print preview</h3><p><a href="#" id="preview-print">Print this page</a> | <a href="#" id="turnoff-print">Return to the normal view</a></p></div>');
			$("#preview-message").hide().slideDown("slow");

			// Switch Back
			$("a#turnoff-print").bind("click", function(){
				$("body").fadeOut("fast", function() {
					$("#preview-message").remove();
					// Switch to screen
					screenSheet.each(function() {
						this.disabled = false;
					});
					printSheet.each(function() {
						this.disabled = true;
					});
					$(this).fadeIn("slow");
				});
				return false;
			});

			// Print this page
			$("a#preview-print").bind("click", function(){
				window.print();
				return false;
			});
		});

		return false;
	});

	// Dont print preview message
	$("head").append(
		'<style type="text/css" media="print" title="Hide print preview message on print">' +
			'#preview-message {' +
					'display: none;' +
			'}' +
		'</style>'
	);



 });

