$(document).ready(function(){
	var i = 0;
	var yStart = -68;
	var ySpace = 28;
	$('#teaser-list dl').each( function(){
		var yTarget = yStart - ( ySpace * i );
		$(this).addClass('item'+i);
		$(this).css('bottom', yTarget+'px');
		$(this).click( clickTeaser );
		i++;
	});

	initTeasers();
	timer = null;
});

function clickTeaser(){
	var id = $('#teaser-list dl').index(this);
	var l = $('#teaser-list dl').length;
	var yStart = -68;
	var height = 124;
	var ySpace = 28;
	
	if( $(this).hasClass('collapsed') ) {
		for( var i=0; i<l; i++ ) {
			if( i <= id ) {
				var yTarget = yStart - ( ySpace * i ) + height;
				$('.item'+i).animate( {bottom: yTarget+'px'}, 500 );
				if( i == id ) {
					$('.item'+i).removeClass('collapsed').addClass('expanded');
				} else {
					$('.item'+i).removeClass('expanded').addClass('collapsed');
				}
			} else {
				var yTarget = yStart - ( ySpace * i );
				$('.item'+i).animate({bottom: yTarget+'px'}, 500 );
				$('.item'+i).removeClass('expanded').addClass('collapsed');
			}
		}
	} else {
		for( var i=0; i<l; i++ ) {
			var yTarget = yStart - ( ySpace * i );
			$('.item'+i).animate({bottom: yTarget+'px'}, 500 );
			$('.item'+i).removeClass('expanded').addClass('collapsed');
		}
	}
	if(timer) clearTimeout(timer);
}

function initTeasers(){
	$('.teaser-item dd').each( function(){
		$(this).click( function(){
			var url = $( "a", this).attr('href');
			window.location.href = '/'+url;
			return false;
		});
	});

}



function firstTimer(){
	$('.collapsed:first').click();
	clearTimeout(timer);
}


/**
 * initialize teaser event handling
 *
 */
 /*
function initTeasers(){
	$('.collapsed').click(expandTeaser);
	$('.teaser-item dd').each( function(){
		$(this).click( function(){
			var url = $( "a", this).attr('href');
			window.location.href = url;
			return false;
		});
	});

}

function firstTimer(){
	$('.collapsed:first').click();
	clearTimeout(timer);
}

//handles expansion
function expandTeaser(){
	if(timer) clearTimeout(timer);
	$('.expanded').click();
	$(this).unbind('click', expandTeaser);
	$('dd', this).slideDown();
	$(this).removeClass('collapsed').addClass('expanded');
	$(this).bind('click', collapseTeaser);
}

//handles collapsing
function collapseTeaser(){
	$(this).unbind('click', collapseTeaser);
	$('dd', this).slideUp();
	$(this).removeClass('expanded').addClass('collapsed');
	$(this).bind('click', expandTeaser);
}
*/