// Homepage Specials JS v0.1 by Josh Lizarraga

(function(){

YAHOO.namespace("duvalmazda");

var MB = YAHOO.duvalmazda;

MB.specials = function(){
	var oPageWidth = 235;
	var oTotalPages = 2;
	var oCurrentPage = 0;
	var oAnimationSpeed = .5;
	var oAutoplaySpeed = 5000;
	var oAutoplay = new Object;
	var oSpecialsContainer = document.getElementById("specials_container");
	var oNext = document.getElementById("mbw_SpecialsNext");
	var oPrev = document.getElementById("mbw_SpecialsPrev");
	var nextPage = function(){
		oCurrentPage = (oCurrentPage == oTotalPages) ? 0 : oCurrentPage + 1;
		var oSlide = new YAHOO.util.Anim(oSpecialsContainer, {
				left: { to: -(oCurrentPage * oPageWidth) }
			}, oAnimationSpeed, YAHOO.util.Easing.backBoth);
		oSlide.animate();
	}; // nextPage()
	var prevPage = function(){
		oCurrentPage = (oCurrentPage == 0) ? oTotalPages : oCurrentPage - 1;
		var oSlide = new YAHOO.util.Anim(oSpecialsContainer, {
				left: { to: -(oCurrentPage * oPageWidth) }
			}, oAnimationSpeed, YAHOO.util.Easing.backBoth);
		oSlide.animate();
	}; // prevPage()
	oAutoplay = setInterval(nextPage, oAutoplaySpeed);
	YAHOO.util.Event.addListener(oNext, "click", function(){
		clearInterval(oAutoplay);
		nextPage();
	});
	YAHOO.util.Event.addListener(oPrev, "click", function(){
		clearInterval(oAutoplay);
		prevPage();
	});
}; // MB.specials()

YAHOO.util.Event.onDOMReady(MB.specials);

})();