﻿/// <reference path="jquery-1.4.4.js" />

/* ============================
DotControl copyright 2010
==============================*/


$(function () {
	// accordion
	var activeItem = 0;
	if (window.location.hash == "#vacancies") {
		activeItem = 2;
	}
	if ($('.page').hasClass('news') || $('.page').hasClass('actueel')) {
		activeItem = false;
	}

	$('.accordion', '.mode-view').each(function () {
		if ($(this).hasClass('nested')) {
			activeItem = false;
		}
		$(this).accordion({
			autoHeight: false,
			active: activeItem
		});
		$(this).show();
	});

	//put vacancies list inside accordion
	$('.synpact .DCSiteAgendaRecent .Items .Item').appendTo('.vacancies-holder').show();

	// news accordion changes background
	var $bg = $('.slide', '.background-image');
	var $staticImage = $('.custom-image img');
	var noImage = $bg.first().attr('src');
	var $activeSlide = $bg.first().addClass('active');
	$('.news-header-link', '.accordion.news').click(function () {
		if (!$(this).hasClass('.rpExpanded')) {
			if ($activeSlide.hasClass('active')) {
				$activeSlide = $bg.not('.active');
			}
			// get image url from hidden field
			var src = $(this).next().find('.hf-image').val();
			//change current image url
			if (src != "") {
				$activeSlide.attr('src', src);
			}
			else {
				if (noImage != "") {
					$activeSlide.attr('src', noImage);
				}
			}
			// switch active class
			$bg.each(function () {
				$(this).toggleClass('active');
			});
			// fade animation after 'active' image loads
			$activeSlide.load(function () {
				$bg.not('.active').fadeOut(1000);
				$staticImage.fadeOut(1000, null, function () {
					$(this).parents('.custom-image').remove();
				});
				$(this).fadeIn(1000);
			});
		}
	});
});
