window.addEvent("load",function() {
	CommentBox.startCommentAnimation();
});

var CommentBox = {
	CommentText : [],
	CommentAuthor : [],
	Container : null,
	Current : 0,
	Total : 0,
	TopLayer : null,
	BottomLayer : null,
	State : 0,

	startCommentAnimation : function() {
		this.Container = $('CommentSideBarContainer');
		if(this.Container==null) return;

		var ci = 0;

		this.CommentText[ci] = "We just tried it last night. It was good, it definitely had a \"healthy\" taste.";
		this.CommentAuthor[ci] = "Neil - Waterloo, Ontario";
		ci++;

		this.CommentText[ci] = "Very tasty and not too salty.  Good on a sandwich, great in the frying pan.";
		this.CommentAuthor[ci] = "Lauren";
		ci++;

		this.CommentText[ci] = "Buggy Boyz summer sausage is the best tasting summer sausage that I have had.";
		this.CommentAuthor[ci] = "Jeff - Waterloo, Ontario";
		ci++;

		this.Total = ci;

		this.TopLayer = $(document.createElement("div"));
		this.TopLayer.setStyles({
			zIndex: 2,
			position: 'absolute',
			top: '0px',
			left: '0px',
			width: '100%',
			backgroundColor: '#FBF4EA'
		});
		this.TopLayer.fade('hide');

		this.BottomLayer = $(document.createElement("div"));
		this.BottomLayer.setStyles({
			zIndex: 1,
			position: 'absolute',
			top: '0px',
			left: '0px',
			width: '100%',
			backgroundColor: '#FBF4EA',
			opacity: '0.95'
		});
		this.setQuote(this.BottomLayer,0);

		this.Container.set('html','');
		this.Container.grab(this.BottomLayer);
		this.Container.grab(this.TopLayer);

		setTimeout("CommentBox.startRotation()",3000);
	},

	setQuote : function(el,index) {
		var q = "<blockquote><p>" + this.CommentText[index] + "</p></blockquote><p style='text-align: right;'>" + this.CommentAuthor[index] + "</p>";
		el.set('html',q);
	},

	startRotation : function() {
		var index = (this.Current + 1) % this.Total;
		if(this.State == 0) {
			this.setQuote(this.TopLayer,index);
			this.TopLayer.fade(0.95);
			this.BottomLayer.fade('out');
			this.State = 1;
		}
		else {
			this.setQuote(this.BottomLayer,index);
			this.BottomLayer.setStyle('opacity','0.95');
			this.TopLayer.fade('out');
			this.State = 0;
		}
		this.Current = index;
		setTimeout("CommentBox.startRotation()",3000);
	}
};
