Event.observe(window,'load', function() {

  if (Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6) {
    if ($$('#header .nav-learnMore')) {
      $$('#header .nav-learnMore').each(function(e) {
        e.observe('mouseenter', function(event) {
          this.addClassName('over');
        });
        e.observe('mouseleave', function(event) {
          this.removeClassName('over');
        });
      });
    }
  }

  /* fix focus state for header search form
	========================================================= */
	if ($('q')) {
		$('q').observe('focus', function(event) {
			this.up().addClassName('focus');
		});
    $('q').observe('blur', function(event) {
			this.up().removeClassName('focus');
		});
	};

  // print this page
  $$('.sharing .share_button_print').invoke('observe', 'click', function(event) {
    window.print();
    event.stop();
  });

  // live chat
  $$('.nav-liveChat a').invoke('observe', 'click', function(event) {
    var width  = 382;
    var height = 252;
    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2;

    _gaq.push(['_trackEvent', 'Live Chat', 'Launch Chat', 'Launch Chat']);

    newwin = window.open(this.href, "livechat", "status=no,toolbar=no,resizable=yes,scrollbars=1,width="+width+",height="+height);
    if (window.focus) {newwin.focus();}

    event.stop();
  });

  // disable call
  $$('.nav-contact a').invoke('observe', 'click', function(event) {
    event.stop();
  });

  // addthis share
  if (typeof addthis != 'undefined')
  {
    addthis.addEventListener('addthis.menu.share', function(event) {
      var data = event.data;

      _gaq.push(['_trackEvent', 'Social', 'Share', data.service]);
    });
  }

  // Follow links share
  $$('.social-links a').invoke('observe', 'click', function(event){
    var element = event.target;

    _gaq.push(['_trackEvent', 'Social', 'Follow', element.innerHTML]);
  });

  /**
   * Flyout: Request a Call
   */
  attachFlyoutBehaviours();
  (function() { Effect.toggle('flyout', 'appear', {duration: 0.3}); }).delay(5);
  
  Event.observe('flyout', 'click', function(event) {
    if(event.target == $('trigger-flyout-submit'))
    {
      event.stop();
      var form = this.down('form');

      new Ajax.Updater('flyout', form.action, {
        parameters: form.serialize(),
        evalScripts: true,
        onCreate: function() {
          form.down('img.ajax-loader').show();
        },
        onComplete: function() {
          attachFlyoutBehaviours();
        },
        on202: function() {
          _gaq.push(['_trackEvent', 'Request a Call', 'Popup Call Request', 'Popup Call Request']);
        }
      });
    }
  });
});

function attachFlyoutBehaviours()
{
  $$('.trigger-flyout-open').invoke('observe', 'click', function(event) {
    event.stop();
    var fly = $('flyout');

    if(fly.className == 'flyout-opened')
    {
      fly.removeClassName('flyout-opened');
    }
    else
    {
      fly.addClassName('flyout-opened');
      if(!$('request-pixel'))
      {
        var img = new Element('img', { src: 'http://pixel.everesttech.net/2984/t?ev_RequestACall=1', 'width': 1, 'height': 1, 'id': 'request-pixel'});
        $('flyout-content').down('p').insert(img);
      }
    }
  })
  
  $$('.trigger-flyout-close').invoke('observe', 'click', function(event) {
    event.stop();
    $('flyout').remove();
  })  
}

// Email protection
function u(a){var b=[],i=ac=c=c1=c2=0;while(i<a.length){c=a.charCodeAt(i);if(c<128){b[ac++]=String.fromCharCode(c);i++}else if((c>191)&&(c<224)){c2=a.charCodeAt(i+1);b[ac++]=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2}else{c2=a.charCodeAt(i+1);c3=a.charCodeAt(i+2);b[ac++]=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3}}return b.join('')}function d(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var c,o2,o3,h1,h2,h3,h4,bits,i=ac=0,dec="",tmp_arr=[];do{h1=b.indexOf(a.charAt(i++));h2=b.indexOf(a.charAt(i++));h3=b.indexOf(a.charAt(i++));h4=b.indexOf(a.charAt(i++));bits=h1<<18|h2<<12|h3<<6|h4;c=bits>>16&0xff;o2=bits>>8&0xff;o3=bits&0xff;if(h3==64){tmp_arr[ac++]=String.fromCharCode(c)}else if(h4==64){tmp_arr[ac++]=String.fromCharCode(c,o2)}else{tmp_arr[ac++]=String.fromCharCode(c,o2,o3)}}while(i<a.length);dec=tmp_arr.join('');dec=u(dec);return dec}function e(a){a=a.replace('--','==');a=a.replace('-','=');a=d(r(a));window.location=r('znvygb')+':'+a}function ri(){var a=new Array();var s="abcdefghijklmnopqrstuvwxyz";for(i=0;i<s.length;i++)a[s.charAt(i)]=s.charAt((i+13)%26);for(i=0;i<s.length;i++)a[s.charAt(i).toUpperCase()]=s.charAt((i+13)%26).toUpperCase();return a}function r(a){if(typeof rmap=='undefined')rmap=ri();s="";for(i=0;i<a.length;i++){var b=a.charAt(i);s+=(b>='A'&&b<='Z'||b>='a'&&b<='z'?rmap[b]:b)}return s}

