jQuery.noConflict();
(function($) {
	$.resizeHandler = function(evt) {
		if ($(window).height() < 615) {
			$('body').addClass('lowres');
		} else {
			$('body').removeClass('lowres');
		}
	};
	$.setFieldsetHeight = function() {
		//fieldsets equal height
		$height = 0;
		$('#form-list-filters .clearfix fieldset').each(function() {
			if ($height < $(this).height()) 
				$height = $(this).height();
		});
		$('#form-list-filters .clearfix fieldset').each(function() {
			$(this).height($height);
		});
	};
	$(document).ready(function() {
		//Afhandeling external link
		$('a[rel=externallink]').bind('click', function(evt){
			evt.preventDefault();
			window.open($(this).attr('href'), '_blank');
		});
		
		$(".tfe-overlay").attr("rel", "tfe-overlay");
		
		var initSearchValue = $('label[for="sword"]').html();
		$('form#searchform').bind('submit', function() {
			if ($('input#sword', this).val() == initSearchValue) {
				$('input#sword', this).val('');
			}
		});
		$('form#searchform input#sword').bind('focus', function(evt) {
			if ($(this).val() == initSearchValue) {
				$(this).val('');
			}
		}).bind('blur', function(evt) {
			if ($(this).val() == '') {
				$(this).val(initSearchValue);
			}
		});
		if ($('input#sword').val() == '') {
			$('input#sword').val(initSearchValue);
		}
		
		$('#sitetoggle').bind('click', function() {
			$('#sitemap').slideToggle('normal');
			$('#sitetoggle').toggleClass('map-open');
			$(this).text($(this).text() == 'Sitemap openen' ? 'Sitemap sluiten' : 'Sitemap openen');
		});
		
		Cufon.replace([
			'h1',
			'#content h2',
			'#content h2 a',
			'.replace',
			'.news-single-item .date',
			'#housing-tabs a'
		]);
		
		$('.print').bind('click', function(e){
			e.preventDefault();
			window.print();
		});
		
		$('.tx-irfaq-dynheader').bind('click', function(){
			$(this).toggleClass('.tx-irfaq-dynheader active');
			return false;
		});
		
		// Home Carousel
		$('.home .tx-actium-carousel-controller .items').cycle({
			prev:'.home .tx-actium-carousel-controller a.prev',
			next:'.home .tx-actium-carousel-controller a.next',
			after:function(curr, next, opts, fwd) {
				$('.home .tx-actium-carousel-controller .nav span.current').html(opts.currSlide + 1);
			}
		});
		
		$('#reparatieverzoek fieldset legend').each(function() {
			if (!$(this).parent().hasClass('tx-powermail-pi1_fieldset_4') && !$(this).parent().hasClass('tx-powermail-pi1_fieldset_12')) {
				$(this).html('<a href="#">' + $(this).html() + '</a>');
				$('a', this).bind('click', function(evt) {
					evt.preventDefault();
					$(this).parent().parent().toggleClass('open');
				});
			}
		});
		
		$.setFieldsetHeight();
		
		// IE6
		if ($.browser.msie && parseInt($.browser.version) <= 6) {
			// Load PNG Fix
			$.getScript('/fileadmin/templates/website/html/js/DD_belatedPNG_0.0.8a.min.js', function() {
				DD_belatedPNG.fix('.home .tx-actium-carousel-controller .item .text, .home .tx-actium-carousel-controller .nav, .thumbs li.active');
			});
			
			$('.tx-tferealestate-controller .list .object').hover(
				function() { $(this).addClass('object-hover');},
				function() { $(this).removeClass('object-hover');}
			);
			
			$('a.teaser-2,a.teaser-3,a.teaser-4,a.teaser-5,a.teaser-8').hover(function() {
				$('.header', this).addClass('hover');
			}, function() {
				$('.header', this).removeClass('hover');
			}).bind('click', function() {
				document.location.href = $(this).attr('href');
			});
		}
		
		// IE6+ie7
		if ($.browser.msie && parseInt($.browser.version) <= 7) {
			
			$('.tx_powermail_pi1_fieldwrap_html_submit input').hover(
				function() { $(this).addClass('submit-hover');},
				function() { $(this).removeClass('submit-hover');}
			);
			
			$('input.tx-powermail-pi1_confirmation_back').hover(
				function() { $(this).addClass('back-hover');},
				function() { $(this).removeClass('back-hover');}
			);
			
			$('input.tx-powermail-pi1_confirmation_submit').hover(
				function() { $(this).addClass('submit-hover');},
				function() { $(this).removeClass('submit-hover');}
			);
		}
		if ($('body').hasClass('home')) {
			$(window).bind('resize', $.resizeHandler);
			$.resizeHandler();
		}
	});
})(jQuery);

/*
 * Javascript functions for TYPO3 plugin freeCap (sr_freecap)
 *
 * TYPO3 CVS ID: $Id$
 */

/*
 * Loads a new freeCap image
 *
 * @param	string		id: identifier used to uniiquely identify the image
 *
 * @return	void
 */
function newFreeCap(id, noImageMessage) {
	if (document.getElementById) {
			// extract image name from image source (i.e. cut off ?randomness)
		var theImage = document.getElementById("tx_srfreecap_pi2_captcha_image_"+id);
		var parts = theImage.src.split("&");
			// add ?(random) to prevent browser/isp caching
			// parts[0] should be base url up to eID parameter
			// parts[1] should be id=page_id
			// parts[2] should be L=sys_language_uid
		var LParameterInUse = (typeof(parts[2]) != "undefined") && (parts[2].indexOf("L=") != -1);
		theImage.src = parts[0] + "&" + parts[1] + (LParameterInUse ? "&" + parts[2] : "") + "&set=" + Math.round(Math.random()*100000);
	} else {
		alert(noImageMessage ? noImageMessage : "Sorry, we cannot autoreload a new image. Submit the form and a new image will be loaded.");
	}
}

/*
 * Plays the audio captcha
 *
 * @param	string		id: identifier used to uniquely identify the wav file
 * @param	string		wavURL: url of the wave file generating script
 *
 * @return	void
 *
 * Note: In order for this to work with IE8, [SYS][cookieDomain] must be set using the TYPO3 Install Tool
 */
function playCaptcha(id, wavURL, noPlayMessage) {
	if (document.getElementById) {
		var theAudio = document.getElementById("tx_srfreecap_pi2_captcha_playAudio_"+id);
		var wavURLForOpera = wavURL + "&nocache=" + Math.random();
		while (theAudio.firstChild) {
			theAudio.removeChild(theAudio.firstChild);
		}
		var objectElement = document.createElement("object");
		objectElement.setAttribute("id", "tx_srfreecap_pi2_captcha_playAudio_object"+id);
		objectElement.setAttribute("type", "audio/x-wav");
		objectElement.setAttribute("data", wavURLForOpera);
		objectElement.setAttribute("height", 0);
		objectElement.setAttribute("width", 0);
		try {
			objectElement.innerHTML = '<a href="' + wavURLForOpera + '">' + (noPlayMessage ? noPlayMessage : 'Sorry, we cannot play the word of the image.') + '</a>';
		} catch (e) {
				// IE8 does not allow any element other than param as child of object
			objectElement.setAttribute("altHTML", '<a href="' + wavURLForOpera + '">' + (noPlayMessage ? noPlayMessage : 'Sorry, we cannot play the word of the image.') + '</a>');
		}
		theAudio.appendChild(objectElement);
			// IE8 needs a delay before the param children are appended...
		window.setTimeout("addAudioCaptchaParams('" + id + "');", 50);
	} else {
		alert(noPlayMessage ? noPlayMessage : "Sorry, we cannot play the word of the image.");
	}
}

function addAudioCaptchaParams(id) {
	var theAudio = document.getElementById("tx_srfreecap_pi2_captcha_playAudio_"+id);
	var objectElement = theAudio.firstChild;
	var url = objectElement.getAttribute("data");
	var parameters = {
		"type"		: "audio/x-wav",
		"filename"	: url,
		"src"		: url,
		"autoplay"	: true,
		"autoStart"	: 1,
		"hidden"	: true,
		"controller"	: false
	};
	for (var parameter in parameters) {
		if (parameters.hasOwnProperty(parameter)) {
			var paramElement = document.createElement("param");
			paramElement.setAttribute("value", parameters[parameter]);
			paramElement.setAttribute("name", parameter);
			paramElement = objectElement.appendChild(paramElement);
		}
	}
}
