var fw = 957;
var cur = 0;
var total = 0;
var autoPlay = true;
var autoTimer;

$(document).ready(function(){
		
	if($("#homeFeature")) {
		total = $("#homeFeature .homeFeatureItem").length;
		var w = 0;
		$("#homeFeature .homeFeatureItem").each(function(){

			$("#homeFeature").css("width", $("#homeFeature").outerWidth() + $(this).outerWidth()+"px");
		});
		
		$("#bhfLeft").click(function(){
			clearInterval(autoTimer);
			cur = cur - 1;
			if(cur < 0) cur = total - 1;
			animateFeature();
			return false;
		});
	
		$("#bhfRight").click(function(){
			clearInterval(autoTimer);
			nextInLine();
			return false;
		});

		autoTimer = setInterval("nextInLine()", 10000);
	}
	
	
	$("#search_input").attr("og",$("#search_input").val());
	$("#search_input").focus(function(){
		if($(this).val() == $(this).attr("og")) $(this).val("");
	});
	$("#search_input").blur(function(){
		if($(this).val() == "") $(this).val($(this).attr("og"));
	});
	
});

function animateFeature() {
	$("#homeFeature").fadeOut("1000", function(){
		$(this).css("left", (-cur * fw)+"px").fadeIn();
	});
}

function nextInLine() {
	cur = cur + 1;
	if(cur >= total) cur = 0;
	animateFeature();
}
