jQuery(document).ready(function($){

	/*
	* ### SLIDER FOR STARTPAGE
	*/
	if ($('#slider').length > 0) {
		$('#slider').s3Slider({
      	timeOut: 7000
   	});
	}
	
	if ($(".news-single-imgcaption").is(":empty") )
    {
		$(".news-single-imgcaption").hide();
	}
	
	
	if ($("#mailformTelefon").length > 0) {
		var $telInput = $("#mailformTelefon");
		var telValue = $telInput.val();
		
		$telInput.focus(function() {
			if ($telInput.val() === telValue) {
				$telInput.val("");
			}
		});
		
		$telInput.blur(function() {
			if ($telInput.val() === "") {
				$telInput.val(telValue);
			};
		});
		
	}
	
	
	/*
	*	###	ACCORDION
	*/
	
	if ($('#content .accordion').length > 0) {
		$('#content .accordion').accordion({
									header: '.accordionHeader',
									collapsible: true,
									autoHeight:false
								});
	}
	
	
	/*
	* ### FUNCTION FOR THE REFERENCES SLIDER
	*/

	// Ein paar Variablen definieren
	var	div = $('#container .sc_menu'),
		ul  = $('#container ul.sliderMenu'),
		ulPadding 	= 15;
	
	// Get menu width
	var divWidth = div.width();
	
	//Remomve scrollbar
	div.css({'overflow': 'hidden'}).find('span').hide();
	
	$('#container ul.sliderMenu a').each(function() {
		var $this = $(this);
		$this.mouseenter(function() {
			$this.find('span').stop().fadeIn();
		})
		.mouseleave(function(e) {
			$this.find('span').stop().fadeOut();
		})
		.click(function() {return false;});
	});

	
	//Find last image container
	var lastLi = ul.find('li:last-child');
	 
	//When user move mouse over menu
	div.mousemove(function(e){
		// As images are loaded ul width increases,
		// so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
		
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
	
	
});
