var sniTweets = new Class({
	Implements: [Events,Options],
	options: {
		wrap: "tweet_wrap",
		container: "sni_tweets",
		interval: 6000,
		count: 1, // count of all Tweets set from pi1 
		tweenOut: {
			"transition": "sine:in:out",
			"duration": "normal"
		}
	},
	initialize: function(options) {
		this.setOptions(options);
		this.wrap = $(this.options.wrap);
		this.container = $(this.options.container);
		this.interval = this.options.interval;
		this.count = this.options.count;
		this.curEl = this.container.getFirst("p");
		this.setStyles();
		if(this.count > 1) {
			this.changeTweet.delay(this.interval,this);
		}
	},
	changeTweet: function() {
		this.curEl.tween("opacity",0).get("tween").chain(function() {
			if(this.curEl.getNext("p")) {
				this.curEl = this.curEl.getNext("p")
			}
			else {
				this.curEl = this.container.getFirst("p");
			}
			this.curEl.tween("opacity",1).get("tween").chain(function() {
				this.changeTweet.delay(this.interval,this);
			}.bind(this));
		}.bind(this));
	},
	setStyles: function() {
		var biggestElHeight = 0;
		this.container.getElements("p").each(function(item,index) {
            if(index != 0) {
                item.setStyle("opacity",0);
            }
			item.setStyles({
				"width": this.curEl.getSize().x,
				"position": "absolute",
				"display": "block"
			});
            var elHeight = item.getSize().y.toInt();
            if(elHeight > biggestElHeight) {
                biggestElHeight = elHeight;
            }
			item.set("tween", this.options.tweenOut)
		}.bind(this));
        this.wrap.setStyle("height",biggestElHeight);
        this.container.setStyles({
            "width": this.wrap.getSize().x,
            "height": biggestElHeight,
            "position": "absolute"
        });
	}
});

