_LOE._classes.ProductShowcase = new Class({
	Implements: [Events, Options, _LOE._libs.jQuery],
	options: {
		scrollInterval: 160,
		pixelsToScroll: 60,
		animationDuration: 160,
		fxInterval: 6
	},
	initialize: function(options) {
		//this.JQ = jQuery;
		this.setJQuery();
		this.jQuery.fx.interval = 20;
		this.setOptions(options);
		this.interValID = null;
		this.btnLeft = this.jQuery('#showcase #stage div.left');
		this.btnRight = this.jQuery('#showcase #stage div.right');
		this.caseBox = this.jQuery('#showcase #stage ul');
		this.setDimensions();
		this.btnLeft.hover(this.startScroll.bind(this, 'right'), this.stopScroll.bind(this));
		this.btnRight.hover(this.startScroll.bind(this, 'left'), this.stopScroll.bind(this));
		this.btnLeft.addClass('end');
	},
	setDimensions: function() {
		var caseBoxChilds = this.caseBox.find('li').length;
		var caseBoxW = caseBoxChilds * 182;
		caseBoxW = caseBoxW - 790;
		this.maxLeft = -caseBoxW;
	},
	startScroll: function(direction) {
		var fn = (direction == 'left') ? this.stepLeft : this.stepRight;
		//this.interValID = window.setInterval(fn.bind(this), 100);
		this.interValID = window.setInterval(fn.bind(this), this.options.scrollInterval);
	},
	/*
	stepLeft: function() {
		var casePos = this.caseBox.position();
		this.caseBox.stop();
		if(this.maxLeft >= casePos.left) {
			return this.stopScroll();
		} else {
			this.caseBox.animate({
				left: '-=50'
			}, 100, 'linear');
		}

	},
	stepRight: function() {
		var casePos = this.caseBox.position();
		this.caseBox.stop();
		if(casePos.left >= 0) {
			return this.stopScroll();
		} else {
			this.caseBox.animate({
				left: '+=50'
			}, 100, 'linear');
		}
	},
	*/
	stepLeft: function() {
		var casePos = this.caseBox.position();
		this.caseBox.stop();
		if(this.maxLeft >= casePos.left) {
			this.btnRight.addClass('end');
			return this.stopScroll();
		} else if(this.maxLeft+this.options.pixelsToScroll*2 >= casePos.left) { 
			this.caseBox.animate({
				left: '-=' + this.options.pixelsToScroll
			}, this.options.animationDuration*2, 'linear');
		} else {
			this.btnRight.removeClass('end');
			this.btnLeft.removeClass('end');
			this.caseBox.animate({
				left: '-=' + this.options.pixelsToScroll
			}, this.options.animationDuration, 'linear');
		}

	},
	stepRight: function() {
		var casePos = this.caseBox.position();
		this.caseBox.stop();
		if(casePos.left >= 0) {
			this.btnLeft.addClass('end');
			return this.stopScroll();
		} else if(casePos.left >= 0-this.options.pixelsToScroll*2) { 
			this.caseBox.animate({
				left: '+=' + this.options.pixelsToScroll
			}, this.options.animationDuration*2, 'linear');
		} else {
			this.btnRight.removeClass('end');
			this.btnLeft.removeClass('end');
			this.caseBox.animate({
				left: '+=' + this.options.pixelsToScroll
			}, this.options.animationDuration, 'linear');
		}
	},
	stopScroll: function() {
		window.clearInterval(this.interValID);
	}
});


jQuery(function(){
	//Fix für Neue Händlersuche - Layout Schmal (Inhalt) auf Entertainmentseite, wenn Inhalt größer ist -> Abstand vergrößern
	try {
		var hsDiff = jQuery('.section.last .tx-bmloewehs-pi5 .dealerSearch a').position().top-(jQuery('.section.last .tx-bmloewehs-pi5').position().top+jQuery('.section.last .tx-bmloewehs-pi5').height());
		hsDiff+=20;
		if(hsDiff<20){
			jQuery('.entertainment div.section').height(jQuery('.entertainment div.section').height()+hsDiff);
		}
	} catch(ex) {
	//
	}

	//Fix für inlineblock-ersatz H1.wbw
	jQuery('h1.wbw').css({padding:0,background:'none'}).html('<span style="background-color: #ffffff;padding: 5px 10px;">'+jQuery('h1.wbw').html()+'</span>');
});



