jQuery(document).ready(function() {
	// handle external links
	$("a[rel='external']").addClass("external")
	$("a[rel='external']").bind("click", function() {
		window.open((this).href);
		return false; 
	});
	
	$('#stories').jcarousel({
		scroll: 1,
		wrap: 'both'
	});
	
	if ($('#featured').length) {
		$('#featured').jcarousel({
			scroll: 1,
			wrap: 'both',
			auto: 4,
			initCallback: initCallback,
			// This tells jCarousel NOT to autobuild prev/next buttons
			buttonNextHTML: null,
			buttonPrevHTML: null
		
		});
	}
	
	// fix IE6
	jQuery("*").fixIE6();
});

function getNumById(id) {
	var num = id.substring(id.lastIndexOf("-") + 1)
	return num;
}

function initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
       	carousel.scroll(jQuery.jcarousel.intval(getNumById(this.id)));
        return false;
    });
};

jQuery.fn.fixIE6 = function() {
	if (jQuery.browser.msie && jQuery.browser.version < 7) {
		return this.each(function() {
			if (jQuery(this).css("float") === "left" || jQuery(this).css("float") === "right") {
				if (jQuery(this).css("display") !== "none") {
					jQuery(this).css("display", "inline");
				}
			}
		});
	} else {
		return this.each(function() {});
	}
};