jQuery(document).ready(function() {
	// handle external links
	$("a[rel='external']").addClass("external")
	$("a[rel='external']").bind("click", function() {
		window.open((this).href); 
		return false; 
	});

	// hide googlesearch background image on click
	$(".googlesearch").bind("click", function() {
		$(this).css("background-image", "none");
	});


	$(".listing.clickable").bind("click", function() {
		window.location = "/listing/view/" + getNumById(this.id) + "/";
	});

	$(".bid.clickable").bind("click", function() {
		window.location = "/bid/view/" + getNumById(this.id) + "/";
	});
	
	$(".user.clickable").bind("click", function() {
		window.location = "/user/" + getNumById(this.id) + "/";
	});

/*
	$(".jcarousel").jcarousel({
		scroll: 1,
		visible: 1,
		initCallback: jCinitCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
	
	
	$(".jcarousel-control a").bind('click', function() { 
		// add active class
		$(".jcarousel-control a").removeClass("active");
		$(this).toggleClass("active");
	});
	
	*/
});
function jCinitCallback(carousel) {
	$('.jcarousel-control a').bind('click', function() {
		// remove hidden clase just in case
		$(".jcarousel-clip").removeClass("hidden");
		// tweaked to use id's instead of numbers
		carousel.scroll(jQuery.jcarousel.intval(getNumById(this.id)));
		return false;
	});

};


function intVal(v) {
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
}

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