$.fn.tagName = function() {
    return this.get(0).tagName;
}

$(document).ready(function() {
	
	var timeout = 5000;
	var speed = 1000;
		if ( adConfig != undefined ) {
			 speed = adConfig.fadeSpeed;
			 timeout = adConfig.visibleTime;
		}
		
	$('div.Advertentie').cycle({
		timeout : timeout,
		speed : speed
	});
	
	$('div.Advertentie div.Afbeelding').cycle({
		timeout : timeout,
		speed : speed
	});
	
	$('.Expandable').click(function() {
				
		if ( $(this).attr('state') == 'opened') {
			// sluiten
			var tag = $(this).tagName();

			$(this).next().removeClass('Expanded').addClass('Collapsed');
			$(this).attr('state', 'closed').removeClass('Expanded').addClass('Collapsed');
		} else {
			// openen
			var tag = $(this).tagName();
			
			$(this).next().removeClass('Collapsed').addClass('Expanded');
			$(this).attr('state', 'opened').removeClass('Collapsed').addClass('Expanded');
		}
	}).each(function() {
		var tag = $(this).tagName();
		if ( $(this).attr('state') == undefined && $(this).hasClass('Collapsed')) {
			$(this).attr('state', 'closed');
			$(this).nextAll().each(function() {
				if ( $(this).tagName() != tag ) {
					$(this).removeClass('Expanded');
					$(this).addClass('Collapsed');
				} else {
					return false;
				}
			});
		} else if ( $(this).attr('state') == undefined && ($(this).hasClass('Expanded') || !$(this).hasClass('Collapsed')) ) {
			$(this).attr('state', 'opened');
			$(this).nextAll().each(function() {
				if ( $(this).tagName() != tag ) {
					$(this).removeClass('Collapsed');
					$(this).addClass('Expanded');
				} else {
					return false;
				}
			});			
		} // else: state was already set
		
		
	});
});

/**
 * function to load the number of weeks in a year
 */ 
function setWeeks( Jaar, Week ) {
	
	var WeekBox = document.getElementById( 'WeekBox' );
	var Jaar = document.Filter.Jaar.value;
	var Week = Week;
	var Weeks = '';
	var i = '';
	
	if( Jaar == 2008 ){
		var Weeks = 52;
	}
	if( Jaar == 2009 ){
		var Weeks = 53;
	}
	if( Jaar == 2010 ){
		var Weeks = 52;
	}	
	if( Jaar == 2011 ){
		var Weeks = 52;
	}
	if( Jaar == 2012 ){
		var Weeks = 53;
	}
	if( Jaar == 2013 ){
		var Weeks = 53;
	}
	while (WeekBox.firstChild){
		WeekBox.removeChild(WeekBox.firstChild);
	}
	
	for ( var i = 1; i <= Weeks; i++ ) {
		
		var Option = document.createElement( 'option' );
		Option.text = i;
		Option.value = i;
		
		if( (Week) == i ) {
			Option.selected = true;
		}
		
		try {
			WeekBox.add( Option, null );
		} catch ( e ) {
			WeekBox.add( Option );
		}
	}
	
}