var coverflow_step = 606;
var coverflow_clicked = false;
/* $(document).ready (function () {
		$('.hide_noscript').removeClass('hide_noscript');
		$('.coverflow .prev, .coverflow .next').click (controlCoverflow);
		$('.coverflow .cover img').ready (function () {
				cover_height = 0;
				$('.coverflow .cover').each (function () {
						oh = $(this).outerHeight();
						if (oh > cover_height) {
							cover_height = oh;
						}
					}).each (function () {
						oh = $(this).outerHeight();
						p = cover_height - oh;
						$(this).css('padding-top', p + 'px');
//							p = ((cover_height - oh) / 2);
//							$(this).css({'padding-top': p + 'px', 'padding-bottom': p + 'px'});
					});
				cf_height = 230;
				cf_width = 0;
				$('.coverflow .title').each (function () {
						oh = $(this).outerHeight();
						ow = $(this).outerWidth(true);
						if (oh > cf_height) {
							cf_height = oh;
						}
						cf_width += ow;
					});
				if (cf_width % coverflow_step != 0) {
					cf_width += coverflow_step - (cf_width % coverflow_step);
				}
				$('.coverflow .titles').css({width: cf_width + 'px'});
				$('.coverflow .title').css({height: cf_height + 'px'});
				$('.coverflow .titles').animate({top: '0px'});
				$('.coverflow .prev, .coverflow .next').animate({top: (cover_height + 22) + 'px'});
				$('.coverflow').animate({height: cf_height + 'px'});
				controlCoverflowArrows();
			});
	});
*/
$(document).ready (function () {
		$('.hide_noscript').removeClass('hide_noscript');
		$('.coverflow .prev, .coverflow .next').click (controlCoverflow);
		$('.coverflow .cover img').ready (function () {
			var cf_width = 0;
			$('.coverflow .title').each (function () {
				cf_width += $(this).outerWidth(true);
			});
			if (cf_width % coverflow_step != 0) {
				cf_width += coverflow_step - (cf_width % coverflow_step);
			}
			$('.coverflow .titles').css({width: cf_width + 'px'});
			controlCoverflowArrows();
		});
});
function controlCoverflow() {
	if (coverflow_clicked == false) {
		coverflow_clicked = true;
		var $this = $(this);
		var $cf = $(this.parentNode);
		var $titles = $cf.find('.titles');
		var pos = $titles.position();
		var l = pos.left;
		if ($this.hasClass('prev') && l < 0) {
			// nach links
			l += coverflow_step;
		} else if ($this.hasClass('next') && l > ($titles.outerWidth() * -1) + coverflow_step) {
			// nach rechts
			l -= coverflow_step;
		}
		$titles.animate({left: l + 'px'},"normal","swing",function(){ coverflow_clicked = false; controlCoverflowArrows(); });
	}
}
function controlCoverflowArrows() {
		var $titles = $('.coverflow .titles');
        if($titles.length > 0) {
            var pos = $titles.position();
            var l = pos.left;
            if (l >= 0) {
                // ende links
                $('.coverflow .prev').css("background-position","left -58px");
            } else {
                $('.coverflow .prev').css("background-position","left top");
            }
            if (l <= ($titles.outerWidth() * -1) + coverflow_step) {
                // ende rechts
                $('.coverflow .next').css("background-position","left -87px");
            } else {
                $('.coverflow .next').css("background-position","left -29px");
            }
        }
}
