jQuery.fn.outerHTML = function (s) {
	return (s)
? this.before(s).remove()
: jQuery("<p>").append(this.eq(0).clone()).html();
}

function tidyUpXforms() {
	$('input.checkbox').each(function () {
		var label = $(this).next();
		var html = '<p>' + $(this).outerHTML() + $(label).outerHTML() + '</p>';
		$($(this).nextAll('br')[0]).remove();
		$(label).remove();
		$(this).replaceWith(html);
	});
}

function setBlockLink(element,src){
	
	$(element).css('cursor','pointer');
	$(element).click(function (e) {
		var link = $(this).find('a:first').attr('href');
		window.location = link;
		return false;
	});
}

// checks for links that should open in a new tab, and forces _blank interaction
function externalLinks() {
	$.each($('a:not(.ignore)'),
	function () {
		var link = $(this).attr('href') || 'not available';
		if (link.substr(0, 7) == "http://") {

			$(this).click(function (e) {
				e.preventDefault();
				window.open($(this).attr('href'), '_blank');
				return false;
			})
		}
	})
}
 
function initStappenPlan() {
	$('#stappenplan li a').each(function () {
		$(this).append('<span class="rightDart"></span>');
		if (!$(this).hasClass('current')) {
			$(this).append('<span class="progress"></span>');
		} else {
			$(this).append('<span class="progressCurrent"></span>');
		} 
	});
}

function initCufon() {
   /* Cufon.replace(['h1', '#navigatie li span:not(#kids #navigatie li span)'], {*/
	Cufon.replace(['h1, #navigatie .topItem > a'], {
		fontFamily: 'Myriad Pro',
		hover: true
	}); 
}

function Watermark(element, value) {
	$(element).addClass("watermark");
	if ($(element).val() == "") { $(element).val(value) }
	$(element).focus(function () {
		$(this).filter(function () {
			return $(this).val() == "" || $(this).val() == value;
		}).removeClass("watermark").val("");
	});
	$(element).blur(function () {
		$(this).filter(function () {
			return $(this).val() == ""
		}).addClass("watermark").val(value);
	});
}

function indexAlphabet() {
	$(".atotz-items li").click(function () {
		window.location = $(this).find("a").attr("href");
		return false;
	});
	$('.atotz a').click(function () {
		var href = $(this).attr("href");
		href = href.substr(1);
		$.scrollTo($("a[name='" + href + "']"), 1200);
		$(".atotz a").removeClass("current");
		$(this).addClass("current");
		return false;
	});
	$('.naarboven a').click(function () {
		var href = $(this).attr("href");
		href = href.substr(1);
		$.scrollTo($("a[name='" + href + "']"), 1200);
		$('.atotz').find('a.current').removeClass('current');
		return false;
	});
}

function listAnimation(element) {
	$(element).hover(function () {
		$(this).animate({ backgroundPosition: "5px 6px" }, 200);
	}, function () {
		$(this).animate({ backgroundPosition: "0px 6px" }, 200);
	});
}

function menuAnimations() {
	$('#navigatie li div.sub').hide();
	$('#navigatie').append('<div id="whiteRabbit"></div>');
	$('#beo').append('<div id="mondriaan"></div>');

	var beoWidth = $('#beo').width();
	var bezoekWidth = $('#bezoek').width();

	$.each($('#navigatie li div.sub'), function () {
		$(this).prepend('<a href="#" class="sluiten"><span>Sluiten</span></a>');
		$(this).find('.sluiten').click(function () {
			$(this).parent().slideUp(150);
		});
	})

	$('#navigatie li a').click(function () {
		var elm = $(this).parent().attr('id');
		if ($("#" + elm).find('.sub').is(':hidden')) {
			$('#navigatie li .sub').slideUp(150);
			$('#navigatie li > a').removeClass('hover')

			$('#' + elm + ' > a').addClass('hover');
			$('#' + elm + ' .sub').slideDown(300);

			if (elm != "bezoek") {
				$('#navigatie #whiteRabbit').hide()
			} else { $('#navigatie #whiteRabbit').show() }
		} else {
			$('#navigatie li > a').removeClass('hover')
			$('#' + elm + ' .sub').slideUp(150);
			$('#navigatie #whiteRabbit').show();
		}
		return false;
	});
}

function loadStep(url) {
	var stepBlock = $('#stepBlock');
	loadStepStart(stepBlock, url);
	$(stepBlock).fadeTo(400, 0.1, function () { loadStepStart(url); });
}

function loadStepStart(stepBlock, url) {
	//var stepBlock = $('#stepBlock');
	$(stepBlock).load(url + ' #stepBlock', function () { loadStepComplete(stepBlock); });
}

function loadStepComplete(stepBlock) {
	//var stepBlock = $('#stepBlock');
	$(stepBlock).fadeTo(400, 1);
	initStappenPlan();
	resizeMedischABCVideos();
}

function resizeMedischABCVideos() {
	$('.medischABCVideo').each(function () {
		var object = $(this).find('object')[0];
		if (object != null) {
			$(object).attr('width', 300);
			$(object).attr('height', 200);
			var embed = $(object).find('embed');
			if (embed != null) {
				$(embed).attr('width', 300);
				$(embed).attr('height', 200);
			}
		}
	});
}


function maatschap(){
	$('.maatschap').each(function(){
		$(this).append('<div class="maatschap-label"></div>');
	});
}

function showPopupForm(backgroundElement, foregroundElement) {
	$(backgroundElement).css('z-index', '53');
	$(backgroundElement).css({opacity: 90}).fadeIn(200).height($(document).height());
	$(foregroundElement).append('<div id="misterDarkBlue"></div>');
	$(foregroundElement).show(400);
	return false;
}

function popupForm(backgroundElement, foregroundElement) {

	$('.popupTrigger').click(function () {
		var elm = $('#popupFormInner');
		if (elm.find('fieldset').length == 0) {
			elm.load(document.location + ' #' + elm[0].id, { ajax: true, reset: true }, function () { showPopupForm(backgroundElement, foregroundElement); });
		} else {
			return showPopupForm(backgroundElement, foregroundElement);
		}
	});

	$('.closePopup').click(function () {
		$(foregroundElement).hide(400);
		$(backgroundElement).hide(100);
		return false;
	});
	$(backgroundElement).click(function () {
		$(this).hide(100);
		$(foregroundElement).hide(400);
		$(this).css('z-index', '53');
		return false;
	});
}

function popupSearch(backgroundElement, foregroundElement) {

	$('.searchTrigger').focus(function () {
		$('.searchTrigger').css('z-index', '180');
		$('.searchTrigger').css('z-index', '1');
		$(this).css('z-index', '520');

		 
		var type = $(this).parent().parent().attr('id');
		if (type == 'treatmentSearch') {
		   /* $('#visitorSearch').find('.searchTrigger').val('');*/
			/* $('#visitorSearch').find('.searchTrigger').val('');*/
			$('#treatmentSearch .universalLink').removeClass('universalActive');
			$('#visitorSearch').find('.searchResults').fadeOut(200);
			$('#visitorSearch').find('.searchDetails').fadeOut(200);

		} else {
		  /*  $('#treatmentSearch').find('.searchTrigger').val('');*/
			/*  $('#treatmentSearch').find('.searchTrigger').val('');*/
			$('#treatmentSearch').removeClass('universalActive');
			$('#treatmentSearch').find('.searchResults').fadeOut(200);
			$('#treatmentSearch').find('.searchDetails').fadeOut(200);
		}

		$('#treatmentSearch .universalLink').addClass('universalActive');
		/* $(backgroundElement).css('filter', 'alpha(opacity=90)').fadeIn(200).height($(document).height());*/
		$(backgroundElement).css({opacity: 90, 'height': '1200px'}).fadeIn(200);

		$(this).parent().css('z-index', '600');
		$(backgroundElement).css({ opacity: 90, 'height': '1200px' }).fadeIn(200);

		return false;
	});

	var allResultsUrl;
	$('.searchTrigger').keyup(function (event) {
		if($('#home').is('*')){
			parentElement = $(this).parent().parent().attr('id');
		} else {
			parentElement = 'content';
		}
		
		if(parentElement === 'visitorSearch'){
			$(document.body).addClass('twisted');
	  }

  if (parentElement === 'treatmentSearch') {
		  $(document.body).removeClass('twisted');
		}
		var readMoreButton = $('.searchResults a.leesVerder');
		if (allResultsUrl == null) {
			allResultsUrl = readMoreButton.attr('href');
		}
		hideDetails();
		if ($(this).val().length > 1 && $(this).val() != 'Aandoening, behandeling of onderzoek' && $(this).val() != 'Polikliniek, (verpleeg)afdeling of kamernummer') {
			var givenValue = $(this).val();
			showResults(givenValue,parentElement);
			var trigger = $(this);
			var searchType = $.trim(trigger.attr('class').replace('watermark', '').replace('activeSearch', '').replace('searchTrigger', ''));
			runSearch(trigger,searchType);
			if (event.keyCode == '40') {
				$('.searchResults li:first a').focus();
				return false;
			}
			readMoreButton.attr('href', allResultsUrl + '?term=' + $(this).val() + '&type=' + searchType);
		} else {
			hideResults();
			$(document.body).removeClass('twisted');
		}
	});

	$('.searchResults li a').click(function () {
		var parentElement = $(this).parent().parent().parent().parent().parent().attr('id');
		showDetails(parentElement);
		return false;
	});

	$(backgroundElement).click(function () {
		$('#treatmentSearch .universalLink').removeClass('universalActive');

		$(this).fadeOut(100);
		$('.searchResults').fadeOut(200);
		$('.searchDetails').fadeOut(200);
		return false;
	});

   $('.searchTrigger').trigger('keyup');
}

function showResults(term,parentElement) {
	$('#' + parentElement).find('.searchResults').fadeIn(400);
	if($('#home #visitorSearch').is('*')){
		$('#home #visitorSearch .searchDetails').css({ 'left': '-530px', 'right': 'auto' });
	}
}

function showDetails(parentElement) {
	$('#' + parentElement + ' .searchDetails').fadeIn(400);
	$('#' + parentElement + ' .searchDetails').height($('.searchResults').height());
}

function hideResults() {
	$('.searchResults').fadeOut(200);
}

function hideDetails() {
   
	$('.searchDetails').fadeOut(200);
}

function faq() {
	$('.faq li:not(".open") > div').hide();
	$('.faq li > a').click(function () {
		if ($(this).hasClass('opened')) {
			$(this).removeClass('opened');
			$(this).parent().find('div:first').fadeOut(100);
		} else {
			$(this).addClass("opened");
			$(this).parent().find('div:first').fadeIn(300);
		}
		return false;
	});
}

function routeTooltip() {
	
	$('.routebeschrijving .tooltipImage').each(function () {
		$(this).parent().append('<a href="#" class="launchTooltip"><span>Bekijk een foto van deze omgeving</span></a>');
		$(this).hide().append('<a href="#" class="close"><span>Sluiten</span></a>');
	});
	$('.launchTooltip').click(function () {
		var position = $(this).position();
		var posBottom = 18;
		var posLeft = position.left;
		if (posLeft > '160') {
			var posLeft = position.left - 358;
			$(this).parent().find('.tooltipImage').addClass('saveposition');
		} else {
			var posLeft = position.left - 205;
		}
		$('.tooltipImage').hide();
		$('#additionalcontent').css('z-index', '300')
		$(this).parent().find('.tooltipImage').css({ 'position': 'absolute', 'left': posLeft, 'bottom': posBottom, 'z-index':999 });
		$(this).parent().find('.tooltipImage').toggle();
		return false;
	});
	$('.close').click(function () {
		$('.tooltipImage').hide();
		$('#additionalcontent').css('z-index', '299');
		// $(this).parent().parent().find('.tooltipImage').toggle();
		return false;
	});
}

function errorMsgs() {
	$('.errorMsg').each(function () {
		$(this).append('<div class="errorSnokje"></div>');
	});
}

function thumbs(){ 
	$('.ttCarousel li').each(function(i){
		$('.ttCarousel-controls a.item' + [i+1]).html($(this).find('img.thumbnail'));
	});
}

function sendQuestion(container) {
	var elm = $($(container)[0]);
	var elmSubmit = elm.find('#versturen')
	elmSubmit.addClass('activeButton');
	elmSubmit.attr('disabled', 'disabled');
	var questionVal = elm.find('* [name="vraag"]').val();
	var nameVal = elm.find('* [name="naam"]').val();
	var emailVal = elm.find('* [name="email"]').val();
	elm.load(document.location + ' #' + $(elm)[0].id, { ajax: true, vraag: questionVal, naam: nameVal, email: emailVal }, function (response, status, xhr) {
		if (status == "error") {
			var msg = "Helaas, er is een fout opgetreden:";
			$("#error").html(msg + xhr.status + " " + xhr.statusText);
		}
		errorMsgs();
	});
}

function sendJobUpdatesRequest(container) {
	var elm = $($(container)[0]);
	var elmSubmit = elm.find('#versturen')
	elmSubmit.addClass('activeButton');
	elmSubmit.attr('disabled', 'disabled');
	var nameVal = elm.find('* [name="naam"]').val();
	var emailVal = elm.find('* [name="email"]').val();
	elm.load(document.location + ' #' + $(elm)[0].id, { ajax: true, naam: nameVal, email: emailVal }, function (response, status, xhr) {
		if (status == "error") {
			var msg = "Helaas, er is een fout opgetreden:";
			$("#error").html(msg + xhr.status + " " + xhr.statusText);
		}
		errorMsgs();
	});
}

function runSearch(trigger, type) {
	var term = trigger.val();
	trigger.addClass('activeSearch');
	switch (type) {
		case 'departments': runRightWidgetSearch(term); break;
		case 'treatmentsdiagnosticsandaffections': runLeftWidgetSearch(term); break;
		default:
	}
}

var ajaxCall;

function AbortActiveCall() {
    if (ajaxCall != null) { ajaxCall.abort(); }
}

function runLeftWidgetSearch(term) {
    var max = 10;
    AbortActiveCall();
	ajaxCall=$.getJSON('/handlers/data.ashx/?action=searchforleftwidget&max=' + (max+1) + '&term=' + term, function (data) {
		renderLeftWidgetSearch(data, term, max);
	});
}

function runRightWidgetSearch(term) {
	var max = 10;
	AbortActiveCall();
	ajaxCall = $.getJSON('/handlers/data.ashx/?action=searchforrightwidget&max=' + (max + 1) + '&term=' + term, function (data) {
		renderRightWidgetSearch(data, term, max);
	});
}

function renderLeftWidgetSearch(data, term, max) {
	var topLevelElm = $('#search');
	if (topLevelElm == null || topLevelElm.length == 0) { topLevelElm = $('#treatmentSearch'); }
	var html = '';
	if ($(data).length > 0) {
		var count = 0;
		html += '<ul>';
		$.each(data, function (i, item) {
			if (count < max) {
				var re = new RegExp('(' + term + ')', 'gi');
				html += '<li><a href="?' + (item.Type.toLowerCase() == '[data] affection' ? 'aid' : 'pid') + '=' + item.PageId + '&type=' + item.Type.toLowerCase() + '">' + item.Name.replace(re, '<span class="highlighted">$1</span>') + '</a></li>';
			}
			count++;
		})
		html += '</ul>';

		var ar = topLevelElm.find('.searchResults .allResults');
		if ($(data).length > max) {
			topLevelElm.find('.searchResults .leesVerder').show();
			ar.attr('href', ar.attr('href') + '?term=' + term);
			ar.show();
		} else {
			topLevelElm.find('.searchResults .leesVerder').hide();
			ar.attr('href', ar.attr('href') + '?term=' + term);
			ar.hide();
		}
	} else {
		html += '<p>Geen resultaten gevonden</p>';
		html += '<a class="leesVerder zoekSite" href="/Overig/Zoekresultaten/?q=' + term + '">Doorzoek de hele site</a>';
		topLevelElm.find('.searchResults .leesVerder').hide();
	}
   
	topLevelElm.find('.searchResultsList').html(html);
	topLevelElm.find('.searchResults li a').click(function () {
		loadLeftWidgetDetails($(this).attr('href').split('?')[1]);
		var parentElement = $(this).parent().parent().parent().parent().parent().attr('id');
		showDetails(parentElement);
		return false;
	});
	topLevelElm.find('.searchTrigger').removeClass('activeSearch');

}

function renderRightWidgetSearch(data, term, max) {
	var topLevelElm = $('#search');
	if (topLevelElm == null || topLevelElm.length == 0) { topLevelElm = $('#visitorSearch'); }
	var html = '';
	if ($(data).length != 0) {
		var count = 0;
		html += '<ul>';
		$.each(data, function (i, item) {
			if (count < max) {
				html += '<li><a href="?pid=' + item.PageId + '">';
				if (item.Tag == 'FoundByNumber') {
					html += 'kamernummer <span class="highlighted">' + term + '</span> (';
				}
				html += item.Name.replace(term, '<span class="highlighted">' + term + '</span>')
				if (item.Tag == 'FoundByNumber') {
					html += ')';
				}
				html += '</a></li>';
			}
			count++;
		})

		html += '</ul>';
		var ar = topLevelElm.find('.searchResults .allResults');
		if ($(data).length > max) {
			topLevelElm.find('.searchResults .leesVerder').show();
			ar.attr('href', ar.attr('href') + '?term=' + term);
			ar.show();
		} else {
			topLevelElm.find('.searchResults .leesVerder').hide();
			ar.attr('href', ar.attr('href') + '?term=' + term);
			ar.hide();
		}
	} else {
		html += '<p>Geen resultaten gevonden</p>';
		html += '<a class="leesVerder zoekSite" href="/Overig/Zoekresultaten/?q=' + term + '">Doorzoek de hele site</a>';
		topLevelElm.find('.searchResults .leesVerder').hide();
	}
	
	topLevelElm.find('.searchResultsList').html(html);
	topLevelElm.find('.searchResults li a').click(function () {
		loadRightWidgetDetails($(this).attr('href').split('?')[1]);
		var parentElement = $(this).parent().parent().parent().parent().parent().attr('id');
		showDetails(parentElement);
		return false;
	});
	topLevelElm.find('.searchTrigger').removeClass('activeSearch');
}

function loadLeftWidgetDetails(querystring) {
	var parts = querystring.split('&');
	var pid = parts[0].split('=')[1];
	var type = parts[1].split('=')[1];
	$.getJSON('/handlers/data.ashx/?action=getforleftwidget&' + querystring, function (data) {
		renderLeftWidgetDetails(data, pid, type);
	});
}

function loadRightWidgetDetails(querystring) {
	var parts = querystring.split('&');
	var pid = parts[0].split('=')[1];
	$.getJSON('/handlers/data.ashx/?action=getforrightwidget&' + querystring, function (data) {
		renderRightWidgetDetails(data, pid);
	});
}

function renderLeftWidgetDetails(data, pid, type) {
	var html = '';
	var isAffection = (type.indexOf('affection') > -1);
	var isTreatment = (type.indexOf('treatment') > -1);
	var isDiagnostic = (type.indexOf('diagnostic') > -1);
	if (isAffection) {
		html += '<h4>' + data.PageName + '</h4>';
		html += '<p>' + data.Description + '</p>';
	}
	if (isTreatment) {
		html += '<a href="' + data.FriendlyUrl + '"><h4>' + data.PageName + '</h4></a>';
		if (data.WhatIsIt != null) {
			html += '<p>' + data.WhatIsIt.replace(/\r\n/g, '<br />') + '</p>';
		}
	}
	if (isDiagnostic) {
		html += '<a href="' + data.FriendlyUrl + '"><h4>' + data.PageName + '</h4></a>';
		if (data.WhatIsIt != null) {
			html += '<p>' + data.WhatIsIt.replace(/\r\n/g, '<br />') + '</p>';
		}
	}
	html += '<table>';

	if (isAffection) {

	    if (data.RelatedDiagnostics != null && data.RelatedDiagnostics.PageLinks != null && data.RelatedDiagnostics.PageLinks.length != 0) {
	        html += '<tr>';
	        html += '<th class="icon-onderzoek">Onderzoeken</th>';
	        html += '<td>';
	        $.each(data.RelatedDiagnostics.PageLinks, function (i, item) {
	            if (i > 0) { html += '; '; }
	            html += '<a href="' + item.FriendlyUrl + '">' + item.Name + '</a>';
	        });
	        html += '</td></tr>';
	    }

	    if (data.RelatedTreatments != null && data.RelatedTreatments.PageLinks != null && data.RelatedTreatments.PageLinks.length != 0) {
	        html += '<tr>';
	        html += '<th class="icon-behandeling">Behandelingen</th>';
	        html += '<td>';
	        $.each(data.RelatedTreatments.PageLinks, function (i, item) {
	            if (i > 0) { html += '; '; }
	            html += '<a href="' + item.FriendlyUrl + '">' + item.Name + '</a>';
	        });
	        html += '</td></tr>';
	    }



	    //REQUESTED 12-10-2011: No specialism info
	    //		if (data.RelatedSpecialisms != null && data.RelatedSpecialisms.PageLinks != null) {
	    //			html += '<tr>';
	    //			html += '<th class="icon-specialisme">Specialismen</th>';
	    //			html += '<td>';
	    //			$.each(data.RelatedSpecialisms.PageLinks, function (i, item) {
	    //				if (i > 0) { html += '; '; }
	    //				html += '<a href="' + item.FriendlyUrl + '">' + item.Name + '</a>';
	    //			});
	    //			html += '</td></tr>';
	    //		}
	}

	if (isTreatment || isDiagnostic) {
	    if (data.MainSpecialismLink != null) {
	        html += '<tr>';
	        html += '<th class="icon-specialisme">Specialisme</th>';
	        html += '<td>';
	        html += '<a href="' + data.MainSpecialismLink.FriendlyUrl + '">' + data.MainSpecialismLink.Name + '</a>';
	        html += '</td></tr>';
	    }

	    if (data.RelatedDepartments != null && data.RelatedDepartments.PageLinks != null) {
	        html += '<tr>';
	        html += '<th class="icon-afdeling">Afdelingen</th>';
	        html += '<td>';
	        $.each(data.RelatedDepartments.PageLinks, function (i, item) {
	            if (i > 0) { html += '; '; }
	            html += '<a href="' + item.FriendlyUrl + '">' + item.Name + '</a>';
	        });
	        html += '</td></tr>'
	    }
	}



	html += '</table>';

//    if (isAffection) {
//        if (data.MoreInfo != null && data.MoreInfo != '') {
//            var linkName = data.MoreInfo.replace('http://', '');
//            if (linkName.substring(linkName.length - 1) == '/') { linkName = linkName.substring(0, linkName.length - 1); }
//            html += '<a class="meerInfo" href="' + data.FriendlyUrl + '">' + linkName + '</a>'
//        }
//    }

	if (isTreatment || isDiagnostic || isAffection) {
		html += '<a class="leesVerder" href="' + data.FriendlyUrl + '">Lees meer over ';
		if (isTreatment) { html += 'deze behandeling'; }
		if (isDiagnostic) { html += 'dit onderzoek'; }
		if (isAffection) { html += 'deze aandoening'; }
		html += '</a>';
	}
	var topLevelElm = $('#search');
	if (topLevelElm == null || topLevelElm.length == 0) { topLevelElm = $('#treatmentSearch'); }

	topLevelElm.find('.searchDetails').html(html);
}

function renderRightWidgetDetails(data, pid) {
	var html = '';
	html += '<a href="' + data.FriendlyUrl + '"><h4>' + data.PageName + '</h4></a>';
	html += '<p>' + data.Intro + '</p>';
	html += '<table>';
	if (data.PhoneNr != null && data.PhoneNr != '') {
		html += '<tr>';
		html += '<th class="icon-contact">Contact</th>';
		html += '<td>' + data.PhoneNr + '</td></tr>';
	}
	if (data.Route != null && data.Route != '') {
		html += '<tr>';
		html += '<th class="icon-route">Route</th>';
		html += '<td>' + data.Route + '</td></tr>';
	}
	html += '</table>';
	html += '<a class="leesVerder" href="' + data.FriendlyUrl + '">Meer informatie</a>';

	var topLevelElm = $('#search');
	if (topLevelElm == null || topLevelElm.length==0) { topLevelElm = $('#visitorSearch'); }

	topLevelElm.find('.searchDetails').html(html);
}



/* 
 SETFORMS
 - Runs thru form set withing contentForm class
 - sets * characters in red.
 - hides some asp generated items, and adds classes to others. */
function setForm() {
	var n = 0;
	$.each($('.contentForm fieldset fieldset'), function () {
		n++
		var txt = $(this).find('legend').text();
		$(this).find('legend').replaceWith('<div class="legendary legend_'+n+'">'+ txt+'</div>');

	});
	
	$.each($('.contentForm label'), function () {
		$(this).html ($(this).text().replace('*','<span class="mandatory">*</span> '));
	});

	$.each($('.contentForm input'), function () {
		if ($(this).attr('type') == "radio") {
			$(this).addClass('radiobutton');
			$(this).next().addClass('radiolabel');
		}
		if ($(this).attr('type') == "checkbox") {
			$(this).addClass('checkbox');
			$(this).next().addClass('checkboxlabel');
		}
	});

	$.each($('.contentForm fieldset fieldset input:not(.contentForm fieldset fieldset fieldset input)'), function () {
		var size = $(this).attr('size');
		
		var unitsize = 10;
		if ($(this).attr('type') == 'text') { $(this).addClass('form_size_' + size); };
	});
	
	$.each($('.contentForm fieldset fieldset span'),function(){
		var id = $(this).attr('id');
		if(id.indexOf('requiredvalidator') == -1) $(this).css('display','none');
	});
	$('.contentForm #ctl00_cphMainContent_btnSend').addClass('standardSubmit');

}

/* Filters for Agenda page*/

function initEventFilters() {
    $('#agenda_categorie').change(function () { filterEvents(); });
    $('#agenda_specialisme').change(function () { filterEvents(); });
    $('#agenda_afdeling').change(function () { filterEvents(); });
}

function filterEvents() {
	if ($('#agenda_categorie').val() != undefined) {
		var cat = $('#agenda_categorie').val();
		var spec = $('#agenda_specialisme').val();
		var afd = $('#agenda_afdeling').val();
		$('#ResultArea').load('?cat=' + cat + '&afd=' + afd + '&spec=' + spec + ' #innerResultArea');
	}
}

/*Function background list click.*/
function interactListBg(element){
	var t = $(element);
	$.each($(element).children('li'), function () {
		var l = $(this).find('a').attr('href');
		$(this).click(function () {
			window.location = l;
			return false;
		}); ;
	});
}

/* EQUALIZE
 @container/element - objects to look for within container
 @min height of objects.

- Function equalize. automaticly corrects heights of floating items in corresponding floating rows.*/

function equalize(obj, minheight){
	var minHeight = minheight || 42;
	var lvl = $(obj).position().top
	var newLvl = lvl;
	var itemArr = new Array();
	var height = 0;
	var newHeight;
	$.each($(obj),function(){
		newLvl = $(this).position().top
		newHeight = $(this).height();
		$(this).css({'height':minHeight+'px'});
		if(newLvl > lvl){
			lvl = newLvl;
			for(var i=0; i<= itemArr.length; i++){
				$(itemArr[i]).css('height', height);
			}
			itemArr = [];
			height = 0;
		}
		if(newHeight > height)height = newHeight;
		itemArr.push($(this));
	})
}


function openTwitter(url) {
	window.open(url, 'Twitter', 'status=1,toolbar=0,location=1,menubar=0,directories=0,resizable=1,scrollbars=0,height=400,width=533');
}

function openFacebook(url) {
	window.open(url, 'Facebook', 'status=1,toolbar=0,location=1,menubar=0,directories=0,resizable=1,scrollbars=0,height=400,width=533');
}

function openHyves(url) {
	window.open(url, 'Hyves', 'status=1,toolbar=0,location=1,menubar=0,directories=0,resizable=1,scrollbars=0,height=450,width=533');
}
