$(document).ready(function(){
    
    $('p.email a').html(function(index, oldHtml){
        return oldHtml.replace(/<.+>/,'@');
    });
    $('p.email a').attr('href', function(index, attr){
        return 'mailto:' + $(this).html();
    });
    
    $('dd.mobile').html(function(index,oldHtml){
        return oldHtml.replace(/DE/,'+49').replace(/EINS/g,'1');
    })
    
    $("body.lang-de div#header input.search-input").click(function(){
		if ($("div#header input.search-input").val() == 'Suche') {
			$("div#header input.search-input").val('').css('color', '#003d5b');
		}
	});
	$("body.lang-de div#header input.search-input").blur(function(){
		if ($("div#header input.search-input").val() == '') {
			$("div#header input.search-input").val('Suche').css('color', '#bbb');
		}
	});
	
	$("body.lang-en div#header input.search-input").click(function(){
		if ($("div#header input.search-input").val() == 'search') {
			$("div#header input.search-input").val('').css('color', '#003d5b');
		}
	});
	$("body.lang-en div#header input.search-input").blur(function(){
		if ($("div#header input.search-input").val() == '') {
			$("div#header input.search-input").val('search').css('color', '#bbb');
		}
	});
	
	
	$('#text-units div.text-unit p.image a, #text-starter-gallery').cycle({ 
		fx : 		'scrollLeft', 
		speed : 	1400, 
		timeout : 	6000,
		delay : 	1000
	});
	
	
	if ($('#text-news div.news-list').length) {
	    var news = $('#text-news div.news-list').moodular({
    		auto: false,
    		item: 'div',
    		speed: 700,
    		api: true
    	});

    	$('#news-list-btn-next').click(function(){
    		news.next(); return false;
    	});

    	$('#news-list-btn-prev').click(function(){
    		news.prev(); return false;
    	});
	}
	
	
	$('#text-starter-gallery a[rel=lightbox]').lightBox({
		imageLoading: 	 staticInclude + '/images/ladeanimation.gif',
		imageBtnPrev: 	 staticInclude + '/images/lightbox-btn-prev.gif',
		imageBtnNext: 	 staticInclude + '/images/lightbox-btn-next.gif',
		imageBtnClose: 	 staticInclude + '/images/lightbox-btn-close.gif',
		imageBlank: 	 staticInclude + '/images/lightbox-blank.gif',
		fixedNavigation: true,
		overlayOpacity:  0.4,
		txtImage: 		 'Bild',
		txtOf : 		 'von'
	});
	
	
	$('#sidenotes-contact-tabs li').click(function(){
		var elementSelector = '#' + $(this).attr('id').replace(/tabs/,'content');
		
		$('#sidenotes-contact-tabs li').removeClass('active');
		$('#sidenotes-contact div').hide();
		$(this).addClass('active');
		$(elementSelector).show();
	});
	
	$('#phone-submit-link').click(function(){
	    $('#phone-form').submit();
	});
	
	$('#persons-submit-link').click(function(){
	    $('#persons-form').submit();
	});
	
	$('#callback-submit-link').click(function(){
	    $('#callback-form').submit();
	});
	
	$('.sidenotes-contact-content select.country').change(function(){
	    var id = $(this).parent().parent().parent().attr('id');
	    var val = $(this).val();
	    $('.sidenotes-contact-content select.country').val(val);
	    if ( val != 1)
	        $('.sidenotes-contact-content-zipcode').hide();
	    else if (id == 'sidenotes-contact-content-phone' || $('#department').val() != 4)
	        $('.sidenotes-contact-content-zipcode').show();
	});
	
	$('.sidenotes-contact-content select.department').change(function(){
	    var value = $(this).val();
	    $('.sidenotes-contact-content select.department').val(value);
	    $('#persons-form').attr('action', contactFormActions[value]);
	    if (value == 4)
	        $('.sidenotes-contact-content-zipcode').hide();
	    else if ($('#country').val() == 1)
	        $('.sidenotes-contact-content-zipcode').show();
	});
	
});

