define(["util", "session"], function (util, session) {
var visibilityApi = util.Module("visibilityApi");
var hidden;
var visibilityChange;
if (document.hidden !== undefined) {
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (document.mozHidden !== undefined) {
hidden = "mozHidden";
visibilityChange = "mozvisibilitychange";
} else if (document.msHidden !== undefined) {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (document.webkitHidden !== undefined) {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
session.on("start", function () {
document.addEventListener(visibilityChange, change, false);
});
session.on("close", function () {
document.removeEventListener(visibilityChange, change, false);
});
function change() {
session.emit("visibility-change", document[hidden]);
}
visibilityApi.hidden = function () {
return document[hidden];
};
return visibilityApi;
});