$(function() {
    $("#contentarea h1:not(.nofrill)")
        .prepend('<span class="frill bigleft" />')
        .append('<span class="frill bigright" />');
    $("#contentarea h2:not(.nofrill)")
        .prepend('<span class="frill left" />')
        .append('<span class="frill right" />');
		
	var imghtml = "";
	$("#slideshow a").each(function() {
		imghtml += '<img src="'+$(this).attr('href')+'" width="380" height="285" alt="'+$(this).html()+'" />';
	});
	if (imghtml) {
		$("#slideshow").append(imghtml).find("img:gt(0)").hide();
		setTimeout(function() { imgrotate(0) }, 5000);
	}
	$("#aside a[rel=productimage]").fancybox({overlayColor: "#4d4d4d"});
	
	var maxheight = 0;
	$(".productthumb").each(function() {
		maxheight = Math.max(maxheight, $(this).height());
	});
	$(".productthumb").height(maxheight).css("min-height", maxheight+"px");
	
	$("#loginform #eaddr").focus();
	
	if ($("#post_same").attr("checked")) {
		$("#post_group").hide();
	}
	$("#post_same").click(function() {
		if ($("#post_same").attr("checked")) {
			$("#post_group").slideUp();
		} else {
			$("#post_group").slideDown();
		}
	});
	
	if ($.browser.msie && $.browser.version < 7) {
		$(".formbutton").hover(
			function() {
				$(this).addClass("buttonhover");
			},
			function() {
				$(this).removeClass("buttonhover");
			}
		);
	}
});

function imgrotate(curimg) {
	$("#slideshow img:eq("+curimg+")").fadeOut("slow");
	curimg++;
	if (curimg >= $("#slideshow img").length || curimg < 0) {
		curimg = 0;
	}
	$("#slideshow img:eq("+curimg+")").fadeIn("slow");
	setTimeout(function() { imgrotate(curimg) }, 5000);
}
