// Navigation

var now = new Array();
function navHover()
{
	$(".pgNav li a").mouseover(

	      function () {

	      	if(now[this.id] != true)
	      	{
	      	now[this.id] = true;
	        $("#sp_"+this.id).animate(
	        	{
	        	width :  "130px"
	        	}, {queue:false, duration:300})
	        }
	      }
    );
    
    $(".pgNav li a").mouseout(

	      function () {
	      if(now[this.id] == true)
	        {
	        $("#sp_"+this.id).animate(
	        	{
		        width :  "0px"
		        },300);
	      	now[this.id] = false;
			}
	      }
    );
}


// Bildslider

function moveIn(id,margin)
{
	$(id).animate({ 
		"opacity": 1,
		"marginLeft": margin
	}, 2000 );
}
function moveOut(id)
{
	height = $(id).css("height");
	$(id).animate({
		"opacity": 0
	}, 1500 ,function(){
		$(id).css({
			"height": height,
			"margin": 0
		});
	});
}

function moveAllIn()
{
	var margin=100;
	for(var i=0; i<4; i++)
	{
		if(lastIndex > parts.length-1)
			lastIndex = 0;
		moveIn("#"+parts[lastIndex++],margin);
		margin += 100;//$("#"+parts[lastIndex]).css("width");
	}
}

function moveAllOut()
{
	var s = lastIndex;
	for(var i=0; i<4; i++)
	{
		s--;
		if(s < 0)
			s = parts.length-1;
		moveOut("#"+parts[s]);
	}
}

function moveParts(){
	moveAllIn();
	window.setTimeout(function(){
		moveAllOut();
		window.setTimeout(function(){moveParts();},800);
	},5000);
}

var lastIndex = 0;
var parts = new Array('br_1','br_2','br_3','br_4','br_5','br_6','br_7','br_8','br_9','br_10'
		,'br_11','br_12','br_13','br_14','br_15');

// Anfahrt

function map()
{
	if($("#map").css("display") == 'none')
	{
		$("#map").slideDown();
		$("#map").click(function(){
			$("#map").slideUp();
		});
	}
	else
		$("#map").slideUp();	
}


// Scrollen

function wheel(event)
{
 
var delta = 0;
 
if (!event)
{
event = window.event;
}
 
if (event.wheelDelta)
{
delta = event.wheelDelta/120;
if (window.opera)
{
delta = -delta;
}
}
 
else if (event.detail)
{
delta = -event.detail/3;
}
 
if (delta)
{
if (delta < 0)
{
scrollend(2);
}
else
{
scrollend(1);
}
}
}

function scrollwheel(vasd){
if(vasd == "on")
{
if (window.addEventListener) { window.addEventListener('DOMMouseScroll', wheel, false); }
 
window.onmousewheel = document.onmousewheel = wheel;
}
else
{
if (window.addEventListener) { window.removeEventListener('DOMMouseScroll', wheel, false); }
window.onmousewheel = document.onmousewheel = "";
}
}
 
var px = 1;
var timer;
var i = 0;
 
function scroll(val)
{
clearTimeout(timer);
i=i+1;
d=document.getElementById('content');
y=d.scrollTop;
 
if(val==1)y-=px+i;
 
if(val==2)y+=px+i;
 
if(y<=d.scrollHeight-d.offsetHeight+px&&y>=0-px)
{
d.scrollTop=y;
timer=setTimeout('scroll('+val+')',30);
}
 
if(y<0||y>d.scrollHeight-d.offsetHeight)
{
scrollend(val);
}
}
 
var ss=20;
function scrollend(val)
{
clearTimeout(timer);
ss=ss-1;
d=document.getElementById('content');
y=d.scrollTop;
 
if(val==1)y-=px+ss;
 
if(val==2)y+=px+ss;
 
if(ss>0 && y<d.scrollHeight-d.offsetHeight)
{
d.scrollTop=y;
timer=setTimeout('scrollend('+val+')',30);
}
 
if(ss==0)
{
clearTimeout(timer);
i= 0;
ss=20;
}
 
if(y>d.scrollHeight-d.offsetHeight)
{
if(val==2)y+=20;
d.scrollTop=y;
}
}


// Slideshow

var showId = -1;
var playing = true;
var gotonow = false;

function startSlideshow()
{
	if(playing)
	{
		$("#sh_"+showId++).fadeOut("500");
		

		
		if(showId>maxId)
			showId = 0;
		setNav();
		
		$("#sh_"+showId).fadeIn("500",function(){
			
			setTimeout("startSlideshow();",3000);	
		});
	}
}

function gotoSlideshow(id)
{
	if(gotonow) return;
	if(playing) playSlideshow();
	if(id == showId) return;

	if(id == 'next')
	{
		if(showId == maxId) id=0;
		else id = showId+1;
	}
	if(id == 'prev')
	{
		if(showId == 0) id=maxId;
		else id = showId-1;
	}
	
	gotonow = true;
	$("#sh_"+showId).fadeOut("500");
	$("#sh_"+id).fadeIn("500",function(){gotonow = false;});
	showId = id;
	setNav();
}

function setNav()
{
	var o1 = document.getElementById('shNav');
	var o2 = document.getElementById('shNav_'+showId);
	var pos = o2.offsetLeft-o1.offsetLeft-(o2.offsetWidth*4);
	if(pos<0)
		pos=0;
	$("#shNav img").css({ "borderColor": "#ffffff" });
	$("#shNav_"+showId+" img").css({ "borderColor": "#CC99CC" });
	$("#shNav").animate( { scrollLeft: pos+"px" }, 500);
}


var pauseDiv = '';
function playSlideshow()
{
	if(pauseDiv == '')
		pauseDiv = $('#shControl').html();
	if(playing)
	{
		playing = false;
		$('#shControl').html('<img src="'+URL+'images/btn_play.png" alt="Abspielen" />');
	}
	else
	{
		playing = true;
		$('#shControl').html(pauseDiv);
		startSlideshow();
	}
}

// Trauringe-Tabs
var aktuTrTab;
function trTab(id)
{
	if(aktuTrTab != id)
	{
		$("#trLi_"+aktuTrTab).css({'fontWeight':'normal'});
		$("#trLi_"+id).css({'fontWeight':'bold'});
		$("#tr_"+aktuTrTab).fadeOut("slow",function (){
			$("#tr_"+id).fadeIn("slow");
			aktuTrTab = id;
			document.getElementById('content').scrollTop = 0;
		});
	}
}

function trTabStart(startId,nbrs)
{
	aktuTrTab = startId;
	$("#trLi_"+startId).css({'fontWeight':'bold'});
	for(var i=0;i<nbrs;i++)
		if(i!=startId)
			$("#tr_"+i).hide();
}


// OnLoad

$(document).ready(function(){
	navHover();
	trTabStart(0,10);
	$(".brands img").css({"opacity": 0});
	moveParts();
});
