﻿$(document).ready(function()
{
    function serviceList(element, height, opacity)
    {
        var parent = $(element).parent();
        parent.toggleClass('active');
        parent.children('.service-list-opener').stop().animate({height: height}, 500);
        
        var list = $('ul.service-list li').not('.active'); 
        list.stop().animate({opacity: opacity}, 500);
        list.children('.service-list-head').children('a').stop().animate({opacity: opacity}, 500);
    }
    
    $('ul.service-list li .service-list-head').mouseover(function()
    {
        serviceList($(this), '70px', 0.3);
    }
    ).mouseout(function()
    {
        serviceList(this, '3px', 1);
    });

    $('a.fancy-image').fancybox({
        overlayColor: '#000',
        centerOnScroll: true,
        titlePosition: 'inside',
        transitionIn: 'elastic',
        transitionOut: 'elastic'
    });
    
    $('a.popup-social').popupWindow(
    { 
        width           : 500,
        height          : 400, 
        centerBrowser   : 1 
    }); 
    
    // Teaser     
    $('.slider-view').Teaser({overview: ".slider-overview", timeout: 3000, speed: 1000});
  
  
    $("ul#navigation li").dropdown('.dropdown', 150);

    // Slideeffekt in Dropdown Menü
    $('.dropdown a.slide').hover(function(){
        $(this).stop(true).animate({paddingLeft: '35px'}, {speed: 200, easing: 'easeOutQuad'});
    }, function(){
        $(this).stop(true).animate({paddingLeft: '0'}, {speed: 200, easing: 'easeOutQuad'});
    });


    // Overlay für Kontaktbereich    
    $('a[rel=kontakt]').click(function(){
        if(!($('#overlay').length > 0))
        {
            $('body').append('<div id="overlay"></div>');
            
            $('body').append('<div id="overlay-contact"></div>');
            $('#overlay-contact').css('opacity', 0);
            $('#overlay-contact').load('ajax.php?interface=kontakt', function()
            {
                $('#overlay')
                .css('opacity', '0')
                .css('backgroundColor', '#000');
                
                $('#overlay').stop().animate({opacity: 0.9}, 1000);
                $('#line').stop().animate({top:0}, 1000, function()
                {
                    $('#overlay-contact').animate({opacity: 1}, 2000);
                    $('input').show();
                    $('textarea').show();
                    $('#contact-submit').show();
                    
                    $('img#close-overlay').show();
                
                    setInputWatermark();
                });

                $('img#logo').parent().removeAttr('href');
                $('img#blog').removeClass("active")
                
                $("#contact-submit").live('click', function()
                {
                    $.post("ajax.php?interface=kontakt", $('#form_contact').serialize(), function(data)
                    {
                        $('#overlay-contact').html(data);
                        
                        setInputWatermark();
                    }); 
                });
            });
        }
        
        return false;
    });
    
    function setInputWatermark()
    {
        $('#name').watermark();
        $('#email').watermark();
        $('#telephone').watermark();
        $('#subject').watermark();
        $('#message').watermark();
    }
    /*
    $('#logo-area').mouseover(function()
    {
        $('#blog.active').show(); 
    }
    ).mouseout(function()
    {
        $('#blog.active').hide(); 
    });
    
    $('#corner-twitter').mouseover(function()
    {
       $('img#twitter').stop().animate({width: "42px", height: "42px"}, 150);
    }
    ).mouseout(function()
    {
       $('img#twitter').stop().animate({width: "35px", height: "35px"}, 150);
    });
    */
    
    $('img#logo').parent().click(function()
    {
        if(($('#overlay').length > 0))
        {
            $('#overlay-contact').remove();
            
            $('#overlay').stop().animate({opacity: 0}, 2000);
            $('#line').animate({top:"-470px"}, 1000);
            setTimeout("$('#overlay').remove();", 1200);
            $('img#close-overlay').hide();
            $('img#blog').addClass("active")
        }
        else
        {
            $(this).attr('href', '');
        }
    });
    
    // Projektliste
    $('ul.project-list li').mouseover(function()
    {
        $(this).children('a').children('img').stop().animate({width: "120px", height: "115px", left: "-5px", top: "-4.5px"}, 300);    
    });
    $('ul.project-list li').mouseout(function()
    {
        $(this).children('a').children('img').stop().animate({width: "100px", height: "96px", left: "5px", top: "5px"}, 300);
    });
    
    // Fotogalerie
    $('ul.moments-list li').mouseover(function()
    {
        $(this).children('a').children('img').stop().animate({width: "116px", height: "116px", left: "-5px", top: "-5px"}, {duration: 600, easing: "easeOutExpo"});    
    });
    $('ul.moments-list li').mouseout(function()
    {
        $(this).children('a').children('img').stop().animate({width: "96px", height: "96px", left: "5px", top: "5px"}, 300);
    });
    
    $('ul.moments-details-list li').mouseover(function()
    {
        $(this).children('a').children('img').stop().animate({width: "150px", height: "150px", left: "-13px", top: "-13px"}, {duration: 600, easing: "easeOutExpo"});    
    });
    $('ul.moments-details-list li').mouseout(function()
    {
        $(this).children('a').children('img').stop().animate({width: "124px", height: "124px", left: "0", top: "0"}, 300);
    });
   
    $(window).keydown(function(event)
    {
        if(event.keyCode == '27')
        {
            if(($('#overlay').length > 0))
            {
                $('#overlay-contact').remove();
                
                $('#overlay').stop().animate({opacity: 0}, 1000);
                $('#line').animate({top:"-470px"}, 1000);
                setTimeout("$('#overlay').remove();", 1200);
            }
        }
    });
});
