﻿(function($) {
	$.checkCookie = function() {
		if(document.cookie.match(/arbeskoCampaign=active/)) {
			return false;
		} else {
			return true;
		}
	},
	$.writeCookie = function() {
		var today = new Date();
		today.setTime(today.getTime());
		var nDays = 5;
		var expire = new Date( today.getTime() + (nDays * 1000 * 60 * 60 * 24));
		document.cookie = "arbeskoCampaign=active;expires="+expire.toGMTString();
	},
	$.fn.startPopCampaign = function(startData,endData) {
		var startDate = Date.parse(startData);
		var endDate = Date.parse(endData);
		var today = new Date();
		today.setTime(today.getTime());
		if(Date.parse(today) >= startDate && Date.parse(today) <= endDate) {
			if($.checkCookie()) {
				$.writeCookie();
				$('.community').hide();
				$(this).modal({
					'opacity': 80,
					'overlayCss': {'background-color': '#000', 'cursor': 'wait'},
					'containerCss': {'color': 'white','background-color':'#333','border': '1px solid #444','width':'625px','height':'760px'},
					'closeHTML': '<div style="position: absolute; top: -25px; background: black; right: 0px; padding: 5px; width: 150px; height: 15px; cursor: pointer">Press ESC to close.</div>',
					'onOpen': function (dialog) {dialog.overlay.fadeIn('slow', function () {dialog.container.slideDown('slow', function () {dialog.data.fadeIn('slow');});});},
					'onClose': function(dialog) { $.modal.close(); $('.community').show(); }
				});
			}
		}
		return this;
	}
})(jQuery);