// JavaScript Document

/*!
 * BEGIN /web/fw/j/homepage_frag/_menu_tabs.js
 */
/*
 * Revision: 1.2 
 *
 * _menu_tabs.js: tabbed component
 */

//metrics setup
if (contenttype == "undefined") var contenttype="";
if (contentgroup == "undefined") var contentgroup="";
if (typeof(vs_pageview) == "undefined") var vs_pageview = function(){};
var vlc=0; // need to prevent logging of mousedowns

if (typeof (cdc) == "undefined") cdc = {};
if (typeof (cdc.homepage) == "undefined") cdc.homepage = {};
if (typeof (cdc.homepage.menutabs) == "undefined") cdc.homepage.menutabs = {

	// Triggers when the page loads.
	initTabs: function() {
		// find our tabsets on the page
		jQuery('#menu-products-tabset').each(function(){
			var tabset = this;
			var currTab = null;
			tabset.innerHTML+='<div class="tabset-extra"></div>';//extra div to carry CSS styles
			jQuery('.tab',tabset).each(function(idx){

				var ctr = this.parentNode;//.infotab-container
				var thisTab = this, thisId = this.id;
				var thisLink = thisTab.getElementsByTagName('a')[0];

				// make first tab active
				if (idx===0) {
					jQuery(ctr).addClass("infotab-active");
					vs_pageview(thisId,contentgroup,"tab",contenttype); // trigger pageview call on active tab
					currTab = thisTab;
				}

				// func to hide old tab and show new one
				var switcher = function(){
					if(currTab===thisTab){return;}
					currTab = thisTab;
					vs_pageview(thisId,contentgroup,"tab",contenttype);
					// display none/block set in css
					jQuery('.infotab-container',tabset).removeClass('infotab-active');
					jQuery(ctr).addClass('infotab-active');
					return;
				};

				// wire up events
				ctr.onmouseover = switcher;
				thisLink.onfocus = switcher;
//				thisLink.onclick = function(){return true;};
				thisTab.onclick = function(){return true;};

			}); // end processing tab
		}); // end processing tabset

		jQuery('#menu-services-tabset').each(function(){
			var tabset = this;
			var currTab = null;
			tabset.innerHTML+='<div class="tabset-extra"></div>';//extra div to carry CSS styles
			jQuery('.tab',tabset).each(function(idx){

				var ctr = this.parentNode;//.infotab-container
				var thisTab = this, thisId = this.id;
				var thisLink = thisTab.getElementsByTagName('a')[0];

				// make first tab active
				if (idx===0) {
					jQuery(ctr).addClass("infotab-active");
					vs_pageview(thisId,contentgroup,"tab",contenttype); // trigger pageview call on active tab
					currTab = thisTab;
				}

				// func to hide old tab and show new one
				var switcher = function(){
					if(currTab===thisTab){return;}
					currTab = thisTab;
					vs_pageview(thisId,contentgroup,"tab",contenttype);
					// display none/block set in css
					jQuery('.infotab-container',tabset).removeClass('infotab-active');
					jQuery(ctr).addClass('infotab-active');
					return;
				};

				// wire up events
				ctr.onmouseover = switcher;
				thisLink.onfocus = switcher;
				thisTab.onclick = function(){return false;};

			}); // end processing tab
		}); // end processing tabset


	} // end init function declaration;
} // end cdc.homepage.menutabs

jQuery('document').ready(cdc.homepage.menutabs.initTabs);
/*
 * END /web/fw/j/homepage_frag/_menu_tabs.js
 */
/*!
 * BEGIN /web/fw/j/homepage_frag/_sitenav.js
 */
/**
 * _sitenav.js
 *
 * Derived from CVS Revision: 1.3.4.6
 * DevKit Revision: 1.4 
 *
 * homepage fragment file, bundled into 'home.js'
 * site nav flydown code
 * depends upon: jQuery 1.2.6
 *
 */

/**
 * Cisco MegaMenu jQuery Plugin
 *
 * REQUIREMENTS:
 *   jQuery 1.2.6
 *
 * AUTHOR:
 *   Amit Asaravala for FivePaths
 */

var cmega_timer;
var cmega_last_opened;


(function($) { //protect jQuery $ namespace

$.fn.ciscomega = function(options) {
  //alert("merge?");
  var megamenuObj = $(this);

  //in FF3.6, we have a 1px shift bug when the window width isn't calculated
  // correctly at the beginning, so we shift if the window is an odd # of pixels
  //Note: mozilla gecko 1.9.2 = Firefox 3.6
  if($.browser.mozilla && parseFloat($.browser.version) >= 1.9 && /Windows/.test(navigator.userAgent)) {
    var matches = ($.browser.version).match(/1\.9\.(\d+)/);
	//alert($.browser.version);
	if(matches != null)
    if(matches[1] && parseInt(matches[1]) >= 2) {  //make sure it's greater than 1.9.2 = FF3.6
      var windowwidth = $(window).width();
      if(windowwidth %2 == 1) {
        $('html').css('margin-left', '-1px');
      }
    }
  }

  // Defaults:
  var config = {
    navWidth: 1002,            //The width in px of the full navbar.
                              // unfort we can't calculate this dynamically because some versions
                              // of Safari return 0. so let's set it explicitly as an option.
    tab: 'td',                //Selector to use for tabs
    container: '.cmega-pane', //Selector to use for tab content container
    showDelay: 300,           //Time in milliseconds to wait before showing a container.
                              // This only applies if coming from outside the tabs,
                              // not when going from tab to tab (which shows instantly.)
    fadeOutSpeed: 'slow',     //Speed at which menu is hidden.
                              // can be 'slow', 'medium', 'fast', or milliseconds
    fadeOutDelay: 250,        //Time in milliseconds to wait before fading out
    IEfadeOutDelay: 35,       //Time in milliseconds to wait before fading out in IE7+
    marginLeftOffset: 0,      //The number of pixels to shift menu containers left, if any.
                              // This can be handy for aligning the container with the left edge
                              // of the tab. Do not add 'px' -- use integers only.
    leftEdgePadding: 15,      //The number of px to leave between the left edge of the nav
                              // and the left edge of a container if it was pushed to the left
                              // but is not the leftmost container.
    rightEdgePadding: 15      //The number of px to leave between the right edge of the nav
                              // and the right edge of a container if it was pushed to the right
                              // but is not the rightmost container.
  }
  opts = $.extend(config, options);

  var containers = $(opts.container);
  var numContainers = containers.length;

  //
  // Now let's adjust the position of all the containers:
  //
  containers.each(function(idx) {
    var tab = $(this).parents(opts.tab);
    var tabpos = tab.position(); //top and left, relative to tab parent
    var tabwidth = tab.outerWidth();
    var contwidth = $(this).outerWidth();
    var contheight = $(this).outerHeight();
    var navwidth = opts.navWidth;
    var leftShift = 0;

    // do we want to force a container to justify with left tab edge?
    if( $(this).hasClass('cmega-left') ) {
      leftShift = 0;
    }

    // or do we want to force a container to justify with right tab edge?
    else if( $(this).hasClass('cmega-right') ) {
      leftShift = tabwidth - contwidth;
    }

    // or do we want to force a container to justify with center of the NAVBAR?
    else if( $(this).hasClass('cmega-center-nav') ) {
      leftShift = -(tabpos.left - ((navwidth - contwidth) / 2));
    }

    // or else by default we position center on the tab
    else {
      if (tabwidth < contwidth) {
        leftShift = -((contwidth / 2) - (tabwidth / 2));
      }
    }

    // make sure we don't shift past left boundary:
    if ( (leftShift + tabpos.left) < 0 ) {
      leftShift = -tabpos.left;
      // maintain extra 15px margin for all but first container:
      if(idx > 0) {
        leftShift += opts.leftEdgePadding;
      }
    }
    // make sure container doesn't flow off right boundary:
    else if( (leftShift + contwidth + tabpos.left) > navwidth ) {
      leftShift = -(tabpos.left + contwidth - navwidth);
      // maintain extra 15px margin for all but last container:
      if(idx < (numContainers - 1)) {
        leftShift -= opts.rightEdgePadding;
      }
    }

    $(this).css('margin-left', (leftShift + opts.marginLeftOffset) + 'px');

    var nocorners = $(this).hasClass('cmega-no-corners');
    if(!($.browser.msie && $.browser.version < 7)) { //all browsers but IE6
      // add shadows:
      $(this).after(
        '<div class="cmega-shadow">' +
          '<div class="cmega-shadow-inner">' +
            '<div class="cmega-shadow-piece cmega-shadow-ul"></div>' +
            '<div class="cmega-shadow-piece cmega-shadow-ur"></div>' +
            '<div class="cmega-shadow-piece cmega-shadow-cl"></div>' +
            '<div class="cmega-shadow-piece cmega-shadow-cr"></div>' +
            '<div class="cmega-shadow-piece cmega-shadow-bl"></div>' +
            '<div class="cmega-shadow-piece cmega-shadow-bc"></div>' +
            '<div class="cmega-shadow-piece cmega-shadow-br"></div>' +
          '</div>' +
        '</div>'
      );

      // add corners:
      if(!nocorners) {
        contheight += 6; //add 6px for corners

        $(this).append(
          '<div class="cmega-corner-bl"></div>' +
          '<div class="cmega-corner-bc"></div>' +
          '<div class="cmega-corner-br"></div>'
        ).css('height', contheight + 'px');

        // set width of bottom center space between corners. 12px = space for corners
        $(this).find('.cmega-corner-bc').css('width', (contwidth - 12) + 'px');

        // in IE7+ we need to include some special binary-transparency GIFs as corner
        //  backgrounds so we can switch to them right before the fadeOut beings:
        if($.browser.msie) {
          $(this).append(
            '<div class="cmega-ie-corner-bl"></div>' +
            '<div class="cmega-ie-corner-br"></div>'
          );
        }
      }

      var shadow = $(this).siblings('.cmega-shadow');
      shadow.css({
        width: (contwidth + 16) + 'px', //add extra width for shadow to appear on left and right
        height: (contheight + 16) + 'px', //extra height for shadow to appear below
        marginLeft: (leftShift + opts.marginLeftOffset - 8) + 'px' //8px = half of extra width (16px)
      });

      //inner shadow container, add 16px for bottom shadow:
      shadow.find('.cmega-shadow-inner').css('height', (contheight + 16) + 'px');
      //center left and center right shadows, subtract 15px for upper shadow corners
      shadow.find('.cmega-shadow-cl, .cmega-shadow-cr').css('height', (contheight - 15) + 'px');
      //bottom center space between corners, subt 6px on each side for corners:
      shadow.find('.cmega-shadow-bc').css('width', (contwidth - 12) + 'px');
    }

    //otherwise, in IE6 add padding to compensate for lack of corners --
    // unless the user has specified that this container should not have corners at all.
    // (i.e., in IE6, the "no corners" spec means don't add padding.)
    else if(!nocorners) {
      $(this).css('padding-bottom', (parseInt($(this).css('padding-bottom')) + 6) + 'px');
    }

  }); //end each

  //
  // Set up the mousenter (hover) event:
  //
  $(opts.tab).bind('mouseenter', function() {
    //first remove hover class from any other open tabs:
    megamenuObj.find(opts.tab).removeClass('hover');
    // hide all open containers. use "stop" to stop any existing fadeouts in their tracks
    megamenuObj.find(opts.container + ',.cmega-shadow').stop(true, true).hide()
    //then add a hover class to the tab that's been entered:
    $(this).addClass('hover');

    var wait_show = 1;
    //only apply a delay on showing container if we haven't come from another tab
    if(cmega_last_opened != 'tab') {
      wait_show = opts.showDelay;
    }
    cmega_last_opened = 'tab';

    //finally set a small delay before showing the container, per spec requirements:
    cmega_timer = setTimeout(function() {
      var tabhov = opts.tab + '.hover';

      // reset to the proper alpha-transparent corners in IE7+
      if($.browser.msie && $.browser.version >= 7) {
        megamenuObj.find(tabhov + ' .cmega-ie-corner-bl,' + tabhov + ' .cmega-ie-corner-br').hide();
        megamenuObj.find(tabhov + ' .cmega-corner-bl,' + tabhov + ' .cmega-corner-br').show();
      }
      // now show our container
      megamenuObj.find(tabhov + ' ' + opts.container + ',' + tabhov + ' .cmega-shadow').show();

    }, wait_show); //end timer declaration
  });  //end mousenter

  //
  // Set up the mouseleave event for when you leave the nav container completely:
  //
  megamenuObj.bind('mouseleave', function() {
    //cancel any existing timer so a container doesn't display at an inappropriate time:
    clearTimeout(cmega_timer);
    cmega_last_opened = null;

    // in IE, we can't fade out due to alpha PNG bug, so we first replace
    //  the corners with non-alpha corners and hide the other shadows:
    if($.browser.msie) {
      $(this).find('.cmega-corner-bl,.cmega-corner-br').hide();
      $(this).find('.cmega-ie-corner-bl,.cmega-ie-corner-br').show();
      $(this).find('.cmega-shadow').hide();
      $(this).find(opts.tab + '.hover').removeClass('hover');
      //we use a special (usually shorter) fadeout delay (IEfadeOutDelay) for IE7+
      if($.browser.version >= 7) {
        $(this).find(opts.container).ciscomega_delay(opts.IEfadeOutDelay).fadeOut(opts.fadeOutSpeed);
      }
      //use standard fadeout delay for IE6 since we don't show shadows anyway
      else {
        $(this).find(opts.container).ciscomega_delay(opts.fadeOutDelay).fadeOut(opts.fadeOutSpeed);
      }
    }
    else {
      $(this).find(opts.tab + '.hover').removeClass('hover');
      $(this).find(opts.container + ',.cmega-shadow')
        .ciscomega_delay(opts.fadeOutDelay).fadeOut(opts.fadeOutSpeed);
    }
  });

  // Handle keyboard navigation:
  // Keyboard navigation is based on tabbing from link to link, not from
  // <td> to <td>, so we need to treat that a little differently:
  $(opts.tab).children('a').focus(function(){
    $(this).parent().trigger('mouseenter');
  });
  // Special case of tabbing off last or first link in menu.
  // The keyboard nav code above won't fire in those cases so we
  //  need to explicitly listen for it and close all containers here:
  megamenuObj.find('a:last').blur(function() {
    megamenuObj.trigger('mouseleave');
  });

  return this; //return jquery object for further chaining

}; //end $.fn.ciscomega()


$.fn.ciscomega_delay = function(duration) {
  $(this).animate({ dummy: 1 }, duration);
  return this;
};


})(jQuery);

      jQuery(document).ready(function() {
        jQuery('.nav-container').ciscomega({
          tab: 'td',
          container: '.menuFrame',
          marginLeftOffset: -28,
          navWidth: 902,
          fadeOutDelay: 250,
          IEfadeOutDelay: 30,
          fadeOutSpeed: 250
        });
      });
/*
 * END /web/fw/j/homepage_frag/_sitenav.js
*/
/*
   // insert the takeover div into the DOM to appear after the IE conditional comments and before any body markup
   jQuery(document).ready(function() {
      jQuery('#gd-top').before(
         '<div id="displaybox" style="display: none; width:100%; height: 50%; position:absolute; top:0px; left:0px;"></div>' + "\n" +
         '<div id="container" style="position:absolute; top:0px; left:50%; margin-left:-1000px; width:902px; height:100%;">'
      );
   });

   // takeover toggle function; needs to be namespaced
   function takeoverExpand() {
      var thediv=document.getElementById('displaybox');
      var takeoverUrl='http://content.ogilvy.edgesuite.net/VideoWall/swf/takeover.swf?takeover_base=http://content.ogilvy.edgesuite.net/VideoWall/';

      if(thediv.style.display == "none"){
         $('#displaybox').css('height', ""+$(document).height()+"px");

         // add an ' ' for ie6, an odd bug where the object tag is only recognized by ie6 if html proceeds the object tag
         if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) {
            thediv.innerHTML = " ";
         }
         else {
            thediv.innerHTML = "";
         }

         thediv.innerHTML += "<object width='100%' height='100%'><param name='allowfullscreen' value='true' /><param name='quality' value='high'><param name='allowscriptaccess' value='always' /><param name='flashvars' value='localConnTime=" + flashTime + "'><param name='movie' value='../Cisco_files/" + takeoverUrl + "' /><param name='wmode' value='transparent' /><embed src='../Cisco_files/" + takeoverUrl + "' type='application/x-shockwave-flash' allowScriptAccess='always' quality='high' allowFullScreen='true' flashvars='localConnTime=" + flashTime + "' wmode='transparent' width='100%' height='100%'></embed></object>";
         thediv.style.display = "";
      }
      else {
         thediv.style.display = "none";
         thediv.innerHTML = '';
      }
      return false;
   }
*/
