$(document).ready(function() {

    $("img[@src$=png]").pngFix();

	if(typeof $('#marquee ul').cycle == 'function') {
		$('#marquee ul').cycle({
			timeout: 10000,
			speed:   1000,
			pause:   1
		});
	}

	if(typeof $('a.lightbox').fancybox == 'function') {
		$('a.lightbox').fancybox();
	}

	$('a.event_detail_link').click(function() {
		var href = $(this).attr('href');
		var poundid = href.replace(/\/events.php\?_id=/i, "#event_");
		$('.event_detail:visible').slideUp();
		$(poundid).slideDown();
		return false;
	});

});

<!--
function validateEmail(myForm) {
	var filter = /^.+@.+\..{2,4}$/;

	if(!(filter.test(myForm.newsletter_email.value))) {
		alert("Please enter a valid e-mail address.");
		return false;
	} else {
		return true;
	}
}

function addToFavorites() {
	if(window.external) {
		window.external.AddFavorite('http://www.creativeknittingmagazine.com/', "Creative Knitting Magazine");
	} else {
		alert("Sorry! Your web browser doesn't support this function.");
	}
}

function newPopupWindow(url, w, h) {
	var features = "resizable=yes,toolbar=no,scrollbars=yes,copyhistory=no,location=no,directories=no,status=no,menubar=no,width=" + w + ",height=" + h;
	popupWindow = window.open(url, 'popup', features);
	popupWindow.focus();
	return true;
}
//-->


var firebug = window.console; // legacy adaptor 

function carousel_callback(carousel) {
	$(".next").bind('click', function() {
		carousel.next();
		return false;
	});
	$(".prev").bind('click', function() {
		carousel.prev();
		return false;
	});
	$(".jcarousel-item").css("height", "auto");
	$(".carousel_control").show();
}
function carousel_before_animation(carousel, item, idx, state) {
	if(state != "init") {
		$('.carousel_control').hide();
		carousel_resize(idx, state);
	}
}
function carousel_after_animation(carousel, item, idx, state) {
	var item_count = $('.jcarousel-item').length;
	if(state == 'init') {
		$('.carousel_container .prev').hide();
		$('.carousel_container .next').fadeIn();
	} else if(idx == 1) {
		$('.carousel_container .next').fadeIn();
	} else if(idx == item_count) {
		$('.carousel_container .prev').fadeIn();
	} else {
		$('.carousel_control').fadeIn();
	}

}
function carousel_resize(idx, state) {

	if(state == 'next') {
		var minOne = idx - 1;
		var minTwo = idx - 2;
		var height1 = $(".jcarousel-item-" + idx    + " .event_list").innerHeight();
		var height2 = $(".jcarousel-item-" + minOne + " .event_list").innerHeight();
		var height3 = $(".jcarousel-item-" + minTwo + " .event_list").innerHeight();
	} else if(state == "prev") {
		var plusOne = idx + 1;
		var plusTwo = idx + 2;
		var height1 = $(".jcarousel-item-" + idx     + " .event_list").innerHeight();
		var height2 = $(".jcarousel-item-" + plusOne + " .event_list").innerHeight();
		var height3 = $(".jcarousel-item-" + plusTwo + " .event_list").innerHeight();
	} else {
		var height1 = $(".jcarousel-item-1" + " .event_list").innerHeight();
		var height2 = $(".jcarousel-item-2" + " .event_list").innerHeight();
		var height3 = $(".jcarousel-item-3" + " .event_list").innerHeight();
	}

	var height = Math.max(height1, height2, height3) + 56;

	$(".jcarousel-item, .jcarousel-list, .jcarousel-clip, .jcarousel-container").animate(
		{height: height}, 
		{queue: false}
	);

}

