
var currentModal;
var currentHash;
var makeAjaxLinks = function(hash) {
	var closeLink = hash.w.find('.closeLink').click(function(e){e.preventDefault();});
	hash.o.jqmAddClose(closeLink);
	currentModal = hash.w;
	currentHash = hash;

	hash.w.find('a').click(function(e)  {
		var href = $(this).attr('href');
		var cls = $(this).attr('class');
		$(this).attr('target', '_blank');

		/* //Mit diesem Block funktionieren die Titellinks nicht, da diese nicht für den PageType 333 konfiguriert wurden.
		if (href.indexOf('fileadmin/') == -1 && (cls != 'normal')) {
			e.preventDefault();
			var divider = ($(this).attr('href').indexOf('?') != -1) ? ('&') : ('?');
			var href = href + divider + 'type=333';
			href = href.replace(/\s/, '');
			currentModal.load(href, function(data) {
				makeAjaxLinks(currentHash);
			});
		}*/
	});
	hash.w.find('form').each(function(index) {
		var action = $(this).attr('action');
		var divider = (action.indexOf('?') != -1) ? ('&') : ('?');
		$(this).attr('action', action + divider + 'type=333');
	});
	hash.w.find('form').ajaxForm({
		success: function(responseText) {
			currentModal.empty().html(responseText);
			makeAjaxLinks(currentHash);
		}
	});
}

$(document).ready(function(){
	$('body').append($('.jqmWindow'));

	var t = $('#door div.jqmdMSG');

	$('.tx-enetadventcalendar-pi1 map > area').each(function(index) {
		clickday = $(this).attr('href');
		clickday = Number(clickday.substr(3,2));
		
		$('body').append($('#door').clone().attr('id', 'door'+clickday));


		if ((clickday == today.getDate()) && (today.getMonth() == 11)) {
			var divider = (urls[clickday].indexOf('?') != -1) ? ('&') : ('?');
			$(this).attr('name', urls[clickday]+divider+'type=333');
			$(this).click(function(e) {
				e.preventDefault();
				clickday = $(this).attr('href');
				clickday = Number(clickday.substr(3,2));
				$('#door'+clickday).jqm({
					ajax: $(this).attr('name'),
					onLoad: makeAjaxLinks
				}).jqmShow();
			});
		} else {
			$(this).click(function(e) {
				e.preventDefault();
			});
		}
	});
});

