// Google Analytics
if (document.domain.indexOf("szafranek.net") != -1) {
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-1016033-2']);
    _gaq.push(['_trackPageview']);
    $('body.home #content .rss a').click(function() {
        _gaq.push(['_trackEvent', 'Main RSS subscription', document.location.href]);
    });
    $('body.home #sidebar .rss a').click(function() {
        _gaq.push(['_trackEvent', 'Links RSS subscription', document.location.href]);
    });
    $('body.post .share .rss a').click(function() {
        _gaq.push(['_trackEvent', 'Main RSS subscription', document.location.href]);
    });
    $('body.post .share .digg a').click(function() {
        _gaq.push(['_trackEvent', 'Sharing on Digg', document.location.href]);
    });
    $('body.post .share .delicious a').click(function() {
        _gaq.push(['_trackEvent', 'Sharing on Delicious', document.location.href]);
    });
    (function() {
        var ga = document.createElement('script');
        ga.type = 'text/javascript';
        ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
    })();
}

$(function() {
	// add class to narrow figures
	var WIDE_IMG_WIDTH = 250;
	var NARROW_IMG_WIDTH = 100;
	var figures = $(".figure");
	figures.each(function() {
		var width = $(this).find("img,object,embed").attr("width");
		if (width > WIDE_IMG_WIDTH) {
			$(this).addClass("wide-figure");
		} else if (width < NARROW_IMG_WIDTH) {
			$(this).addClass("narrow-figure");
		}
		var legend = $(this).find(".legend");
		legend.css("width", width + "px");
	});
	if ($.fn.minigallery) {
		$('.minigallery').minigallery();
	}
	// make sure one-line paragraphs are not indented
	var paragraphs = $("#content div.post p, #panel .comment p");
	$("#content div.post").append("<p id='tmp-empty'>.</p>");
	var pHeight = $("#tmp-empty").height();
	$("#tmp-empty").remove();
	paragraphs.each(function(){
		if ($(this).height() <= pHeight) {
			$(this).addClass("oneline");
		}
	});

	// initialize Lightbox
	if ($.Lightbox) {
		$.Lightbox.construct({files: {
			js: {
				lightbox:	'/theme/j/unc.jquery.lightbox.js',
				colorBlend:	'/theme/j/jquery.color.js'
			},
			css: {
				lightbox:	'/theme/c/jquery.lightbox.css'
			},
			images: {
				prev:		'/theme/i/lightbox/prev.gif',
				next:		'/theme/i/lightbox/next.gif',
				blank:		'/theme/i/lightbox/blank.gif',
				loading:	'/theme/i/lightbox/loading.gif'
			}
		},
		ie6_support: false,
		show_linkback: false,
		auto_relify: false, // othwerwise broken with jQuery 1.3
		opacity: 0.9
		});
		// have mercy for me
		if (navigator.userAgent.indexOf('MSIE 6') == -1) {
			// create an overlay
			$(".figure>a:not([class=page]), .minigallery a.minigallery-img-link").
				append('<span class="lightbox-overlay"></span><span class="lightbox-enlarge">Enlarge</span>').
				lightbox();
		}
	}
});
