$(document).ready(function()
{
	/** Autocomplete **/
	$("#psString").autocomplete({ source: "/_system/include/psAutocomplete.php", minLength: 1 });
	
	if ( $("#bsString").length > 0  )
	{
		$("#bsString").autocomplete(
		{
			minLength: 1,
			source: "/_system/include/bsAutocomplete.php",
			focus: function(event, ui)
			{
				$('#bsString').val(ui.item.text);
				return false;
			},
			select: function(event, ui)
			{
				$('#bsString').parents('form').attr("action",ui.item.link);
				$('#bsString').val(ui.item.text);
				return false;
			}

		})
		.data( "autocomplete" )._renderItem = function( ul, item )
		{
			return $( "<li></li>" ).data( "item.autocomplete", item ).append( "<a>" + item.text + "</a>" ).appendTo( ul );
		};
	}


	/** Newsslider **/
	$('#newsSlider').bxSlider({
		alignment: 'vertical',													// 'horizontal', 'vertical' - direction in which slides will move
		controls: false,														// determines if default 'next'/'prev' controls are displayed
		speed: 1500,															// amount of time slide transition lasts (in milliseconds)
		pager: false,															// determines if a numeric pager is displayed (1 2 3 4...)
		pager_short: false,														// determines if a 'short' numeric pager is displayed (1/4)
		margin: 0,																// if 'horizontal', applies a right margin to each slide, if 'vertical' a bottom margin is applied. example: margin: 50
		auto: true,																// determines if slides will move automatically
		pause: 5000,															// time between each slide transition (auto mode only)
		auto_direction: 'next',													// order in which slides will transition (auto mode only)
		auto_hover: true,														// determines if slideshow will pause while mouse is hovering over slideshow
		auto_controls: false,													// determines if 'start'/'stop' controls are displayed (auto mode only)
		ticker: false,															// determines if slideshow will behave as a constant ticker
		ticker_controls: false						// determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
	});

	/** Scrollpane **/		
	$('.scrollpane').jScrollPane({showArrows: false, scrollbarWidth: 13, reinitialiseOnImageLoad: true});
	reinitialiseScrollPane = function() { $('.scrollpane').jScrollPane({showArrows: false, scrollbarWidth: 13, reinitialiseOnImageLoad: true}); }


	/** Shopping **/			
	$('.shoppingHover').hover(
		function()
		{
			$('.shopping_home').addClass('home_hover');
			$('.layer_shopping').show();
		},
		function()
		{
			$('.shopping_home').removeClass('home_hover');
			$('.layer_shopping').hide();
		}
	);
	
	/** Multiplex Kino **/
	$('.multiplexKinoHover').hover(
		function()
		{
			$('.multiplexKino_home').addClass('home_hover');
			$('.layer_multiplexKino').show();
		},
		function()
		{
			$('.multiplexKino_home').removeClass('home_hover');
			$('.layer_multiplexKino').hide();
		}
	);
	
	/** Gastro & Hotel **/
	$('.gastroHotelHover').hover(
		function()
		{
			$('.gastroHotel_home').addClass('home_hover');
			$('.layer_gastroHotel').show();
		},
		function()
		{
			$('.gastroHotel_home').removeClass('home_hover');
			$('.layer_gastroHotel').hide();
		}
	);
	
	/** Wellness & Gesundheit **/
	$('.wellnessGesundheitHover').hover(
		function()
		{
			$('.wellnessGesundheit_home').addClass('home_hover');
			$('.layer_wellnessGesundheit').show();
		},
		function()
		{
			$('.wellnessGesundheit_home').removeClass('home_hover');
			$('.layer_wellnessGesundheit').hide();
		}
	);
	
	/** Papiersaal **/
	$('.papiersaalHover').hover(
		function()
		{
			$('.papiersaal_home').addClass('home_hover');
			$('.layer_papiersaal').show();
		},
		function()
		{
			$('.papiersaal_home').removeClass('home_hover');
			$('.layer_papiersaal').hide();
		}
	);
	
	/** Events **/
	$('.eventsHover').hover(
		function()
		{
			$('.events_home').addClass('home_hover');
			$('.layer_events').show();
		},
		function()
		{
			$('.events_home').removeClass('home_hover');
			$('.layer_events').hide();
		}
	);
	
	/** Services **/
	$('.servicesHover').hover(
		function()
		{
			$('.services_home').addClass('home_hover');
			$('.layer_services').show();
		},
		function()
		{
			$('.services_home').removeClass('home_hover');
			$('.layer_services').hide();
		}
	);	
});

function limitChars(textid, limit, infodiv)
{
	var text = $('#'+textid).val(); 
	var textlength = text.length;

	if(textlength > limit)
	{
		//$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else
	{
		$('#' + infodiv).html('('+(limit - textlength)+')');	
		return true;
	}
}
