try{Typekit.load();}catch(e){}

var Gta = function(){
    var host = 'http://' + window.location.host;
    var currentUrl = window.location.href;
    var currentPage = window.location.pathname;
    var initialClass = '';
    var imageCache = [];
    var backgroundImages = {
        'thinking' : '/images/layout/blueprint-thinking.png', 
        'media' : '/images/layout/blueprint-media.png', 
        'publicity' : '/images/layout/blueprint-publicity.png', 
        'digital' : '/images/layout/blueprint-digital.png', 
        'creative-design' : '/images/layout/blueprint-creative.png'
    };
    
    var listingItems = [];
    
    var initHeader = function() 
    {
        $('#hd .menu-item').hover(
            function(){
                var key  = $(this).attr('id');
                $('#header').removeClass();
                $('#header').addClass('hd-' + key);
            }, function() {
                var key  = $(this).attr('id');
                $('#header').removeClass('hd-' + key);
            }
        );
    };
    
    var initSlider = function() 
    {
        $('.searchResults').before('<div class="next"></div>');
        $('.searchResults').before('<div class="prev"></div>');
        $('.searchResults').replaceWith('<div class="searchResults"><ul>' + $('.searchResults').html() + '</ul></div>');
        $('.searchResults .result').each(function(){
            listingItems.push($(this).find('.title a').attr('href'));
            $(this).replaceWith('<li class="result">'+ $(this).html() +'</li>');
        })
        $('.searchResults .result:last').addClass('lastItem');
        jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
            return -c * ((t=t/d-1)*t*t*t - 1) + b;
        };
        jQuery(function( jq ){
            jq('.searchResults').jCarouselLite({
                auto:3000,
                speed:1500,
                visible:3,
                scroll: 3,
                btnNext: '#body .next',
                btnPrev: '#body .prev',
                easing: 'easeOutQuart',
                hoverPause: true,
                start:0
            });
            /*jq('.searchResults').serialScroll({
                items: 'li',
                prev:'#body .prev',
                next:'#body .next',
                start:0,
                duration:1500,
                step:3,
                force:false,
                stop:true,
                lock:true,
                cycle:true,
                easing:'easeOutQuart',
                interval:3000
            });
            jq('.searchResults ul li').hover(function(){
                jq(this).stop().trigger('stop');
            },function(){
                jq(this).stop().trigger('start');
            });*/
        });
    };
    
    var initLightBox = function() 
    {
        // attach the fancybox event to every links on the listing
        $('.searchResults li a').each(function(){
            var href = $(this).attr('href');
            $(this).fancybox({
                ajax : {
                    type : 'POST',
                    data    : '_getContent=1'
                },
                'onComplete' : function(){
                    $('#fancybox-content > div').css('overflow', 'visible');
                }
            });
        });
        $('#header .menu-item').fancybox({
            ajax: {
                type: 'POST',
                data: '_getContent=1'
            },
            'onComplete' : function(){
                $('#fancybox-content > div').css('overflow', 'visible');
            }
        });
        
    }
    
    return {
        /**
         * Init method
         * 
         * @return  void
         */
        init: function () {
            $('#ft .snippet-telephone .text').prepend('(t)');
            $('#ft .snippet-fax .text').prepend('(f)');
            $('#ft .snippet-email .text').prepend('(e)');
            initHeader();
            initSlider();
            initLightBox();
        },
        preloadBackgroundImages: function() {
            for (key in backgroundImages) {
                var cacheImage = document.createElement('img');
                cacheImage.src = backgroundImages[key];
                imageCache.push(cacheImage);
            }
        }
    };
}();

$(document).ready(function() {
    Gta.init(); 
});

$(window).bind('load', function() {
    Gta.preloadBackgroundImages();
});
