window.addEvent('domready',function(){
	if ($('comment_form')) hookUpCommentFields();
})

/* Now boots from ouweDoosBlockClass.onLoadData ) :) */
function ouwe_shit() {
	var teller = 0;
	var fotos = $$('div.ouwefoto');
	var aantal = fotos.length;
	$('ouwe_links').addEvent('click',function(){
		leftx = document.getElementById('ouwefotos');
		x = leftx.style.left.toInt();
		if(x == "" || isNaN(x)){
			x = 0;
		}
		if (teller > 0) {
			teller--;
			$('ouwefotos').effect('left',{ duration: 500, transition: Fx.Transitions.Bounce.easeOut, wait:true }).start(x, 0-(teller * 82) );
		}
	})

	$('ouwe_rechts').addEvent('click',function(){
		rightx = document.getElementById('ouwefotos');
		x = rightx.style.left.toInt();
		if(x == "" || isNaN(x)){
			x = 0;
		}
		if (teller < (aantal-3)) {
			teller++;
			$('ouwefotos').effect('left',{ duration: 500, transition: Fx.Transitions.Bounce.easeOut, wait:true }).start(x, 0-(teller * 82) );
		}
	})
}

var allChecksPassed = true;

function hookUpCommentFields ()
{
  var form = $('comment_form');
  var fields = ['name', 'email', 'website', 'comment', 'antispam'];
  var values = ['Naam', 'E-mail', 'Website', 'Reactie...', 'Bovenstaande tekens'];
  var checks = values.associate( fields );
  var elements = form.getElements('input').extend( form.getElements('textarea') );
  elements.each( function ( item ) {
    if ( fields.contains( item.name ) ) {
      item.addEvent( 'check', function () { if ( !allChecksPassed ) return false; else return allChecksPassed = (this.value != checks[this.name]); } );
      item.addEvent( 'focus', function () { if ( this.value == checks[this.name] ) this.value = ''; } );
      item.addEvent( 'blur',  function () { if ( this.value == '' ) this.value = checks[item.name]; } );
    }
  } );
}

function checkCommentForm ()
{
  var form = $('comment_form');
  var fields = ['name', /*'email', 'website',*/ 'comment', 'antispam'];
  var elements = form.getElements('input').extend( form.getElements('textarea') );
  elements.each( function ( item ) {
    if ( fields.contains( item.name ) ) {
      item.fireEvent( 'check' );
    }
  } );

  if ( !allChecksPassed ) {
    allChecksPassed = true;
    alert( "Helaas, naam en reactie verplicht." );
    return false;
  } else {
    allChecksPassed = true;
    return true;
  }
}

function refreshCaptcha ()
{
  $('captcha_image').src = '/index.php/antispam/?rand=' + randomString();
  return false;
}

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function showNewsLetterSignOff ()
{
  var div = $('newsletter');
  div.empty();
  div.appendChild( new Element( 'p' ).setText( 'Meld je hier af voor de Streetpioneers nieuwsbrief' ) );
  form = new Element( 'form' );
  form.setAttribute( 'action', '/index.php/newsletter/unsubscribe' );
  form.setAttribute( 'method', 'post' );
  form.appendChild( new Element( 'input',  {'name': 'newsletter_email'} ) );
  form.appendChild( new Element( 'br' ) );
  form.appendChild( new Element( 'br' ) );
  form.appendChild( new Element( 'button', {'type': 'submit'} ).setText( 'Uitschrijven' ) );
  div.appendChild( form );
  return false;
}

function archiveGotoPage( page )
{
  $('archiveFilter').getElement( 'input[name=page] ').value = parseInt(page);
  $('archiveFilter').submit();
  return false;
}