$(document).ready(function() {

    $(".extendable > a").click(function(e) {
        e.preventDefault();
        $(this).siblings().slideToggle();
        $(this).toggleClass('extended');
    });


    $("a[rel^='lightbox'], a[href$='.jpg'], a[href$='.jpeg'], a[href$='.gif'], a[href$='.png']").slimbox({/* Put custom options here */}, null, function(el) {
            return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
    });

    fadeOpacity = 0.5;
    $("a.fade").css( "opacity", fadeOpacity);
    $("a.fade").hover(
        function() {
            $(this).fadeTo('fast', 1);
        },
        function() {
            $(this).fadeTo(450, fadeOpacity);
        }
    );

    teaserOpacity = 0.7;
    $(".teaser .offers a").css( "opacity", teaserOpacity);
    $(".teaser .offers a").hover(
        function() {
            $(this).addClass('transition').css('opacity', 1).fadeTo('fast', 0.1, function() {
                if( $(this).hasClass('transition') ) {
                    $(this).addClass('hover').fadeTo(500, 1).removeClass('transition');
                }
            });
        },
        function() {
            $(this).fadeTo(50, 0.1, function() {
                $(this).removeClass('transition hover').fadeTo('fast', teaserOpacity);
            });
        }
    );

    $(".wp-post-image").css( "opacity", "0.6" );
    imgFadeOpacity = 0.6;
    $("img.fade").css( "opacity", imgFadeOpacity);
    $("img.fade").hover(
        function() {
            $(this).fadeTo('fast', 1);
        },
        function() {
            $(this).fadeTo(450, imgFadeOpacity);
        }
    );
        
    $(".portfolio-post").hover(
        function() {
            $(this).find(".wp-post-image").animate( {
                "opacity": "1.0"
            }, {
                duration: 300,
                queue: false
            });
        },
        function() {
            $(this).find(".wp-post-image").animate( {
                "opacity": "0.6"
            }, {
                duration: 500,
                queue: false
            });
        }
    );
    $(".attachment-single-post-thumbnail").hover(
        function() {
            $(this).animate( {
                "opacity": "1.0"
            }, {
                duration: 300,
                queue: false
            });
        },
        function() {
            $(this).animate( {
                "opacity": "0.6"
            }, {
                duration: 500,
                queue: false
            });
        }
        );


    $(".hints-header a").click(function() {
        $('.hints-list').slideToggle(500);
        $('.hints-header').toggleClass('alt');
    });

    $("#s-navigation > li > a").hover(
        function() {
            $(this).parent().find("ul.sub-navigation").stop(true,true).hide().slideDown('fast').show();
            $(this).addClass('hover');

            $(this).parent().hover( function() {
            }, $.proxy(function(){
                $(this).parent().find("ul.sub-navigation").fadeOut();
                $(this).removeClass('hover');
            }, this));
        },
        function() {
        }
    );



    // jQuery SmoothScroll
    $('a[href*=#]').click(function() {

        // duration in ms
        var duration=1000;

        // easing values: swing | linear
        var easing='swing';

        // get / set parameters
        var newHash=this.hash;
        var target=$(this.hash+', a[name='+this.hash.slice(1)+']').offset().top;
        var oldLocation=window.location.href.replace(window.location.hash, '');
        var newLocation=this;

        // make sure it's the same location
        if(oldLocation+newHash==newLocation)
        {
            // set selector
            if($.browser.safari) var animationSelector='body:not(:animated)';
            else var animationSelector='html:not(:animated)';

            // animate to target and set the hash to the window.location after the animation
            $(animationSelector).animate({
                scrollTop: target
            }, duration, easing, function() {

                // add new hash to the browser location
                window.location.href=newLocation;
            });

            // cancel default click action
            return false;
        }
    });

});
