$(document).ready(function() {
    jQuery.extend( jQuery.easing,
    {
        def: 'easeInSine',
        swing: function (x, t, b, c, d) {
            //alert(jQuery.easing.default);
            return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
        },
        easeInSine: function (x, t, b, c, d) {
            return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
        },
        easeOutSine: function (x, t, b, c, d) {
            return c * Math.sin(t/d * (Math.PI/2)) + b;
        },
        easeInOutSine: function (x, t, b, c, d) {
            return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
        },
        easeInOutCirc: function (x, t, b, c, d) {
            if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
            return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
        },
        easeInExpo: function (x, t, b, c, d) {
            return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
        },
        easeOutExpo: function (x, t, b, c, d) {
            return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
        },
        easeInOutExpo: function (x, t, b, c, d) {
            if (t==0) return b;
            if (t==d) return b+c;
            if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
            return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
        }
    });
    
    function repaintAwardsHeight() {
        var award_height = $('.awards-year:visible').height();
        $('#awards .panes').height(award_height);
    }
    repaintAwardsHeight();

    $.tools.tabs.addEffect("fastfade", function(i, done) {
        var current = this.getCurrentPane().css('z-index', 1);
        this.getPanes().eq(i).css('z-index', 2).fadeIn(this.getConf().fadeInSpeed, function(){
          current.fadeOut(0, done)
        })
    });

    $('.messages').live('click', function(){$(this).fadeOut()});

    $.tools.tabs.addEffect("teasers", function(i, done) {
        var conf = this.getConf(), 
             panes = this.getPanes(),
             color = panes.eq(i).find('.bgcolor');

        this.getCurrentPane().fadeOut(conf.fadeOutSpeed, function(){
            panes.eq(i).fadeIn(conf.fadeInSpeed, done)
        })
            $('.teaser-pager,ul.pager,.panes').animate({backgroundColor: color.css('background-color')}, conf.fadeOutSpeed+conf.fadeInSpeed)
    });

    $.tools.tabs.addEffect("lightbox", function(i, done) {
        var conf = this.getConf(), 
             panes = this.getPanes(),
             pane = panes.eq(i);
        this.getCurrentPane()
            .parent().css('height', this.getCurrentPane().height())
            .end()
            .fadeOut(conf.fadeOutSpeed, function(){pane.fadeIn(conf.fadeInSpeed, done )} );
        panes.parent().animate({height:panes.eq(i).height()}, conf.fadeInSpeed+conf.fadeOutSpeed, 'easeOutExpo')
    }); 


    $('.container').hover(
        function(){
            $(this).stop(true, false).animate({
                backgroundColor: "#FCFCFC"
            }, 600);
        },
        function(){
            $(this).stop(true, false).animate({
                backgroundColor: "#F7F7F7"
            }, 600);
        }
    );

    $('.first_container').hover(
        function(){
            $(this).stop(true, false).animate({
                backgroundColor: "#FCFCFC"
            }, 600);
            $(this).addClass('gradient_effect', 600);
        },
        function(){
            $(this).stop(true, false).animate({
                backgroundColor: "#F7F7F7"
            }, 600);
            $(this).removeClass('gradient_effect', 600);
        }
    );


    $('#homepage-teasers')
        .tabs('div.panes > div', {fadeInSpeed: 300, fadeOutSpeed:200, effect: 'teasers', rotate:true, initialIndex:0})
        .slideshow({clickable:false, autoplay:true, interval: 6000});

    $('#gallery .pager, .project-images .pager, .office-pics .pager')
        .tabs('div.panes > div', {fadeInSpeed: 300, effect: 'fastfade', rotate:true, initialIndex:0})
        .slideshow({clickable:false, autoplay:true, interval: 6000});

    $('.next-image, .prev-image')
         .css('opacity',0)
         .hover(function(){$(this).stop().animate({opacity:1});}, function(){$(this).stop().animate({opacity:0});} );
         
   /*$('.panes, .next-image, .prev-image')
            //.css('opacity',0)
            .hover(function(){$('.next-image, .prev-image').stop().animate({opacity:1});}, function(){$('.next-image, .prev-image').stop().animate({opacity:0});} );*/

    $('ul.tabs').tabs('div#awards .panes > div', {effect: 'lightbox', fadeOutSpeed:200, fadeInSpeed: 400});
    // $('ul.tabs li a').click(function(){
    //     repaintAwardsHeight();
    // });

    $(window).resize(function(){
        var margin = $(window).width()>960 ? - ($(window).width()-960)/2 : 0;
        $('#teasers.panes, #teasers').css({
            // left: margin,
            width: Math.max($(window).width(),960)
        });
        $("#teasers.panes").css({
            marginRight: margin
        });
    }).resize();

    $(".subtitle").each(function(i, e){
        $(e).css( 'opacity', '0' );
        $(e).css( 'padding-top', ((185-$(e).find('span.the_text').height())/2)+'px' );
            //top: 185-($(e).height()/2)+'px'
        //});
    });
    
    $("div.project-thumb").hover(
        function(){
            $(this).find(".subtitle").stop(true, false).animate({
                //bottom: 0,
                opacity: '1'
            }, 200);
        },
        function(){
            $(this).find(".subtitle").stop(true, false).animate({
                //bottom: '-'+$(this).height(),
                opacity: '0'
            }, 200);
        }
    );
    
    $("div.project-title").hover(
        function(){
            $(this).parent().children("div.project-thumb").find(".subtitle").stop(true, false).animate({
                //bottom: 0,
                opacity: '1'
            }, 200);
        },
        function(){
            $(this).parent().children("div.project-thumb").find(".subtitle").stop(true, false).animate({
                //bottom: '-'+$(this).height(),
                opacity: '0'
            }, 200);
        }
    );
        
    $('.scrollable-gallery ul').jcarousel({scroll:1,wrap: "circular",easing: "easeInOutCirc",animation:500});
           
   if(navigator.appName == "Netscape")
   {
   
       //Similar project collumn
       $('.similar li').mouseover(function(){
          $(this).addClass('current');
          //$('.triple_column li').not('.current').css('opacity', '0.5');
          $('.similar li').not('.current').stop().animate({opacity: 0.5}, 200);
       });

       $('.similar li').mouseout(function(){
          $(this).removeClass('current');
          //$('.triple_column li').not('.current').css('opacity', '1');
          $('.similar li').not('.current').stop().animate({opacity: 1}, 200);
       });
   
       //Home triple collumn
       $('.triple_column li').mouseover(function(){
          $(this).addClass('current');
          //$('.triple_column li').not('.current').css('opacity', '0.5');
          $('.triple_column li').not('.current').stop().animate({opacity: 0.5}, 200);
       })

       $('.triple_column li').mouseout(function(){
          $(this).removeClass('current');
          //$('.triple_column li').not('.current').css('opacity', '1');
          $('.triple_column li').not('.current').stop().animate({opacity: 1}, 200);
       })

       //Home six collumn
       $('.six_column li').mouseover(function(){
          $(this).addClass('current');
          $('.six_column li').not('.current').stop().animate({opacity: 0.5}, 200);
       })

       $('.six_column li').mouseout(function(){
          $(this).removeClass('current');
          $('.six_column li').not('.current').stop().animate({opacity: 1}, 200);
       })

       //Home RSS
       $('ul.news li').mouseover(function(){
          $(this).addClass('current');
          $('ul.news li').not('.current').stop().animate({opacity: 0.5}, 200);
       })

       $('ul.news li').mouseout(function(){
          $(this).removeClass('current');
          $('ul.news li').not('.current').stop().animate({opacity: 1}, 200);
       })

       //Footer links style
       $('ul.services li').mouseover(function(){
          $(this).addClass('current');
          $('ul.services li').not('.current').stop().animate({opacity: 0.5}, 200);
       })

       $('ul.services li').mouseout(function(){
          $(this).removeClass('current');
          $('ul.services li').not('.current').stop().animate({opacity: 1}, 200);
       })

       //RSS Footer style
       $('ul.rss-footer li').mouseover(function(){
          $(this).addClass('current');
          $('ul.rss-footer li').not('.current').stop().animate({opacity: 0.5}, 200);
       })

       $('ul.rss-footer li').mouseout(function(){
          $(this).removeClass('current');
          $('ul.rss-footer li').not('.current').stop().animate({opacity: 1}, 200);
       })
    
   }
    
    //Styling the inquiry
    $('.inquiry-button').click(function(){
       var width = document.width;
       var height = document.height + 20;
       
       $('.mask').css('width', width);
       $('.mask').css('height', height);
       $('.mask').css('display', 'block');
       $('.mask').stop().animate({opacity: 0.7}, 200);
       
       $('.container.inquiry .contact-form').css('display', 'block');
    })
    
    $('.container.inquiry .contact-form-wrapper .contact-form .close-button').click(function(){
       $('.mask').stop().animate({opacity: 0}, 200);
       $('.mask').css('display', 'none');
       $('.container.inquiry .contact-form').css('display', 'none');
    })
    
    
    //Resizing the map
    var width = $(document).width();
    $('#map').css('width', width);
    
    
    //Project top gallery
    var count = $('.project-images ul.pager li').length;
    count = count*19;
    $('.project-images ul.pager').css('width', count);
});

