
var actual_brand = 1;

$(document).ready(function() {
	$(".brand_selector").fadeTo("slow", 0.3); // This sets the opacity of the
												// thumbs to fade down to 30%
												// when the page loads
		$(".brand_selector").hover(function() {
			$(this).fadeTo("fast", 1.0); // This should set the opacity to
											// 100% on hover

			pieces = this.id.split("_");
			a = parseInt(pieces[2]);
			unfadeBrands(a);
			actual_brand = -5000;
			
			}, function() {
			//	$(this).fadeTo("fast", 0.3); // This should set the opacity
												// back to 30% on mouseout
				
//				actual_brand = 1;
				unfadeBrands(a);
				actual_brand = a;
				
			});
		setInterval("rotateBrands()", 1000);
//		setInterval("rotateBrands()", 300);
});



function rotateBrands()
{
	if (logo_count + 1 == actual_brand)
	{
		scrollReset();
		actual_brand = 1;
		$("#brand_selector_" + logo_count).fadeTo("fast", 0.3);
	}
	prev_brand = actual_brand - 1;
	

	if (actual_brand > 7)
		scrollBrandsLeft();


	$("#brand_selector_" + actual_brand).fadeTo("fast", 1.0);
	$("#brand_selector_" + prev_brand).fadeTo("fast", 0.3);
	actual_brand = actual_brand + 1;
}

function unfadeBrands (actual)
{
	for (i = 1; i <= logo_count; i++)
	{
		if (i != actual)
			$("#brand_selector_" + i).fadeTo("fast", 0.3);
	}
}

function scrollReset()
{
	var brands = $(".brand_selector_content");
	brands.animate( {
//		"left" : newLeft + "px"
		"left" : "0px"
	}, "fast");
	return false;
}

function scrollBrandsLeft() {
	var brands = $(".brand_selector_content");
	var left = parseInt(brands.css("left").split("px")[0]);
	var width = parseInt(brands.css("width").split("px")[0]);
	var shownWidth = parseInt($(".brand_selector_container").css("width")
			.split("px")[0]);

	var newLeft = left - 400;
	if (-newLeft > (width - shownWidth)) {
		newLeft = -(width - shownWidth);
	}
	brands.animate( {
		"left" : newLeft + "px"
	}, "fast");
	return false;
}

function scrollBrandsRight() {
	var brands = $(".brand_selector_content");
	var left = parseInt(brands.css("left").split("px")[0]);

	var newLeft = left + 400;
	if (newLeft > 0) {
		newLeft = 0;
	}
	brands.animate( {
		"left" : newLeft + "px"
	}, "fast");
	return false;
}


