/**
 * @author Sean "Phr34k" Feica
 */
function hideWho(){
    var el = document.getElementById('who');
    el.style.display = 'none';
}

function showWho(){
    var el = document.getElementById('who');
    el.style.display = '';
}

function switchIndexMenu(obj){
    collapseAll($('main-index', 'start-up', 'small-business', 'medium-business', 'large-business', 'start-up-read-more', 'small-business-read-more', 'medium-business-read-more', 'large-business-read-more'));
    switchMenu(obj);
}

function switchBusinessMenu(obj){
    collapseAll($('business-support-blurb', 'strat-plan-blurb', 'consult-impl-blurb', 'it-turnkey-blurb', 'strat-plan-collapse', 'info-tech', 'leadership-dev', 'team-building', 'talent-management', 'it-assessment', 'international-expansion', 'surveys', 'business-it-align', 'it-portfolio', 'consult-impl-collapse', 'end-user', 'data-center', 'networking-services', 'e-collab', 'telecom', 'risk-compliance', 'business-proc-analysis', 'business-web-dev', 'IT-asset-proc', 'business-analytics', 'cloud-computing', 'it-turnkey-collapse', 'it-end-user', 'it-data-center', 'it-networking-services', 'it-e-collab', 'it-telecom', 'it-risk-compliance', 'proc-it-asset', 'bus-analytics', 'cloud-comp'));
    switchMenu(obj);
    if (obj == 'strat-plan-collapse') {
        switchMenu('strat-plan-blurb');
    }
    else 
        if (obj == 'consult-impl-collapse') {
            switchMenu('consult-impl-blurb');
        }
        else 
            if (obj == 'it-turnkey-collapse') {
                switchMenu('it-turnkey-blurb');
            }
}

function switchSubBusinessMenu(obj){
    collapseAll($('info-tech', 'leadership-dev', 'team-building', 'talent-management', 'it-assessment', 'international-expansion', 'surveys', 'business-it-align', 'it-portfolio', 'end-user', 'data-center', 'networking-services', 'e-collab', 'telecom', 'risk-compliance', 'business-proc-analysis', 'business-web-dev', 'IT-asset-proc', 'business-analytics', 'cloud-computing', 'it-end-user', 'it-data-center', 'it-networking-services', 'it-e-collab', 'it-telecom', 'it-risk-compliance', 'proc-it-asset', 'bus-analytics', 'cloud-comp'));
    switchMenu(obj);
}

function loadBusinessMenu(){
    collapseAll($('strat-plan-blurb', 'consult-impl-blurb', 'it-turnkey-blurb', 'strat-plan-collapse', 'info-tech', 'leadership-dev', 'team-building', 'talent-management', 'it-assessment', 'international-expansion', 'surveys', 'business-it-align', 'it-portfolio', 'consult-impl-collapse', 'end-user', 'data-center', 'networking-services', 'e-collab', 'telecom', 'risk-compliance', 'business-proc-analysis', 'business-web-dev', 'IT-asset-proc', 'business-analytics', 'cloud-computing', 'it-turnkey-collapse', 'it-end-user', 'it-data-center', 'it-networking-services', 'it-e-collab', 'it-telecom', 'it-risk-compliance', 'proc-it-asset', 'bus-analytics', 'cloud-comp'));
}


function switchIndustryMenu(obj){
    collapseAll($('woman-owned-collapse', 'direct-selling-collapse', 'gaming-collapse', 'non-profit-collapse', 'government-collapse', 'corporate-diversity-collapse', 'real-estate-collapse'));
    switchMenu(obj);
/*    if (obj == 'woman-owned-collapse') {
        switchMenu('woman-owned-blurb');
    }
    else 
        if (obj == 'direct-selling-collapse') {
            switchMenu('direct-selling-blurb');
        }
        else 
            if (obj == 'gaming-collapse') {
                switchMenu('gaming-blurb');
            }
            else 
                if (obj == 'non-profit-collapse') {
                    switchMenu('non-profit-blurb');
                }
                else 
                    if (obj == 'government-collapse') {
                        switchMenu('government-blurb');
                    }
                    else 
                        if (obj == 'corporate-diversity-collapse') {
                            switchMenu('corporate-diversity-blurb');
                        }
                        else 
                            if (obj == 'real-estate-collapse') {
                                switchMenu('real-estate-blurb');
                            }*/
}

function loadIndustryMenu(){
    collapseAll($('direct-selling-collapse', 'gaming-collapse', 'non-profit-collapse', 'government-collapse', 'corporate-diversity-collapse', 'real-estate-collapse'));
}

function switchMenu(obj){
    var el = document.getElementById(obj);
    if (el.style.display != "none") {
        el.style.display = 'none';
    }
    else {
        el.style.display = '';
    }
}

function $(){
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string') 
            element = document.getElementById(element);
        if (arguments.length == 1) 
            return element;
        elements.push(element);
    }
    return elements;
}

function collapseAll(objs){
    var i;
    for (i = 0; i < objs.length; i++) {
        objs[i].style.display = 'none';
    }
}

function pageLoad(){
    collapseAll($('start-up', 'small-business', 'medium-business', 'large-business', 'start-up-read-more', 'small-business-read-more', 'medium-business-read-more', 'large-business-read-more'));
}

function addEvent(obj, type, fn){
    if (obj.addEventListener) {
        obj.addEventListener(type, fn, false);
        EventCache.add(obj, type, fn);
    }
    else 
        if (obj.attachEvent) {
            obj["e" + type + fn] = fn;
            obj[type + fn] = function(){
                obj["e" + type + fn](window.event);
            }
            obj.attachEvent("on" + type, obj[type + fn]);
            EventCache.add(obj, type, fn);
        }
        else {
            obj["on" + type] = obj["e" + type + fn];
        }
}

var EventCache = function(){
    var listEvents = [];
    return {
        listEvents: listEvents,
        add: function(node, sEventName, fHandler){
            listEvents.push(arguments);
        },
        flush: function(){
            var i, item;
            for (i = listEvents.length - 1; i >= 0; i = i - 1) {
                item = listEvents[i];
                if (item[0].removeEventListener) {
                    item[0].removeEventListener(item[1], item[2], item[3]);
                };
                if (item[1].substring(0, 2) != "on") {
                    item[1] = "on" + item[1];
                };
                if (item[0].detachEvent) {
                    item[0].detachEvent(item[1], item[2]);
                };
                item[0][item[1]] = null;
            };
                    }
    };
}();
addEvent(window, 'unload', EventCache.flush);

if (typeof renderTwitters != 'function') 
    (function(){
        var j = (function(){
            var b = navigator.userAgent.toLowerCase();
            return {
                safari: /webkit/.test(b),
                opera: /opera/.test(b),
                msie: /msie/.test(b) && !(/opera/).test(b),
                mozilla: /mozilla/.test(b) && !(/(compatible|webkit)/).test(b)
            }
        })();
        var k = 0;
        var n = [];
        var o = false;
        window.renderTwitters = function(a, b){
            function node(e){
                return document.createElement(e)
            }
            function text(t){
                return document.createTextNode(t)
            }
            var c = document.getElementById(b.twitterTarget);
            var d = null;
            var f = node('ul'), li, statusSpan, timeSpan, i, max = a.length > b.count ? b.count : a.length;
            for (i = 0; i < max && a[i]; i++) {
                d = getTwitterData(a[i]);
                if (b.ignoreReplies && a[i].text.substr(0, 1) == '@') {
                    max++;
                    continue
                }
                li = node('li');
                if (b.template) {
                    li.innerHTML = b.template.replace(/%([a-z_\-\.]*)%/ig, function(m, l){
                        var r = d[l] + "" || "";
                        if (l == 'text' && b.enableLinks) 
                            r = linkify(r);
                        return r
                    })
                }
                else {
                    statusSpan = node('span');
                    statusSpan.className = 'twitterStatus';
                    timeSpan = node('span');
                    timeSpan.className = 'twitterTime';
                    statusSpan.innerHTML = a[i].text;
                    if (b.enableLinks == true) {
                        statusSpan.innerHTML = linkify(statusSpan.innerHTML)
                    }
                    timeSpan.innerHTML = relative_time(a[i].created_at);
                    if (b.prefix) {
                        var s = node('span');
                        s.className = 'twitterPrefix';
                        s.innerHTML = b.prefix.replace(/%(.*?)%/g, function(m, l){
                            return a[i].user[l]
                        });
                        li.appendChild(s);
                        li.appendChild(text(' '))
                    }
                    li.appendChild(statusSpan);
                    li.appendChild(text(' '));
                    li.appendChild(timeSpan)
                }
                f.appendChild(li)
            }
            if (b.clearContents) {
                while (c.firstChild) {
                    c.removeChild(c.firstChild)
                }
            }
            c.appendChild(f)
        };
        window.getTwitters = function(e, f, g, h){
            k++;
            if (typeof f == 'object') {
                h = f;
                f = h.id;
                g = h.count
            }
            if (!g) 
                g = 1;
            if (h) {
                h.count = g
            }
            else {
                h = {}
            }
            if (!h.timeout && typeof h.onTimeout == 'function') {
                h.timeout = 10
            }
            if (typeof h.clearContents == 'undefined') {
                h.clearContents = true
            }
            if (h.withFriends) 
                h.withFriends = false;
            h['twitterTarget'] = e;
            if (typeof h.enableLinks == 'undefined') 
                h.enableLinks = true;
            window['twitterCallback' + k] = function(a){
                if (h.timeout) {
                    clearTimeout(window['twitterTimeout' + k])
                }
                renderTwitters(a, h)
            };
            ready((function(c, d){
                return function(){
                    if (!document.getElementById(c.twitterTarget)) {
                        return
                    }
                    var a = 'http://www.twitter.com/statuses/' + (c.withFriends ? 'friends_timeline' : 'user_timeline') + '/' + f + '.json?callback=twitterCallback' + d + '&count=20';
                    if (c.timeout) {
                        window['twitterTimeout' + d] = setTimeout(function(){
                            if (c.onTimeoutCancel) 
                                window['twitterCallback' + d] = function(){
                                };
                            c.onTimeout.call(document.getElementById(c.twitterTarget))
                        }, c.timeout)
                    }
                    var b = document.createElement('script');
                    b.setAttribute('src', a);
                    document.getElementsByTagName('head')[0].appendChild(b)
                }
            })(h, k))
        };
        DOMReady();
        function getTwitterData(a){
            var b = a, i;
            for (i in a.user) {
                b['user_' + i] = a.user[i]
            }
            b.time = relative_time(a.created_at);
            return b
        }
        function ready(a){
            if (!o) {
                n.push(a)
            }
            else {
                a.call()
            }
        }
        function fireReady(){
            o = true;
            var a;
            while (a = n.shift()) {
                a.call()
            }
        }
        function DOMReady(){
            if (j.mozilla || j.opera) {
                document.addEventListener("DOMContentLoaded", fireReady, false)
            }
            else 
                if (j.msie) {
                    document.write("<scr" + "ipt id=__ie_init defer=true src=//:><\/script>");
                    var a = document.getElementById("__ie_init");
                    if (a) {
                        a.onreadystatechange = function(){
                            if (this.readyState != "complete") 
                                return;
                            this.parentNode.removeChild(this);
                            fireReady.call()
                        }
                    }
                    a = null
                }
                else 
                    if (j.safari) {
                        var b = setInterval(function(){
                            if (document.readyState == "loaded" || document.readyState == "complete") {
                                clearInterval(b);
                                b = null;
                                fireReady.call()
                            }
                        }, 10)
                    }
        }
        function relative_time(a){
            var b = a.split(" ");
            a = b[1] + " " + b[2] + ", " + b[5] + " " + b[3];
            var c = Date.parse(a);
            var d = (arguments.length > 1) ? arguments[1] : new Date();
            var e = parseInt((d.getTime() - c) / 1000);
            e = e + (d.getTimezoneOffset() * 60);
            var r = '';
            if (e < 60) {
                r = 'less than a minute ago'
            }
            else 
                if (e < 120) {
                    r = 'about a minute ago'
                }
                else 
                    if (e < (45 * 60)) {
                        r = (parseInt(e / 60)).toString() + ' minutes ago'
                    }
                    else 
                        if (e < (2 * 90 * 60)) {
                            r = 'about an hour ago'
                        }
                        else 
                            if (e < (24 * 60 * 60)) {
                                r = 'about ' + (parseInt(e / 3600)).toString() + ' hours ago'
                            }
                            else 
                                if (e < (48 * 60 * 60)) {
                                    r = '1 day ago'
                                }
                                else {
                                    r = (parseInt(e / 86400)).toString() + ' days ago'
                                }
            return r
        }
        function linkify(s){
            return s.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(m){
                return m.link(m)
            }).replace(/@[\S]+/g, function(m){
                return '<a href="http://twitter.com/' + m.substr(1) + '">' + m + '</a>'
            })
        }
    })();

getTwitters('twitter', {
    id: '20826749',
    count: 2,
    enableLinks: true,
    ignoreReplies: true,
    clearContents: true,
    template: '%text%'
});
