/// <reference path="../../CMSScripts/jquery-1.3.2-vsdoc.js" />

var itemCounter = 0;
/*
TopZIndex 1.1 (September 23, 2009) plugin for jQuery
http://topzindex.googlecode.com/
Copyright (c) 2009 Todd Northrop
http://www.speednet.biz/
Licensed under GPL 3, see  <http://www.gnu.org/licenses/>
*/
(function (a) { a.topZIndex = function (b) { return Math.max(0, Math.max.apply(null, a.map(a(b || "body *"), function (d) { return parseInt(a(d).css("z-index")) || null }))) }; a.fn.topZIndex = function (b) { if (this.length === 0) { return this } b = a.extend({ increment: 1, selector: "body *" }, b); var d = a.topZIndex(b.selector), c = b.increment; return this.each(function () { a(this).css("z-index", d += c) }) } })(jQuery);

jQuery(function () {
  //    Add a the class SmallRounded to each nested ul
  //    If IE, add a div to each nested ul for a drop shadow effect on the dropdown
  if (jQuery.browser.msie) {
    jQuery('#navigationBar ul li div ul').each(function () {
      itemCounter++;
      //    Help from http://placenamehere.com/article/384/CSS3BoxShadowinInternetExplorerBlurShadow
      var itemPos = jQuery(this).position();
      jQuery(this).after('<div class="IEShadow IEShadow' + itemCounter + '"></div>');
      jQuery('.IEShadow' + itemCounter).height(jQuery(this).height() - 10);
      jQuery('.IEShadow' + itemCounter).width(jQuery(this).width() - 3);
      jQuery('.IEShadow' + itemCounter).css('left', itemPos.left + 'px');
      jQuery('.IEShadow' + itemCounter).css('top', itemPos.top + 'px');
    });
  }

  var contextCalendar = jQuery("#plc_lt_zoneMain_PagePlaceholder_PagePlaceholder_lt_zoneContent_EventCalendar_calItems");
  contextCalendar.attr({ 'cellpadding': '0' });
  if ($.browser.msie && $.browser.version < 8) {
    var numCalendarCells = jQuery('td,th', contextCalendar).length;
    jQuery('td,th', contextCalendar).each(function () {
      jQuery(this).css({ 'position': 'relative', 'z-index': numCalendarCells });
      numCalendarCells--;
    });
  }

  jQuery('.CalendarEvent', contextCalendar).hover(
    function () {
      jQuery('.EducationCentsEvent', this).css('z-index', '10000').addClass('EducationCentsEventPopup');
    },
    function () {
      jQuery('.EducationCentsEvent', this).css('z-index', '0').removeClass('EducationCentsEventPopup');
    }
  );



  if (jQuery(".Calendar").length != 0) jQuery(".Calendar").find("table").attr('title', '');

  if (jQuery("#BlogPagination .PagerNumberArea").length != 0) {
    blogPagination = jQuery("#BlogPagination .PagerNumberArea");
    jQuery(".SelectedPrev", blogPagination).html("Newer Posts");
    jQuery(".UnselectedPrev", blogPagination).html("Newer Posts");
    jQuery(".SelectedNext", blogPagination).html("Older Posts");
    jQuery(".UnselectedNext", blogPagination).html("Older Posts");
    blogPagination.css('visibility', 'visible');
  };

  // Blog Comments Add Confirmation
  if (jQuery(".BlogRequiredValidator input.SubmitButton").length != 0) {
    var blogSubmitCaption = "Blog comments are moderated.  Your comment will appear when it has been approved by the moderator.";
    $("body").append('<div style="display:none;" id="blog-submit-block" class="ModalBlock"></div><div id="blog-submit-container" class="ModalContainer" style="display: none;"><div id="blog-submit-background" class="ModalBackground"><p></p><div id="blog-submit-buttons" class="ModalButtons"><input id="blog-submit-accept" class="ModalButtonLeft" type="button" value="accept" /><input id="blog-submit-cancel" type="button" value="cancel" /></div></div></div>');
    $("#blog-submit-background").find("p").html(blogSubmitCaption);

    // Modal click events
    $("#blog-submit-cancel").click(function () {
      hideBlogSubmitDialog();
    });

    $("#blog-submit-accept").click(function () {
      hideBlogSubmitDialog();
      jQuery(".BlogRequiredValidator input.SubmitButton").click();
    });

    // Hide add button
    jQuery(".BlogRequiredValidator input.SubmitButton").hide();

    // Create alternative add button for comments
    var addButton = jQuery('<input type="button" id="btnAddComment" value="Add">').click(function () {
      showBlogSubmitDialog();
    });

    jQuery(".BlogRequiredValidator input.SubmitButton").after(addButton);
  };

});

function showBlogSubmitDialog() {
  jQuery("#blog-submit-block").fadeIn('fast');
  jQuery("#blog-submit-container").fadeIn("slow");
}

function hideBlogSubmitDialog() {
  jQuery("#blog-submit-container").fadeOut("slow", function () {
    jQuery("#blog-submit-block").hide();
  });
}
