$(document).ready(function() {
    
    /* Platzhaltertext für Suchfeld
     ----------------------------------------------------------------------------- */
    
    // Aktive Sprache ermitteln
    var currentLang = $('#sprachauswahl').find('.active a').text();
    
    // Text für die verschiedenen Sprach definieren
    switch (currentLang) {
        case "DE":  var platzhalterText = 'Suchebegriff eingeben...';
                    break;
        case "FR":  var platzhalterText = '[Für Französisch anpassen!]';
                    break;
        case "IT":  var platzhalterText = '[Für Italienisch anpassen!]';
                    break;
        case "EN":  var platzhalterText = '[Für Englisch anpassen!]';
                    break;
        default:    var platzhalterText = 'search...';
    }
    
    // Suchfeld finden und Platzhaltertext einfügen
    var suchfeld = $('#suchbegriff');
	suchfeld.val(platzhalterText);
	
	
	// Click in Suchfeld
	suchfeld.focus(function(){
	    //console.log('focus');
	    if ( $(this).val() == platzhalterText ) $(this).val('');
    });
	
	// Ausserhalb von Suchfeld klicken
	suchfeld.blur(function(){
	    //console.log('blur');
	    if( $(this).val() == '' ) $(this).val(platzhalterText);
    });
    
    
    /* Animationen in Startseite
     ----------------------------------------------------------------------------- */
    
    var speedDown = 500;
    var speedUp = 600;
     
    $('.einszwei-familien').click(function() {
        $('.active').stop().animate({
            'top': -380
        }, speedUp, function(){
            $(this).removeClass('active');			
        });
        
        $('.box1').stop().animate({
            'top': 0
        }, speedDown, function(){
            $(this).addClass('active');
        });
    });
    
    $('.mehrfamilien-uberbauungen').click(function() {
        $('.active').stop().animate({
            'top': -380
        }, speedUp, function(){
            $(this).removeClass('active');
        });
        
        $('.box2').stop().animate({
            'top': 0
        }, speedDown, function(){
            $(this).addClass('active');
        });
    });
    
    $('.gewerbe-industrie').click(function() {
        $('.active').stop().animate({
            'top': -380
        }, speedUp, function(){
            $(this).removeClass('active');
        });
        
        $('.box3').stop().animate({
            'top': 0
        }, speedDown, function(){
            $(this).addClass('active');
        });
    });
    
    $('.gastgewerbe-hotels').click(function() {
        $('.active').stop().animate({
            'top': -380
        }, speedUp, function(){
            $(this).removeClass('active');
        });
        
        $('.box4').stop().animate({
            'top': 0
        }, speedDown, function(){
            $(this).addClass('active');
        });
    });
	
	$('.close-me').each(function(i) {
        $(this).click(function(){
            $(this).parent().animate({
                'top': -380
            }, speedUp, function(){
                $(this).removeClass('active');
            });
        });
    });
    
    
    /* remove info-box on second click
     ----------------------------------------------------------------------------- */
    $('.einszwei-familien').click(function() {
        $('.active').stop().animate({
            'top': -380
        }, speedUp, function(){
            $(this).removeClass('active');			
        });        
    });
    
	$('.mehrfamilien-uberbauungen').click(function() {
        $('.active').stop().animate({
            'top': -380
        }, speedUp, function(){
            $(this).removeClass('active');			
        });        
    });
	
	$('.gewerbe-industrie').click(function() {
        $('.active').stop().animate({
            'top': -380
        }, speedUp, function(){
            $(this).removeClass('active');			
        });        
    });
	
	$('.gastgewerbe-hotels').click(function() {
        $('.active').stop().animate({
            'top': -380
        }, speedUp, function(){
            $(this).removeClass('active');			
        });        
    });
    
    /* Besuchen der Links .shortlink verhindern
       > Verhindert Neuladen der Seite in IE9 und Animationsfehler
     ----------------------------------------------------------------------------- */
    $('.shortlink').click(function(e){
        e.preventDefault();
    });
    
});
