var interval;
var newsinterval;
var loadInterval;
var homeTimer = lockInterval = controlshidden = noloop = loadTimeout = 0;
var carouselStart = "";
var stopTicker = scrolling = playerReady = playerGotMeta = false;
//timers in milliseconds 
var pageLoadTimerDelay = 5000; //how long before the background changes after the home page is loaded
var inactivityTimerDelay = 10000; // 5000; //how long the mouse is inactive before the background changes
var transitionInterval = 4000; //time between switching backgrounds
var slideTimer = 100; //time it takes to slide menus
var fadeDuration = 600; //how long it takes for background and search to fade and for dienamic to retract
var menuTimeout = 500; //how long the mouse is outside of the menu before it closes.
var tickerScrollSpeed = 7000; //how long it takes for the last visible letter to scroll across the bottom of the screen

var isHTML5 = Framework.Video.HTML5Video.NO;
var INTEL_VIDEOPLAYER_ID = "IntelScalableFlashVideoPlayer";
var videoplayer;

var BrowserDetect = {
    init: function() {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function(data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1) return data[i].identity;
            } else if (dataProp) return data[i].identity;
            }
    },
    searchVersion: function(dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [{
            string: navigator.userAgent,
            subString: "Chrome",
            identity: "Chrome"
    }, {
        string: navigator.userAgent,
            subString: "OmniWeb",
            versionSearch: "OmniWeb/",
            identity: "OmniWeb"
        },
        {
            string: navigator.vendor,
            subString: "Apple",
            identity: "Safari",
            versionSearch: "Version"
    }, {
            prop: window.opera,
            identity: "Opera"
    }, {
            string: navigator.vendor,
            subString: "iCab",
            identity: "iCab"
    }, {
            string: navigator.vendor,
            subString: "KDE",
            identity: "Konqueror"
    }, {
            string: navigator.userAgent,
            subString: "Firefox",
            identity: "Firefox"
    }, {
            string: navigator.vendor,
            subString: "Camino",
            identity: "Camino"
    }, { // for newer Netscapes (6+)
            string: navigator.userAgent,
            subString: "Netscape",
            identity: "Netscape"
    }, {
            string: navigator.userAgent,
            subString: "MSIE",
            identity: "Explorer",
            versionSearch: "MSIE"
    }, {
            string: navigator.userAgent,
            subString: "Gecko",
            identity: "Mozilla",
            versionSearch: "rv"
    }, { // for older Netscapes (4-)
            string: navigator.userAgent,
            subString: "Mozilla",
            identity: "Netscape",
            versionSearch: "Mozilla"
    }],
    dataOS: [{
            string: navigator.platform,
            subString: "Win",
            identity: "Windows"
    }, {
            string: navigator.platform,
            subString: "Mac",
            identity: "Mac"
    }, {
            string: navigator.userAgent,
            subString: "iPhone",
            identity: "iPhone/iPod"
    }, {
            string: navigator.platform,
            subString: "Linux",
            identity: "Linux"
    }]

};
BrowserDetect.init();

if ((navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1)) {
    document.write('<link rel="stylesheet" type="text/css" href="/etc/designs/intel/us/en/css/intel.iOS.css" media="screen" />');
}

function HideHTML5Player() {
    document.getElementById('IntelScalableHTML5VideoPlayer').style.display = Framework.CSS.Display.NONE;
}

function ShowHTML5Player() {
    document.getElementById('IntelScalableHTML5VideoPlayer').style.display = Framework.CSS.Display.BLOCK;
}

function InitHtml5PlayerControls() {
    if (isHTML5) {
        document.getElementById('video-player-controls-container-1').style.display = Framework.CSS.Display.BLOCK;

        var playButton = new Framework.Controls.HTML5VideoPlayButton(document.getElementById('video-player-control-play'), videoplayer, true);
        var pauseButton = new Framework.Controls.HTML5VideoPauseButton(document.getElementById('video-player-control-pause'), videoplayer, true);
        var muteButton = new Framework.Controls.HTML5VideoMuteButton(document.getElementById('video-player-control-audible'), videoplayer, true);
        var unmuteButton = new Framework.Controls.HTML5VideoUnMuteButton(document.getElementById('video-player-control-muted'), videoplayer, true);
    }
}

function CheckPlayerOnLoad() {
    if (isHTML5 == Framework.Video.HTML5Video.NO) {
        // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
        var swfVersionStr = "10.0.0";

        // To use express install, set to expressInstall.swf, otherwise the empty string.
        var expressInstall = "/etc/designs/intel/us/en/flash/expressInstall.swf";

        var flashvars = {
            // video width and height should match the actual dimensions of the video.  Used by flash for scaling.
            videoWidth: 768,
            videoHeight: 432,
            videoPath: "",
            useFlashPlayerControls: true,
            debug: true
        };

        var params = {};
        params.quality = "high";
        params.bgcolor = "#ffffff";
        params.allowscriptaccess = "sameDomain";
        params.allowfullscreen = "true";
        params.wmode = "opaque";

        var attributes = {};
        attributes.id = "IntelScalableFlashVideoPlayer";
        attributes.name = "IntelScalableFlashVideoPlayer";

        swfobject.embedSWF("/etc/designs/intel/us/en/flash/IntelScalableVideoPlayer.swf", "videoFlashContent", "100%", "100%", swfVersionStr, expressInstall, flashvars, params, attributes);
    }
}
// --------------------------------- END Flash Player Setup -------------------------------------------------



// --------------------------------- Interact with the player via javascript ------------------------------------------------- 

var INTEL_VIDEOPLAYER_ID = "IntelScalableFlashVideoPlayer";

function intelVideoLoadVideo(path) {
    if (isHTML5 == Framework.Video.HTML5Video.YES) {
    	var fileExt = path.lastIndexOf(".");
    	var mp4AssetPath = path.substring(0, fileExt) + ".mp4";
        var m4vAssetPath = path.substring(0, fileExt) + ".m4v";
        var oggAssetPath = path.substring(0, fileExt) + ".ogv";
        var webmAssetPath = path.substring(0, fileExt) + ".webm";
        var jpgAssetPath = path.substring(0, fileExt) + ".jpg";
        $(videoplayer.VideoElement).attr("poster", jpgAssetPath);
        $(videoplayer.VideoElement).attr("preload","preload");
        $(videoplayer.VideoElement).attr("controls", "controls");
        $("#mp4").attr("src",mp4AssetPath);
        $("#ogg").attr("src",oggAssetPath);
        $("#webm").attr("src",webmAssetPath);
        if($.browser.mozilla == true){
            $(videoplayer.VideoElement).attr("src", oggAssetPath);
        } else if(Framework.IsiPad) {
            $(videoplayer.VideoElement).attr("src", m4vAssetPath);
            $("#mp4").attr("src",m4vAssetPath).attr("type","video/m4v");
        } else {
            console.log(mp4AssetPath);
            $(videoplayer.VideoElement).attr("src", mp4AssetPath);
        }
        videoplayer.VideoElement.load();
    } else {
        getFlashMovie(INTEL_VIDEOPLAYER_ID).loadVideo(path);
    }
}

function intelVideoPlay() {
    if (isHTML5 == Framework.Video.HTML5Video.YES) {
        videoplayer.Play();
    } else {
        getFlashMovie(INTEL_VIDEOPLAYER_ID).playVideo();
    }
}

function loadHomeVideo(path) {
    if (playerReady) {
        loadInterval = window.clearInterval(loadInterval);
        var delay = 3000 - loadTimeout;
        if (delay < 1) {
            delay = 1;
        }
        loadTimeout = 0;
        lockInterval = 1;
        if (homeTimer) {
            interval = window.clearTimeout(interval);
        }
        window.setTimeout(function() {
            var videoid = "#IntelScalableFlashVideoPlayer";
            if (isHTML5 == Framework.Video.HTML5Video.YES) {
                videoid = "#IntelScalableHTML5VideoPlayer";
                ShowHTML5Player();
            }
            $(videoid).show();
            try {
                intelVideoLoadVideo(path);
                intelVideoPlay();
                lockInterval = 1;
                if (homeTimer) {
                    interval = window.clearTimeout(interval);
                }
            } catch (err) {
                showHomeControls();
            }

        }, delay);

    } else {
        $("#IntelScalableFlashVideoPlayer, #IntelScalableHTML5VideoPlayer").hide();
        loadTimeout += 500;
        if (loadTimeout > 30000) {
            loadInterval = window.clearInterval(loadInterval);
            showHomeControls();            
        }
    }
}

function intelVideoPause() {
    if (isHTML5 == Framework.Video.HTML5Video.YES) {
        videoplayer.Pause();
    } else {
        getFlashMovie(INTEL_VIDEOPLAYER_ID).pauseVideo();
    }
}

function intelVideoMute() {
    if (isHTML5 == Framework.Video.HTML5Video.YES) {
        videoplayer.Muted(Framework.Video.HTML5VideoMuteState.MUTED);
    } else {
        getFlashMovie(INTEL_VIDEOPLAYER_ID).muteVideo();
    }
}

function intelVideoUnmute() {
    if (isHTML5 == Framework.Video.HTML5Video.YES) {
        videoplayer.Muted(Framework.Video.HTML5VideoMuteState.AUDIBLE);
    } else {
        getFlashMovie(INTEL_VIDEOPLAYER_ID).unmuteVideo();
    }
}

function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}



// ---------------------------------- Play State Event Callbacks ------------------------------------------------------------ 

function intelVideoReadyToRecieveCommands() {
    //console.log("player is ready to recieve javascript commands");
    playerReady = true;
}

function intelVideoConnected() {
    //console.log("video player connected");
}

function intelVideoComplete() {
    //console.log("video player complete");
    $("#video-preview-image").css("z-index", 1);
    $("#background-wrapper .background-item").show();
    $("#background-video-player").appendTo("#background-items"); 
    showHomeControls();
}

function intelVideoRecievedMetaData() {
    //console.log("video player got meta data");
    playerGotMeta = true;
}

function intelVideoMuted() {
    //console.log("video player muted");
}

function intelVideoUnMuted() {
    //console.log("video player unmuted");
}

function intelVideoPaused() {
    //console.log("video player paused");
    showHomeControls();
}

function intelVideoStopped() {
    //console.log("video player stopped");
    showHomeControls();
}

function intelVideoStarted() {
    //console.log("video player started");
    hideHomeControls();
    lockInterval = 1;
    if (homeTimer) {
        interval = window.clearTimeout(interval);
    }
}

function intelVideoProgress(percentageComplete, time, duration) {
    //console.log("video progress: " + percentageComplete + " time: " + time + " duration: " + duration);
}

$(function() {
/*----------------------------------- browser check and applying class name to body element -----------------------------------------*/
    var str=navigator.appVersion.toLowerCase().replace(/[^a-zA-Z 0-9 . / _]+/g,"").split(" ");var bN;var bV;var OS=str[1].substr(0,3);if($.browser.msie){bN="ie";OS=str[4].substr(0,3);bV=$.browser.version}if($.browser.opera){bN="opera";bV=$.browser.version.substr(0,4)}if($.browser.mozilla){var moz=navigator.userAgent.toLowerCase();moz=moz.replace(/[^a-zA-Z 0-9 . / _]+/g,"").split(" ");
    bN="ff";bV=moz[moz.length-1].split("/",2)[1].substr(0,3)}if($.browser.webkit){if(str[str.length-2].split("/",2)[0]==="chrome"){bN=str[str.length-2].split("/",2)[0];bV=str[str.length-2].split("/",2)[1].substr(0,4)}else if(str[str.length-2].split("/",2)[0]==="mobile"){bN=str[str.length-2].split("/",2)[0].substr(0,1)+"_"+str[str.length-1].split("/",2)[0];bV=str[6];if(str[1]==="ipad"){bV=str[5]}}else{bN=str[str.length-1].split("/",2)[0];bV=str[str.length-2].split("/",2)[1]}}$("body").addClass(OS+" "+bN+" "+bN+bV.replace(/[^0-9]+/g,"_"));
/*----------------------------------- end of browser check and applying class name to body element -----------------------------------------*/             
	
    var windowHeight = $(window).height();
    var windowWidth = $(window).width();
    var bandwidth = readCookie("detected_bandwidth");
    
    if ($("#home, .home").length > 0) {
        if (windowWidth > 1399 && bandwidth != "low" && bandwidth != "lo") {
            loadBackgrounds("hi");
        } else if (windowWidth > 1199 && windowWidth < 1399 && bandwidth != "low" && bandwidth != "lo") {
            loadBackgrounds("med");
        } else {
            loadBackgrounds("low");
        }
        //centerInParent("#home-copy", 88, 0);
        centerInParentX($("#background-wrapper img"));
        //        centerInPadding("#home-copy", 88, 60, 0, 60);
    }

    // clear input on focus (header search form) then return text if field is still empty on blur
    var clearMe = '';
    $('.clearOnFocus[title="password"], .clearOnFocus[title="Password"]').focus(function() {
        if ($(this).siblings().length > 0) {
            $(this).hide().siblings().removeClass("hidden").show();
        }
    });

    $('.clearOnFocus[type="password"]').blur(function() {
        if ($(this).siblings().length > 0 && $(this).val() == "") {
            $(this).hide().siblings().removeClass("hidden").show();
        }
    });

    $('.clearOnFocus').focus(function() {
        if ($(this).val() == $(this).attr('title')) {
            clearMe = $(this).val();
            $(this).val('');
        }
    });

    $('.clearOnFocus').blur(function() {
        if ($(this).val() == '') {
            $(this).val(clearMe);
        }
    });

    /*********************************************
    BEGIN HOME CODE
    *********************************************/
    /*
    if (!homeTimer) {
    homeTimer = 1;
    interval = window.setTimeout(nextBG, pageLoadTimerDelay);
    } else {
    interval = window.clearTimeout(interval);
    interval = window.setTimeout(nextBG, pageLoadTimerDelay);
    }
    */
    if ($("body#home, body.home").length > 0) {

        $("#background-wrapper img").load(function() {
            centerInParentX(this);
        });

        $(document).bind('mousemove', function(event) {
            if (!lockInterval && !noloop) {
                if (!homeTimer) {
                    homeTimer = 1;
                    interval = window.setTimeout('rotate()', inactivityTimerDelay);
                } else {
                    interval = window.clearTimeout(interval);
                    interval = window.setTimeout('rotate()', inactivityTimerDelay);
                }
            }
        });
    }
    $("#background-slider-items").width(77 * $(".slider-item").length); //wide enough to fit all images if they were all selected
    $("#background-chooser-toggle").click(function() {
        if (!$("#background-chooser").hasClass("closed")) {
            hideHomeControls();
        } else {
            showHomeControls();
        }
    });

    $(".slider-item").live("mouseenter", function() {
        $(this).attr("hasmouse", "true");
        if (!$(this).hasClass("selected")) {
            var selectedImage = $(this).attr("src");
            var dot = selectedImage.lastIndexOf('.');
            if (dot >= 0) {
                selectedImage = selectedImage.replace(".57.38", ".75.49");
            }
            $(this).attr("src", selectedImage);
            $(".slider-item.selected").css({
                width: 55,
                height: 36
            });
        }
    });

    $(".slider-item").live("mouseleave", function() {
        $(this).attr("hasmouse", "");
        var $this = $(this);
        if (!$(this).hasClass("selected")) {
            var selectedImage = $(this).attr("src");
            var dot = selectedImage.lastIndexOf('.75.49');
            if (dot >= 0) {
                selectedImage = selectedImage.replace(".75.49", ".57.38");
            }
            $(this).attr("src", selectedImage);
            if($(".slider-item.selected").length <= 0){
            	$(this).addClass("selected");
            }
            if (($(".slider-item.selected").position().left + $("#background-slider-items").position().left) >= 0) {
                $(".slider-item.selected").css({
                    width: '',
                    height: ''
                });
            }
        }
        window.setTimeout(function() {
            if ($(".tooltip-flyout").attr("hasmouse") != "true" && $this.attr("hasmouse") != "true") {
                hideTooltip();
            }
        }, 150);
    });
    /*********************************************
    END HOME CODE
    *********************************************/
    /*********************************************
    BEGIN MENU CODE
    *********************************************/

    $(".subheading.show-more").live("click", function() {
        $(this).parent().removeClass("collapsed");
        updateMenuHeight();
    });

    $(".subheading.show-less").live("click", function() {
        $(this).parent().addClass("collapsed");
        updateMenuHeight();
    });

    $(".directory").live("click mouseenter", function(event) {
        if (event.type == "click" && $(this).attr("hasmouse") == "true") {
            $(this).attr("hasmouse", "");
            closeNavMenu(1);
        } else {
            $(this).attr("hasmouse", "true");
            if (!$(this).find("a").hasClass("selected")) {
                $(".directory a, .sites a, .library a, .my-intel .link, .my-intel-link, .save").removeClass("selected");
                closeMyIntel();
                closeSigninBox();
                $(this).find("a").addClass("selected");
                $(this).addClass("selected");
                $("#menu-wrapper").show();
                $(".boxnav.navbg").slideDown(slideTimer, function() {
                	$('#subnav-wrapper, #submenu-wrapper').show();
                    $("#subnav-wrapper").css({
                        position: "fixed",
                        top: "61px"
                    	});
                    $('#subnav-wrapper ul.subnav').css('background-position', '-934px bottom');
                    $('#subnav-wrapper ul.subnav li:first-child').addClass('active');
                });
                updateMenuHeight();
                //closeNavMenu();
            }            
        }
    });
    
 // allow background image click
    $('a.home-img-link').click(function(e){
    	if($('.boxnav.navbg').is(':visible')){
    		$('a.home-img-link').css('cursor', 'auto');
    		return false;
    	}
    	else{
    		return true;
    	}
    });
    
    $("#close-menu").live("click", function(event) {
        closeNavMenu(1);
    });

    $(".subnavtext").each(function(index) {
        $(this).bind("click mouseenter", function(event) {
            $(this).attr("hasmouse", "true");
            var $this = $(this);
            var timeout = 1;
            if (event.type == "mouseenter") {
                timeout = 100;
            }
            window.setTimeout(function() {
                if (!$this.hasClass("active") && $this.attr("hasmouse") == "true") {
                    $(".subnavtext").removeClass("active");
                    $(".submenu").hide();
                    $(".submenu").eq(index).show();
                    $("#submenu-wrapper").slideDown(slideTimer, function() {
                        if ($this.attr("hasmouse") == "true") {
                            $(".subnavtext").removeClass("active");
                            $this.addClass("active");
                            updateMenuHeight();
                        }
                    });
                    closeNavMenu();
                }
            }, timeout);
        });
    });

    $(".subnavtext").live("mouseleave", function(event) {
        $(this).attr("hasmouse", "");
    });

    $(".boxnav, .directory").live("mouseenter", function(event) {
        $(this).attr("hasmouse", "true");
    });

    $(".boxnav, .directory").live("mouseleave", function(event) {
        $(this).attr("hasmouse", "");
        closeNavMenu();        
    });

    $("#menu-close-btn").live("click", function() {
        closeNavMenu(1, true);
    });

    $(".language").live("click", function() {
        $("#language-chooser").slideToggle(fadeDuration, function() {
            $("#language-chooser").toggleClass("hidden");
            $(".language").toggleClass("selected");
        });
    });


    $("#language-chooser .close-button").live("click", function() {
        closeLanguageMenu(1, true);
    });



    $(".tools").live("click", function(e) {
        e.preventDefault();
        $("#tools-chooser").slideToggle(fadeDuration, function() {
            $("#tools-chooser").toggleClass("hidden");
            $(".tools").toggleClass("selected");
        });
    });


    $("#tools-chooser .close-button").live("click", function() {
        closeToolsMenu(1, true);
    });
/*
    $("#tools-chooser ul img").hover(function(e) {
        var itemInfo = '#' + $(this).attr('class');
        var position = $(this).position();
        $(itemInfo).css({
            position: 'absolute',
            top: position.top + 45,
            left: position.left + 40
        }).show();
    }, function() {
        var itemInfo = '#' + $(this).attr('class');
        $(itemInfo).hide();
    });
*/
    $(".my-intel-link").bind("mouseenter", function(e) {
        $this = $(this);
        $this.attr("hasmouse", "true");
        var x = $this.offset().left + $this.outerWidth() / 2 * 0;
        var y = $this.offset().top + ($this.outerHeight() / 2);
        window.setTimeout(function() {
            if ($this.attr("hasmouse") == "true" && $(".tooltip-flyout").attr("hasmouse") != "true") {
                showTooltip($this.attr("alt"), $this);
            }
        }, 100);
    });

    $(".my-intel-link, .save").bind("mouseleave", function(e) {
        if (!($(e.target).hasClass("my-intel-link") || $(e.target).hasClass("save")) || true) {
            $(this).attr("hasmouse", "");
        }

        window.setTimeout(function() {
            if ($(".tooltip-flyout").attr("hasmouse") != "true" && $(".my-intel-link, .save").attr("hasmouse") != "true") {
                hideTooltip();
            }
        }, 150);

    });

    // Commented out on 7/17/11
    // $(".my-intel-link").one("click", function(e) { loadsso(ssoJsSrc); });
    function loadsso(src) {
        var scriptElem = document.createElement('script');
        scriptElem.setAttribute('src', src);
        scriptElem.setAttribute('type', 'text/javascript');
        document.getElementsByTagName('head')[0].appendChild(scriptElem);
    }

    $(".save, .my-intel-link").bind("click", function(e) {
        e.preventDefault();
        if ($(".my-intel-link, .save").hasClass("selected")) {
            closeMyIntel(1, true);
        } else {
            //saveHistory();
            closeSigninBox();
            $(".my-intel .link, .currentpage").removeClass("selected");
            $(".boxnav.myintelbg").slideDown(function() {
                $(".my-intel-link, .save").addClass("selected");
            });
        }
    });

    $(".create-btn").bind("click", function(e) {
        e.preventDefault();
        $(".register-myintel").addClass("boxnav myintelbg").removeClass("hidden").show();
        $(".savedcontent").addClass("hidden").removeClass("boxnav myintelbg").hide();
    });
    $(".register-myintel .cancel").bind("click", function(e) {
        e.preventDefault();
        $(".savedcontent").addClass("boxnav myintelbg").removeClass("hidden").show();
        $(".register-myintel").addClass("hidden").removeClass("boxnav myintelbg").hide();
    });

    $(".savedcontent .sign-in").live("click", function(e) {
        e.preventDefault();
        $(".savedcontent .navigationmyintelfirst ul.login").addClass("hidden").hide();
        $(".savedcontent .navigationmyintelfirst ul.profile").removeClass("hidden").show();
    });
    $(".savedcontent .log-out").live("click", function(e) {
        //e.preventDefault();
        $(".savedcontent .navigationmyintelfirst ul.profile").addClass("hidden").hide();
        $(".savedcontent .navigationmyintelfirst ul.login").removeClass("hidden").show();
    });

    $(".myintelbg .close-button, .myintel-close-btn").live("click", function() {
        closeMyIntel(1, true);
    });

    $(".searchmyintel li a").live("click", function(e) {
        e.preventDefault();
        $(".searchmyintel li a").removeClass("selected");
        $(this).addClass("selected");
        var index = $(".searchmyintel li a").index(this);
        $(".middlemyintel > div").removeClass("selected").addClass("hidden");
        $(".middlemyintel > div").eq(index).addClass("selected").removeClass("hidden");
    });

    $("#footnotes .close-button").live("click", function(e) {
        e.preventDefault();
        $(this).removeClass("close-button").addClass("open-button").parents(".module").addClass("closed").find(".module-content").slideUp();
    });

    $("#footnotes .open-button").live("click", function(e) {
        e.preventDefault();
        $(this).removeClass("open-button").addClass("close-button").parents(".module").removeClass("closed").find(".module-content").slideDown();
    });

    $(document).bind('click', function(event) {
        if ($(event.target).parents(".boxnav.navbg, .directory, .sites, .library, .background-slider-items").length == 0) {
            if (!$(event.target).hasClass("slider-item") || $(event.target).attr("hasmouse") != "true") { //keep nav menu from closing on background change
                closeNavMenu(1);
            }
        }
        if ($(event.target).parents(".menu-wrappermyintel, .savedcontent, .register-myintel, .my-intel-link, .save, .tooltip-flyout, .background-slider-items").length == 0 && !$(event.target).hasClass("savedcontent") && !$(event.target).hasClass("save") && !$(event.target).hasClass("my-intel-link") && !$(event.target).hasClass("register-myintel")) {
            if (!$(event.target).hasClass("slider-item") || $(event.target).attr("hasmouse") == "true") { //keep nav menu from closing on background change
                closeMyIntel(1);
            }
        }
        if ($(event.target).parents("#language-chooser, .language, .background-slider-items").length == 0 && !$(event.target).hasClass("language") && !$(event.target).hasClass("slider-item")) {
            closeLanguageMenu(1);
        }
        if ($(event.target).parents("#tools-chooser, .tools, .background-slider-items").length == 0 && !$(event.target).hasClass("tools") && !$(event.target).hasClass("slider-item")) {
            closeToolsMenu(1);
        }
        if ($(event.target).parents("#hpsform, .predictive-search, .background-slider-items").length == 0 && !$(event.target).hasClass("predictive-search") && !$(event.target).hasClass("slider-item")) {
            $('#hpsform .predictive-search').addClass('hideme');
            $('#searchBox').attr('value', $('#searchBox').attr('title'));
        }
        /* --------------------- Sigin Functionality -------------------------------*/
		if ($(event.target).parents(".signin-nav-box, .sign-in-link").length == 0 && !$(event.target).hasClass("signin-nav-box")) {
			closeSigninBox(1);
        }


    });
    //added for saved content navigation for myintel
    $('.searchmyintel li.savedCont a').mouseenter(
    function() {
        $('.recetlyViewedframe').hide();
        $('.savedframe').show();
    }, function() {
        $('.recetlyViewedframe').hide();
    });
    $('.searchmyintel li.recentViewed a').mouseenter(

    function() {
        $('.savedframe').hide();
        $('.recetlyViewedframe').show();
    }, function() {
        $('.recetlyViewedframe').hide();
        $('.savedframe').show();
    });
    /*********************************************
    END MENU CODE
    *********************************************/
    /*********************************************
    FOOTER CODE
    *********************************************/

    $("#footer .latest-news .toggle").live("click", function(e) {
        e.preventDefault();
        toggleFooterNews();
    });

    scrolling = false;

    if (newsinterval != undefined) {
        newsinterval = window.clearInterval(newsinterval);
    }
    newsinterval = window.setInterval(scrollTicker, tickerScrollSpeed);

    /*********************************************
    END FOOTER CODE
    *********************************************/

    $("#content").not(".home #content").css("min-height", ($(".boxnav.navbg").outerHeight() + 60) + "px");

    $(window).resize(function() {
        if ($(".filter-lists-container").length > 0) {
            matchHeights();
        }
        updateMenuHeight();

        if ($("body#home, body.home").length > 0) {
            centerInParentX($("#background-wrapper").find("img"));
        }
    });


    /*********************************************
    NAVIGATION MENUS WITH CARATS
    *********************************************/

    $("ul.subnav li.subnavtext").bind("click mouseenter", function(index) {
        var mywidth = $(this).outerWidth();
        var myoffset = $(this).position();

        var myx = Math.round(myoffset.left);
        var moveto = myx + Math.round(mywidth / 2) - 1000;

        var mybgpos = moveto + "px bottom";

        if(!$(this).children(".sign-in-link").length > 0 || $(this).children(".lock-icon").length > 0){
	    	$("ul.subnav").css("background-position", mybgpos);
		}
    });

    $("ul.subnav li.subnavtext").bind("mouseleave", function(index) {
        if ($("ul.subnav li.selected").length > 0) {
            var mywidth = $("ul.subnav li.selected").outerWidth();
            var myoffset = $("ul.subnav li.selected").position();

            var myx = Math.round(myoffset.left);
            var moveto = myx + Math.round(mywidth / 2) - 1000;

            var mybgpos = moveto + "px bottom";
            $("ul.subnav").css("background-position", mybgpos);
        }
    });
    /*
    this gets reset in:
    window.setTimeout()
    */

    $(".my-intel .link").bind("click mouseenter", function(index) {
        var mywidth = $(this).width();
        var myoffset = $(this).offset();

        var myx = Math.round(myoffset.left);
        var moveto = myx + Math.round(mywidth / 2) - 4000;

        if ($(this).is(".my-intel-link") || $(this).is(".save")) {
            moveto -= $("#my-intel-count").width();
        }

        var mybgpos = moveto + "px top";

        if(!$(this).parents(".sign-in-link").length > 0 || $(this).children(".lock-icon").length > 0){
	    	$(".home.wrapper #header").css("background-position", mybgpos);
		}
    });

    $(".my-intel .link").bind("mouseleave", function(index) {
        if ($(".my-intel .link.selected").length > 0) {
            var mywidth = $(".my-intel .link.selected").width();
            var myoffset = $(".my-intel .link.selected").offset();

            var myx = Math.round(myoffset.left);
            var moveto = myx + Math.round(mywidth / 2) - 4000;

            if ($(this).is(".my-intel-link") || $(this).is(".save")) {
                moveto -= $("#my-intel-count").width();
            }

            var mybgpos = moveto + "px top";

            $(".home.wrapper #header").css("background-position", mybgpos);
        } else {
            $(".home.wrapper #header").css("background-position", "");
        }
    });


    /*
     * added for carat for sign in link
     */

    $(".sign-in-link .link").live("click mouseenter", function (index) {
        var mywidth = $(this).width();
        var myoffset = $(this).offset();

        var myx = Math.round(myoffset.left);
        var moveto = myx + Math.round(mywidth / 2) - 4000;

        if ($(this).is(".sign-in-link")) {
            moveto -= $("#sign-in-link").width();
        }

        var mybgpos = moveto + "px top";
        if($(this).children(".down-arrow").length <= 0){
        	$(".wrapper #header").css("background-position", mybgpos);
        }        
    });

    $(".sign-in-link .link").live("mouseleave", function (index) {
        if ($(".my-intel .link.selected").length > 0) {
            var mywidth = $(".my-intel .link.selected").width();
            var myoffset = $(".my-intel .link.selected").offset();

            var myx = Math.round(myoffset.left);
            var moveto = myx + Math.round(mywidth / 2) - 4000;

            if ($(this).is(".sign-in-link")) {
                moveto -= $("#sign-in-link").width();
            }

            var mybgpos = moveto + "px top";

            $(".wrapper #header").css("background-position", mybgpos);
        } else {
            $(".wrapper #header").css("background-position", "");
        }
    });
    /*********************************************
    end NAVIGATION MENUS WITH CARATS
    *********************************************/

    /* home page new carousel */
    //var speed = 6000;
    //interval = setInterval('rotate()', transitionInterval);

    if (!noloop) {
        if (!homeTimer) {
            homeTimer = 1;
            interval = window.setTimeout('rotate()', transitionInterval);
        } else {
            interval = window.clearTimeout(interval);
            interval = window.setTimeout('rotate()', transitionInterval);
        }
    }
    $(".intel-search input").live("focus", function() {
        interval = window.clearTimeout(interval);
        lockInterval = true;
    });
    $(".intel-search input").live("blur", function() {
        if (!homeTimer) {
            homeTimer = 1;
            interval = window.setTimeout('rotate()', transitionInterval);
        } else {
            interval = window.clearTimeout(interval);
            interval = window.setTimeout('rotate()', transitionInterval);
        }
        lockInterval = false;
    });
    var wraper_width = $('#background-slider-items img').outerWidth();
    var elem_left = 0; //wraper_width * (-1)
    //$('#background-slider-items img:first').insertAfter($('#background-slider-items img:last'));

    $('#background-slider-items').css({
        'left': elem_left
    });

    //if user clicked on prev button
    $('#prev-arrow').click(function(event) {
        //prevent double clicking
        if (!event.detail || event.detail == 1) {
            event.preventDefault();
            var left_indent = parseInt($('#background-slider-items').css('left')) + wraper_width;
            var prevSlide = $(".slider-item.selected").prev(".slider-item");

            prevSlide.trigger("click");
            if ($(".background-slider-items img").length > 4) {
                $('#background-slider-items').animate({
                    'left': left_indent
                }, 'fast', function() {

                    $('#background-slider-items img:first').before($('#background-slider-items img:last'));
                    $('#background-slider-items').css({
                        'left': elem_left
                    });
                    if (!homeTimer) {
                        homeTimer = 1;
                        interval = window.setTimeout('rotate()', transitionInterval);
                    } else {
                        interval = window.clearTimeout(interval);
                        interval = window.setTimeout('rotate()', transitionInterval);
                    }
                });
            } else {
                $('#background-slider-items img:last').before($('#background-slider-items img:first'));
                $('#background-slider-items').css({ 'left': elem_left });
                if (!lockInterval && !noloop) {
                    if (!homeTimer) {
                        homeTimer = 1;
                        interval = window.setTimeout('rotate()', transitionInterval);
                    } else {
                        interval = window.clearTimeout(interval);
                        interval = window.setTimeout('rotate()', transitionInterval);
                    }
                }
            }
        }
        //cancel the link behavior           
        return false;
    });

    $('#next-arrow').click(function(event) {
        //prevent double clicking
        if (!event.detail || event.detail == 1) {
            event.preventDefault();
            var left_indent = parseInt($('#background-slider-items').css('left')) - wraper_width;
            var nextSlide = $(".slider-item.selected").next(".slider-item");
            if (carouselStart == "") {
                carouselStart = $.trim(nextSlide.attr("class"));
            } else if (carouselStart == $.trim(nextSlide.attr("class"))) {
                noloop = 1;
                lockInterval = 1;
                interval = window.clearInterval(interval);
            }
            nextSlide.trigger("click");
            if ($(".background-slider-items img").length > 4) {
                $('#background-slider-items').animate({
                    'left': left_indent
                }, 'fast', function() {
                    $('#background-slider-items img:last').after($('#background-slider-items img:first'));
                    $('#background-slider-items').css({
                        'left': elem_left
                    });
                    if (!lockInterval && !noloop) {
                        if (!homeTimer) {
                            homeTimer = 1;
                            interval = window.setTimeout('rotate()', transitionInterval);
                        } else {
                            interval = window.clearTimeout(interval);
                            interval = window.setTimeout('rotate()', transitionInterval);
                        }
                    }
                });
            } else {
                $('#background-slider-items img:last').after($('#background-slider-items img:first'));
                $('#background-slider-items').css({
                    'left': elem_left
                });
                if (!lockInterval && !noloop) {
                    if (!homeTimer) {
                        homeTimer = 1;
                        interval = window.setTimeout('rotate()', transitionInterval);
                    } else {
                        interval = window.clearTimeout(interval);
                        interval = window.setTimeout('rotate()', transitionInterval);
                    }
                }
            }
        }

        //cancel the link behavior
        return false;
    });

    //if mouse hover, pause the auto rotation, otherwise rotate it
    $('#background-slider-items img').hover(
        function() {
            clearTimeout(interval);
        }, function() {
            //interval = setInterval('rotate()', transitionInterval);
            if (!noloop) {
                if (!homeTimer) {
                    homeTimer = 1;
                    interval = window.setTimeout('rotate()', inactivityTimerDelay);
                } else {
                    interval = window.clearTimeout(interval);
                    interval = window.setTimeout('rotate()', inactivityTimerDelay);
                }
            }
    });

 // new ie drop shadow
	if(bN == 'ie' && bV <= '9.0'){
		$("#menu-wrapper").append("<div class='ie_shadow'></div>");
	}
    
    var covFlow = [];

    $('.background-item img').each(function() {
        imgWidth = $(this).attr("src");
        covFlow.push(imgWidth);
    });

    $(covFlow).preload();

    //new code for password in sign in
    var clrSgn = '';
    $('.clrSgn').live('focus', function () {
        if ($(this).val() == $(this).attr('title')) {
            clrSgn = $(this).val();
            $(this).val('');
            $(this).css({
                'color': '#000',
                'border-color': '#0071C5'
            });
        }
    });

    $('.clrSgn').live('blur', function () {
        if ($(this).val() == '') {
            $(this).val(clrSgn);
            $(this).css({
                'color': '#ccc',
                'border-color': '#8E8F8F'
            });
            }
        });
});

    $('.typTxt').show();
    $('.typPass').hide();

    $('.typTxt').live('focus click', function () {
        $(this).hide();
        $('.typPass').show();
        $('.typPass').css({
            'color': '#000',
            'border-color': '#0071C5'
                   });
        setTimeout(function() { $('.typPass').focus(); }, 10);
    });
    $('.typPass').live('blur', function () {
        if ($('.typPass').val() == '') {
            $('.typTxt').show();
            $('.typPass').hide();
            $('.typTxt').css({
                'color': '#ccc',
                'border-color': '#8E8F8F'
            });
        }
    });


/*------------------------------------------ close new sigin box ------------------------------------------*/
function closeSigninBox(duration, override) {
    if ($(".sign-in-link, .tooltip-flyout, .signin-nav-box").attr("hasmouse") != "true" || override) {
        $(".signin-nav-box").slideUp("fast", function () {
            $(".sign-in-link .link a").removeClass("selected");
            $(".currentpage").addClass("selected");
        });

        if ($(".sign-in-link .link.selected").length > 0) {
            var mywidth = $(".sign-in-link .link.selected").width();
            var myoffset = $(".sign-in-link .link.selected").offset();

            var myx = Math.round(myoffset.left);
            var moveto = myx + Math.round(mywidth / 2) - 4000;

            if ($(this).is(".sign-in-link") || $(this).is(".save")) {
                moveto -= $("#sign-in-link").width();
            }

            var mybgpos = moveto + "px top";

            $(".home.wrapper #header").css("background-position", mybgpos);
        } else {
            $(".home.wrapper #header").css("background-position", "");
        }

    }
}


//a timer will call this function, and the rotation will begin

function rotate() {
    $(".slider-item").removeClass("disabled");
    $('#next-arrow').click();
}

function changeBG(color, headlineColor, contentdiv, slideritem, headline, text, link, linktextColor, headlineCarat, linktextCarat) {
    if (!color) {
        var color = "#ffffff";
    }
    if (!contentdiv) {
        var contentdiv = "";
    }
    if (!headline) {
        var headline = "";
    }
    if (!text) {
        var text = "";
    }
    if (!link) {
        var link = "";
    }
    if(!headlineColor || headlineColor == "undefined" || headlineColor == "#"){
    	headlineColor="#ffffff";    	
    }else{	$("#home-copy h2").css('color', headlineColor);
    }
    
    if(!linktextColor || linktextColor == "undefined" || linktextColor == "#"){
    	linktextColor="#ffffff";
    }else{$("#home-copy h4").css('color', linktextColor)}
    
    
    if (slideritem && !$(slideritem).hasClass("selected") && !$(slideritem).hasClass("disabled")) {
        $(".slider-item").addClass("disabled");
        var selectedImage, dot;
        $(".slider-item.selected").css({
            width: '',
            height: ''
        });
        $(".slider-item").each(function(index) {
            if ($(this).hasClass("selected")) {
                $(this).removeClass("selected");
                var selectedImage = $(this).attr("src");
                var dot = selectedImage.lastIndexOf('.75.49');
                if (dot >= 0) {
                    selectedImage = selectedImage.replace(".75.49", ".57.38");
                }
                $(this).attr("src", selectedImage);
            }
        });
        selectedImage = $(slideritem).attr("src");
        dot = selectedImage.lastIndexOf('.');
        if (dot >= 0 && selectedImage.indexOf(".75.49") == -1) {
            selectedImage = selectedImage.replace(".57.38", ".75.49");
        }
        $(slideritem).attr("src", selectedImage).addClass("selected");
        var $oldItem = $("#background-wrapper").children();
        if ($(contentdiv).hasClass("background-video")) {
            //$("#" + INTEL_VIDEOPLAYER_ID).find("param[name=flashvars]").val("videoWidth=640&videoHeight=480&videoPath=" + $(content).attr("data") + "&useFlashPlayerControls=true&debug=true");
            if ($("#background-video-player .videoContainer img").length > 0) {
                $("#background-video-player .videoContainer img").attr("src", $(contentdiv).attr("still")).hide();
            } else {
                $("#background-video-player .videoContainer").prepend("<img alt='' src='" + $(contentdiv).attr("still") + "' />");
            }
            //            $("#background-video-player").hide().css("background-color", color).prependTo($("#background-wrapper")).fadeIn(fadeDuration, function() {
            $("#background-video-player").hide().css("background-color", color).prependTo($("#background-wrapper")).fadeIn(1, function() {
                $("#background-video-player").show();
                if ($(contentdiv).hasClass("background-video")) {
                    // --------------------------------- Resizing Static Image with Constant Aspect Ratio Setup -------------------------------------------------
                    var resizingImageBackground = new Framework.Controls.ResizingBackground(document.getElementById('video-preview-image'), new Framework.Drawing.Dimension(1593, 894));
                    resizingImageBackground.MinimumWidth = 1034;
                    resizingImageBackground.MinimumHeight = 784;
                    resizingImageBackground.ResizeBackground();
                    // --------------------------------- End Resizing Static Image with Constant Aspect Ratio Setup -------------------------------------------------

                    if (isHTML5 == Framework.Video.HTML5Video.YES) {
                        // --------------------------------- HTML5 Player Setup ------------------------------------------------- 
                        var resizingVideoBackground = new Framework.Controls.ResizingBackground(document.getElementById('IntelScalableHTML5VideoPlayer'), new Framework.Drawing.Dimension(720, 404));
                        resizingVideoBackground.MinimumWidth = 1024;
                        resizingVideoBackground.MinimumHeight = 768;
                        resizingVideoBackground.ResizeBackground();


                        //var videoplayer = new Framework.Controls.HTML5VideoPlayer(document.getElementById('IntelScalableHTML5VideoPlayer'));
                        isHTML5 = !!videoplayer.CanPlayType ? Framework.Video.HTML5Video.YES : Framework.Video.HTML5Video.NO;
                        if (Framework.IsIE6() || Framework.IsIE7() || Framework.IsIE8() || Framework.IsSafari()) { isHTML5 = Framework.Video.HTML5Video.NO; }
                        if (Framework.IsiPad()) { isHTML5 = Framework.Video.HTML5Video.YES; }
                    }
                    lockInterval = 1;
                    if (homeTimer) {
                        interval = window.clearTimeout(interval);
                    }
                    $("#background-video-player .videoContainer img").show();
                    $.ajax({
                        url: $(contentdiv).attr("data"),
                        type: 'HEAD',
                        error:
                        function() {
                            loadInterval = window.clearInterval(loadInterval);
                            showHomeControls();
                            if (isHTML5 == Framework.Video.HTML5Video.YES) {
                                $("#IntelScalableHTML5VideoPlayer").hide();
                            } else {
                                $("#IntelScalableFlashVideoPlayer").hide();
                            }
                        },
                        success: function () { 
                            if (isHTML5 == Framework.Video.HTML5Video.YES) {                            	
                                $("#IntelScalableHTML5VideoPlayer").show();
                                intelVideoLoadVideo($(contentdiv).attr("data"));
                                hideHomeControls();
                                intelVideoPlay();
                            } else {
                                loadInterval = window.setInterval(function () {                               
                                	loadHomeVideo($(contentdiv).attr("data"));
                                }, 500);
                            }
                        }
                    });

                } else if (controlshidden) {
                    showHomeControls();
                }
            });
            if (isHTML5 != Framework.Video.HTML5Video.YES) {
                $(contentdiv).hide().css("background-color", color).prependTo($("#background-wrapper")).fadeIn(fadeDuration);
            } else {
            	$(contentdiv).hide().css("background-color", color).appendTo($("#background-wrapper")).fadeIn(fadeDuration);
            }
            $("#background-wrapper").animate({
                backgroundColor: color
            }, fadeDuration, function() {
                $("#background-wrapper").css("background-color", color);
            });
            //centerInParent($("#background-video-player"));
        } else {
            $(contentdiv).hide().css("background-color", color).prependTo($("#background-wrapper")).fadeIn(fadeDuration);
            $("#background-wrapper").animate({
                backgroundColor: color
            }, fadeDuration, function() {
                $("#background-wrapper").css("background-color", color);
            });
            //centerInParent($(contentdiv));
        }
        
        $("#background-wrapper").animate({
            backgroundColor: color
        }, fadeDuration, function() {
            $("#background-wrapper").css("background-color", color);
        });
        centerInParentX($("#background-wrapper").find("img"));
        $oldItem.fadeOut(fadeDuration, function() {
            $oldItem.appendTo("#background-items");
            $(".slider-item").removeClass("disabled");
            $("body, #content").css("background-color", color);
        });
        
        if (headline != "") {
        	if (headlineCarat != "")
                $("#home-copy h2").html(headline + "<span style='color:"+ headlineColor +" !important;' class = 'caret'>&gt;</span>");
        	else
        		$("#home-copy h2").html(headline);
        	
        	if (linktextCarat != "")
                $("#home-copy h4").html(text + "<span class = 'caret'>&gt;</span>");
        	else
        		$("#home-copy h4").html(text);
        	
        	
            //$("#home-copy h4").text(text);
            $("#background-chooser").find("a#home-copy").attr("href", link);
        }
    }
    //centerInParent("#home-copy", 88, 0);
}

function hideHomeControls() {
    $("#background-chooser").animate({
        left: -560
    }, 'slow').addClass("closed");
    if($("#home-search").length > 0){
    	$("#home-search").fadeOut(fadeDuration);
    }
    controlshidden = 1;
}

function showHomeControls() {
    $("#background-chooser").animate({
        left: 0
    }, 'slow').removeClass("closed");
    if($("#home-search").length > 0){
    	$("#home-search").fadeIn(fadeDuration);
    }
    lockInterval = 0;
   if (!noloop) {
        if (!homeTimer) {
            homeTimer = 1;
            interval = window.setTimeout('rotate()', transitionInterval);
        } else {
            interval = window.clearTimeout(interval);
            interval = window.setTimeout('rotate()', transitionInterval);
        }
    }
}

function centerInParent(element, topOffset, leftOffset) {
    if (!topOffset) {
        var topOffset = 0;
    }
    if (!leftOffset) {
        var leftOffset = 0;
    }
    $(element).css({
        position: 'absolute',
        top: 0,
        left: 0
    });
    var maxWidth = $(element).parent().outerWidth() - (leftOffset);
    var maxHeight = $(element).parent().outerHeight() - (topOffset);
    var elementTop = (maxHeight - $(element).innerHeight()) / 2;
    var elementLeft = (maxWidth - $(element).innerWidth()) / 2;

    $(element).css({
        position: 'absolute',
        top: elementTop,
        left: elementLeft
    });
}

function centerInParentX(element, topOffset, leftOffset) {
    if (!topOffset) {
        var topOffset = 0;
    }
    if (!leftOffset) {
        var leftOffset = 0;
    }
    $(element).css({
        position: 'absolute',
        top: 0,
        left: 0
    });
    var maxWidth = $(element).parent().outerWidth() - (leftOffset);
    var maxHeight = $(element).parent().outerHeight() - (topOffset);
    var elementTop = topOffset;
    var elementLeft = (maxWidth - $(element).innerWidth()) / 2;

    $(element).css({
        position: 'absolute',
        top: elementTop,
        left: elementLeft
    });
}

function centerInPadding(element, topOffset, leftOffset, addedTop, addedLeft) {
    if (!topOffset) {
        var topOffset = 0;
    }
    if (!leftOffset) {
        var leftOffset = 0;
    }
    if (!addedTop) {
        var addedTop = 0;
    }
    if (!addedLeft) {
        var addedLeft = 0;
    }

    $(element).css({
        //position: 'absolute',
        paddingTop: 0,
        paddingLeft: 0,
        paddingBottom: 0
    });

    var maxWidth = $(element).parent().outerWidth() - (leftOffset);
    var maxHeight = $(element).parent().outerHeight() - (topOffset);
    var elementTop = (maxHeight - $(element).innerHeight()) / 2;
    var elementLeft = (maxWidth - $(element).innerWidth()) / 2;
    var elementBottom = elementTop;

    $(element).css({
        //position: 'absolute',
        paddingTop: elementTop + addedTop,
        paddingLeft: elementLeft + addedLeft,
        paddingBottom: elementBottom
    });
}

function closeMyIntel(duration, override) {
    if ($(".boxnav.myintelbg, .tooltip-flyout, .save, .my-intel-link").attr("hasmouse") != "true" || override) {
        $(".boxnav.myintelbg").slideUp("fast", function () {
            $(".my-intel-link, .save").removeClass("selected");
            $(".currentpage").addClass("selected");
            $(".register-myintel").removeClass("boxnav myintelbg").addClass("hidden");
            $(".savedcontent").addClass("boxnav myintelbg");

            if ($(".my-intel .link.selected").length > 0) {
                var mywidth = $(".my-intel .link.selected").width();
                var myoffset = $(".my-intel .link.selected").offset();

                var myx = Math.round(myoffset.left);
                var moveto = myx + Math.round(mywidth / 2) - 4000;

                if ($(this).is(".my-intel-link") || $(this).is(".save")) {
                    moveto -= $("#my-intel-count").width();
                }

                var mybgpos = moveto + "px top";

                $(".home.wrapper #header").css("background-position", mybgpos);
            } else {
                $(".home.wrapper #header").css("background-position", "");
            }
        });
    }
}

function closeNavMenu(timeout, override) {
    if (!timeout) {
        var timeout = menuTimeout;
    }
    if (!override) {
        var override = false;
    }
    if (override) {
        $(".subnavtext").removeClass("active");
        $(".directory, .directory a, .sites a, .library a").removeClass("selected");
        $("#submenu-wrapper").slideUp(slideTimer);
        $(".boxnav.navbg").slideUp(slideTimer, function () {
            updateMenuHeight();
            $("#menu-wrapper").hide();
            if (!$(".my-intel-link, .save").hasClass("selected")) {
                $(".currentpage").addClass("selected");
            }
            $('a.home-img-link').css('cursor', 'pointer');
        });
        return;
    }
    window.setTimeout(function () {
        if ($(".boxnav.navbg").attr("hasmouse") != "true" && $(".directory").attr("hasmouse") != "true") {
            $(".subnavtext").removeClass("active");
            $(".directory, .directory a, .sites a, .library a").removeClass("selected");
            $("#submenu-wrapper").slideUp(slideTimer);
            $(".boxnav.navbg").slideUp(slideTimer, function () {
                updateMenuHeight();
                $("#menu-wrapper").hide();
                if (!$(".my-intel-link, .save").hasClass("selected")) {
                    $(".currentpage").addClass("selected");
                }

                /* reset the background-position    */
                $("ul.subnav").css("background-position", "left bottom");
                $('a.home-img-link').css('cursor', 'pointer');
            });
        }
    }, timeout);
    
}

function updateMenuHeight() {
    $(".navright, .home #content, body").css("min-height", "");
    if ($("#submenu-wrapper:visible").length > 0) {
        $("#content").css("min-height", ($(".boxnav.navbg").outerHeight() + 60) + "px");
        $("body").css("min-height", ($(".boxnav.navbg").outerHeight() + 65) + "px");
        $(".navright, .navigation").css("min-height", "").css("min-height", ($(".boxnav.navbg").innerHeight() - 135));
        $("#background-player, #background-wrapper").height($("body").innerHeight());
        $(".ie_shadow").css("min-height","").css("min-height", ($(".boxnav.navbg").innerHeight() - 45)).show(); //added for shadow in ie
    } else {
		$(".ie_shadow").hide().css("min-height", ""); //added for shadow in ie
        $("body, .home #content, #background-player, #background-wrapper, .navright, .navigation").css("min-height", "");
        $("#background-player, #background-wrapper").height($(".home.wrapper").innerHeight());
    }
}

function toggleFooterNews() {
    if ($("#footer .latest-news a").hasClass("open")) {
        stopTicker = true;
        $(".news-items").stop().css({
            left: ""
        });
        window.clearInterval(newsinterval);
        $("#footer .latest-news").animate({
            width: 68
        }, 'fast', function() {
            $("#footer .latest-news").addClass("closed")
        });
        $("#footer .latest-news a").removeClass("open");
    } else {
        if (newsinterval != undefined) {
            newsinterval = window.clearInterval(newsinterval);
        }
        newsinterval = window.setInterval(scrollTicker, tickerScrollSpeed);
    }
}

function closeLanguageMenu() {
    $("#language-chooser").slideUp(fadeDuration);
    $(".language").removeClass("selected");
}

function closeToolsMenu() {
    $("#tools-chooser").slideUp(fadeDuration);
    $(".tools").removeClass("selected");
}

function nextCarousel(container, carousel) {
    if ($(container).find(".carousel-item.active").length > 0) {
        $(container).find(".carousel-item").not(".active").css({
            left: $(container).innerWidth()
        });
        var carouselItemPrev = $(container).find(".carousel-item.active");
        carouselItemPrev.css({
            left: 0
        });
        var carouselDotNext = $(carousel).find(".carousel-dot.active").next(".carousel-dot");
        if (carouselDotNext.length == 0) {
            carouselDotNext = $(carousel).find(".carousel-dot").first();
        }
        var carouselItemNext = $(container).find(".carousel-item.active").next(".carousel-item");
        if (carouselItemNext.length == 0) {
            carouselItemNext = $(container).find(".carousel-item").first();
        }
        $(carousel).find(".carousel-dot").removeClass("active");
        $(carouselDotNext).addClass("active");
        if ($(carousel).find(".carousel-dot.active").prev(".carousel-dot").length == 0) {
            $(carousel).find('.carousel-left').css("visibility", "hidden");
        } else {
            $(carousel).find('.carousel-left').css("visibility", "");
        }
        if ($(carousel).find(".carousel-dot.active").next(".carousel-dot").length == 0) {
            $(carousel).find('.carousel-right').css("visibility", "hidden");
        } else {
            $(carousel).find('.carousel-right').css("visibility", "");
        }
        $(container).find(".carousel-item").css("z-index", "0").removeClass("active");
        carouselItemNext.css("z-index", "1");
        carouselItemPrev.animate({
            left: -730
        }, 500);
        carouselItemNext.animate({
            left: 0
        }, 500, function () {
            $(container).find(".carousel-item").not(carouselItemNext).removeClass("active").css({
                left: $(container).innerWidth()
            });
            carouselItemNext.addClass("active");
        });
    }
}

function prevCarousel(container, carousel) {
    if ($(container).find(".carousel-item.active").length > 0) {
        $(container).find(".carousel-item").not(".active").css({
            left: -$(container).innerWidth()
        });
        var carouselItemPrev = $(container).find(".carousel-item.active");
        carouselItemPrev.css({
            left: 0
        });
        var carouselDotNext = $(carousel).find(".carousel-dot.active").prev(".carousel-dot");
        if (carouselDotNext.length == 0) {
            carouselDotNext = $(carousel).find(".carousel-dot").last();
        }
        var carouselItemNext = $(container).find(".carousel-item.active").prev(".carousel-item");
        if (carouselItemNext.length == 0) {
            carouselItemNext = $(container).find(".carousel-item").last();
        }
        $(carousel).find(".carousel-dot").removeClass("active");
        $(carouselDotNext).addClass("active");
        if ($(carousel).find(".carousel-dot.active").prev(".carousel-dot").length == 0) {
            $(carousel).find('.carousel-left').css("visibility", "hidden");
        } else {
            $(carousel).find('.carousel-left').css("visibility", "");
        }
        if ($(carousel).find(".carousel-dot.active").next(".carousel-dot").length == 0) {
            $(carousel).find('.carousel-right').css("visibility", "hidden");
        } else {
            $(carousel).find('.carousel-right').css("visibility", "");
        }
        $(container).find(".carousel-item").css("z-index", "0").removeClass("active");
        carouselItemNext.css("z-index", "1");
        carouselItemPrev.animate({
            left: 730
        }, 500);
        carouselItemNext.animate({
            left: 0
        }, 500, function () {
            $(container).find(".carousel-item").not(carouselItemNext).removeClass("active").css({
                left: -$(container).innerWidth()
            });
            carouselItemNext.addClass("active");
        });
    }
}

function scrollTicker() {
    if ((stopTicker != undefined && stopTicker) || scrolling) {
        return false;
    }
    scrolling = true;
    var currentItem = $("#footer .latest-news .news-item.selected").show();
    var nextItem = currentItem.next(".news-item");
    if (currentItem.next(".news-item").length <= 0) {
        nextItem = $("#footer .latest-news .news-item:first");
    }
    currentItem.fadeOut('fast', function() {
        currentItem.removeClass("selected");
        nextItem.fadeIn('fast', function() {
            nextItem.addClass("selected");
            stopTicker = false;
            scrolling = false;
        });
    });
}

function createTooltip(text) {
    var tooltipHTML = '<div class="tooltip-flyout hidden">';
    tooltipHTML += '<div class="top">';
    tooltipHTML += '<div class="right"></div>';
    tooltipHTML += '</div>';
    tooltipHTML += '<div class="middle">';
    tooltipHTML += '<div class="right">';
    tooltipHTML += '<div class="content">';
    tooltipHTML += '<p>' + text + '</p>';
    tooltipHTML += '</div>';
    tooltipHTML += '</div>';
    tooltipHTML += '</div>';
    tooltipHTML += '<div class="bottom">';
    tooltipHTML += '<div class="right"></div>';
    tooltipHTML += '</div>';
    tooltipHTML += '</div>';
    $('body').append(tooltipHTML);

    $(".tooltip-flyout").live("mouseenter", function (e) {
        $(this).attr("hasmouse", "true");
    });

    $(".tooltip-flyout").live("mouseleave", function (e) {
        $(this).attr("hasmouse", "");
        window.setTimeout(function () {
            hideTooltip();
        }, 100);
    });
    $(".tooltip-flyout").live("click", function (e) {
        $(this).attr("hasmouse", "");
        hideTooltip();
    });
}

function showTooltip(text, posx, posy) {
    if (!posx && !posy) {
        var posx = 0;
        var posy = 0;
        if (!e) var e = window.event;
        if (e.pageX || e.pageY) {
            posx = e.pageX;
            posy = e.pageY;
        } else if (e.clientX || e.clientY) {
            posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
            posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
        }
    } else if (!posy) {
        var $this = $(posx);
        var posx = $this.offset().left + $this.outerWidth() / 4;
        var posy = $this.offset().top + ($this.outerHeight() / 2);
        $(".tooltip-flyout").die("click");
        $(".tooltip-flyout").live("click", function (e) {
            //$this.trigger("click");
            $(".tooltip-flyout").attr("hasmouse", "");
            hideTooltip();
        });
    }

    if ($(".tooltip-flyout").length < 1) {
        createTooltip(text);
    } else {
        $(".tooltip-flyout .content p").text(text);
    }
    $(".tooltip-flyout").offset({
        top: 0,
        left: 0
    });

    //set the bottom left corner of the tooltip to the center of the anchor
    $(".tooltip-flyout").removeClass("hidden").show();
    var left = posx - $(".tooltip-flyout").outerWidth() - 30;
    var top = posy + ($(".tooltip-flyout").outerHeight() / 3);
    if (top < 50) {
        top = 50;
    }
    if (left < 0) {
        left = 0;
    }
    $(".tooltip-flyout").css({
        top: top + "px",
        left: left + "px"
    });
}

function hideTooltip() {
    if ($(".tooltip-flyout").attr("hasmouse") != "true") {
        $(".tooltip-flyout").addClass("hidden").hide();
    }
}

function toggleChat() {
    $("#lpInvite").slideToggle();
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function setAgnosticCookie() {
    if (readCookie("usertype") == null) {
        createCookie("usertype", "agnostic", 60);
        setNavClassFromCookie();
    }
}

function setNavClassFromCookie() {
    var usertype = readCookie("usertype");
    if (usertype == "business") {
        $(".boxnav.navbg").addClass("business").removeClass("consumer");
        if ($(".slider-item.work").length > 0) {
            $(".slider-item.work").first().trigger("click");
        }
    } else {
        $(".boxnav.navbg").addClass("consumer").removeClass("business");
        if ($(".slider-item.home").length > 0) {
            $(".slider-item.home").first().trigger("click");
        }
    }
}

function showPeekaboo() {
    if (readCookie("usertype") == null) {
        return true;
    } else {
        return false;
    }
}

function ShowLoadingIcon() {
    document.getElementById('video-loading-icon').style.display = Framework.CSS.Display.BLOCK;
}

function HideLoadingIcon() {
    document.getElementById('video-loading-icon').style.display = Framework.CSS.Display.NONE;
}

function loadBackgrounds(size) {
    $(".background-item").each(function(index) {
        var res = "";

        var src = $(this).attr("data");
        if (src != "" && src != undefined) {
            var x = src.lastIndexOf(".");
            var suffix = src.substring(x);
            var imgName = src.substring(0, x);
            switch (size) {
                case "hi":
                case "high":
                    res = imgName + "_large" + suffix;
                    break;
                case "med":
                case "medium":
                    res = imgName + "_med" + suffix;
                    break;
                case "novideo":
                    $(".background-video").hide();
                case "lo":
                case "low":
                default:
                    res = imgName + "_low" + suffix;
                    break;
            }

            var alt = $(this).attr("data-alt");
            if (src == undefined || src == null || src == "") {
                return;
            }
            if ($(this).hasClass("background-video")) {
                res = $(this).attr("still");
            }
            if ($(this).find("img").length > 0) {
                $(this).find("img").attr("src", res).attr("alt", alt);
            } else if($(this).children('a').length > 0){
                $(this).children('a').append("<img src='" + res + "' alt='" + alt + "' />");
            } else {
                $(this).append("<img src='" + res + "' alt='" + alt + "' />");
            }
        }
    });

    videoplayer = new Framework.Controls.HTML5VideoPlayer(document.getElementById('IntelScalableHTML5VideoPlayer'));
    isHTML5 = !!videoplayer.CanPlayType ? Framework.Video.HTML5Video.YES : Framework.Video.HTML5Video.NO;
    if (Framework.IsIE6() || Framework.IsIE7() || Framework.IsIE8() || Framework.IsSafari()) { isHTML5 = Framework.Video.HTML5Video.NO; }
    if (Framework.IsiPad()) { isHTML5 = Framework.Video.HTML5Video.YES; }

    videoplayer.RegisterEventHandler(new Framework.CustomEventHandler('PlayerLoadStartEventHandler1',
    Framework.Video.HTML5VideoEvent.LOAD_START,
    function() { InitHtml5PlayerControls(); }));

    videoplayer.RegisterEventHandler(new Framework.CustomEventHandler('VideoStartHandler1',
    Framework.Video.HTML5VideoEvent.PLAY,
    function() { ShowHTML5Player(); ShowLoadingIcon(); console.log("Video Started "); }));

    videoplayer.RegisterEventHandler(new Framework.CustomEventHandler('VideoPauseHandler1',
    Framework.Video.HTML5VideoEvent.PAUSE,
    function () { }));
    
    videoplayer.RegisterEventHandler(new Framework.CustomEventHandler('VideoCompleteHandler1',
    Framework.Video.HTML5VideoEvent.ENDED,
    function() { console.log('media end'); 
    	videoplayer.ResetMedia();
    	intelVideoComplete();
    })); 

    videoplayer.RegisterEventHandler(new Framework.CustomEventHandler('VideoCanPlayHandler1',
    Framework.Video.HTML5VideoEvent.PLAYING,
    function () { HideLoadingIcon(); console.log("Video can play"); }));
    // --------------------------------- End HTML5 Player Setup ------------------------------------------------- 

    // --------------------------------- Flash Player Setup -------------------------------------------------
    Framework.AddHandler(window, Framework.Events.WindowEvents.LOAD, function() { CheckPlayerOnLoad(); });
    // --------------------------------- End Flash Player Setup -------------------------------------------------
    
}

function setConsumerCookie() {
    createCookie("usertype", "consumer", 60);
    setNavClassFromCookie();
}

function setBusinessCookie() {
    createCookie("usertype", "business", 60);
    setNavClassFromCookie();
}

$.fn.preload = function() {
    this.each(function() {
        var imageObject = new Image();
        imageObject.src = this;
    });
}
