var contentWidth = 990;
var slideSpeed = 1000;
var homeTeaserSlide = false;
var homeTeaserSlideInterval = false;

$(document).ready(function(e){
	$('#hometeaser-icons li a').click(function(e){
		e.preventDefault();
		clearInterval(homeTeaserSlideInterval);
		homeTeaserRotate($(this));
		return false;
	});
	if($('#hometeasers').length > 0)
	{
		homeTeaserSlideInterval = window.setTimeout("homeTeaserRotateInterval()", 5000);
	}

	if($('#content div.accordion').length > 0)
	{
		if(location.hash.length > 0 && $(location.hash).length > 0 && $(location.hash).parent().hasClass('accordion'))
			var accordionCurPane = $(location.hash);
		else
			var accordionCurPane = false;

		var accordionKey = 0;
		$('#content div.accordion').each(function(){
			$(this).attr('id', 'jq-accordion-' + accordionKey);
			if(accordionCurPane && accordionCurPane.parent().attr('id') == $(this).attr('id'))
				var paneIndex = accordionCurPane.index();
			else
				var paneIndex = null;
			$(this).tabs('#jq-accordion-' + accordionKey + ' div.pane', { tabs: 'h2', effect: 'slide', initialIndex: paneIndex });
			accordionKey++;
		});

	}
});

function homeTeaserRotateInterval()
{
	homeTeaserSlideInterval = window.setTimeout("homeTeaserRotateInterval()", 7000);

	var next = $('#hometeaser-icons li a.active').parent().next().find('a');
	if(next.length == 0)
		var next = $('#hometeaser-icons li:first a');

	homeTeaserRotate(next, true);
}

function homeTeaserRotate(elem, forceLeft)
{
	var teaserNum = $(elem).closest('li').index();
	if(!$('#hometeaser-icons li:eq(' + teaserNum + ') a').hasClass('active'))
	{
		var date = new Date();
		var timestamp = date.getTime();
		if(homeTeaserSlide)
		{
			window.setTimeout(function(){  homeTeaserRotate(elem) }, homeTeaserSlide - timestamp);
		}
		else
		{
			$('#screen').css('overflow-x', 'hidden');
			homeTeaserSlide = timestamp + slideSpeed + 100;
			if($('#hometeaser-icons li a.active').closest('li').index() <= teaserNum || forceLeft)
				var move = 1;
			else
				var move = -1;

			$('#hometeaser-icons li a.active').removeClass('active').attr('href', '#');
			$(elem).addClass('active').removeAttr('href');

			if($.browser.msie && $.browser.version <= 7)
			{
				$('#hometeasers .hometeaser.active').animate({ left:  [move*-1*(contentWidth+500) + 'px', 'swing']}, slideSpeed,
					function(){ $(this).removeClass('active'); homeTeaserSlide = false; $('#screen').css('overflow-x', 'visible'); });
				$('#hometeasers .hometeaser:eq(' + teaserNum + ')').css('left', move*contentWidth + 'px')
					.addClass('active').animate({ left:  ['0', 'swing'] }, slideSpeed);
			}
			else
			{
				$('#hometeasers .hometeaser.active').animate({ opacity: 0, left:  [move*-1*contentWidth + 'px', 'swing']}, slideSpeed,
					function(){ $(this).removeClass('active'); homeTeaserSlide = false; $('#screen').css('overflow-x', 'visible'); });
				$('#hometeasers .hometeaser:eq(' + teaserNum + ')').css('left', move*contentWidth + 'px').css('opacity', 0)
					.addClass('active').animate({ opacity: 1, left:  ['0', 'swing'] }, slideSpeed);
			}
		}
	}
}

/* User Agent (Browserkennung) auf einen bestimmten Browsertyp prüfen */
function checkBrowserName(sName)
{
	var sAgent = navigator.userAgent.toLowerCase();
	if (sAgent.indexOf(sName.toLowerCase())>-1) {
		return true;
	}
	return false;
} // function

