﻿///<reference path="jquery-1.4.2-vsdoc.js" />
function getGlobalVar(globalVarName) {
    return eval(globalVarName);
}
function setGlobalVar(globalVarName, value) {
    eval(globalVarName + "='" + value + "';");
}

var externWin; var newWin; function openPortfolioWindow(strContent, myHeight, myWidth, blnShowClose, blnShowPrev, blnShowNext) {
    if (newWin != null) { newWin.close(); }
    newWin = window.open('/compelling_creative/portfolio/portfolio_item.aspx?fldEntryID=' + strContent + '&fldHeight=' + myHeight + '&fldWidth=' + myWidth + '&fldShowClose=' + blnShowClose + '&fldShowPrev=' + blnShowPrev + '&fldShowNext=' + blnShowNext + '&fldTest', "myWindow", "HEIGHT=" + (myHeight + 65) + ", WIDTH=" + (myWidth + 75) + ",resizable=yes,top=50,left=50,scrollbars=yes");
}

function openPopupName(strName, strURL, intHeight, intWidth, intTop, intLeft, blnLocation, blnMenuBar, blnResizable, blnScrollbars, blnStatus, blnToolbar) {
    if (!externWin || externWin.closed) { externWin = window.open(strURL, strName, "height=" + intHeight + ",width=" + intWidth + ",top=" + intTop + ",left=" + intLeft + ",location=" + blnLocation + ",menubar=" + blnMenuBar + ",resizable=" + blnResizable + ",scrollbars=" + blnScrollbars + ",status=" + blnStatus + ",toolbar=" + blnToolbar); }
    else { externWin.location = strURL; externWin.focus(); }
}

function print_mail_to_link(lhs, strName, rhs) { document.write("<A HREF=\"mailto"); document.write(":" + lhs + "@"); document.write(rhs + "\">" + strName + "<\/a>"); }


function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
		((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);

            if (c_end == -1) c_end = document.cookie.length;

            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function getQSParameter(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
}

/* Portfolio Campaign Popup Start */
var globalCampaignID = "";
var globalBoolShowCaseHistory = false;
var displayCampaignDataTimer;
var showPortfolioCampaign;
function loadCampaign(campaignID) {
    //alert("calling ajax with campaign=" + campaignID);
    //globalCampaignID = campaignID;
    setGlobalVar("globalCampaignID", campaignID)
    //alert("set globalCampaignID: " + globalCampaignID);
    jQuery.get("/What-We-Do/Our-Work/getPortfolioCampaignForAjax.aspx", "campaign=" + campaignID, function(data) { displayCampaignData(data); }, "html");
}

function displayCampaignData(theData) {
    clearTimeout(displayCampaignDataTimer);
    if (jQuery('#portfolioCampaignData').length > 0) {
        jQuery('#portfolioCampaignData').html(theData);
        //Setup the campaign fields after the data is loaded
        setupPortfolioCampaignContainer(); //this function in portfolioCampaign.js
    } else {
        //sleep a bit and try again
        //displayCampaignDataTimer = setTimeout(displayCampaignData, 200, theData);
		displayCampaignDataTimer = setTimeout(function() { displayCampaignData(theData) }, 200); //IE compatible version
    }
}
/* Portfolio Campaign Popup End */

jQuery(document).ready(function () {
    jQuery.preloadCssImages();

    //Email spam prevention
    jQuery(".godfreyEML").each(function () {
        jQuery(this).replaceWith(function () {

            var arr = jQuery(this).attr("title").replace(/&#34;/g, "\"").split(":");

            if (arr.length == 2) {
                //return "<a href=\"mailto" + ":" + arr[1].split("").reverse().join("").replace(/\"/g, "&#34;") + "@" + arr[0].split("").reverse().join("").replace(/\"/g, "&#34;") + "\">" + jQuery(this).html() + "<\/a>";
                return "<a href=\"mailto" + ":" + arr[1].split("").join("").replace(/\"/g, "&#34;") + "@" + arr[0].split("").join("").replace(/\"/g, "&#34;") + "\">" + jQuery(this).html() + "<\/a>";
            } else {
                return jQuery(this).html();
            }
        });
    });

    /* Portfolio Campaign Popup Start */
    showPortfolioCampaign = function showTheModal(campaignID, boolShowCaseHistory) {
        //alert("showing the modal with campaignID=" + campaignID);
        jQuery('#portfolioPopup').modal({
            closeClass: "PCCloseIt",
            overlayId: 'portfolioOverlay',
            containerId: 'portfolioPopup',
            opacity: '75',
            onOpen: function (dialog) {
                dialog.overlay.fadeIn('slow', function () {
                    dialog.container.slideDown('slow', function () { dialog.data.fadeIn('slow'); });
                });
            }, onShow: function (dialog) {
                //Load the campaign
                //delay load so animation has time to complete
                setGlobalVar("globalBoolShowCaseHistory", boolShowCaseHistory);
                //loadCampaign(campaignID);
                //var timer = setTimeout(loadCampaign, 2000, campaignID);
                var timer = setTimeout(function () { loadCampaign(campaignID) }, 2000); //IE compatible version
            }
                 , onClose: function (dialog) {
                     dialog.overlay.fadeOut('slow', function () {
                         dialog.container.slideUp('slow', function () {
                             dialog.data.fadeOut('slow');
                             jQuery.modal.close();
                         });
                     });
                 }
        });
    };
    /* Portfolio Campaign Popup End */


    jQuery("#dvFreeSearchAudit").mouseover(function () {
        jQuery("#dvFreeSearchAuditOpen").show();
        jQuery("#dvFreeSearchAuditClosed").hide();
        jQuery("#dvFreeSearchAuditOpenCenter").slideDown("slow");
    }); /*.mouseout(function() {
        //bkw this needs to be fixed
        jQuery("#dvFreeSearchAuditOpenCenter").slideUp();
        jQuery("#dvFreeSearchAuditClosed").show();
        jQuery("#dvFreeSearchAuditOpen").hide();
    });
    jQuery("#dvFreeSearchAuditOpenTop").click(function() {
        jQuery("#dvFreeSearchAuditOpenCenter").slideUp();
        jQuery("#dvFreeSearchAuditClosed").show();
        jQuery("#dvFreeSearchAuditOpen").hide();
    });
*/


    //Use this to swap up/down states on imges inside of link tags
    jQuery('a.swapUpDnImage').hover(function () {
        jQuery(this).children('img').attr("src", jQuery(this).children('img').attr("src").replace("_up.", "_dn."));
    }, function () {
        jQuery(this).children('img').attr("src", jQuery(this).children('img').attr("src").replace("_dn.", "_up."));
    });
    //Swap images themselves
    jQuery('.swapUpDnImage').hover(function () {
        jQuery(this).attr("src", jQuery(this).attr("src").replace("_up.", "_dn."));
    }, function () {
        jQuery(this).attr("src", jQuery(this).attr("src").replace("_dn.", "_up."));
    });

    //Search start
    jQuery("#searchAnchor").mouseover(function () {
        jQuery("#searchInput").show();
        jQuery("#searchAnchorText").hide();
    }).mouseout(function () {
        jQuery("#searchInput").hide();
        jQuery("#searchAnchorText").show();
    });
    jQuery("input[id$='tbSearch']").click(function () {//use ends with due to .net name mangling
        jQuery("input[id$='tbSearch']").val("");
    });
    jQuery("#searchBtn").click(function () {
        window.location.href = "/Godfrey Home?q=" + jQuery("#tbSearch").val();
    });

    //Search end

    //Social start
    jQuery("#imgRSS").mouseover(function () {
        jQuery("#dvFollowHeadline").text('Subscribe to Godfrey B2B News Feeds');
    });
    jQuery("#imgLinkedIn").mouseover(function () {
        jQuery("#dvFollowHeadline").text('Connect with Godfrey B2B on LinkedIn');
    });

    jQuery("#imgTwitter").mouseover(function () {
        jQuery("#dvFollowHeadline").text('Follow Godfrey B2B on Twitter');
    });

    jQuery("#imgFacebook").mouseover(function () {
        jQuery("#dvFollowHeadline").text('Follow Godfrey B2B on Facebook');
    });

    jQuery("#imgEnews").mouseover(function () {
        jQuery("#dvFollowHeadline").text('Subscribe to B2B Insights E-newsletter');
    });

    //Social LG
    jQuery("#imgLgRSS").mouseover(function () {
        jQuery("#dvFollowHeadlineLarge").text('Subscribe to Godfrey B2B News Feeds');
    });
    jQuery("#imgLgLinkedIn").mouseover(function () {
        jQuery("#dvFollowHeadlineLarge").text('Connect with Godfrey B2B on LinkedIn');
    });

    jQuery("#imgLgTwitter").mouseover(function () {
        jQuery("#dvFollowHeadlineLarge").text('Follow Godfrey B2B on Twitter');
    });

    jQuery("#imgLgFacebook").mouseover(function () {
        jQuery("#dvFollowHeadlineLarge").text('Follow Godfrey B2B on Facebook');
    });

    jQuery("#imgLgYoutube").mouseover(function () {
        jQuery("#dvFollowHeadlineLarge").text('Follow Godfrey B2B on YouTube');
    });

    jQuery("#imgLgGooglePlus").mouseover(function () {
        jQuery("#dvFollowHeadlineLarge").text('Follow Godfrey B2B on Google Plus');
    });

    jQuery("#imgLgEnews").mouseover(function () {
        jQuery("#dvFollowHeadlineLarge").text('Subscribe to B2B Insights E-newsletter');
    });

    /* jQuery("img[class='socialMedia']").each(function() {
    jQuery(this).mouseout(resetFollowText);
    jQuery(this).onImagesLoaded(function(_this) {
    prepareMouseOverImage(_this, jQuery(_this).attr("src"));
    });
    });
    */
    //Social end

    //gray out mouseovered images
    //grayOutImages();
    //jQuery("img[class *='mouseOverColor']").each(function() {
    //	grayOutImage(this);
    //jQuery(this).onImagesLoaded(function(_this) {
    //	prepareMouseOverImage(_this, jQuery(_this).attr("src"));
    //});
    //});

    jQuery(".megamenu").each(function () {
        var menuID = jQuery(this).attr('id');
        jQuery("#" + menuID + " div[class $='columnleft'] li a").each(function () {
            jQuery(this).mouseover(function () {
                jQuery("span[id $='" + menuID + "']").text(jQuery(this).attr('title'));
            }).mouseout(function () {
                jQuery("span[id $='" + menuID + "']").text('');
            });
        });
    });



    // Background Image set postion properly
    //    var DefaultHeight = jQuery(document).height();
    //    if (jQuery(window).height() >= DefaultHeight) {
    //        jQuery("#dvContainer").css('height', jQuery(window).height());
    //    } else {
    //        jQuery("#dvContainer").css('height', DefaultHeight);
    //    }

    /* bkw 8-5-2011 added delayed call to updateContainerBGImage() to allow page to complete loading */
    setTimeout("updateContainerBGImage()", 1000);

    jQuery(window).resize(function () {
        updateContainerBGImage();
        //        DefaultHeight = jQuery("#dvContainer").height();
        //        if (jQuery(window).height() >= DefaultHeight) {
        //            jQuery("#dvContainer").css('height', jQuery(window).height());
        //        } else {
        //            jQuery("#dvContainer").css('height', DefaultHeight);
        //        }
    });
    //End of backgound section
    //});


    //Social Media More
    var overMoreMenu = false;
    jQuery("#aSocialMedia").mouseover(function () {
        jQuery(this).hide();
        jQuery("#dvSocialMediaMore").fadeIn('fast', function () {
            jQuery(this).css('visibility', 'visible');
        });
    });
    jQuery("#dvSocialMediaMore").mouseout(function () {
        setTimeout(function () { closeSocialMore(); }, 500);
        overMoreMenu = false;
    });
    jQuery("#dvSocialMediaMore").mouseover(function () {
        overMoreMenu = true;
    });

    function closeSocialMore() {
        if (!overMoreMenu) {
            jQuery("#dvSocialMediaMore").hide();
            jQuery("#aSocialMedia").fadeIn("fast");
            overMoreMenu = false;
        }
    };
    jQuery("#dvSocialMediaMore").hide();
    if (jQuery("#dvSocialMediaMore").length != 0) {
        if (jQuery.browser.msie) {
            //curvyCorners.init();  commented out for now the popup error was driving me nuts. Not sure why this is called for dvSocialMediaMoreLarge on pages that don't contain dvSocialMediaMoreLarge
        }
    }
    //});

    jQuery("#aSocialMediaLarge").mouseover(function () {
        jQuery(this).hide();
        jQuery("#dvSocialMediaMoreLarge").fadeIn('fast', function () {
            jQuery(this).css('visibility', 'visible');
        });
    });
    jQuery("#dvSocialMediaMoreLarge").mouseout(function () {
        setTimeout(function () { closeSocialMoreLarge(); }, 500);
        overMoreMenu = false;
    });
    jQuery("#dvSocialMediaMoreLarge").mouseover(function () {
        overMoreMenu = true;
    });
    function closeSocialMoreLarge() {
        if (!overMoreMenu) {
            jQuery("#dvSocialMediaMoreLarge").hide();
            jQuery("#aSocialMediaLarge").fadeIn("fast");
            overMoreMenu = false;
        }
    };
});

/* bkw 8-5-2011 moved outside of page loaded function */
function updateContainerBGImage() {
    var DefaultHeight = jQuery(document).height();
    //alert("heights window / document " + jQuery(window).height() + " / " + jQuery(document).height());
    if (jQuery(window).height() >= DefaultHeight) {
        jQuery("#dvContainer").css('height', jQuery(window).height());
    } else {
        jQuery("#dvContainer").css('height', DefaultHeight);
    }
}


//function grayOutImages() {
//	jQuery("img[class *='mouseOverColor']").each(function() {
//		jQuery(this).onImagesLoaded(function(_this) {
//		if (jQuery(_this).attr("src").indexOf("data:image/png;base64") == -1) {
//				prepareMouseOverImage(_this, jQuery(_this).attr("src"));
//			}
//		});
//	});
//}


function resetFollowText() {
jQuery("#dvFollowHeadline").text('Follow Godfrey B2B');
}

//jkmegamenu.definemenu("anchorID", "menu ID", "Action(mouseover/click)",hasform,"alternative Text-used for top nav");
//jkmegamenu.definemenu("megaanchor", "megamenu1", "mouseover", false,'WHAT WE DO');
//jkmegamenu.definemenu("megaanchor2", "megamenu2", "mouseover", false,'WHO WE ARE');
//jkmegamenu.definemenu("megaanchor3", "megamenu3", "mouseover", false,'HOW WE THINK');
//jkmegamenu.definemenu("megaanchor4", "megamenu4", "mouseover", true, '');

// function logFileClick(strMyFile) {
// pageTracker._trackPageview(strMyFile);
// }

/* bkw 8-5-2011 this is not used or needed see updateContainerBGImage()
function setBodyResizeHandler() {
var t = setTimeout("resetPageBottom()", 100);
}

function resetPageBottom() {
var containerElement = document.getElementById("dvMainBodyOverLay");
containerElement.style.backgroundImage = "none";
containerElement.style.backgroundPosition = "center bottom";
containerElement.style.backgroundImage = "url(/images/layout/mainBkgd-bottom-large.jpg)";
}
*/
