
    // focus returns to this element after popup is hidden
    var returnFocus;
    j$.fn.extend({
        social: {

            // add events to icons from the array
            addPopupEvents: function(arr) {

                j$(arr).each(function() {
                    var icon_id = this[0];
                    var td_id = this[1];
                    var popup_id = this[2];
                    var url = this[3];

                    // show popup when icons are clicked
                    j$(icon_id).click(function(e) {
                        j$.fn.social.iconAction(icon_id, td_id, popup_id, url);
                        e.stopPropagation();
                        e.preventDefault();
                    });

                    // actions for pressing enter and esc on icons
                    j$(icon_id).keypress(function(e) {
                        if (e.keyCode == 13) // Enter
                        {
                            j$.fn.social.iconAction(icon_id, td_id, popup_id, url);
                            e.preventDefault();
                        }
                        else if (e.keyCode == 27) // Esc
                            j$.fn.social.removePopup();
                    });

                    // do not hide the popup if blank area on it is clicked
                    j$(popup_id).click(function(e) {
                        e.stopPropagation();
                    });

                    // remove popup when a link is clicked on popup
                    j$(popup_id).find("a").each(function(el) {
                        var pClick = this.onclick;
                        this.onclick = null;
                        j$(this).click(function(e) {
                        
                            j$.fn.social.removePopup();
                            e.stopPropagation();
                            if (pClick != undefined)
                                pClick(e);    
                            //e.preventDefault();    
                        });
                    });

                    // remove popup if escape is pressed
                    j$(popup_id).find("a").keydown(function(e) {
                        if (e.keyCode == 27)
                            j$.fn.social.removePopup();
                    });

                    // remove popup if tab is pressed on last link
                    // do not remove if shift+tab is pressed
                    j$(popup_id).find("a:last").keydown(function(e) {
                        if (!e.shiftKey && e.keyCode == 9)
                            j$.fn.social.removePopup();
                    });

                    // remove popup if shift+tab is pressed on first link
                    // do not remove if tab is pressed
                    j$(popup_id).find("a:first").keydown(function(e) {
                        if (e.shiftKey && e.keyCode == 9)
                            j$.fn.social.removePopup();
                    });

                });

                // remove popup if clicked elsewhere
                j$(document).click(function() {
                    j$.fn.social.removePopup();
                });
            },

            // first remove all open popups then open one and focus its first link
            showPopup: function(pop_id) {
                j$.fn.social.removePopup();
                j$(pop_id).css("display", "block");
                j$(pop_id).find("a:first").focus();
            },

            // remove all open popups
            removePopup: function() {
                j$(popup_array).each(function() {
                    if (j$(this[2]).css("display") && j$(this[2]).css("display") != "none") {
                        j$(this[2]).css("display", "none");
                    }
                });
                j$(returnFocus).focus();
            },

            iconAction: function(icon_id, td_id, pop_id, url) {
                if (td_id)
                    j$(pop_id).appendTo(j$(td_id));
                else
                    j$(pop_id).appendTo(j$(icon_id).parent());
                if (url != "" && url != "#") {
                    j$(pop_id).find("a").each(function() {
                        j$(this).attr("href", url);
                    });
                }
                returnFocus = icon_id;
                j$.fn.social.showPopup(pop_id);
            }

        }
    });

var _vCalUrl = "/Portals/66/Calendar/AddToCalendar_Outlook.vcs";
var _iCalUrl = "/Portals/66/Calendar/AddToCalendar_Lotus.ics";

function vCalendar()
{
	document.location = _vCalUrl;
}

function iCalendar()
{
	document.location=_iCalUrl;
}


var popup_stuff=new Array([j$('#lnkAddCal'), j$('#tdCal'), j$('#ctl00_ContentPlaceHolder1_lstCal'), '#']);

j$(document).ready(function() 
{ popup_array = popup_stuff; j$.fn.social.addPopupEvents(popup_array); 
if (j$("#NFContainerContainer").height() > 150) j$("#NFContainerContainer").height(150); });


function addGoogle()
{
	window.open("http://www.google.com/calendar/event?action=TEMPLATE&text=5th+Annual+TPM+Asia+Conference&dates=20111011T010000Z/20111012T090000Z&location=Intercontinental+Shenzhen%2c+China&trp=false&details=The%205th%20annual%20TPM%20Asia,%20Asia's%20Global%20Container%20Conference,%20will%20take%20place%20on%2011-12%20October%202011%20at%20the%20Intercontinental%20Hotel%20Shenzhen,%20China.%20%20Once%20again%20senior%20level%20decision%20makers%20will%20gather%20at%20Asia's%20leading%20container%20event%20to%20debate%20issues%20facing%20the%20container%20industry%20for%20trade%20-%20Trans-Pacific%20,%20Asia-Europe%20and%20Intra-Asia.%20This%20conference%20will%20address%20issues%20head%20on%20with%20keynote%20speakers,%20roundtable%20discussions%20and%20formal%20presentations.%20%20Last%20year%20600%20delegates%20gathered%20with%20a%20particularly%20impressive%20line%20up%20of%20shippers%20and%20BCOs%20including:%20Walmart%20*%20Target%20*%20Electrolux%20*%20Home%20Depot%20*%20Nike%20*%20JC%20Penney%20*%20VF%20Asia%20Ltd%20*%20Samsung%20*%20Lowe's%20*%20Pier%201%20Imports%20*%20Hasbro%20*%20Phillips-Van%20Heusen%20and%20many%20more!",'','width=600px,height=500px,resizable=1,scrollbars=1');
}

function addYahoo()
{
	window.open("http://calendar.yahoo.com/?v=60&view=d&type=20&title=5th+Annual+TPM+Asia+Conference&st=20111011T090000Z&in_loc=Intercontinental+Shenzhen%2c+China&URL=http%3a%2f%2fwww.tpm-asia.com&desc=The%205th%20annual%20TPM%20Asia,%20Asia's%20Global%20Container%20Conference,%20will%20take%20place%20on%2011-12%20October%202011%20at%20the%20Intercontinental%20Hotel%20Shenzhen,%20China.%20%20Once%20again%20senior%20level%20decision%20makers%20will%20gather%20at%20Asia's%20leading%20container%20event%20to%20debate%20issues%20facing%20the%20container%20industry%20for%20trade%20-%20Trans-Pacific%20,%20Asia-Europe%20and%20Intra-Asia%20%3Cbr%3E%20%3Cbr%3EThis%20conference%20will%20address%20issues%20head%20on%20with%20keynote%20speakers,%20roundtable%20discussions%20and%20formal%20presentations.%20%20Last%20year%20600%20delegates%20gathered%20with%20a%20particularly%20impressive%20line%20up%20of%20shippers%20and%20BCOs%20including:%20Walmart%20*%20Target%20*%20Electrolux%20*%20Home%20Depot%20*%20Nike%20*%20JC%20Penney%20*%20VF%20Asia%20Ltd%20*%20Samsung%20*%20Lowe's%20*%20Pier%201%20Imports%20*%20Hasbro%20*%20Phillips-Van%20Heusen%20and%20many%20more!",'','width=600px,height=500px,resizable=1,scrollbars=1');
}


