﻿var SOS = SOS || {};

SOS.Util = (function ($) {

	return {
		_default_time: 600,
		_fast_time: 200,
		_really_fast_time: 10,
		_semi_hidden_opacity: 0.15,

		getAnnouncement: function (id) {
			var announcement = $('#' + id.replace('#', ''));
			if (!announcement || announcement.length == 0) { alert('No announcement found in DOM for: ' + id); return null; }
			return announcement;
		},

		openAnnouncement: function (id, ms) {
			var announcement = this.getAnnouncement(id),
			time = (ms || this._default_time);

			//slide down the announcement while fading to fully visible
			if (announcement) {
				announcement.animate({ opacity: 1.0, height: 'toggle' }, time);
			}
		},

		closeAnnouncement: function (id, ms, keepInDom) {
			var announcement = this.getAnnouncement(id),
			time = (ms || this._default_time),
			remover = function () { if (!keepInDom) { announcement.remove(); } };

			//fade out the announcement to 25% opacity while sliding up, after call remover
			if (announcement) {
				announcement.animate({ opacity: this._semi_hidden_opacity, height: 'toggle' }, time, remover);
				//also clear any text boxes/areas in the announcement we are closing
				$('input[type=text], input[type=password], textarea', announcement).val('');
				//and hide any flashmsgs
				$('#flashmessage', announcement).hide();
			}
		},

		hideAnnouncementOnLoad: function (id) {
			var announcement = this.getAnnouncement(id);

			//use opacity to hide, should already be hidden w/ display: none;
			if (announcement) {
				announcement.css({ opacity: this._semi_hidden_opacity });
			}
		},

		isChecked: function (selector) {
			var c = false;
			$(selector).each(function () { if (this.checked) c = true; });
			return c;
		}
	};

})(jQuery);

