$(function(){
				
				var defaultDurationScrollToNext=2000;
				var durationWaitBeforeBeginToScrollLongText=2000;
				var durationWaitAfterScrollLongText=2000;
				var durationBeforeScrollToNextText=5000;
				
				var newscount=0;
				var actualnews=0;
				
				function newNews(newsId,duration,init,callback){
					
										
					if(typeof callback != 'function') callback=function(){};
					actualnews=newsId;
					if(typeof duration != 'number'){
						duration=defaultDurationScrollToNext;
					}
					//console.log(duration,'duration');
					var news=$('#slider div[newsId='+newsId+']');
					//console.log(newsId,'newsId');
					if(init == true)$('#desc').html('<div>'+news.attr('headline')+'</div>');
					var mt=-1 * news.position().top;
					var animation={ marginTop :mt};
                    //console.log('animate',animation);
					$('#slider').animate(animation,duration,function(){
						if(actualnews=='LAST'){
                                
							newNews(0,0,true);
                            actualnews=0;
                            newsId=0;
                            news=$('#slider div[newsId=0]');
						}
						var newdesc=$('<div />').html(news.attr('headline'));
						var effect='drop';
						$('#desc *').hide(0,function(){$(this).remove()});
						newdesc.hide();
						newdesc.prependTo('#desc');
						newdesc.show(0);
						
						var newadditional=$('<div />').html(news.attr('additional'));
						var effect='drop';
						$('#additional *').hide(0,function(){$(this).remove()});
						newadditional.hide();
						newadditional.prependTo('#additional');
						newadditional.show(0);
						//$('#desc').html(news.attr('headline'));
						//$('#additional').html(news.attr('additional'));
						if(news.height()>$('#box').height()){
							//console.log('text bigger than box');
							var offset=news.height()-$('#box').height();
							var animation={marginTop:-1*(news.position().top+offset-news.height()+news.innerHeight())};
							//console.log(animation);
							//console.log(offset);
							$('#slider').delay(durationWaitBeforeBeginToScrollLongText).animate(animation,parseInt(offset*75),'linear').delay(durationWaitAfterScrollLongText,callback());
						}else{
							//console.log('textheight ok');
							$('#slider').delay(durationWaitBeforeBeginToScrollLongText).delay(durationWaitAfterScrollLongText,callback());
						}
						});
				}
				$('news item').each(function(){
					var $this=$(this);
					var me=$('<div>').addClass('newsitem');
					me.html($('text',$this).html());
					me.attr('headline',$('headline',$this).html());
					me.attr('additional',$('additional',$this).html());
					me.attr('newsId',newscount++);
					me.appendTo('#slider');
					var boxheight=$('#box').height()
					if(me.height()<boxheight){
						me.css('height',boxheight);
					}
					
				});
				$('news item:first').each(function(){
					var $this=$(this);
					var me=$('<div>').addClass('newsitem');
					me.html($('text',$this).html());
					me.attr('headline',$('headline',$this).html());
					me.attr('additional',$('additional',$this).html());
					me.attr('newsId','LAST');
					me.appendTo('#slider');
					var boxheight=$('#box').height()
					if(me.height()<boxheight){
						me.css('height',boxheight);
					}
					
				});
				newNews(0,false,true);
				
				
				function waitToSlide(){
					setTimeout(slideIt,durationBeforeScrollToNextText);
				}
				function slideIt(){
					var nextnews;
					//console.log(actualnews,'actualnews');
					//console.log(newscount,'newscount');
					if(actualnews<newscount-1){
						nextnews=actualnews+1;
					}else{
						nextnews='LAST';
					}
					newNews(nextnews,false,false,waitToSlide);
					
				}
				slideIt();
				
			});
