$(document).ready(function() {
	runSleight();
	menuItems();
	doVestigingen();
	regelHover();
	$("input[type=checkbox]").each(function() {
		$(this).css("border", "0");
	});
	
	$("input[type=radio]").each(function() {
		$(this).css("border", "0");
	});
});

function runSleight() {
	if (typeof supersleight == "object")
		supersleight.run();
}

function menuItems() {
	$('.dubbelregel div, .enkeleregel div').hover(function() {
		$(this).children("a").addClass("hover");
	}, function() {
		$(this).children("a").removeClass("hover");
	});
}

function doVestigingen() {
	$('.vestigingContainer div').each(function() {
		var kaartMaxWidth = $('.kaart').offset().left + $('.kaart').parent().width();
		var piontInnerWidth = $(this).children('img').width() + $(this).children('span').width() + 4;
		var pointMaxWidth = $(this).offset().left + piontInnerWidth;
		var newOffsetLeft = $(this).offset().left - piontInnerWidth;

		$(this).css("top", (($(this).css("top")).replace("px", "") - (2)) + "px");

		if (pointMaxWidth >= kaartMaxWidth) {
			$(this).addClass("alt");
			$(this).width(piontInnerWidth + 4);
			$(this).css("left", (($(this).css("left")).replace("px", "") - (piontInnerWidth - 7)) + "px");
		}
	});

	$('.vestigingContainer div img').hover(function() {
		$(this).parent().addClass("hover");
	}, function() {
		$(this).parent().removeClass("hover");
	});
}


function appendModal() {
	modal = '<div class="modalContainer">' +
				'	<div class="modalBlock">' +
				'		<div class="modalTitle"></div>' +
				'		<div class="modalContent"></div>' +
				'	</div>' +
				'</div>' +
				'<div class="modalBackground"></div>';

	if ($('.modalContainer').length == 0) {
		$("body").html($("body").html() + modal);
	}
	else {
		$('.modalTitle').html("");
		$('.modalContent').html("");
	}
}

function closeModal() {
	$('.modalContainer').remove();
	$('.modalBackground').remove();
}

function showLoadingModal(title, content) {
	appendModal();
	$('.modalTitle').html(title);
	$('.modalContent').html("<div style='text-align:center;'><img src='images/layout/loading.gif' /><br />" + content + "</div>");
}

function regelHover() {
	$('.regel div').each(function() {
		$(this).attr("title", $(this).text());
	});
}
