var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-4742815-3']);
_gaq.push(['_trackPageview']);
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

$(document).ready(function() {

	rss_clientcallback();

	
	$('#menu li a').each(function(){
		$(this).wrapInner('<span />');
	})

	//select first menu item if none is selected 
	var active_is_set=false;
	
	$('#menu ul li').each(
			function(){
			if ($(this).hasClass('active'))
				var active_is_set=false;
			})
		 
	 if (!active_is_set){
			$('#menu ul li:first').addClass('active'); 
	}
	
	$("li:has(a:empty)").remove();
	$("li:has(ul)").addClass("submenu");
	
	$('#uPrefix').remove()
	$('#pPrefix').remove()

	$('#segmentLogin_submit input').attr('id', 'login');

	$('#segmentLogin_username').append($('#segmentLogin_password').html())
	$('#segmentLogin_username').append($('#segmentLogin_submit').html())
	$('#segmentLogin_username input:first').val('Gebruikersnaam');
	$('#segmentLogin_password').remove()
	$('#segmentLogin_submit').remove();
	$( 'form[name=segmentLogin] input' ).one( 'focus', function() {
		$( this ).attr( 'value', '' );
	} );
	
	$( 'head' )
		.attr( 'profile', 'http://www.w3.org/2005/10/profile' )
		.append( '<link rel="icon" type="image/png" href="/files/88/favicon.png" />' )
	;
	
	$( '#inschrijfForm' ).submit( function() {
		var errors = false;
		$( this )
			.find( '.error' ).addClass('hiding').slideUp( function() { $( this ).remove(); } ).end()
			.find( 'input[name=voornaam], input[name=achternaam], input[name=geboortedatum], textarea[name=adres], input[name=postcode_plaats], input[name=tel], input[name=emeel]' )
				.each( function() {
					if( $( this ).val() == '' )
					{
						$( this )
							.after( '<p class="error">Dit veld is verplicht</p>' )
							.next()
								.hide()
								.slideDown()
						;
						errors = true;
					}
				} )
			.end()
			.find( 'input[name=accept_gedragscode]' )
				.each( function() {
					if( !$( this ).attr( 'checked' ) )
					{
						$( this ).parent()
							.append( '<p class="error">U moet met de gedragscode instemmen om in te schrijven</p>' )
							.find( '.error' )
								.hide()
								.slideDown()
						;
						errors = true;
					}
				} )
			.end()
			.find( 'input[name=accept_voorwaarden]' )
				.each( function() {
					if( !$( this ).attr( 'checked' ) )
					{
						$( this ).parent()
							.append( '<p class="error">U moet met de gedragscode instemmen om in te schrijven</p>' )
							.find( '.error' )
								.hide()
								.slideDown()
						;
						errors = true;
					}
				} )
			.end()
		;
		if( errors ) $( 'html, body' ).animate( { scrollTop: $('p.error:not(.hiding):first').offset().top - 100 } );
		return !errors;
	} );
	
	$( 'td.rating input' ).change( function() {
		$( this )
			.nextAll( 'label' ).removeClass( 'checked' ).end()
			.prevAll( 'label' ).addClass( 'checked' ).end()
			.next().addClass( 'checked' )
		;
	} );
	$( 'td.rating input:checked' ).change();
	$( 'td.rating label' ).click( function() {
		$( 'input#' + $( this ).attr( 'for' ) ).change();
	} );
});


function rss_clientcallback(){
	$('.rsslink').each(function()
	{
	  $(this).wrapInner("<h1></h1>");
	  $(this).parent().append('<a style=\'float:right\' href=\''+ $(this).attr('href')+'\'>Lees verder</a><br>');
	});
  	Cufon.replace('h1, h2, h4', { fontFamily: 'Lintel' });
		Cufon.replace('#menu li span a, .button', { fontFamily: 'Melbourne', hover: true });
		$('.rss_next').css('float','right');
		$('.rss_previous').css('float','left');

		

}

