/* Author by Le Yang */

var TestimonialScroll = {
	
	index : 1,
	
	init : function(obj, offset){
		
	
		//get list length
		var sum = obj.find('ul.cite-wrap').children('li').length;
		
		// modify the whole width
		var width = (sum + 1) * obj.find('.cite-box').outerWidth();
		obj.find('ul.cite-wrap').css('width', width);
	
		obj.find('.prev').click(function(){
			TestimonialScroll.prevHandler(obj, offset);
			return false;
		});
		
		obj.find('.next').click(function(){
			TestimonialScroll.nextHandler(obj, offset, sum);
			return false;
		});
	},

	prevHandler : function(obj, offset){
		
		var ul_obj = obj.find('ul.cite-wrap');
		ul_obj.stop(true, true);
		
		if (TestimonialScroll.index > 1){
			
			ul_obj.animate({left: '+=' + offset}, 1000);
			TestimonialScroll.index --;
			TestimonialScroll.changePhoto(obj);
		}
	},
	
	changePhoto : function(obj){
		obj.find('img').addClass('hide');
		obj.find('img').eq(TestimonialScroll.index - 1).removeClass('hide');
		
	},
	
	nextHandler : function(obj, offset, sum){
		var ul_obj = obj.find('ul.cite-wrap');
		ul_obj.stop(true, true);
		
		if (TestimonialScroll.index < sum){
			
			ul_obj.animate({left: '-=' + offset}, 1000);
			TestimonialScroll.index ++;
			TestimonialScroll.changePhoto(obj);
		}
	}
	
	
	
}



if ($('body.who').length > 0){
	TestimonialScroll.init($('.testimonial-listing'), 430);
}
else {
	TestimonialScroll.init($('.testimonial-listing'), 690);
}
