
if( window.jQuery )  // Avoid more errors in IE 5.0
{
  $(document).ready(function(){
    window.ThemeBoard = new ClassThemeBoard();

    // Give links with rel="external" a target="_blank" attribute
    $(document.links).filter('[href][rel=external]').each(function() { this.target = '_blank'; });

    $("#print a").click( function ( event )
    {
      window.print();
    } );

    // Show "infolink" elements, add an onclick handler,
    // to toggle the display of moreinfo/lessinfo elements.
    $('#page a.infolink')
      .show().css('display', 'inline')  // workarround for default 'display:block', fixes Konqueror.
      .click( function() {
      $(this.parentNode.parentNode).find('.moreinfo').toggle().end()
                                   .find('.lessinfo').toggle();
      return false;  // block default link href processing.
    });

    // Hide "moreinfo" elements, and insert a span with ellipses to the elements whose parent has class "desc". Show elements with class "lessinfo".
    $('#page .moreinfo').hide().parent('.desc').children('span.moreinfo').before('<span class="lessinfo">&#0133;</span>');
    $('#page .lessinfo').show().css('display', 'inline');  // make sure the element has the proper default to toggle later.

    // Handle searchbox default text by defining blur and focus event handlers
    window.defaultSearchText = 'ik zoek...';
    $('#q').focus( function() { this.value == defaultSearchText ? this.value = "" : false; } );
    $('#q').blur(  function() { this.value == '' ? this.value = defaultSearchText : false; } );
  });

}


function ClassThemeBoard() {
	this.CurrentItem = 0;
	this.ItemCount = $('#themeview div').size();
	this.slidesteps = 9;
	this.stepsize = 2; /* 'em' units */
	this.xleft = 0;
	this.steps = 0;
	this.timerId;

	this.setButtons = function() {
		this.CurrentItem > 0 ? $('#arrowleft').show() : $('#arrowleft').hide();
		this.CurrentItem < this.ItemCount -1 ? $('#arrowright').show() : $('#arrowright').hide();
	}

	this.onClick = function(_step) {
		if (this.steps == 0) {
			var direction = '';

			if (_step==-1) {
				direction = "left";
				this.CurrentItem--;
			}
			else if (_step==1) {
				direction = "right";
				this.CurrentItem++;
			}

			this.setButtons();

			if (direction.length > 0) {
				var dit = this;
				dit.slideImages(direction);

				this.timerId = setInterval(function() {
					dit.slideImages(direction);
				}, 30);
			}
		}
	}

	this.slideImages = function(_direction) {
		if (this.steps == this.slidesteps) {
			clearInterval(this.timerId);
			this.steps = 0;
		}
		else {
			this.xleft += (_direction == 'left') ? this.stepsize : -1 * this.stepsize
			document.getElementById('themeview').style.left = this.xleft + 'em';
			this.steps++;
		}
	}
}


// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)

/* prevent IE6 background-image flickering, see www.mister-pixel.com
try {
  document.execCommand("BackgroundImageCache", false, true);
}
catch(err) {}*/

/*@end @*/
