﻿$(document).ready(function() {

  $(document).ready(function() {
    $('ul.sf-menu').superfish({
			hoverClass: 'hover',
      onBeforeShow: function() {
        var nih = $(this).parent().height();
        var sheight = getWindowScroll();
        var wheight = getWindowHeight();
        var height = $(this).height();

        //var nioy = $(this).parent().offset().top - sheight;
        var nioy = 0;

        var diff = wheight - (nioy + height + nih);

        if (diff < 0 && Math.abs(diff) > nioy) {
          $(this).css('margin-top', -(nioy + nih));
        } else if (diff < 0) {
          $(this).css('margin-top', diff - nih);
        }

        //        console.clear();
        //        console.log('nioy: ' + nioy);
        //        console.log('height: ' + height);
        //        console.log('nih: ' + nih);
        //        console.log('window height: ' + wheight);
        //        console.log('diff: ' + diff);
      },
      speed: 0
    });

    function getWindowHeight() {
      var theWidth, theHeight;

      if (window.innerWidth) {
        theWidth = window.innerWidth;
      }
      else if (document.documentElement && document.documentElement.clientWidth) {
        theWidth = document.documentElement.clientWidth;
      }
      else if (document.body) {
        theWidth = document.body.clientWidth;
      }
      if (window.innerHeight) {
        theHeight = window.innerHeight;
      }
      else if (document.documentElement && document.documentElement.clientHeight) {
        theHeight = document.documentElement.clientHeight;
      }
      else if (document.body) {
        theHeight = document.body.clientHeight;
      }

      return theHeight;
    }

    function getWindowScroll() {
      var s = 0;
      if (typeof (window.pageYOffset) == 'number') {
        s = window.pageYOffset;
      } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        s = document.body.scrollTop;
      } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        s = document.documentElement.scrollTop;
      }
      return s;
    }
  });

});

//-- sIFR --//
if(typeof sIFR == "function"){
  sIFR.bHideBrowserText = true;
  sIFR.setup(); 
  sIFR.replaceElement('.sifrtitle', named({sFlashSrc: rootpath + 'utils/myriad-pro-condensed.swf', sColor:'#375B56', sWmode:'transparent'}));
  sIFR.replaceElement('.sifrpagetitle', named({sFlashSrc: rootpath + 'utils/myriad-pro-condensed.swf', sColor:'#ffffff', sWmode:'transparent'}));
  sIFR.replaceElement('.content-title h2', named({sFlashSrc: rootpath + 'utils/myriad-pro-condensed.swf', sColor:'#F7941E', sWmode:'transparent'}));
};
