$(document).ready(function(){
		
		
		
		//Sort "Betriebe" by category or alphabetically
		$("#branche").hide();
		$(".alphabetisch").css("background" , "#CFE3A3");
		$(".alphabetisch, .branche").click(function(){
			var sorting = $(this).attr("class");
			if(sorting == "alphabetisch") {
				$(".alphabetisch").css("background" , "#CFE3A3");
				$(".branche").css("background" , "#ccc");
				$("#"+sorting).show();
				$("#branche").hide();
				}
			if(sorting == "branche") {
				$(".branche").css("background" , "#CFE3A3");
				$(".alphabetisch").css("background" , "#ccc");
				$("#"+sorting).show();
				$("#alphabetisch").hide();
				}
			});
		
		//add hijack class for anchor tags in scrollpane
		$("#alphabetisch a, #branche a").addClass("jspHijack");
		
		//scrollpane for normal content
		//$("#scrollcontainer").jScrollPane({
//			autoReinitialise: true
//			/*showArrows: true,
//			verticalArrowPositions: 'split',*/});
		
		//Betriebe scrollpane	
		var pane = $("#berieb_container").jScrollPane({
			arrowButtonSpeed : 300,
			animateScroll: true,
			showArrows: true,
			hijackInternalLinks: true,
			//autoReinitialise: true,
			//autoReinitialiseDelay: 500,
			verticalArrowPositions: 'split'});	
		
		//Use jScrollPane Api functino scrollToX to randomly jump to a 
		//scroll-position
		function GetRandom( min, max ) {
			if( min > max ) {
				return( -1 );
			}
			if( min == max ) {
				return( min );
			}
				return( min + parseInt( Math.random() * ( max-min+1 ) ) );
		}
		
		var api = pane.data('jsp');
		api.scrollToX(GetRandom(0,14)*217);	//anzhal der Elemente (14) * breite des Elements
		
		
		//zebra for betriebe
		$(".overview li:nth-child(odd)").addClass("odd");
			
		
		//Open Betrieb-Deteil in fancybox	
		$("a.mehrinfos").fancybox({
			autoDimensions: false,
			width: 1024,
			height: 375,
			padding: 0,
			'overlayShow': true,
			'overlayOpacity': 0.1,
			scrolling: 'no',
			onClosed : function() {
				history.go(0); //reload page to reinitialize jscrollpane
			},
			onComplete: function () { //start cycle plugin on fb load complete
				console.log("fb open");
				
				
			}
		});
		$(".imgcontainer").cycle({
			width: '350px'});	
		
		$("a.jspHijack").fancybox({
			autoDimensions: false,
			width: 1024,
			height: 375,
			padding: 0,
			'overlayShow': true,
			'overlayOpacity': 0.1,
			scrolling: 'no'
		});
		
		
		
	});
		
	jQuery(function( $ ){
		
		
		/*$('a.mehrinfos').click(function(){
			//alert("ok");
			target =$(this).attr("href");
			//taraget = target.substring(1);
			//el = document.getElementById(target.slice(1));
			//alert(target.slice(1));
			$("#berieb_container").scrollTo( target, {duration: 1000});
		});
		*/
	});
		
