$(document).ready(function () {


	// Variables
	var fader = '';
	var items = $('#news-home ul.blocks li.list');
	var speed = 750;
	var timeout = 6000;
	var easingtype = 'easeOutBounce';

	// Init Shadowbox
	Shadowbox.init();

	/**
	 * Animation for quicklinks
	 */

	$('#ql_list').innerfade({
		animationtype: 'fade',
		speed: speed,
		timeout: timeout,
		type: 'sequence',
		containerheight: '121px'
	});

	/**
	 * Script to fade between news and calendar
	 */

	$('#news-home ul.blocks li.list').css ("display", "none");
	$('#news-home ul.blocks li.active').css ("display", "block");

	var fader = setInterval (function () {

		// Remove active
		active_block = $('#news-home ul.blocks li.active');

		// Calculate next
		next = items.index(active_block) + 1;

		// Check for offset
		if (next == items.length) {
			next = 0;
		}

		// Fetch next
		slide_block = $('#news-home ul.blocks li#block_' + next);

		// Remove active
		$(active_block).removeClass('active');
		$(slide_block).addClass('active');

		$(active_block).fadeOut(speed);
		$(slide_block).fadeIn (speed);

	}, timeout);


	/**
	 * Mouse interaction
	 */

	$('.edu-item').mouseenter (function () {

		var height = parseInt ($(this).find('.mo-bottom-content').height());
		var new_height = height + 70;

		$(this).find('.mo-top').stop().animate({
			'height' : 137, 'top': -137},
			speed,
			easingtype
		);

		$(this).find('.mo-bottom').stop().animate({
			'height' : new_height},
			speed,
			easingtype
		);

	}).mouseleave (function () {

		$(this).find('.mo-top').stop().animate({
			'height' : 0, 'top': 0},
			speed,
			easingtype
		);

		$(this).find('.mo-bottom').stop().animate({
			'height' : 0},
			speed,
			easingtype
		);
	});

	/**
	 * Mouse interaction on first item in main menu
	 */

	$('#edu-mainmenu').mouseenter (function () {

		// Get content height
		//var height = $(this).find('#sub-education ul').height();
		/*
		$(this).find('#sub-education').stop().animate({
			'height' : 320},
			speed,
			easingtype
		);
		*/

		$(this).find('#sub-education').stop().animate({
			'height' : 100},
			speed,
			easingtype
		);

	}).mouseleave (function () {

		$(this).find('#sub-education').stop().animate({
			'height' : 0},
			speed,
			easingtype
		);
	});

	/**
	 * Mouse interaction on page title menulist
	 */

	$('#page-title').mouseenter (function () {

		// Get content height
		var height = $(this).find('#page-title-list ul').height();
		height += 40;

		$(this).find('#page-title-list').stop().animate({
			'height' : height},
			speed,
			easingtype
		);

	}).mouseleave (function () {

		$(this).find('#page-title-list').stop().animate({
			'height' : 0},
			speed,
			easingtype
		);
	});

	/**
	 * Mouse interaction on education block on home
	 */
	$('#edu-header li a').mouseenter (function () {

		$('#edu-header li a').css('background-position', '0 0');
		$(this).css('background-position', '20px 0');

		var id = $(this).attr('id');
		id = id.replace ('item', 'image');

		$('#edu-image div.item-con').css('display', 'none');
		$('#edu-image div#' + id).css('display', 'block');

		$('#home-img').css('display', 'none');
		$('.ql-top-home').css('display', 'none');

	});

	/*
	.mouseleave (function () {

		$('#edu-header li a').css('background-position', '0 0');
		$('#edu-image div.item-con').css('display', 'none');
	});
	*/

	$('#edu-header-con').mouseleave (function () {

		$('#edu-header li a').css('background-position', '0 0');
		$('#edu-image div.item-con').css('display', 'none');

		$('#home-img').css('display', 'block');
		$('.ql-top-home').css('display', 'block');

	});

	$('.header-block').mouseenter(function () {

		if ($(this).hasClass('high')) {

			$(this).css('background', 'url(\'gfx/bg-home-block-high-active.png\')');
		} else {

			$(this).css('background', 'url(\'gfx/bg-home-block-active.png\')');
		}

		$(this).find('.person').css('display', 'none');
		$(this).find('.person-mo').css('display', 'block');

	}).mouseleave(function () {

		if ($(this).hasClass('high')) {

			$(this).css('background', 'url(\'gfx/bg-home-block-high-inactive.png\')');
		} else {

			$(this).css('background', 'url(\'gfx/bg-home-block-inactive.png\')');
		}

		$(this).find('.person').css('display', 'block');
		$(this).find('.person-mo').css('display', 'none');
	});

	/**
	 * Registerform
	 */

	$('input.register').change(function () {

		if ($(this).attr('id') != 'register1') {

			$('#num_persons').val('');
			$('#intake').attr('checked', false);
		}
	});

});


