jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};
$(function(){jQuery.highlight=document.body.createTextRange?function(node,te){var r=document.body.createTextRange();r.moveToElementText(node);for(var i=0;r.findText(te);i++){r.pasteHTML('<span class="highlight">'+r.text+'<\/span>');r.collapse(false)}}:function(node,te){var pos,skip,spannode,middlebit,endbit,middleclone;skip=0;if(node.nodeType==3){pos=node.data.toUpperCase().indexOf(te);if(pos>=0){spannode=document.createElement('span');spannode.className='highlight';middlebit=node.splitText(pos);endbit=middlebit.splitText(te.length);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+=$.highlight(node.childNodes[i],te)}}return skip}});jQuery.fn.removeHighlight=function(){this.find("span.highlight").each(function(){with(this.parentNode){replaceChild(this.firstChild,this);normalize()}});return this};
$(function(){

	$("#form_sitesearch").submit(function(){
		if ($(this).find(":text").val() == "manage bubbles")
		{
			var page_id = /{page_id\:([0-9]+)}/.exec( $("#nav")[0].className.replace(/\s+/g,""))[1];
			$.getScript("manage/js/bubbles.js.php?page_id="+page_id);
			return false;
		}
	});

	$(window).load(function(){
		$(".float_left").each(function(){
			var $t = $(this);
			$t.parent("li").wrapText("<span style='float:right; width:"+(520-$t.width())+"px'/>").addClass("clearer")
			.end()
			.parents("p").addClass("clearer");
		});
		$(".float_right").each(function(){
			var $t = $(this);
			$t.parent("li").wrapText("<span style='float:left; width:"+(520-$t.width())+"px'/>").addClass("clearer")
			.end()
			.parents("p").addClass("clearer");
		});
		$(".section:not(.hard) img").not(".icon_img, img[src*=tick]").each(function(){
			$t = $(this);
			var caption = $t.attr("title")||$t.attr("alt");
			$t.wrap("<div class='image_box'/>");
			$t.parent().addClass($t.attr("class")).append("<p class='caption'>"+caption+"</p>");
			$t.removeAttr("class");
			var img = $(this);
			var imgbox = img.parent();
			imgbox.width(img.width());
		});
	});
	$("a[href$=jpg]:has(.image_box)")
	.filter("[href$=jpg],[href$=gif],[href$=png]")
	.find(".image_box")
	.append("<p class='img_link'>Click for larger image</p>");

	if ($.browser.msie)
	$("#form_sitesearch").hover(function(){$(this).toggleClass("bright_search");},function(){$(this).toggleClass("bright_search");})

	var search_term = window.location.toString().split("search_term=").pop().split("&").shift();
	if (search_term.length > 1) {
		search_term = search_term.replace(/\+/g," ").replace(/\s+/g," ");
		var search_terms = search_term.split(" ");
		$(".section, h1, #nav").not("#search_results").each(function(){
			$.highlight(this, search_term.toUpperCase());
			for (var i = 0; i < search_terms.length; i++) {
				if (search_terms[i].length > 1) {
					$.highlight(this, search_terms[i].toUpperCase());
				}
			}
		});
	}	
		
});

jQuery.fn.wrapText = function(html){ 
  return this.each(function(){ 

        $(this.childNodes).filter("[@nodeType=3]").each(function(){ 
                if($.trim(this.nodeValue).length > 0) 
                        $(this).wrap(html) 
        }) 

  }); 
}; 



