var timer;
var counter = 0;
jQuery(document).ready(function($){

	//Pictures Slider Top
	if($('#slider-top-1').length != 0){
		stepcarousel.setup({
	                  galleryid: 'slider-top-1', //id of carousel DIV
	                  beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
	                  panelclass: 'panel', //class of panel DIVs each holding content
	                  panelbehavior: {speed:500, wraparound:true, persist:false},
	                  defaultbuttons: {enable: true, moveby: 1, leftnav: ['standards/images/prev.png', 0, 50], rightnav: ['standards/images/next.png', -70, 50]},
	                  statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
	                  contenttype: ['inline'], //content setting ['inline'] or ['external', 'path_to_external_file'],
					  opacity: 0.2
	    });
 	}
	$('#btn-next-top-1').click(function(){
            stepcarousel.stepBy('slider-top-1', 1, $);
            return false;
    });
    $('#btn-prev-top-1').click(function(){
            stepcarousel.stepBy('slider-top-1', -1, $);
            return false;
    });

	//Slider
	$('#content .slider').each(function(i, val){
			gallery_id = 'slider-'+(i+1);
			stepcarousel.setup({
		                  galleryid: gallery_id, //id of carousel DIV
		                  beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
		                  panelclass: 'panel', //class of panel DIVs each holding content
		                  panelbehavior: {speed:500, wraparound:true, persist:false},
		                  defaultbuttons: {enable: false, moveby: 1, leftnav: ['standards/images/prev.png', 30, 270], rightnav: ['standards/images/next.png', -70, 270]},
		                  statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
		                  contenttype: ['inline'], //content setting ['inline'] or ['external', 'path_to_external_file'],
						  opacity: 1
		    });
			$('#btn-next-'+(i+1)).click(function(){
		            stepcarousel.stepBy('slider-'+(i+1), 1, $);
		            return false;
		    });
		    $('#btn-prev-'+(i+1)).click(function(){
		            stepcarousel.stepBy('slider-'+(i+1), -1, $);
		            return false;
		    });
	});
	$('#content .slider-small').each(function(i, val){
			gallery_id = 'slider-small-'+(i+1);
			stepcarousel.setup({
		                  galleryid: gallery_id, //id of carousel DIV
		                  beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
		                  panelclass: 'panel', //class of panel DIVs each holding content
		                  panelbehavior: {speed:500, wraparound:true, persist:false},
		                  defaultbuttons: {enable: false, moveby: 1, leftnav: ['standards/images/prev.png', 30, 270], rightnav: ['standards/images/next.png', -70, 270]},
		                  statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
		                  contenttype: ['inline'], //content setting ['inline'] or ['external', 'path_to_external_file'],
						  opacity: 1
		    });
			$('#btn-next-small-'+(i+1)).click(function(){
		            stepcarousel.stepBy('slider-small-'+(i+1), 1, $);
		            return false;
		    });
		    $('#btn-prev-small-'+(i+1)).click(function(){
		            stepcarousel.stepBy('slider-small-'+(i+1), -1, $);
		            return false;
		    });
	});
	$('#content .slider-middle').each(function(i, val){
			gallery_id = 'slider-middle-'+(i+1);
			stepcarousel.setup({
		                  galleryid: gallery_id, //id of carousel DIV
		                  beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
		                  panelclass: 'panel', //class of panel DIVs each holding content
		                  panelbehavior: {speed:500, wraparound:true, persist:false},
		                  defaultbuttons: {enable: false, moveby: 1, leftnav: ['standards/images/prev.png', 30, 270], rightnav: ['standards/images/next.png', -70, 270]},
		                  statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
		                  contenttype: ['inline'], //content setting ['inline'] or ['external', 'path_to_external_file'],
						  opacity: 1
		    });
			$('#btn-next-middle-'+(i+1)).click(function(){
		            stepcarousel.stepBy('slider-middle-'+(i+1), 1, $);
		            return false;
		    });
		    $('#btn-prev-middle-'+(i+1)).click(function(){
		            stepcarousel.stepBy('slider-middle-'+(i+1), -1, $);
		            return false;
		    });
	});

	$().keydown(
		function(e){
			var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
			if(key == 49 || key == 97){
				window.location.href = $('#navigation .dial-1')[0].href;
			}
			else if(key == 50 || key == 98){
				window.location.href = $('#navigation .dial-2')[0].href;
			}
			else if(key == 51 || key == 99){
				window.location.href = $('#navigation .dial-3')[0].href;
			}
			else if(key == 52 || key == 100){
				window.location.href = $('#navigation .dial-4')[0].href;
			}
			else if(key == 53 || key == 101){
				window.location.href = $('#navigation .dial-5')[0].href;
			}
			else if(key == 54 || key == 102){
				window.location.href = $('#navigation .dial-6')[0].href;
			}
			else if(key == 55 || key == 103){
				window.location.href = $('#navigation .dial-7')[0].href;
			}
			else if(key == 56 || key == 104){
				window.location.href = $('#navigation .dial-8')[0].href;
			}
			else if(key == 57 || key == 105){
				window.location.href = $('#navigation .dial-9')[0].href;
			}
			else if(key == 48 || key == 96){
				window.location.href = $('#navigation .dial-0')[0].href;
			}
		}
	);

	
	//Storefinder - Tabellensortierung
	 $("#store-finder").tablesorter({sortList: [[4,0]]} );

	//Homepageanmiation
	if($('#homepage').length != 0){
		timer = setTimeout(function(){changeColor($);},100);
	}
	
});

function startSlideshow2($){
	$("#slider-home-2").easySlider({
			auto: true,
			continuous: true,
			controlsShow: false,
			vertical: true,
			direction: 'down',
			pause: 4000
	});
}

function changeColor($){
	if(counter <= 3){
			if(counter%2 == 0){
				$('#homepage').css('background-color','#FFFFFF');
			}else{
				$('#homepage').css('background-color','#000000');
			}
			counter += 1;			
			timer = setTimeout(function(){changeColor($);},100); 
			if(counter == 1){
				$("#slider-home-1").easySlider({
						auto: true,
						continuous: true,
						controlsShow: false,
						vertical: true,
						pause: 4000
				});
				if($('#slider-home-2').length != 0){
					timeout = setTimeout(function(){startSlideshow2($);},4000); 
				}
			}
			
	}else{
		clearTimeout(timer);
		
	}
	
}







