$(document).ready(function () {

    $('.mm1CMSListMenuLink').each(function () {
        var updated = '<span class="menuText">' + $(this).html() + '</span>';
        $(this)
        .html(updated);
    })

    $('.mm1CMSListMenuLinkHighlighted').each(function () {
        var updated = '<span class="menuText">' + $(this).html() + '</span>';
        $(this)
        .html(updated);
    })

    



    $('UL .mm1CMSListMenuLI').mouseover(function () {
        $(this)
        .addClass('hovering');
    })
    $('UL .mm1CMSListMenuLI').mouseout(function () {
        $(this)
        .removeClass('hovering');
    })

    $('UL .mm1CMSListMenuLIFirst').mouseover(function () {
        $(this)
        .addClass('hovering');
    })
    $('UL .mm1CMSListMenuLIFirst').mouseout(function () {
        $(this)
        .removeClass('hovering');
    })

    $('UL .mm1CMSListMenuLILast').mouseover(function () {
        $(this)
        .addClass('hovering');
    })
    $('UL .mm1CMSListMenuLILast').mouseout(function () {
        $(this)
        .removeClass('hovering');
    })

    $('input.srchText').each(function () {
        $(this)
      .data('default', $(this).val())
      .addClass('inactive')
      .focus(function () {
          $(this).removeClass('inactive');
          if ($(this).val() == $(this).data('default') || '') {
              $(this).val('');
          }
      })
      .blur(function () {
          var default_val = $(this).data('default');
          if ($(this).val() == '') {
              $(this).addClass('inactive');
              $(this).val($(this).data('default'));
          }
      });
    });

    $('input.subscrText').each(function () {
        $(this)
      .data('default', $(this).val())
      .addClass('inactive')
      .focus(function () {
          $(this).removeClass('inactive');
          if ($(this).val() == $(this).data('default') || '') {
              $(this).val('');
          }
      })
      .blur(function () {
          var default_val = $(this).data('default');
          if ($(this).val() == '') {
              $(this).addClass('inactive');
              $(this).val($(this).data('default'));
          }
      });
    });

    $('input.SubscriptionTextbox').each(function () {
        $(this)
      .data('default', $(this).val())
      .addClass('inactive')
      .focus(function () {
          $(this).removeClass('inactive');
          if ($(this).val() == $(this).data('default') || '') {
              $(this).val('');
          }
      })
      .blur(function () {
          var default_val = $(this).data('default');
          if ($(this).val() == '') {
              $(this).addClass('inactive');
              $(this).val($(this).data('default'));
          }
      });
    });


    $('#faq ul > li').click(function () {
        $('#faq .active').removeClass("active");
        var selfClick = $(this).find('ul:first').is(':visible');
        if (!selfClick) {
            $(this).addClass('active');
            $(this)
            .parent()
            .find('> li ul:visible')
            .slideToggle();
        } else {
            $(this).removeClass('active');
        }
        $(this)
        .find('ul:first')
        .slideToggle();
    });




    $('UL .mm2CMSListMenuUL').mouseover(function () {
        $(this)
        .parent()
        .addClass('hovering');
    })
    $('UL .mm2CMSListMenuUL').mouseout(function () {
        $(this)
        .parent()
        .removeClass('hovering');
    })


    var screenWidth = $(window).width();
    var screenBottom = $(window).scrollTop() + $(window).height();

    $(".mm2CMSListMenuUL").each(function () {
        // grab the containing element
        $container = $(this).parent();

        // give it relative position if required
        if ($container.css("position") != 'absolute'
          && $container.css("position") != "fixed") {
            $container.css({ position: 'relative' });
        }

        var totalHeight = $container.height() + $(this).outerHeight();
        var width = $(this).outerWidth();
        var offset = $container.offset();

        // now we get the position the tip
        var top = $container.height(); // default placement
        var left = 0;

        // re-position if it's off the right of the screen
        if (offset.left + width > screenWidth) {
            left = 0 - width + $container.width();
            $(this).addClass('left');
        } else {
            $(this).removeClass('left');
        }

        // re-position if it's off the bottom of the screen
        //        if (offset.top + totalHeight > screenBottom) {
        //            top = 0 - $(this).outerHeight();
        //            $(this).addClass('above');
        //        } else {
        //            $(this).removeClass('above');
        //        }

        // finally set the css properties to position onscreen
        $(this).css({
            "top": top,
            "left": left
        });
    });

});


