﻿//jQuery was used in this instance because it allowed for an easy graceful degradation.  So if a user didn't have 
//javascript they would be able to still access the events and promotons, and more importantly this allows the 
//google bot to still be able to crawl our page effectivly.
function getEvent(id) {
    PHC.EventService.GetEvents(id, OnComplete, OnTimeOut, OnError);
    return true;
}
function OnComplete(args) {
    $('#modalpopup').html(args);
    center($('#modalpopupcontainer').fadeIn());
    $("#backgroundPopup").css({ "opacity": "0.4" }).fadeIn("slow");
}
function OnTimeOut(args) {
    alert("Service call timed out.");
}
function OnError(args) {
    alert("Error calling service method.");
}
function center(item) {
    item.css("position", "absolute")
    .css("top", ($(window).height() - item.height()) / 2 + $(window).scrollTop() + "px")
    .css("left", ($(window).width() - item.width()) / 2 + $(window).scrollLeft() + "px");
}
function closeModal() {
    $('#modalpopupcontainer').fadeOut();
    $("#backgroundPopup").fadeOut();
}
$(document).keypress(function(key) {
    if (key.which == 0 || key.which == 27) {
        closeModal();
    }
});
$(document).ready(function() {
    $('img#close, div#backgroundPopup').click(function() {
        closeModal();
    });
    $('div.scrollitem a, div.calendarText a, div.promotion a').click(function(e) {
        e.preventDefault();
        getEvent(this.id);
    });
});
