function tooltip_get_container() {
	if (jQuery("#tooltip_container").length == 0) {
		jQuery("body").append('<div id="tooltip_container" />');
		jQuery("#tooltip_container").mouseover(function(e){
			jQuery(this).css('left', e.pageX+5).css('top', e.pageY-25);
		});
	}
	return jQuery("#tooltip_container");
}

jQuery(function(){
	jQuery(".txt a.foto").attr('rel', 'in_text').each(function(){
		jQuery(this).attr('title', jQuery(this).text());
	});
	jQuery(".txt a.foto").colorbox({current: "zdjęcie {current} z {total}"});

	jQuery("#iconsWrapper img").hover(function(e){
		if (jQuery(this).attr('longdesc') != '') {
			tooltip_get_container().html(jQuery(this).attr('longdesc'));
			tooltip_get_container().fadeIn(150);
			jQuery(this).fadeTo(150, 0.43);
		}
	}, function(e){
		if (jQuery(this).attr('longdesc') != '') {
			tooltip_get_container().fadeOut(150);
			jQuery(this).fadeTo(150, 1.00);
		}
	}).mousemove(function(e){
		tooltip_get_container().css('left', e.pageX+5).css('top', e.pageY-25);
	});
	
	jQuery('#iconsWrapper a').colorbox({
		iframe: false,
		current: "zdjęcie {current} z {total}",
		onComplete:function(){
			$.colorbox.resize(
				{
					innerHeight:($('#ajaxContent').outerHeight()),
					innerWidth:800
				}
			);
			$("#ajaxContent img").load(function(){
				$.colorbox.resize(
					{
						innerHeight:($('#ajaxContent').outerHeight()),
						innerWidth:800
					}
				);
			});
		}
	});
});
