window.addEvent('domready', function(){

	var teaserBoxHome = $$('#teaserbox-home');
	var homePage = $$('#home');

	if(homePage.length > 0) {
		var szNormal = 145, szSmall = 100, szFull = 280;
	} else {
		var szNormal = 145, szSmall = 113, szFull = 260;
	}

	var teaserSquares = $$("#teaserbox-home ul li");
	var fxBox = new Fx.Elements(teaserSquares, {wait: false, duration: 300, transition: Fx.Transitions.Pow.easeOut});

	var elText = new Array(3);
	var textSlide = new Array(3);

	teaserSquares.each(function(square, i) {
		elText[i] = square.getElement('p').addClass('ie6-hide');
		textSlide[i] = new Fx.Slide(elText[i], {duration: 100}).hide();

		square.addEvent("mouseenter", function(event) {
			var o = {};
			o[i] = {width: [square.getStyle("width").toInt(), szFull]}
			teaserSquares.each(function(other, j) {
				if(i != j) {
					var w = other.getStyle("width").toInt();
					o[j] = {width: [w, szSmall]
					};
					textSlide[j].show();
					textSlide[j].hide();
				}
			});

			var x = new Chain();
			x.chain(function() {
				fxBox.start(o);
			});  
			x.chain(function() {
				elText[i].removeClass('ie6-hide');
				textSlide[i].slideIn();
			});
			x.callChain();
			x.callChain.delay(100, x);
		});

		square.addEvent("mouseleave", function(event) {
			textSlide[i].slideOut();
			elText[i].addClass('ie6-hide');
		});
	});


	if(teaserBoxHome.length > 0) {
		$("teaserbox-home").addEvent("mouseleave", function(event) {
			var o = {};
			teaserSquares.each(function(square, i) {
				o[i] = {width: [square.getStyle("width").toInt(), szNormal]}
			});
			fxBox.start(o);	
			
			teaserSquares.each(function(square, i) {
				textSlide[i].slideOut();
				elText[i].addClass('ie6-hide');
			});
		});
	}

});