$(function() {
/* Info-Box */
// Default-Werte
	var ibDefault = {
		url:'/infobox.php',
//		showEffect:'show', // fadeIn, slideDown, show
//		hideEffect:'hide', // fadeOut, slideUp, hide
//		showEffect:'fadeIn', // fadeIn, slideDown, show
//		hideEffect:'fadeOut', // fadeOut, slideUp, hide
		showEffect:'slideDown', // fadeIn, slideDown, show
		hideEffect:'slideUp', // fadeOut, slideUp, hide
		showDuration:400, // ms
		hideDuration:200, // ms
		offset:5, // Box-Abstand zum Viewport-Rand in px
		onlyOneBox:true
	};	
	$('a[class^=info-click-]').click(function(e) {
		var id, box, w, wW, wH, sL, sT, bL, bT, bW, bH, s1;
		id = (id = $(this).attr('class')).substr(id.lastIndexOf('-')+1);
		if (isNaN(id)) {
			id += '_' + $('a[class^=info-click-]').index($(this));
		}
		box = $('#info-'+id);
		if (ibDefault.onlyOneBox) {
			$("div[id^=info-]").not(box).remove();
		}
		if (!box[0]) {
			$.get(ibDefault.url, {id:id}, function(data) {
				if (data) {
					$('body').append(data);
					box = $('#info-'+id);
					box.bgiframe();
					w = $(window);
					wW = w.width();
					wH = w.height();
					sL = w.scrollLeft();
					sT = w.scrollTop();
					bW = box.outerWidth();
					bH = box.outerHeight();
					bO = ibDefault.offset;
					bL = Math.max(sL + bO, Math.min(e.pageX, sL + wW - bW - bO));
					bT = Math.max(sT + bO, Math.min(e.pageY, sT + wH - bH - bO));
//					box.css({left:bL+"px", top:bT+"px"}).slideDown(ibDefault.fadeIn);
					s1 = 'box.css({left:bL+"px", top:bT+"px"}).'+ibDefault.showEffect+'(ibDefault.showDuration)';
					eval(s1);
					$('a.info-close').click(function(e) {
						e.stopImmediatePropagation();
//						ibDefault.fadeOut? box.slideUp(ibDefault.fadeOut, function(){ box.remove(); }) : box.remove();
						if (ibDefault.hideDuration) {
							s1 = 'box.'+ibDefault.hideEffect+'(ibDefault.hideDuration, function(){ box.remove(); })';
							eval(s1);
						}
						else {
							box.remove();
						}
						e.preventDefault();
					}).attr('title', 'Schliessen');
				}
			});
		}
		e.preventDefault();
	});
});
