﻿var newBrandServiceInfo;
var extendBrandServiceInfo;
var nonProfitBrandServiceInfo;
var serviceInfoToLoad;
var serviceInfoData;

function initServices() {
    // set service info data
    newBrandServiceInfo = new ServiceInfo(
                "new-brand-content",
                "home_pg_whatwedo_brandpersonality_temp.png",
                "New Brand Service",
                "Strategic processes are too often laborious exercises in learning what you already know. So we ask the big questions, skip the jibber jabber and identify the insights that matter. Then we bring those insights to life. Ultimately, it's about defining your brand essence. What's that? It's the thing that your customer wants, that you provide, that isn't available anywhere else. It's also the distinctive way you relate to your customer [aka your brand personality].",
                "patelco",
                "Patelco",
                "brand-strategy");

    extendBrandServiceInfo = new ServiceInfo(
                "extend-brand-content",
                "home_pg_whatwedo_extendbrand_temp.png",
                "Extend Brand Service",
                "While Iron has built many brands from the ground up, a key strength of the agency is our ability to assimilate into an existing brand environment - creating marketing materials that are perfectly consistent with the design and copy cues established by the brand to date. It is this ability that is cited by brands like Levi's, Dockers and Specialized when they contract us to produce customer marketing materials to accompany a mass media consumer push, driven by a sophisticated brand campaign.",
                "levis",
                "Levi's",
                "brand-strategy");

    nonProfitBrandServiceInfo = new ServiceInfo(
                "non-profit-brand-content",
                "home_pg_whatwedo_nonprofit_temp.png",
                "Non-Profit Brand Service",
                "The ability to effectively communicate your brand essence - the central message and character driving your organization - dictates how successful you will be. The irony is that non-profit organizations often struggle to justify spending hard-earned funds on marketing. But if you're not actively managing people's perception of your organization, your chances of success become rather slim. So you need to do it, and you need to do it right - which is where Iron comes in. We fuse aggressive consumer marketing strategy with extensive non-profit know-how.",
                "deyoung",
                "deYoung",
                "non-profit");

    // set service clicks
    $('.services div[id]').each(function () {
        $(this).click(function () {
            window.location = $('.find-out-more a', this).attr('href');
        });
    });

    $('.services div[id]').each(function () {
        $(this).hover(
        // mouseover
            function () {
                $('h1', this).addClass('over');
            },
        // mouseout
            function () {
                $('h1', this).removeClass('over');
            }
            );
    });
}

function closeServiceInfo() {
    $('.services-contents').animate({ 'height': 0 },
                    {
                        duration: 1000,
                        easing: 'easeInOutExpo',
                        complete: function () {
                            $(this).removeClass('active');
                            $(this).empty();

                            if (serviceInfoToLoad == 'services') {
                                UpdateServiceOverlay('');
                                UpdatePosition('#what-we-do', 1000);
                                $(this).addClass('active');
                            } else if (serviceInfoToLoad != '') {
                                UpdateServiceOverlay(serviceInfoToLoad);
                                loadServiceInfo();
                            }
                        }
                    });
}

function openServiceInfo() {
    $('.services-contents').animate({ 'height': 418 },
                    {
                        duration: 1000,
                        easing: 'easeInOutExpo',
                        complete: function () {
                            $(this).addClass('active');
                            serviceInfoToLoad = '';
                        }
                    });
}

function loadServiceInfo() {
    var data = serviceInfoData;
    
    $('#service-tmpl').tmpl({
        id: data.id,
        path: data.path,
        alt: data.alt,
        content: data.content,
        link: data.link.replace(' ', '-'),
        client: data.client,
        category: data.category.replace(' ', '-')
    }).prependTo('.services-contents');
    
    // raise above h2 by 10px
    UpdateCustomPosition('.services h2', 1000, 195, openServiceInfo);
}

function UpdateServiceOverlay(view) {
    // clear overlay
    $('.services div[id]').each(function () {
        var serviceId = $(this).attr('id');
        serviceId = serviceId.replace('-service', '');
        $(this).removeClass('overlay');
        $('a', this).removeClass('close-more').addClass('more').text('Find Out More').attr('href', '#/what-we-do/' + serviceId);

        if (view != '') {
            if (view == serviceId) {
                $('a', '#' + view + '-service').removeClass('more').addClass('close-more').text('Close').attr('href', '#/what-we-do/');
            } else {
                $(this).addClass('overlay');
            }
        }
    });
}

/* ServiceInfo model */
function ServiceInfo(id, path, alt, content, link, client, category) {
    this.id = id;
    this.path = path;
    this.alt = alt;
    this.content = content;
    this.link = link;
    this.client = client;
    this.category = category;
}
