var trigger = 0;
var offset = 0;
var anz = 0;
var delayTime = 300;

jQuery.fn.reverse = function() {
    return this.pushStack(this.get().reverse(), arguments);
};

$(document).ready(function() {
	
		var maxSliders = $('#teaserInner').children('.teaser').length;

	  	$('#arrowLeft').hover(function(){
			trigger = 1; $(this).css({backgroundPosition: 'left bottom'});
		}
		,function(){
			trigger = 0; $(this).css({backgroundPosition: 'left 0'});
		});
		
	  	$('#arrowRight').hover(function(){
			trigger = 1; $(this).css({backgroundPosition: 'right bottom'});
		}
		,function(){
			trigger = 0; $(this).css({backgroundPosition: 'right 0'});
		});
		
	  	$('#teaserPic').mouseenter(function(){
			trigger = 1;
			$('#arrowLeft, #arrowRight').stop(false,true).fadeIn('slow');
		});
	  	$('#teaserPic').mouseleave(function(){
			setTimeout(function(){if (trigger!=1) $('#arrowLeft, #arrowRight').stop(false,true).fadeOut('slow');},500);
			trigger = 0;
		});
		
		$('#arrowLeft').click(function(){
			delayTime = 300;
			if (anz>0){
				oldanz=anz;
				anz=parseInt(anz-1);
				$('.teaser').reverse().each(function(){
					$(this).delay(delayTime).animate({left:'+=233'},{easing:'easeOutSine',duration:575});
					delayTime=delayTime+100;
				});
			}
		});
		
		$('#arrowRight').click(function(){
			delayTime = 300;
			if (anz<maxSliders-4){
				oldanz=anz;
				anz=parseInt(anz+1);
				$('.teaser').each(function(){
					$(this).delay(delayTime).animate({left:'-=233'},{easing:'easeOutSine',duration:575});
					delayTime=delayTime+100;
				});
			}
		});
		
		$('.productContainer').eq(0).css({display:'block'});
		
		$('.headlineLeft').click(function(){
			$('#rechts').find('.csc-textpic-text').slideUp();
			$('#rechts').find('.tx-powermail-pi1').slideUp();
			$('#rechts').find('.newsLatest').slideUp();
			$(this).next('.csc-textpic-text').slideDown();
			$(this).next('.tx-powermail-pi1').slideDown();
		});
		
		$('.productsAll').find('.headlineRight').click(function(){
			$(this).parents('.productsAll').find('.productContainer').slideUp();
			$(this).parent('.productCatCont').find('.productContainer').slideDown();
		});
		
		$('.productInner,.productTitle').click(function(){
			$('.productDetails').remove();
			var thisis = $(this);
			var id = $(this).parent('.product').attr('class').split(' ');
			var endid = id[1].split('prodId');
			$.post("fileadmin/php/productDetails.php", {id:endid[1]}, function(data){
				$(thisis).parent('.product').append(data);
				$('.productDetails').animate({width: '386px'},'slow',function(){});
				var bodyheight = $('body').innerHeight();
				$('#overlay').css({height:bodyheight});
				$('#overlay').fadeIn();
			}); 	
		});
		
		$('.productClose').live('click',function(){
			$('.productDetails').animate({width:'0px'}, function(){
				$('.productDetails').delay(1500).remove();
				$('#overlay').fadeOut();
				//$('.productDetails').before('.cleaner').remove();
			});
		});
		
		$('#overlay').click(function(){
			$('.productDetails').animate({width:'0px'}, function(){
				$('.productDetails').delay(1500).remove();
				$('#overlay').fadeOut();
				//$('.productDetails').before('.cleaner').remove();
			});
		})
		
		$('#c41').find('td:contains("x")').html('<img src="fileadmin/images/bread.png" border="0">');

		//console.log(.toString().search(new RegExp(/x/i)));
		
});
