function ready() {
	$("ul.list-tabs li").roundcorner('top');
	$("div.list-box h2").roundcorner('top');
	$("img.small").roundcorner('both', '-5-white');

	$('div.results-cnt').highlight().config();
	$('h3.artikelen').highlight().config();
	$('div.config label.more').config();
	$('div.results-tab').roundcorner('top', '-ddd');
	$('div.zoek-box').roundcorner('both');
	$('div.zoek-box').moreLess();
	$('div.zoek-box').find('button').bind("click", function(){
		$(this).parents('form').eq(0).submit();
	});
	$('div.zoek input[@type=text]').focus();
	$('ul.list-tabs li.leeg a').bind('click', function(evt) {
		evt.preventDefault();
	});
	
	$('div.zoek input').keywordFilter();
	$('#trefwoord ul.list-tabs li a').keywordTabs();
	
	$('#trefwoord dt.rel-community').addTabbedMovieLists($('table.result').length > 0 ? ['rated', 'hot'] : ['hot']);
	$('#TVgids dt.rel-community').addTabbedMovieLists(['ratedOnTv', 'hotOnTv']);
	
	$('div.list-box').keywordListJump();
	
	var city = $('h3.artikelen span');
	if (city.length > 0 && city.text() == '') {
		$('div.results-cnt').click();
	}
	
	// Televisie
	$('#longView dd').selectLongView();
	//$('tr.light').addClass('hidden');
	$('td.past img').click(function() {
		$('tr.light').toggleClass('hidden');
		$(this).toggleClass('fold');
	});
}

/** 
* Open config dialog.
* @alias jQuery.prototype.config
* @return {jQuery}
*/
jQuery.fn.config = function() {
	return this.click(function() {
		//if ($.browser.msie) // slideToggle doesn't work in IE (jquery 1.1.4) or anywhere else :(
			$('div.config').toggleClass('hidden');
		//else
		//	$('div.config').slideToggle();
		return false;
	});
}
/** 
* Adjust pagesize.
* @alias jQuery.prototype.pageSize
* @return {jQuery}
*/
jQuery.fn.pageSize = function() {
	return this.each(function() {
		var initialized = false;
		var span = $(this).find('span');
		var len = span.text();
		$(this).hover(function() {
			$(this).addClass('highlight');
			span.text('');
			var lengths = [10, 25, 50];
			for (var l in lengths) {
				if (lengths[l] == len) {
					var b = $.create('b');
					b.html(len);
					span.append(b);
				} else {
					var a = $.create('a');
					a.attr('href', '?' + changeUrlParam('pageSize', lengths[l]));
					a.click(function() {
						len = lengths[l];
					});
					a.html(lengths[l]);
					span.append(a);
				}
				span.append(document.createTextNode(' '));
			}
		}, function() {
			$(this).removeClass('highlight');
			//$(this).find('span').text($(this).find('b').text());
			$(this).find('span').text(len);
		});
	});
};

/** 
* Filter trefwoorden
* @alias jQuery.prototype.keywordFilter
* @return {jQuery}
*/
jQuery.fn.keywordFilter = function() {
	return this.bind('keyup', null, function(e) {
		var z = this.value.toLowerCase();
		var trefwoorden = $('ol.trefwoorden li');
		trefwoorden.each(function(i, el) {
			var woord = $(el).text().toLowerCase();
			if (match(z, woord)) {
				$(el).removeClass('hidden');
			} else {
				$(el).addClass('hidden');
			}
		
		});
		
	});
	
	function match(zoek, subject) {
		if (zoek == '')
			return true;

		var m = false;
		$.each(zoek.split(/ /g), function(i, z) {
			$.each(subject.split(/[ -]/g), function(j, s) {
				if (z != '' && s.indexOf(z) == 0) {
					m = true;
					return;
				}
			});		
		});
		return m;
	}
}

/** 
* Keyword browser tabs
* @alias jQuery.prototype.keywordTabs
* @return {jQuery}
*/
jQuery.fn.keywordTabs = function() {
	return this.click(function() {
		var list = $('ol.trefwoorden');
		var type = $(this).parents('li').attr('className');
		var text = $(this).text();
				
		$('#keyword-head span').text(text);
		
		var titleReg = /-.+-/;/* capture part between first and last dash */
		function changeTitle(to){
			document.title = document.title.replace(titleReg, to);
		}
		switch(type.match(/[^\s]+/)[0]){
			case "genres":
				changeTitle("- Genres -");
				break;
			case "countries":
				changeTitle("- Landen -");
				break;
			case "tags":
				changeTitle("- Tags -");
				break;
			default:
				/* all or selected */
				var selection = $('h1.head');
				if(selection.length > 0 && selection.children().length > 0){					
					var arrSel = new Array();
					selection.find("> *").each(function(){
						 arrSel.push($(this).text());
					});					
					changeTitle("- "+ arrSel.join('') +" -");					
				}else{
					changeTitle("- Alles -");
				}												
		}		
		list.removeClass('only-genres').removeClass('only-countries').removeClass('only-tags');		
		if (type != 'alles')
			list.addClass('only-'+type);
		var h2 = $(this).parents('div.list-box').find('h2');
		h2.removeClass('genres').removeClass('countries').removeClass('tags');
		if (type != 'alles')
			h2.addClass(type);
		return false;
	});
}

/** 
* Jump in 3tabs-component.
* @alias jQuery.prototype.keywordListJump
* @return {jQuery}
*/
jQuery.fn.keywordListJump = function() {
	return this.each(function() {
		var container = $(this);
		var ul = container.find('ul.top');
		container.find('h5').each(function(){
			var h5 = $(this);
			var list = h5.next('ul, ol');
			
			container.listJumpIcon(ul, 'tag', h5, list.children().length, container.find('div.keywords-scroll'));
		});
	});
};

/** 
* Jump in 3tabs-component.
* @alias jQuery.prototype.selectLongView
* @return {jQuery}
*/
jQuery.fn.selectLongView = function() {
	var shortView = $.cookie('view') == 'short';
	var elts = $(this);
	switchView(elts);

	return this.each(function() {
		$(this).click(function() {
			shortView = this.id != 'longViewOption';
			$.cookie('view', shortView ? 'short' : 'long');
			switchView(elts);
			return false;
		})
	});
	
	function switchView(elt) {
		if (shortView) {
			//$('div.description').slideUp();
			$('div.description').addClass('hidden');
		} else {
			//$('div.description').slideDown();
			$('div.description').removeClass('hidden');
		}
		elt.parent().find('dd').each(function() {
			if ((this.id == 'longViewOption') ^ shortView)
				$(this).addClass('selected');
			else
				$(this).removeClass('selected');
		})
	}
};