// JavaScript Document
//written by John Andrew Lumbre 11/12/08
//property of webultima.com
function car_carousel() {
	var hash = window.location.hash;
	var hash = hash.substring(1);
	var li_width = jQuery("#carousel_window li").width();
	
	if (hash == '') {
		var li = 1;
	}
	else {
		var li = hash;
		li = li.substring(6);
	}
	
	var i = 0;
	var nth_place = 1;
	jQuery("#carousel_window").find("li").each(function() {
		var id = (jQuery(this).attr("id"));
		if(li == id) {
			nth_place = i + 1;
			var init_pos = (i * -li_width);
			jQuery("#carousel_window ul").css("left", init_pos);
		}
		//we put our counter here so index/left position multiplier will start at 0;
		i++;
	});
	
	//set the width of the ul to float the li
	jQuery("#carousel_window ul").css("width", (li_width * i) + "px");

	//when overflow is set on the css, the floated li(s) are not visible 
	//when their index is not zero (0) upon page load, 
	//so we set the overflow of the carousel window to hidden here via jquery
	jQuery("#carousel_window").css("overflow", "hidden");
		
	if (nth_place >= i) {
		jQuery("#carousel_next").html("");
		jQuery("#carousel_next").html("next");			
	}
	
	if (nth_place == 1) {
		jQuery("#carousel_previous").html("");
		jQuery("#carousel_previous").html("previous");			
	}
	
	jQuery("#carousel_previous").click(function() {
		if (nth_place == 2) {
			jQuery(this).html("");
			jQuery(this).html("previous");
		}
		if (nth_place <= 1) {
			return false;
		}
		else {
			jQuery("#carousel_next").html("");
			jQuery("#carousel_next").html("next &gt;&gt;");			
			var position = jQuery("#carousel_window ul").position().left;
			jQuery("#carousel_window ul").animate({
				left: position + li_width
			});
			nth_place --;
			return false;
		}
	});
	
	jQuery("#carousel_next").click(function() {
		if (nth_place == i-1) {
			jQuery(this).html("");
			jQuery(this).html("next");
			var position = jQuery("#carousel_window ul").position().left;
			jQuery("#carousel_window ul").animate({
				left: position - li_width
			});
			nth_place ++;
			return false;
		}
		else if (nth_place >= i) {
			return false;
		}
		else {
			jQuery("#carousel_previous").html("");
			jQuery("#carousel_previous").html("&lt;&lt; previous");			
			var position = jQuery("#carousel_window ul").position().left;
			jQuery("#carousel_window ul").animate({
				left: position - li_width
			});
			nth_place ++;
			return false;
		}
	});
}

