$(function() {

	$.ajaxSetup ({  
	    //cache: false  
	});
	
	var loadUrl = "/pressroom.php";

	var ajax_load = "Loading";
	
	var count = 0;
	
	$(window).bind('load', function() {
	
		$('#test').animate({ opacity: 0 });
		
		//$('#newsticker').append('<div></div><div></div><div></div>');
		
		var cur = 0;
		var numLines = 3;
		var nextHeadline = function() {
			
			if(cur == numLines) {
				cur = 1;
				count++;	
			} else {
				cur++;
				count++;
			}
			
			//alert(cur);
			if(count <= numLines) {
				$('#newsticker').append('<div></div>');
			}
			$('#newsticker div:nth-child(' + (cur+1) + ')').load(loadUrl + ' #col_2 p:nth-child(' + (cur+1) + ')', function() {
				//$('#newsticker').css({ width: +$('#newsticker div:nth-child(' + (n-1) + ')').width() });
				//alert($(this).width());
				
				//alert($(this).html());
				//$(this).children('p').children('a').css({ color: 'red' });
				
				$(this).css('filter', 'alpha(opacity=0)');
				$(this).css({ opacity: 0 });
				
				$(this).children('p').css({ position: 'relative' });
				
				//$(this).children('p').append('<span style="position: absolute; top: 0px; left: 770px; width: 20px; background: #ffffff; border: 1px solid red;">...</span>');
				
				$(this).children('p').children('a').attr('href', '/pressroom.php?link='+cur);
				
				if(cur > 1) {
					//alert('if');
					$('#newsticker div:nth-child(' + (cur) + ')').animate({ top: '-11px', opacity: 0 }, 400, function() {
						$(this).css({ top: '11px' });
						$(this).css('filter', 'alpha(opacity=0)');
						$(this).css({ display: 'none' });
					});
					$('#newsticker div:nth-child(' + (cur) + ')').fadeOut();
				} else {
					$('#newsticker div:nth-child(' + (numLines+1) +')').animate({ top: '-11px', opacity: 0 }, 400, function() {
						$(this).css({ top: '11px' });
						$(this).css('filter', 'alpha(opacity=0)');
						$(this).css({ display: 'none' });
					});
					$('#newsticker div:nth-child(' + (numLines+1) +')').fadeOut();
				}
				
				$(this).css({ display: 'block' });
				$(this).fadeIn();
				$(this).animate({ opacity: 1, top: '0px' }, 400, function() {
					//$(this).delay(1000).animate({ left: -$(this).width()+760 }, (1*$(this).width()), 'linear', function() {
					//$(this).delay(1000).animate({ top: '-31px' }, function() {
						setTimeout (function(){ nextHeadline() }, 7000);
						//setTimeout ('nextHeadline()', 1000);
					//});
				});
			});
		}
		
		nextHeadline();
		
		/*for(var n = 2; n < 5; n++) {
			
			$('#newsticker div:nth-child(' + n + ')').load(loadUrl + ' #col_2 p:nth-child(' + (n+1) + ')', function() {
				//$('#newsticker').css({ width: +$('#newsticker div:nth-child(' + (n-1) + ')').width() });
				alert($(this).width());
			});
		}*/
	
	});

});
