bDisplayBubble = 0;
jQuery.fn.highlight = function(pat) {
	function innerHighlight(node, pat) {
		var skip = 0;
		if (node.nodeType == 3) {
			var pos = node.data.toUpperCase().indexOf(pat);
			if (pos >= 0) {
				var spannode = document.createElement('span');
				spannode.className = 'highlight';
				var middlebit = node.splitText(pos);
				var endbit = middlebit.splitText(pat.length);
				var middleclone = middlebit.cloneNode(true);
				spannode.appendChild(middleclone);
				middlebit.parentNode.replaceChild(spannode, middlebit);
				skip = 1;
			}
		}
		else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
			for (var i = 0; i < node.childNodes.length; ++i) {
				i += innerHighlight(node.childNodes[i], pat);
			}
		}
		return skip;
	}
	return this.each(function() {
		innerHighlight(this, pat.toUpperCase());
	});
};

$(document).ready(function()
{
	var words_array = []; 
	var ids_array = [];
 
	// creating the words array
	$(function(){
		$('div#parcare_bannere div.cntxt').each(function(){ 
			ids_array[ids_array.length] = $(this).attr('id');
			words_string = $(this).attr('id').substr(6);
			words_array = words_string.split("_");
		}); 
	});

	// highlighting words on the page
	for ( i=0; i<words_array.length; i++ )
	{
		// replace #page_content with your main website content zone id or class
		$('#primary_main').highlight(words_array[i]);
	}

	// close button function
	$('.cntxt_close').click(function()
	{
		$(this).parent().parent().css('display', 'none').css('visibility', 'hidden');
		this.blur();
		return false;
	});

	//cntxt methods
	$('.cntxt').hover(
		function () {bDisplayBubble = 1}
/*
,
		function () {
			bDisplayBubble = 0; 
			$('.cntxt').css('display', 'none').css('visibility', 'hidden');
			//$('.current .cntxt').appendTo('#parcare_bannere');
			$('.current').removeClass('current');
			$('.cntxt').css('display', 'none').css('visibility', 'hidden');}
*/
	);
	
	// show the ad on mouse over
	$('.highlight').hover(
	function () {
		$(this).addClass('current');
		$('.cntxt_content').children().each(function(){if ($(this).is("script")) $(this).remove()});
		/*$('.cntxt').appendTo('.current');
		$('.cntxt').css('display', 'block').css('visibility', 'visible');*/
		var f = $(this).offset();
		var coord = new Array();
		coord["top"] = parseInt(f.top) + 10;
		coord["left"] = parseInt(f.left) + 10;
		$('.cntxt').css('display', 'block').css('visibility', 'visible').css('top', coord["top"]).css('left', coord["left"]);
	}, function () {}
/*
, 
	function () {
		setTimeout(function () {
			if (parseInt(bDisplayBubble) == 0)
			{
				$('.cntxt').css('display', 'none').css('visibility', 'hidden');
				//$('.current .cntxt').appendTo('#parcare_bannere');
				$(this).removeClass('current');
				$('.cntxt').css('display', 'none').css('visibility', 'hidden');
			};
		}, 100);

	}*/);

});
