window.addEvent('domready', function() {
	var Morphy = new Class({
		initialize: function() {	
			var el_pi1 = $$('div.tx-lwflexheader-pi1')
			var el = el_pi1[0].getElements('div.image-wrap');
			if($defined(el)) {
				el.each(function(els) {
					this.setImages(els);
					this.imageMorph.periodical(3000, this, els);
				}.bind(this));
			}
		},
		setImages: function(wrapper) {
			var quotes = wrapper.getElements('img');
			if($defined(quotes)) {
				quotes.each(function(quote, key) {
					if(key != 0) {
						quote.setOpacity(0);
						quote.setStyle('z-index', '0');
					} else {
						quote.setStyle('z-index', '1');
					}
				});
			}
		},
		imageMorph: function(wrapper) {

			var quotes = wrapper.getElements('img');
			if($defined(quotes)) {
				var quoteLen = quotes.length;
				quotes.each(function(el, k) {		
					if(el.get('opacity') != 0) {
						el.setStyle('z-index', '0');
						if((quoteLen-1)>k) {					
							quotes[k+1].fade(1);
							quotes[k+1].setStyle('z-index', '1');
							if((k-1)>=0) {
								quotes[k-1].setOpacity('0');
							}
						} else {
							quotes[0].setStyle('z-index', '1');
							quotes[0].fade(1);
							quotes.each(function(q,qk) {
								if(qk != 0) {
									if(q.get('opacity')!=0) {
										q.fade(0);
									}
								}
							});
						}
					}
				});
			}
		}
	});
	var morph = new Morphy();
});
