$.fn.wait = function(time, type)
{
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function()
	{
        var self = this;
        setTimeout(function()
		{
            $(self).dequeue();
        }, time);
    });
};

$().ready(function()
{		
	/* Aktuelles-Teaser */ 
	$('.nt-prev,.nt-next').show();
	$('#news-teaser').cycle(
	{
		fx:			'scrollHorz',
		prev:		'.nt-prev', 
		next:		'.nt-next', 
	    timeout:	6000,
		//timeout:	0,
		speed: 		2000,
		easing: 	'easeOutQuart', 
		pause:		1,
		prevNextClick: function(isNext, zeroBasedSlideIndex, slideElement)
		{
			if ( isNext )
			{
				$(this.next).hide();
			}
			else
			{
				$(this.prev).hide();
			}
		},
		after: function(currSlideElement, nextSlideElement, options, forwardFlag)
		{
			$('div.teaserimage img:hidden').show();
		}
	});
	
	/* LOUIS INTERNETspeed */ 
	var sperre = 0;
	
	$("#li-speed-fuer-eilige").show();
	$("#li-speed-fuer-eilige").click(function ()
	{
		$("#speed").show().css('height',$(document).height());
		
		$(".preloader").wait(300).fadeIn(1000);
		$("#innerspeed").wait(250).fadeIn(2000, function ()
		{		
			if (sperre != 1)
			{
				$.ajax(
				{
					type: "GET",
					async: false,
					url: base+"image.speed.szenen.html",
					success: function(data)
					{	
						$("#placeholder").html(data);
						$(".preloader").hide();
						$("#szene1").show();
						//$("#speednext").click();
					}
				});
				sperre = 1;
			}
		});
	});		
	
	var x = 2;
	z = 1;
	buttons(z);
	
	$("#speedprev").click(function ()
	{
		var y = x-1;
		if ( y > 1 )
		{				
			$("#szene"+y).fadeOut("slow");
			x--;
		}		
		z = x-1;		
		buttons(z);
    });	
	
	$("#speednext").click(function ()
	{
		if ( x < 20 )
		{			
			$("#szene"+x).fadeIn("slow");
			x++;	
		}
		z = x-1;
		buttons(z);
		return false;
    });
	
	$("#speedclose").click(function ()
	{
		$("#speed").fadeOut(1500);
		$("#innerspeed").fadeOut(1000);
		$(".szene").fadeOut(1500);
		$("#szene1").fadeIn(1500);
		x = 2;
		z = 1;
		return false;
	});
	
	$("#get_vcard").click(function ()
	{
		window.open(this.href,'_blank');
		return false;
	});
	
	function buttons(z)
	{
		if ( z === 18 )
		{
			$('#get_vcard').show();
		}
		else
		{
			$('#get_vcard').hide();
		}
		
		if (z == 1)
		{
			$("#speedprev").addClass('inactive');
			$("#speednext").removeClass('inactive');
		}
		else if (z == 19)
		{
			$("#speedprev").removeClass('inactive');
			$("#speednext").addClass('inactive');
		}
		else {			
			$("#speedprev, #speednext").removeClass('inactive');
		}
	}
});