$(document).ready(function(){
	$('a.tooltip').cluetip({splitTitle: '|', tracking: true, clickThrough: true, cluetipClass: 'jtip', positionBy: 'mouse', topOffset: 65, width: 185, dropShadow: false });

	// Expand content
	$('#slickbox').hide();
	$('a#slick-toggle').toggle(function(){
		$(this).addClass('active');
		}, function () {
		$(this).removeClass('active');
	});
	$('a#slick-toggle').click(function() {
	$('#slickbox').slideToggle(400);
		return false;
	});
	
	// Social Bookmarks
	$("a[sharewith]").click(function(ev) {
		var rel = $(this).attr("sharewith");
		var url = encodeURIComponent(self.location.href);
		var title = encodeURIComponent($("title:first").html());
		rel = rel.replace("{url}",url);
		rel = rel.replace("{title}",title);
		self.location.href = rel;
		return false;
	});
	
	// Add to favorites
	if(window.opera) {
		if ($("a.bookmark").attr("rel") != "") {
			$("a.bookmark").attr("rel","sidebar");
		}
	}
	$("a.bookmark").click(function(event) {
		event.preventDefault();
		if (window.sidebar) {
			window.sidebar.addPanel(this.title, this.href, "");
		} else if(window.external) {
			window.external.AddFavorite(this.href, this.title);
		} else if(window.opera) {
			return false;
		} else {
			alert('Bitte fügen sie die Seite manuell zu Ihren favoriten ein.');
		}
	});

	// Popup bubble
	$(function () {
		$('.bubbleInfo').each(function () {
			var distance = 10;
			var time = 250;
			var hideDelay = 500;
			var hideDelayTimer = null;
			var beingShown = false;
			var shown = false;
			var trigger = $('.trigger', this);
			var info = $('.popup', this).css('opacity', 0);
	
			$([trigger.get(0), info.get(0)]).mouseover(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				if (beingShown || shown) {
					// don't trigger the animation again
					return;
				} else {
					// reset position of info box
					beingShown = true;
					info.css({
						top: -128,
						left: -138,
						display: 'block'
					}).animate({
						top: '-=' + distance + 'px',
						opacity: 1
					}, time, 'swing', function() {
						beingShown = false;
						shown = true;
					});
				}
				return false;
			}).mouseout(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);
				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					info.animate({
						top: '-=' + distance + 'px',
						opacity: 0
					}, time, 'swing', function () {
						shown = false;
						info.css('display', 'none');
					});
				}, hideDelay);
				return false;
			});
		});
	});

})
