/**
 * 
 */
jQuery(document).ready(function(){
	var tsWidth = (jQuery('#slidebox>.angebot_ts:first').css('width'));
	var tsHeight =(jQuery('#slidebox>.angebot_ts:first').css('height'));
	
	//Slidebog wird um ein vielfaches So breit wie ein einzelner Teaser
	if (tsWidth) {
		var slideboxWidth =	((jQuery('#slidebox>.angebot_ts').length) * tsWidth.substring(0, tsWidth.length - 2) + 100) + "px";
	}
	jQuery('#slidebox').css('width', slideboxWidth);
	jQuery('#slidebox').css('height', tsHeight);

	jQuery('#visibleWindow').css('width', tsWidth);
	jQuery('#visibleWindow').css('height', tsHeight);
	
	
	// Wechselintervall falls mehr als 1 Angebot vorhanden
	if((jQuery('#slidebox>.angebot_ts').length) > 1){
		var sliderAktiv = setInterval('slideRight()', 5000);
	}
	else{
		jQuery('.slide_nav').hide();
	}

	jQuery('.slide_nav>.slideLeft').click(function(){
		slideLeft();
		clearInterval(sliderAktiv);
	});
	jQuery('.slide_nav>.slideRight').click(function(){
		slideRight();
		clearInterval(sliderAktiv);
	});


});

function slideLeft(){
	jQuery('#slidebox>.angebot_ts:last').clone(true).prependTo('#slidebox');
	jQuery('#slidebox>.angebot_ts:first').css('left', ('-'+jQuery('#slidebox>.angebot_ts:first').css('width')));
	jQuery('#slidebox>.angebot_ts:first').next().css('left', ('-'+jQuery('#slidebox>.angebot_ts:first').css('width')));
	jQuery('#slidebox>.angebot_ts:last').detach();
	
	jQuery('#slidebox>.angebot_ts:first').animate({
		left: ('+='+jQuery('#slidebox>.angebot_ts:first').css('width'))},
		2000,
		function(){}
	);
	jQuery('#slidebox>.angebot_ts:first').next().animate({
		left: ('+='+jQuery('#slidebox>.angebot_ts:first').css('width'))},
		2000,
		function(){
			jQuery('#slidebox>.angebot_ts').each(function(){
				jQuery(this).css('left','0px');
			});
		}
	);
}

function slideRight(){
	jQuery('#slidebox>.angebot_ts:first').animate({
		left: ('-='+jQuery('#slidebox>.angebot_ts:first').css('width'))},
		2000,
		function(){}
);
jQuery('#slidebox>.angebot_ts:first').next().animate({
	left: ('-='+jQuery('#slidebox>.angebot_ts:first').css('width'))},
	2000,
	function(){
		jQuery('#slidebox>.angebot_ts:first').clone(true).appendTo('#slidebox');
		jQuery('#slidebox>.angebot_ts:first').detach();
		jQuery('#slidebox>.angebot_ts').each(function(){
			jQuery(this).css('left','0px');
		});
	}
);
}
