// JavaScript Document
actionpage = '';
$(document).ready(function() {
				   
	$(".videoslider a[rel='videos']").colorbox({transition:"fade",iframe:true, innerWidth:640, innerHeight:390});
	$(".rightvideo a[rel='videos']").colorbox({transition:"fade",iframe:true, innerWidth:640, innerHeight:390});	
	$(".websiteslide a[rel='website']").colorbox();
	$(".homepage-slide a[rel='homepage']").colorbox();
	
	$(".popup_difmoe").colorbox({width:962,inline:true, href:"#difmoe"});
	$(".popup_cee").colorbox({width:962,inline:true, href:"#cee"});
	$('.pagemenuhidden').css({opacity:0}).removeClass('pagemenuhidden');
	$('.pagelogohidden').css({opacity:0}).removeClass('pagelogohidden');
	
	$('ul.pagenavi a[rel], ul.pagemenu a, .hnavi a, .pagelogo a, a.kontaktanfrage').click(function(){
		
		$('.hnavi a').removeClass('up').addClass('down');
		$('span.pagetitle').removeClass('gold');
														   
		hash = $(this).attr('rel');
		if(hash=='') return false;
		
		if(hash==actionpage)
		{actionpage='';
			$('.pagemenu').stop().animate({opacity:0},'normal');
			$('.pagelogo').stop().animate({opacity:0},'normal');
			$('.box2').stop().animate({height:1},'normal',function(){
				$.scrollTo($('#'+hash),'slow',function(){ });
				
			});
			return false;
		}
		
		actionpage = hash;
		
		$('#'+hash+' .hnavi a').removeClass('down').addClass('up');
		$('#'+hash+' span.pagetitle').addClass('gold');
		//pos = $(this.hash+' .box2').offset();
		
		$('.pagemenu').stop().animate({opacity:0},'normal');
		$('.pagelogo').stop().animate({opacity:0},'normal');
		$('.box2').stop().animate({height:1},'normal',function(){
		
			$.scrollTo($('#'+hash),'normal',function(){
				if($('#'+hash+' .boxinner'))
				{
					ht = $('#'+hash+' .boxinner').innerHeight();
					$('#'+hash+' .pagemenu').stop().animate({opacity:1},'slow');
					$('#'+hash+' .pagelogo').stop().animate({opacity:1},'slow');
					
					$('#'+hash+' .box2').stop().animate({height:ht+5},'normal','easeInSine',function(){	
																					  
					});
				}
			});	
		});
		
		return false;
		
	});
});

	
$(document).ready(function() {
	   naviVideoSlide('website-slide-control','websiteslide','next');
	   naviHomepageSlide('homepage-slide-control','homepage-slide','next');
});


sltimer ={'imgslider':null,'slider':null,'homepage-slide':null,'websiteslide':null,'kundenslider':null};




function naviVideoSlide(bx,cls,pos)
{	
	clearTimeout(sltimer[cls]);
	sltimer[cls]= setTimeout("naviVideoSlide('"+bx+"','"+cls+"','"+pos+"');",3500);	
	boxw = $('div.'+cls).width();
	liboxes = $('ul.'+cls+' li');
	inboxw = liboxes.width();						
	nos = Math.round(boxw / inboxw);
	limit = liboxes.length - nos;
	$('ul.'+cls).width((liboxes.length * inboxw)+500);
	
	if(limit<0) return;
//	alert(limit);
	curent = $('#'+bx).attr('rel');
	if(pos=='prev'){
		curent--; 
		if(curent<0) curent=(limit);
		$('#'+bx).attr('rel',curent);
	}else{
		curent++; 
		if(curent>(limit)) curent=0;
		$('#'+bx).attr('rel',curent);
	}
	
	$('div.'+cls).stop().scrollTo( liboxes[curent], 'normal' );
	
	
}

function naviHomepageSlide(bx2,cls2,pos2)
{	
	clearTimeout(sltimer[cls2]);
	sltimer[cls2]= setTimeout("naviHomepageSlide('"+bx2+"','"+cls2+"','"+pos2+"');",3500);
	boxw = $('div.'+cls2).width();
	liboxes = $('ul.'+cls2+' li');
	inboxw = liboxes.width();						
	nos = Math.round(boxw / inboxw);
	limit = liboxes.length - nos;
	$('ul.'+cls2).width((liboxes.length * inboxw)+500);
	
	if(limit<0) return;
//	alert(limit);
	curent = $('#'+bx2).attr('rel');
	if(pos2=='prev'){
		curent--; 
		if(curent<0) curent=(limit);
		$('#'+bx2).attr('rel',curent);
	}else{
		curent++; 
		if(curent>(limit)) curent=0;
		$('#'+bx2).attr('rel',curent);
	}
	
	$('div.'+cls2).stop().scrollTo( liboxes[curent], 'normal' );
}

		
