var blank = new Image();
blank.src = 'images/blank.gif';

$(document).ready(function(){


 
   // PNG Fix IE6
 
   var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
   if (badBrowser) {
     // get all pngs on page
     $('img[src$=.png]').each(function() {
       if (!this.complete) {
         this.onload = function() { fixPng(this) };
       } else {
         fixPng(this);
       }
     });
   }


    //Kontaktseite

    $('.down_button').css('background-image', 'url(images/down.jpg)').css('background-repeat','no-repeat').css('background-position','right top');
  
    var kflag = 0 ;
    $('div#kontaktbutton').click(function(){
    
        if(kflag==0){
            $('#formular').slideDown("slow");
            $('.down_button').css('background-image', 'url(images/up.jpg)').css('background-repeat','no-repeat').css('background-position','right top');
            kflag=1;
        }else{
            $('#formular').slideUp("slow");
            $('.down_button').css('background-image', 'url(images/down.jpg)').css('background-repeat','no-repeat').css('background-position','right top');
            kflag=0;        
        };
    
    });
    
     
    $(".kontaktformular").bind("submit", function() {
                var flag = 0;
                if ($("#vorname").val().length < 1 ) {
                    $("#error_vorname").show();
                    $.fancybox.resize();
                }else{$("#error_vorname").hide();
                    $.fancybox.resize();
                    flag = flag + 1;}

                if ($("#nachname").val().length < 1 ) {
                    $("#error_nachname").show();
                    $.fancybox.resize();
                }else{$("#error_nachname").hide();
                    $.fancybox.resize();
                    flag = flag + 1;}

                if ($("#strasse").val().length < 1 ) {
                    $("#error_strasse").show();
                    $.fancybox.resize();
                }else{$("#error_strasse").hide();
                    $.fancybox.resize();
                    flag = flag + 1;}

                if ($("#plz").val().length < 1 ) {
                    $("#error_plz").show();
                    $.fancybox.resize();
                }else{$("#error_plz").hide();
                    $.fancybox.resize();
                    flag = flag + 1;}

                if ($("#ort").val().length < 1 ) {
                    $("#error_ort").show();
                    $.fancybox.resize();
                }else{$("#error_ort").hide();
                    $.fancybox.resize();
                    flag = flag + 1;}
                    
                if ($("#email").val().length < 1 ) {
                    $("#error_email").show();
                    $.fancybox.resize();
                }else{$("#error_email").hide();
                    $.fancybox.resize();
                    flag = flag + 1;}
                    
                if ($("#anliegen").val().length < 1 ) {
                    $("#error_anliegen").show();
                    $.fancybox.resize();
                }else{$("#error_anliegen").hide();
                    $.fancybox.resize();
                    flag = flag + 1;}
                    
            if(flag != 7)
            {return false;}
            else
            {
            alert("Ihre Nachricht wurde an uns übermittelt !")
            return true;}
  
        });
    
    // Leistungen
   
    
    var flag = 0 ;
    $('.leistungen').hide();
    $('.leistungen').after('<div class="mehr_leistungen">Erfahren Sie mehr ...</div>');
    
   
    $('.mehr_leistungen').click(function() {
        if(flag==0){
        
                $(this).prev('.leistungen').prev('ul').slideUp();
                $(this).prev('.leistungen').slideDown();
                $(this).text('... Zurück zur Übersicht');
                flag=1;
        }else{
            $(this).prev('.leistungen').slideUp();
            if($.browser.msie && ($.browser.version < 8) ){
                $(this).prev('.leistungen').prev('ul').show();
                }else{$(this).prev('.leistungen').prev('ul').slideDown();};
            
            
            $(this).text('Erfahren Sie mehr ...');
                 flag=0;
        };
        
    });

    // Auflistungen
    
    $('dd:not(:first)').hide();
    $("dt a").click(function(){
            $("dd:visible").slideUp("slow");
            $(this).parent().next().slideDown("slow");
            return false;
        });

    
   // Sliden
    $('div.s_angebot:not(:first)').hide();
    $('div.s_angebot[name$="fruehling"]').show();
    $('.angebotlink:first').css('color','#3e9ea5').css('font-weight','bold');
    
    $('.angebotlink').click(function(){
        var season = $(this).attr('name');
        
        if($.browser.msie && ($.browser.version < 8) ){
        $('div.s_angebot[name$="'+season+'"]').show();
        $('div.s_angebot:not([name$="'+season+'"])').hide();
        }else{
          $('div.s_angebot[name$="'+season+'"]').slideDown();
        $('div.s_angebot:not([name$="'+season+'"])').slideUp();
        };
        
        $(this).css('color','#3e9ea5').css('font-weight','bold').css('font-size','14px');
        $('.angebotlink:not(.angebotlink[name$="'+season+'"])').css('color','grey').css('font-weight','normal').css('font-size','12px');

        return false;
    });
    
    // Fancybox
    
       $("a.imagebox").fancybox({
                'titleShow'     : false,
                'transitionIn'  : 'elastic',
                'transitionOut' : 'elastic',
                'showCloseButton': true
            });
            
       $("a.rundgang").fancybox({
                'width' : 400,
                'height' : 400,
                'titlePosition'     : 'inside',
                'transitionIn'  : 'elastic',
                'transitionOut' : 'elastic'

            });
            
       $(".links a").fancybox({
                'autoScale'         : true,
                'type'              : 'iframe',
                'width'         :   800,
                'height'         :   600,
                'showCloseButton': true
                
            });
            
            
     // Teamseite   
     
       $('div.mitarbeiter').find('#text').hide();
       $('div.mitarbeiter').find('.work_picture').hide();



      $('div.mitarbeiter').hoverIntent(makeTall,makeShort)

              
       
        function makeTall(){                
                $(this).find('.mehr_text').slideToggle('slow');
                $(this).find('#text').slideToggle('slow');
                $(this).find('.work_picture').toggle('slow');

                if (badBrowser){
                    $(this).resize();
                }}
        function makeShort(){                
                $(this).find('.mehr_text').slideToggle('slow');
                $(this).find('#text').slideToggle('slow');
                $(this).find('.work_picture').toggle('slow');

                if (badBrowser){
                    $(this).resize();
                }}




       
       $("a.picture_link").fancybox({
                'titleShow'     : false,
                'transitionIn'  : 'elastic',
                'transitionOut' : 'elastic',
                'showCloseButton': true
            });
            
      // Header Slide Out Kids
      $('.kids').hide();
      
        $(".handle").click().toggle(function() {
            $('.kids').animate({
                width: 'show'
            }, 'slow');
            $(this).css('background','url(images/tab.png) no-repeat scroll 0 40% transparent');

        }, function() {
            $('.kids').animate({
                width: 'hide'
            }, 'slow');
            $(this).css('background','url(images/tab.gif) no-repeat scroll 0 40% transparent');
        });
        

        
      
      

});

 function fixPng(png) {
   // get src
   var src = png.src;
   // set width and height
   if (!png.style.width) { png.style.width = $(png).width(); }
   if (!png.style.height) { png.style.height = $(png).height(); }
   // replace by blank image
   png.onload = function() { };
   png.src = blank.src;
   // set filter (display original image)
   png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "')";
 };


