// Ensure LIT namespace is available
if (typeof(LIT) == "undefined")
{
    var LIT = {};
}

/**
 * Handles random display of testimonials in the testimonial section.
 */
LIT.Testimonials =
{
    container: "content",
    menuContainer: "sidebar",

    employees: [
        {id: 1,
         name: "Aislinn",
         title: "Senior Verification Engineer",
         joined: "January 2004",
         content: [
            {question: "How did you end up in Liberty IT?", answer: ["I took a year out after university to travel, before joining Liberty on the graduate recruitment programme."]},
            {question: "Why did you accept the offer?", answer: ["Because Liberty is seen as a good company."]},
            {question: "How did you settle in?", answer: ["I was fully into it after the first three weeks, which was the induction period where you learned about the organisation. We were encouraged to take part in away days and other events and this gave me a feeling of confidence. After this I went into the verification team. Later I was promoted to a senior position."]},
            {question: "What are you working on now?", answer: ["Being in the verification team means I work on a range projects across all market areas within Liberty IT. I travel to the US regularly to meet new clients. Each project and client I'm involved with brings new challenges and demands, which means there's a lot of diversity in my work."]},
            {question: "What do you like best about working in Liberty IT?", answer: ["Being listened to. They are interested in things like your well-being and health and you are consulted about the day-to-day things that affect you."]}
         ]},
        {id: 2,
         name: "Graham",
         title: "Project Manager",
         joined: "October 2001",
         content: [
            {question: "How did you end up in Liberty IT?", answer: ["I'd gone straight into British Telecom in 1992 after graduating, landing in with a strong team and mentor mentality and a very professional attitude to work that has served me well to this day. But I was working for another company prior to joining Liberty, which happened as a result of talking to the MD at the time."]},
            {question: "Why did you accept the offer?", answer: ["I saw stability both at Liberty and in the insurance markets at a time when venture capital was draining out of the industry here. Also they had a great reputation for working in modern technologies."]},
            {question: "How did you settle in?", answer: ["I've always been a self starter and as I was given a new area to develop I got stuck in straight away. My initial task was building and managing a Belfast-based team working on projects for Business Markets in Portsmouth, New Hampshire. It presented many opportunities and challenges for myself, my team and Liberty IT, including helping to drive through a major technology shift - towards J2EE architectures."]},
            {question: "What are you working on now?", answer: ["I'm currently working with Agency Markets, a new area for LIT based in Indianapolis, Indiana. Over the past three years this area has been growing and diversifying. It's providing a steady stream of challenging work for my teams. We've been involved with major enhancements of existing applications that allowed us to build a great reputation from the bottom up and engage with Liberty Mutual management from the top down."]},
            {question: "What do you like best about working in Liberty IT?", answer: ["The freedom. Building great customer relationships and working with some of the best IT consultants in the country."]}
         ]},
        {id: 3,
         name: "Neil",
         title: "Software Engineer",
         joined: "March 2006",
         content: [
            {question: "How did you end up in Liberty IT?", answer: ["After my degree I took a break and then started looking around. Liberty IT had by far the best graduate programme, so they were my first port of call."]},
            {question: "Why did you accept the offer?", answer: ["As I didn't drive then, a big plus was being in the city centre. It's easy to get the train from where I live. Another thing was the in-house training. If you need training here you just ask. If it's appropriate to your role you'll get it."]},
            {question: "How did you settle in?", answer: ["On my first day I was brought out to lunch by my manager. That was a great help in meeting people and started me settling in socially. Work-wise the graduate programme really helped me to make a smooth transition from what I learned as a student, to what the industry expects from software professionals."]},
            {question: "What are you working on now?", answer: ["So far I have been working with technologies such as C++, JSP, HTML, SQL under Unix and Windows environments."]},
            {question: "What do you like best about working in Liberty IT?", answer: ["You mean apart from payday! Probably meeting new people and travelling. I spent a week in the US last year working with colleagues which was great."]}
         ]},
        {id: 4,
         name: "Tim",
         title: "Technologist",
         joined: "April 2005",
         content: [
            {question: "How did you end up in Liberty IT?", answer: ["After university I worked in a Research & Development company, then moved to out-sourcing and then spent 7 years working in IT for one of the UK's biggest banks. I applied to Liberty IT because it had a reputation of having very high technical standards."]},
            {question: "Why did you accept the offer?", answer: ["Liberty offered a lot of things that were attractive: An office in the City centre with the chance of international travel, working in the sort of technologies I specialized in, a dynamic and enthusiastic workforce and above all it also had a genuine career path for someone who is more technically minded. The decision to accept was pretty easy."]},
            {question: "How did you settle in?", answer: ["Settling is was easy. Liberty always has a lot of work on, so you just hit the ground running. I joined a really good team with great team spirit so it was really just a question of getting stuck in."]},
            {question: "What are you working on now?", answer: ["I now work across teams in the Commercial Markets area of Liberty IT, providing design, architecture and process consultancy and technical leadership for a range of projects. My current main project is creating an internet application using a combination of JSF, Jboss, the Spring framework and the JPA. The project is being delivered through agile software development methodologies, with Scrum as the project management framework."]},
            {question: "What do you like best about working in Liberty IT?", answer: ["I really enjoy the challenging work and the travel opportunities that come along with it."]}
         ]}

    ],

    init: function()
    {
        DomBuilder.apply(window);
        this.generateMenu();

        // Show a random employee
        var randomEmployee = this.employees[Math.floor(Math.random() * this.employees.length)];
        this.showEmployee(randomEmployee);
    },

    findEmployee: function(id)
    {
        var employee = null;
        for (var i = 0, l = this.employees.length; i < l; i++)
        {
            if (id == this.employees[i].id)
            {
                employee = this.employees[i];
                break;
            }
        }
        return employee;
    },

    generateMenu: function()
    {
        var container = $(this.menuContainer);
        if (!container)
        {
            return;
        }
        this.clearElement(container);

        var ul = UL();
        for (var i = 0, l = this.employees.length; i < l; i++)
        {
            ul.appendChild(
                LI(
                    A({href: "#", onclick: this.showEmployeeHandler(this.employees[i].id)},
                      this.employees[i].name)));
        }
        container.appendChild(ul);
    },

    showEmployee: function(employee)
    {
        var container = $(this.container);
        if (!container)
        {
            return;
        }

        var content =
            DIV(
                H1(employee.name),
                H2(employee.title),
                P("Joined us in " + employee.joined)
            );

        for (var i = 0; i < employee.content.length; i++)
        {
            content.appendChild(H3(employee.content[i].question));
            for (j = 0; j < employee.content[i].answer.length; j++)
            {
                content.appendChild(P(employee.content[i].answer[j]));
            }
        }
        content.lastChild.className = "last";

        this.clearElement(container);
        container.className = "employees-" + employee.name.toLowerCase();
        container.appendChild(content);
    },

    showEmployeeHandler: function(id)
    {
        return function(e)
        {
            Event.stop(e);
            this.showEmployee(this.findEmployee(id));
        }.bindAsEventListener(this);
    },

    /**
     * Clears the given DOM element of any content.
     *
     * @param el {Element} the element to be cleared of content.
     */
    clearElement: function(el)
    {
        while(el.firstChild)
        {
            el.removeChild(el.firstChild);
        }
    }
};

// Always initialise on page load
Event.observe(window, "load", LIT.Testimonials.init.bind(LIT.Testimonials));