function highlightWords(data,textStatus) {	
	//get current html
	var currentContent = jQuery("#content").html()
	var links = new Object();
  // create list of links indexed by link id
	for (var i=0; i < data.links.length; i++)
	 links[data.links[i].uid] = data.links[i]; 
	// replace keywords with links
	for(var i=0; i < data.keywords.length; i++) {
		keyword = data.keywords[i]
		var newstr = '<a class="slink" href="'+links[keyword.lid].url+'" rel="#slink'+keyword.lid+'" title="'+links[keyword.lid].title+'">'+keyword.word+'</a>'
		//replace word with the new html
		var reg = new RegExp("([\\s\\x00-\\x2F\\x3A-\\x40\\x5B-\\x5E\\x60\\x7B-\\x7F])" + keyword.word + "(?=[\\s\\x00-\\x2F\\x3A-\\x40\\x5B-\\x5E\\x60\\x7B-\\x7F])", "g");
		currentContent = currentContent.replace(reg, "$1" + newstr);
	}
	// create divs for all links (one per link id!)
	for (var i=0; i < data.links.length; i++) {
    link = data.links[i];
		var linkstr = '<a href="'+link.url+'">'
		if (link.image) 
      linkstr += '<img src="'+link.image+'" alt="" />';
		if (link.description == '')
		  linkstr += link.url + '</a>';
		else
		  linkstr += link.description + '</a>';
		currentContent += '<div id="slink'+link.uid+'" >' +linkstr +'</div>';    
  }
	//update it	
	jQuery("#content").html(currentContent);
	jQuery('a.slink').cluetip({ cluetipClass: 'tm', dropShadow: false, local: true, sticky: true, mouseOutClose: true, closePosition: 'title',closeText: 'Zamknij' });
	jQuery(".jqfancybox").fancybox({"hideOnContentClick": 0, "zoomSpeedIn":500,"zoomSpeedOut":500,"overlayShow":1, "overlayOpacity":0.6});	
}

var modalWindow = {  
	parent:"body",  
	windowId:null,  
	content:null,  
	width:null,  
	height:null,  
	close:function() {  
		jQuery(".modal-window").remove();  
		jQuery(".modal-overlay").remove();  
  },  
	open:function() {
    var modal = "";
    modal += "<div class=\"modal-overlay\"></div>";
    modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
    modal += this.content;
    modal += "</div>";  
   
    jQuery(this.parent).append(modal);   
    jQuery(".modal-window").append("<a class=\"close-window\"></a>");
    jQuery(".close-window").click(function(){modalWindow.close();});
    jQuery(".modal-overlay").click(function(){modalWindow.close();});
  }  
};  

var openMyModal = function(source) {  
  modalWindow.windowId = "myModal";  
  modalWindow.width = 480;  
  modalWindow.height = 405;  
  modalWindow.content = "<iframe width='480' height='405' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";  
  modalWindow.open();  
};  

jQuery.noConflict();
jQuery(document).ready(
	function() {
		jQuery("li#s_menu").hover(function() {jQuery("div.sub_menu").show();},function() {jQuery("div.sub_menu").hide();});
		jQuery("div.dziecko").hover(function(){jQuery(this).find("div").show();},function(){jQuery(this).find("div").hide();});
		jQuery('#mm1').simpletip({ content: '0-12 miesięcy', fixed: true, position: 'top' }); 
		jQuery('#mm2').simpletip({ content: '2-3 rok życia', fixed: true, position: 'top' }); 
		jQuery('#mm3').simpletip({ content: '4-5 rok życia', fixed: true, position: 'top' }); 
		jQuery('#mm4').simpletip({ content: 'podstawówka', fixed: true, position: 'top' }); 
		jQuery('#mm5').simpletip({ content: 'gimnazjum', fixed: true, position: 'top' }); 
		jQuery(".jqfancybox").fancybox({"hideOnContentClick": 0, "zoomSpeedIn":500,"zoomSpeedOut":500,"overlayShow":1, "overlayOpacity":0.6});
		//jQuery('a').livequery('click', function(event) {if(jQuery(this).attr('name') != '#'){event.preventDefault();jQuery("#loading").show();jQuery('#content').load(jQuery(this).attr('href'),function(){jQuery("#content").find('a');Refresh();jQuery("#loading").hide();});} else {return true;}});
		//jQuery('div.form_comments').lightBox(); 
	
		var content = jQuery("#content").text()
		var words = content.split(/[\s\x00-\x2F\x3A-\x40\x5B-\x5E\x60\x7B-\x7F]/)
		//store unique words
		var uWords = new Object()
		for (var i=0; i<words.length;i++) {
			var word = words[i];
			if (word != '' && uWords[word] == null) uWords[word] = '';
		}
		//convert to array
		var aWords = new Array();
		for (var w in uWords) aWords.push(w);
		if (aWords.length) jQuery.post('/term.php',{termList:aWords.toString()},highlightWords,"json");	

		tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
		imgLoader = new Image();// preload image
		imgLoader.src = tb_pathToImage;
	  
		var button = jQuery('#button1'), interval;
		
		var options = { 
			target:        '#formout',   // target element(s) to be updated with server response 
			//beforeSubmit:  showRequest,  // pre-submit callback 
			//success:       showResponse  // post-submit callback 
 
			// other available options: 
			//url:       url         // override for form's 'action' attribute 
			//type:      type        // 'get' or 'post', override for form's 'method' attribute 
			//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
			//clearForm: true        // clear all form fields after successful submit 
			//resetForm: true        // reset the form after successful submit 
 
			// $.ajax options can be used here too, for example: 
			//timeout:   3000 
		}; 
 
		// bind form using 'ajaxForm'	 
		jQuery('#myForm').ajaxForm(options); 
	}
);

