jQuery(function() {
		//scrollpane parts
		var scrollPane = jQuery( ".scroll-pane" ),
			scrollContent = jQuery( ".scroll-content" );
		
		//build slider
		var scrollbar = jQuery( ".scroll-bar" ).slider({
			slide: function( event, ui ) {
				if ( scrollContent.width() > scrollPane.width() ) {
					scrollContent.css( "margin-left", Math.round(
						ui.value / 100 * ( scrollPane.width() - scrollContent.width() )
					) + "px" );
				} else {
					scrollContent.css( "margin-left", 0 );
				}
			}
		});
		
		//append icon to handle
		var handleHelper = scrollbar.find( ".ui-slider-handle" )
		.mousedown(function() {
			scrollbar.width( handleHelper.width() );
		})
		.mouseup(function() {
			scrollbar.width( "100%" );
		})
		.append( '<span class="ui-icon ui-icon-triangle-2-e-w"></span>' )
		.wrap( '<div class="ui-handle-helper-parent"></div>' ).parent();
		
		//change overflow to hidden now that slider handles the scrolling
		scrollPane.css( "overflow", "hidden" );
		
		//size scrollbar and handle proportionally to scroll distance
		function sizeScrollbar() {
			var remainder = scrollContent.width() - scrollPane.width();
			var proportion = remainder / scrollContent.width();
			var handleSize = 20;
			scrollbar.find( ".ui-slider-handle" ).css({
				width: handleSize,
				"margin-left": -handleSize / 2,
				"margin-top": -18
			});
			handleHelper.width( "" ).width( scrollbar.width() - handleSize );
		}
		
		//reset slider value based on scroll content position
		function resetValue() {
			var remainder = scrollPane.width() - scrollContent.width();
			var leftVal = scrollContent.css( "margin-left" ) === "auto" ? 0 :
				parseInt( scrollContent.css( "margin-left" ) );
			var percentage = Math.round( leftVal / remainder * 100 );
			scrollbar.slider( "value", percentage );
		}
		
		//if the slider is 100% and window gets larger, reveal content
		function reflowContent() {
				var showing = scrollContent.width() + parseInt( scrollContent.css( "margin-left" ), 10 );
				var gap = scrollPane.width() - showing;
				if ( gap > 0 ) {
					scrollContent.css( "margin-left", parseInt( scrollContent.css( "margin-left" ), 10 ) + gap );
				}
		}
		
		//change handle position on window resize
		jQuery( window ).resize(function() {
			resetValue();
			sizeScrollbar();
			reflowContent();
		});
		//init scrollbar size
		setTimeout( sizeScrollbar, 10 );//safari wants a timeout
		
		function scrollIconRight() {
			scrollpos = 'right';
			var aktpos_string = scrollContent.css( "margin-left");
			aktpos = aktpos_string.replace('px','');
			var max_pos = (scrollPane.width() - scrollContent.width());
			var procent = ((aktpos*-1) * 100)/(max_pos*-1);
			if ( max_pos < aktpos ) {
				scrollContent.css( "margin-left",  (aktpos-1) + "px" );
				jQuery('.ui-slider-handle').css('left',procent+'%');
				scrollIcon = setTimeout(scrollIconRight, 50);
			} else {
				scrollIcon = setTimeout(scrollIconLeft, 50);
			}
	   
	   
		}
		
		function scrollIconLeft() {
			scrollpos = 'left';
			var aktpos_string = scrollContent.css( "margin-left");
			var aktpos = aktpos_string.replace('px','');
			var max_pos = (scrollPane.width() - scrollContent.width());
			var procent = ((parseInt(aktpos)*-1) * 100)/(max_pos*-1);
			if ( parseInt(aktpos) < 0) {
				scrollContent.css( "margin-left",  (parseInt(aktpos) + 1) + "px" );
				jQuery('.ui-slider-handle').css('left',procent+'%');
				scrollIcon = setTimeout(scrollIconLeft, 50);
			} else {
				scrollIcon = setTimeout(scrollIconRight, 50);
			}
	   
	   
		}
		var scrollpos = 'right';
		var scrollIcon = setTimeout(scrollIconRight, 1000);
		jQuery( ".scroll-content > div" ).mouseover(function(){ clearTimeout(scrollIcon); });
		jQuery( ".scroll-content > div" ).mouseout(function(){ if (scrollpos == 'left'){ scrollIcon = setTimeout(scrollIconLeft, 50); }else{ scrollIcon = setTimeout(scrollIconRight, 50); } });
	});

function showStartSearch(search_type){
	if (search_type=='branchen'){
		jQuery("#Navbranchen").attr('class','aktiv');
		jQuery("#Navwissen").attr('class','inaktiv');
		jQuery("#Navprofi").attr('class','inaktiv');
		jQuery("#headerSearchWissen").hide();
		jQuery("#headerSearchProfi").hide();
		jQuery("#headerSearchBranchen").show();
		jQuery('#iconnavigation').show();
		jQuery("#wissenLatest").show();
		jQuery("#WissenStartList").hide();
		jQuery("#ProfiStartList").hide();
		jQuery("#BranchenStartList").show();
		jQuery('#profiLatest').hide();
		
	}else if (search_type=='wissen'){
		jQuery("#Navwissen").attr('class','aktiv');
		jQuery("#Navbranchen").attr('class','inaktiv');
		jQuery("#Navprofi").attr('class','inaktiv');
		jQuery("#headerSearchBranchen").hide();
		jQuery("#headerSearchProfi").hide();
		jQuery("#headerSearchWissen").show();
		jQuery('#iconnavigation').hide();
		jQuery("#wissenLatest").hide();
		jQuery("#BranchenStartList").hide();
		jQuery("#ProfiStartList").hide();
		jQuery("#WissenStartList").show();
		jQuery('#profiLatest').show();
		
	}else if (search_type=='profi'){
		jQuery("#Navprofi").attr('class','aktiv');
		jQuery("#Navwissen").attr('class','inaktiv');
		jQuery("#Navbranchen").attr('class','inaktiv');
		jQuery("#headerSearchBranchen").hide();
		jQuery("#headerSearchWissen").hide();
		jQuery("#headerSearchProfi").show();
		jQuery('#iconnavigation').hide();
		jQuery("#WissenStartList").hide();
		jQuery("#BranchenStartList").hide();
		jQuery("#ProfiStartList").show();
		jQuery('#profiLatest').show();
		jQuery("#wissenLatest").show();
	}
}

function setSearch(search_type){
	jQuery('#showB').val(search_type);
	jQuery('#topnavsearch').submit();
}


function showSearch(search_type){
	if (search_type=='branchen'){
		jQuery("#Navbranchen").attr('class','aktiv');
		jQuery("#Navwissen").attr('class','');
		jQuery("#Navprofi").attr('class','');
		jQuery("#headerSearchWissen").hide();
		jQuery("#headerSearchBranchen").show();
		jQuery('#iconnavigation').show();
		
	}else if (search_type=='wissen'){
		jQuery("#Navwissen").attr('class','aktiv');
		jQuery("#Navbranchen").attr('class','');
		jQuery("#Navprofi").attr('class','');
		jQuery("#headerSearchBranchen").hide();
		jQuery("#headerSearchWissen").show();
		jQuery('#iconnavigation').hide();
		
	}else if (search_type=='profi'){
		jQuery("#Navprofi").attr('class','aktiv');
		jQuery("#Navwissen").attr('class','');
		jQuery("#Navbranchen").attr('class','');
	}
}

function sendContactForm(kontaktAnfragePid,uid){
	$.post('/index.php?id='+kontaktAnfragePid+'&tx_hdbranchen_pi2[uid]='+uid,{'send[]': $(":input").serialize()},
		function(data){
			//alert('pos_1: '+data.indexOf('kontakt-wrapper')+26);
			//alert('pos_2: '+data.indexOf('</form>')+21);
			var insert_data = data.substring(data.indexOf('<div id="kontakt-wrapper">')+26,data.indexOf('</form>')+7);
			//alert(insert_data+'</div></div>');
			$('#kontakt-wrapper').html(insert_data+'</div></div>');
		});
}

jQuery(document).ready(function() {
	jQuery("#contact_name").focus(function () { if (this.value == 'Name eingeben') { this.value = ''; } });
	jQuery("#contact_mail").focus(function () { if (this.value == 'Emailadresse eingeben') { this.value = ''; } });
	jQuery("#contact_phone").focus(function () { if (this.value == 'Telefonnummer eingeben') { this.value = ''; } });
});
	
	
