var base = {
    layout : {
        init : function() {
            window.$layout = {
                top       : $('#top'),
                fg        : $('#fade_gallery'),
                chained   : $('#chained'),
                montage   : $('#montage'),
                slideshow : $('.slideshow'),
                scnav     : $('.scrollable-nav')
            };

            $.ajax({
                type: 'GET',
                url: '/assets/js/plugins/jquery.pngFix.pack.js',
                dataType: 'script',
                async: false,
                cache: true,
                success: function() {
                    $(document).pngFix();
                }
            });

            $.ajax({
                type: 'GET',
                url: '/assets/js/plugins/jquery.cufon.js',
                dataType: 'script',
                async: false,
                cache: true,
                success: function() {}
            });

            $.ajax({
                type: 'GET',
                url: '/assets/js/plugins/jquery.tools.min.js',
                dataType: 'script',
                async: false,
                cache: true,
                success: function() {}
            });

            if( $layout.fg.length > 0 ) {
                $layout.slideshow.tabs(".slideshow > div", {
                    effect: 'fade',
                    fadeOutSpeed: 1000,
                    fadeInSpeed: 1000,
                    autoplay: true,
                    interval: 5000,
                    clickable: false,
                    rotate: true
                }).slideshow();
                $.timer(5, 'slideshow', null);
            }

            $('#team_image_map').find('area').each(function(e) {
                var id = $(this).attr('rel');
                $(this).hover(function(i) {
                    $(id).addClass('hover');
                },function(j) {
                    $(id).removeClass('hover');
                });
            });

            $layout.chained.scrollable({
                easing: 'custom',
                speed: 500,
                circular: true,
                mousewheel: true
            }).navigator({
                navi: 'div.scrollable-nav'
            });
            $(window).load(function(){
              $layout.chained.data("scrollable").begin(50); // FF3.6 fix
            });

            if( $layout.scnav.length > 0 ) {
                $layout.scnav.find('a').each(function(i) {
                    $(this).html((i+1));
                    if(i>0) $(this).prepend('<span>/</span>');
                });
            }
        }
    },
    forms : {
        init : function() {
            window.$forms = {
                cf_c : $('#contact_form_container')
            };

            $.ajax({
                type: 'GET',
                url: '/assets/js/plugins/jquery.labels.js',
                dataType: 'script',
                async: false,
                cache: true,
                success: function() {
                    $forms.cf_c.labels({ cls:'dim'});
                }
            });
        }
    }
};

$.timer = function(secs, type, var1) {
    if(secs > 0) {
        setTimeout((function() {
            secs--;
            $.timer(secs, type, var1);
        }), 1000);
    } else {
        if(type == 'slideshow') {
            $layout.slideshow.data("slideshow").play();
        }
    }
};

$.easing.custom = function (x, t, b, c, d) {
    return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
};
