/**
 * Common functions/objects & page scripts
 * 
 * Also Peppered config (jQuery.ppprd) is defined here 
 * 
 * Requires: jQuery (1.2.x, 1.3.x, 1.4.x)
 * load: head
 * 
 * @author AK
 */

// console
if (typeof console == 'undefined') {
	console = {
		log: function(){},
		debug: function(){}
	};
}

function isEmpty(str) { if (typeof str == 'undefined' || str === null || str === '' || str == 0) { return true; } return false; }

//jQuery getQueryParam Plugin 1.0.0 (20100429)
//By John Terenzio | http://plugins.jquery.com/project/getqueryparam | MIT License
(function($){$.getQueryParam=function(param){var pairs=location.search.substring(1).split('&');for(var i=0;i<pairs.length;i++){var params=pairs[i].split('=');if(params[0]==param){return params[1]||'';}}return undefined;};})(jQuery);

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
 jQuery.cookie = function (key, value, options) {
    
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

//console.log(Boolean($.cookie('filterOpen')) == true);

var P = {};

P._glob = {};

P._isInIFrame = (window.location != window.parent.location) ? true : false;

;(function($){

/**
 * various functions and definitions
 *
 */
/**
 * Peppered config
 */
$.ppprd = {
	debug: {
		enabled: true,
		logAlerts: false // alerts for clients that don't have the firebug console (otherwise silent)
	}
};


/**
 * Debug/logging
 * Uses Firebug (window.console) when present
 */
$.log = function(message){
	if (!$.ppprd.debug.enabled) {
		return false;
	}
	if (window.console && window.console.debug) {
		console.debug(message);
	}
	else {
		if ($.ppprd.debug.logAlerts) {
			alert(message);
		}
		else {
			return;
		}
	}
};


/**
 * Image Replace
 * Appends some spans to selection, to aid in IR (css)
 * @author AK|Peppered
 */
$.fn.ImageReplace = function(){
	return this.each(function(){
		$(this).addClass('ir');
		$(this).append('<span class="ir-aid"><span></span></span>');
	});
};


/**
 * autoSelect, jQuery plugin
 * 
 * Auto-submit forms when select options have changed
 * Smoothens out (almost) behavioural differences between browsers.
 * Inpsired on: http://themaninblue.com/writing/perspective/2004/10/19/
 * 
 * usage: $selection.autoSelect({options})
 * 
 * @author AK | Peppered
 * @version 1.0.1
 */
(function(a){a.fn.autoSelect=function(){return this.each(function(){var b=a(this);b.validKeyChange=true;b.initValue=a(this).val();b.change(function(){if(b.validKeyChange&&(this.value!=b.initValue)){b.initValue=this.value;this.form.submit()}});b.keydown(function(c){if((c.keyCode==13||c.keyCode==9)&&this.value!=b.initValue){b.validKeyChange=true;b.change()}else{if(c.keyCode==27||((c.keyCode==13||c.keyCode==9)&&this.value==b.initValue)){this.value=b.initValue}else{b.validKeyChange=false}}})})}})(jQuery);


/**
 * PopupWindow object
 * spawns/handles ye classic popup windows
 *
 * @author AK
 *
 * requires: jQuery 1.2.x, 1.3.x
 */
window.PopupWindow = function(){
	this.width = 500;
	this.height = 500;
	this.$container = $(window);
	this.offsetLeft = 0;
	this.offsetTop = 0;
	this.menubar = 'no';
	this.location = 'yes';
	this.resizable = 'yes';
	this.scrollbars = 'yes';
	this.status = 'yes';
	this.name = 'popupWindow';
	this.url = '';
};
window.PopupWindow.prototype.prepare = function(){
	var oAnchor = this.anchor;
	if (typeof oAnchor.data('popWinObject') == 'object') {
		var oPopWin = oAnchor.data('popWinObject');
		if (!oPopWin.closed) {
			oPopWin.close();
		}
	}
	var sHref = oAnchor.attr('href');
	if (sHref.indexOf('?') > -1) {
		sHref += '&';
	} else {
		sHref += '?';
	}
	sHref += 'popup=true';
	this.url = sHref;
};
window.PopupWindow.prototype.spawn = function(){
	this.prepare();
	var x = this.$container.width() / 2 - (this.width / 2);
	var y = this.$container.height() / 2 - (this.height / 2);
	
	if (x < 0) { x = 0; }
	if (y < 0) { y = 0; }
	
	if (typeof window.screenX !== 'undefined') {
		x += window.screenX;
		y += window.screenY;
	}
	else if (typeof window.screenLeft !== 'undefined') {
		x += window.screenLeft;
		y += window.screenTop / 2;
	}
	
	this.offsetLeft = x;
	this.offsetTop = y;
	
	var oPopWin = window.open(this.url, this.name, 'width=' + this.width + ',height=' + this.height + ',left=' + this.offsetLeft + ',top=' + this.offsetTop + ',menubar=' + this.menubar + ',location=' + this.location + ',resizable=' + this.resizable + ',scrollbars=' + this.scrollbars  + ',status=' + this.status);
	
	if (typeof oPopWin != 'undefined') {
		this.anchor.data('popWinObject', oPopWin);
		return true;
	}
	return false;
};

/**
 * Common P object functions
 */

P.spotlight = {
	init: function() {
		var flashConfig = {};
		
		flashConfig = $.extend(true, {
			file: '/flash/slideHome.swf',
			id: 'spotlight',
			width: 928,
			height: 380,
			version: '10',
			expressInstallSwfurl: null,
			flashvars: {
				contentType: 'showcase',
				slideInterval: 5
			},
			params: {
				wmode: 'opaque',
				bgscolor: '#ff0000'
			},
			attributes: {},
			callbackFn: function(e){
				if (e.success) {
					$('#slide').addClass('swfobject');		
				}
				// wait a bit before undoing fixed height (replacement is not perse finished)
				//window.setTimeout(function(){ $cont.height('auto') }, 200);
			}
		}, flashConfig);	
		
		swfobject.embedSWF(flashConfig.file, flashConfig.id, flashConfig.width, flashConfig.height, flashConfig.version, flashConfig.expressInstallSwfurl, flashConfig.flashvars, flashConfig.params, flashConfig.attributes, flashConfig.callbackFn);

	}
};

P.basicSlide = {
	init: function(config) {
		var flashConfig = {};
		
		// some helper div's, for smoother replacement (no 'jumping') & print support
		$('#pageImg').after('<div id="pageSlideWrap"><div id="pageSlideSWF"></div></div>').hide().addClass('print');
		
		flashConfig = $.extend(true, {
			file: '/flash/slideInfo.swf',
			id: 'pageSlideSWF',
			width: 412,
			height: 178,
			version: '10',
			expressInstallSwfurl: null,
			flashvars: {
				imgString: config.imgString,
				slideInterval: 5
			},
			params: {
				wmode: 'opaque',
				bgscolor: '#ff0000'
			},
			attributes: {},
			callbackFn: function(e){
				$.log(e)
				if (e.success) {
					$('#slide').addClass('swfobject');		
				}
				// wait a bit before undoing fixed height (replacement is not perse finished)
				//window.setTimeout(function(){ $cont.height('auto') }, 200);
			}
		}, flashConfig);	
		
		swfobject.embedSWF(flashConfig.file, flashConfig.id, flashConfig.width, flashConfig.height, flashConfig.version, flashConfig.expressInstallSwfurl, flashConfig.flashvars, flashConfig.params, flashConfig.attributes, flashConfig.callbackFn);

	}
};

P.detailSlide = {
		init: function(mediaGalerijId) {
			var flashConfig = {};
			
			// some helper div's, for smoother replacement (no 'jumping') & print support
			$('#showingImg').after('<div id="showingSlideWrap"><div id="showingSlideSWF"></div></div>').hide().addClass('print');
			
			flashConfig = $.extend(true, {
				file: '/flash/slideDetail.swf',
				id: 'showingSlideSWF',
				width: 670,
				height: 380,
				version: '10',
				expressInstallSwfurl: null,
				flashvars: {
					contentType: 'media_galerij',
					media_galerij_id: mediaGalerijId,
					slideInterval: 5
				},
				params: {
					wmode: 'opaque',
					bgscolor: '#ff0000'
				},
				attributes: {},
				callbackFn: function(e){
					$.log(e)
					if (e.success) {
						$('#slide').addClass('swfobject');		
					}
					// wait a bit before undoing fixed height (replacement is not perse finished)
					//window.setTimeout(function(){ $cont.height('auto') }, 200);
				}
			}, flashConfig);	
			
			swfobject.embedSWF(flashConfig.file, flashConfig.id, flashConfig.width, flashConfig.height, flashConfig.version, flashConfig.expressInstallSwfurl, flashConfig.flashvars, flashConfig.params, flashConfig.attributes, flashConfig.callbackFn);

		}
	};

P.calendar = {
	init: function() {
		var $calendar = $('#calendar'),
			$form = $calendar.find('form'),
			$selects = $form.find('select')
		;
		$form.find('input[type="submit"]').hide();
		$selects.change(function(){
			$form.submit();
		});
	}
};


P.cart = {
	init: function() {
		//return false;
		var _this = this,
			$cart = $('#cart'),
			$showingDetail = $('#showingDetail'),
			justAdded = $cart.data('justadded'),
			$item,
			html
		;
		
		
		// justAdded
		// @todo support for showcase
		if (justAdded > 0) {			
			$cart.find('.report.ok').hide();
			
			if ($showingDetail.length) {
				$item = $showingDetail;
				teaser = $item.data('teaser');
			}
			else {
				$item = $('.overviewItem[data-id="'+justAdded+'"]');
				teaser = $item.find('.teaser').html();
			}
			
			if (!$item.length) { return false; } // showcase..
			
			var thumb = $item.data('thumb-overview'),
				date = $item.find('.date').html(),
				time = $item.find('.time').html(),
				room = $item.find('.room').html(),
				title = $item.find('.title').html(),
				checkoutOnClick;
			
			if (P._glob.loggedIn) {
				checkoutOnClick = 'return true;';
			}
			else {
				checkoutOnClick = "$('#uiDialog-justAdded').dialog('close'); P.mtBox.spawnLoginBox('/mijntheater/reserveer/'); return false;";
			}
			
			if ($cart.data('action') == 'add_wensenlijst') {
				h = 'Deze voorstelling is toegevoegd aan uw wensenlijstje';
				btns = '\
					<ul class="buttons">\
						<li><span class="btnWrap fwd"><a class="btn large" href="/mijntheater/wensenlijstje/" onclick="'+checkoutOnClick+'">Naar wensenlijstje</a></span></li>\
						<li><a class="more continue" href="#" onclick="$(\'#uiDialog-justAdded\').dialog(\'close\'); return false;">Verder</a></li>\
					</ul>\
				';
			}
			else {
				h = 'Deze voorstelling is toegevoegd aan uw winkelwagentje';
				btns = '\
					<ul class="buttons">\
						<li><span class="btnWrap fwd"><a class="btn large" href="#"" onclick="$(\'#uiDialog-justAdded\').dialog(\'close\'); return false;">Verder winkelen</a></span></li>\
						<li><a class="more continue" href="/mijntheater/reserveer/" onclick="'+checkoutOnClick+'">Stoelen kiezen</a></li>\
					</ul>\
				';
			}
			
			html = '\
				<h1>' + h + '</h1>\
				<div class="overviewItem default">\
					<span class="wrap">\
						<img width="134" height="134" alt="" src="'+thumb+'" />\
						<span class="date">'+date+'</span><br />\
						<span class="title">'+title+'</span><br />\
						<span class="teaser">'+teaser+'</span><br />\
						<span class="meta">'+room+' | '+time+'</span><br />\
					</span>\
				</div>\
			' + btns;
			
			//console.log($item);
			
			$.pDialog({
				id: 'justAdded',
				type: 'message',
				width: 670,
				height: 'auto',
				title: 'Deze voorstelling is toegevoegd aan uw winkelwagentje',
				content: html,
				extraClass: 'hideTitleTxt',
				resizable: false
			});
		}
		
		// open bigCart
		$('#cart .showAll a.more').click(function(e){
			var $this = $(this),
				href = $this.attr('href')
			;
			if (!P._glob.checkingOut) {
				_this.spawnBigCart(href);
				e.preventDefault();
			}
		});
		
		// checkout
		$('#cart .btn.checkout').click(function(e){
			var $this = $(this),
				href = $this.attr('href')
			;
			if (!P._glob.loggedIn) {
				P.mtBox.spawnLoginBox(href);				
				e.preventDefault();
			}
		});
		
	},
	
	spawnBigCart: function(href){
		$.pDialog({
			id: 'cart',
			type: 'iframe',
			load: href + (href.indexOf('?') > 0 ? '&' : '?') +  'modal=true',
			width: 670,
			height: 500,
			keepInDom: false/*,
			open: function(e, ui){
				var $iframe = $(this).find('iframe');
				$iframe.load(function(){ console.log(this)});
				
			}*/
		});
	}
};

/**
 * bigCart
 */
P.bigCart = {
	init: function() {
		//return false;
		var isInIFrame = (window.location != window.parent.location) ? true : false,
			$bigCart = $('#bigCart')
		;
		
		if ($.getQueryParam('modal') == 'true') {
			
			$bigCart.find('ul.overview a').click(function(e){
				window.parent.location.href = $(this).attr('href');
				e.preventDefault();
			});
			
			$bigCart.find('.btn.continueShopping').click(function(){
				this.form.target = '_parent';
			});
			
			$bigCart.find('.btn.checkout').click(function(){
				if (P._glob.loggedIn == true) {
					this.form.target = '_parent';
				}
				else {
					this.form.action = $.url.query.set(this.form.action, {modal: 'true'});
				}
			});
			
			$bigCart.find('.btn.clear').click(function(){
				this.form.action = $.url.query.set(this.form.action, {modal: 'true'});

			});
		
		}
	
	
	}
};


P.mtBox = {
		
	spawnLoginBox: function(href) {
		$.pDialog({
			id: 'login',
			type: 'iframe',
			load: href + (href.indexOf('?') > 0 ? '&' : '?') +  'modal=true',
			width: 670,
			height: 500,
			keepInDom: false,
			open: function(){
				var $this = $(this);
				$this.append(
					$('<a class="more cancel" href="#">Annuleren</a>').click(function(){
						$this.dialog('close');
					})
				);
				//console.log($(this));
			}
		});
	},
	
	init: function() {
		//return false;
		var $body = $('body'),
			$dialogAnchors,
			_this = this;
		
		if (P._glob.guestKnown == true && P._glob.loggedIn == false ) {
			$dialogAnchors = $('#mtBox li.register a, #mtBox li.login a, #mtBox li.mt a');
		}
		else {
			$dialogAnchors = $('#mtBox li.register a, #mtBox li.login a');
		}
		
		$dialogAnchors.click(function(e){
			var $this = $(this),
				$parent = $this.parent(),
				href = $this.attr('href')
			;			
			_this.spawnLoginBox(href);			
			e.preventDefault();
		});
	},
	
	/**
	 * spawnMessagePop
	 * shows form report in message dialog
	 * invoked from login tpl (iframe)
	 */	
	spawnMessagePop: function() {
		//var $ = window.parent.jQuery;
		//var $document = P._isInIFrame ? $('.ui-dialog-content iframe').contents() : $('body');
		var $document = $('body');
		var $document = $('#uiDialog-login iframe').contents();
		
		var $report = $document.find('.report');
		
		if ($report.length) {
			//var $ = window.parent.jQuery;
			
			//console.log($report.data())
			
			//var $report = $document.find('.report');
			var $msg = $report.wrap('<div/>').parent();
			var msgHTML = $msg.html();
			$msg.remove();
			
			var continueUrl = $report.data('continue-url');
			var btnText = $report.data('btn-text');
			
			var closeFn = null;
			
			if (!isEmpty(continueUrl)) {
				closeFn = function(){
					window.location = continueUrl;
				}
			}
			
			$.pDialog({
				type: 'message',
				id: 'mtFormReport',
				content: msgHTML,
				modal: true,
				keepInDom: false,
				close: closeFn,
				buttons: [{
					text: isEmpty(btnText) ? 'Sluiten' : btnText,
					click: function() {
//						if (!isEmpty(continueUrl)) {
//							window.location = continueUrl;
//						}
						$(this).dialog('close');
					},
					'class': 'btn'
				}]
			});
			
			if ($report.data('close-iframe') == true) {
				$('#uiDialog-login').dialog('close');
			}
		
		}
	}
};

// share

P.share = {
	init: function() {
		var popWin = null;
		$('.share .facebook a,  .share .twitter a, .share .hyves a').click(function(e) {
			var $this = $(this);
			
			popWin = new PopupWindow();
			popWin.anchor = $this;
			popWin.width = 550;
			popWin.height = 436;
			if (popWin.spawn()) {
				e.preventDefault();
			}
			
			

		});
	}
};

/**
 * Writings
 */
P.writings = {
	init: function() {
		var $section = $('#writings div.section'),
			label = ''
		;
		
		$section.each(function() {
			var $section = $(this),
				minHeight
			;
			if ($section.hasClass('open')) {
				label = 'verbergen';
			}
			else {
				label = 'tonen';
				$section.children('.content').hide();
			}
			
//			if (section_id == 'twitter') {
//				
//			}
			
			$('<a class="toggle" href="#">'+label+'</a>')
				.click(function(e){
					var $this = $(this),
						$section = $this.parent(),
						$content = $section.children('.content'),
						section_id = $section.attr('id')
					;
					
					if (section_id == 'twitter') {
						if ($content.is(':hidden')) {
							minHeight = $section.height();
							$teaserTweet = $section.find('.tweet.teaser');
							$section.css('minHeight', minHeight);
							//$teaserTweet.css({ position: 'absolute', left: '20px' });
							$teaserTweet.hide();
						}
						else {
							//$section.css('minHeight', 0);
							//$teaserTweet.css('position', 'static');
							//$teaserTweet.show();
						}
						
						$content.slideToggle(function(){
							if ($content.is(':hidden')) {
								//$teaserTweet.css('position', 'static');
								$teaserTweet.show();
								$section.removeClass('open').addClass('closed');
								$this.text('tonen');
							}
							else {
								$teaserTweet.hide();
								//$section.css('minHeight', minHeight);
								$section.removeClass('closed').addClass('open');
								$this.text('verbergen');
							}
						});	
					}
					else {
						$content.slideToggle(function(){
							if ($content.is(':hidden')) {
								$section.removeClass('open').addClass('closed');
								$this.text('tonen');
							}
							else {
								$section.removeClass('closed').addClass('open');
								$this.text('verbergen');
							}
						});	
					}
					
					e.preventDefault();
				})
				.appendTo($section)
			;
		});
	}
};

/**
 * Paging
 * 
 * .last() is used, as this script can be invoked multiple times (multiple paginations)
 */
P.paging = {
	init: function() {
		var $paging = $('div.paging').last(),
			$form = $paging.find('form')
		;
		$form.find('input[type="submit"]').hide();
		$form.find('select').change(function(){
			$.log('option change, submit');
			this.form.submit();
		});
		$form.submit(function(e){
			$.log('paging submit');
			$.log(this)
			e.preventDefault();
		});
	}
};

/**
 * P.showingsFilter
 */
(function() {
	
	// globals
	var $unit,
		submitDelayTime = 750;
	
	P.showingsFilter = {
			
		// init
		init: function() {
			$unit = $('#showingsFilter');			
			var $btn = $unit.find('.showHideToggle a'),
				$btn_lbl = $btn.find('.lbl'),
				$toggleSelection = $unit.find('fieldset div.wrap'),
				$options = $unit.find('input[type="checkbox"]'),
				$selects = $unit.find('select'),
				optionsChangeTimeout = null,
				delayedSubmit = function() {	
					window.clearTimeout(optionsChangeTimeout);
					optionsChangeTimeout = window.setTimeout(function(){
						$.log('submit now');
						$options.click(function(){ return false; });
						$('body, #showingsFilter form *').css('cursor', 'wait');
						$('body, #showingsFilter form').submit();
					}, submitDelayTime)
				}
			;
			$('.defaulthidden').removeClass('hidden');
			$unit.find('input.submit').hide();
			$btn.click(function(e){
				$unit.addClass('toggling');
				$toggleSelection.slideToggle(function(){
					$unit.removeClass('toggling');
					if ($(this).is(':hidden')) {
						document.cookie = 'filterOpen=false; path=/';
						$unit.addClass('closed');
						$btn_lbl.text('Openen');
					}
					else {
						document.cookie = 'filterOpen=true; path=/';
						$unit.removeClass('closed');
						$btn_lbl.text('Sluiten');
					}
					$btn.fadeIn(200);
				});
				$btn.fadeOut(200);
				e.preventDefault();
			});
			
			$unit.find('input.groep-deselect').click(function(){
				var inputs = $(this).parents('fieldset').find('input');
				inputs.removeAttr('checked');
				inputs.first().attr('checked', 'checked');
				return true;
			});
			
			// wait a bit before doing a submit (user might choose other options)
			$options.click(delayedSubmit);
			$selects.change(delayedSubmit);
		},
		
		// removeKenmerk
		removeKenmerk: function(groupName,kenmerkId) {
			var idToRemove = groupName + '_' + kenmerkId;
			var	$input = $unit.find('input#' + idToRemove);
			console.log(idToRemove);
			submitDelayTime = 0;
			if($input != null && $input.length != 0)
			{
				$input.click();
			}
			else
			{

				$input = $unit.find('select#' + groupName);
				$input.find('option:selected').removeAttr('selected');
				$input.change();
			}
			return false;
		}
		
	};
	
})();


P.searchBox = {
	init: function() {
		var $input = $('#searchInput'),
			dummyTxt = 'Trefwoord...';
		$input
			.val(dummyTxt)
			.focus(function(){
				if ($input.val() == dummyTxt) {
					$input.val('');
				}
				$input.removeClass('dummyTxt')
			})
			.blur(function(){
				if ($input.val() == '') {
					$input.val(dummyTxt);
					$input.addClass('dummyTxt')
				}
			})
			.addClass('dummyTxt')
		;
	}
};

P.newsletterSubscribe = {
	init: function() {
		var $input = $('#nlForm-email'),
			dummyTxt = 'E-mailadres...';
		$('#nlForm label').hide();
		$input
			.val(dummyTxt)
			.focus(function(){
				if ($input.val() == dummyTxt) {
					$input.val('');
				}
				$input.removeClass('dummyTxt')
			})
			.blur(function(){
				if ($input.val() == '') {
					$input.val(dummyTxt);
					$input.addClass('dummyTxt')
				}
			})
			.addClass('dummyTxt')
		;
	}
};

P.showingDates = {
	init: function(showAlternativeDates) {
		var $unit = $('#showingDates'),
			$h = $unit.find('h2'),
			$ul = $unit.find('ul')
			showAlternativeDates = showAlternativeDates || false,
			$btn = $('<a href="#" class="btn toggle">' + (showAlternativeDates ? 'Verbergen' : 'Andere speeldata') + '</a>').click(function(e){
				$ul.slideToggle(function(){
					var $this = $(this);
					if ($this.is(':hidden')) {
						$btn.text('Andere speeldata');
					}
					else {
						$btn.text('Verbergen');
					}
				});
				e.preventDefault();
			});
		
		$ul.after($btn);
		if (!showAlternativeDates) {
			$ul.hide();
		}		
		$h.addClass('noscr');
	}
};

P.prices = {
	init: function(query) {
		var $table = $(query).find('table'),
			$successiveTbodies = $table.find('tbody:not(.first)'),
			$btn
		;
		if ($successiveTbodies.length) {
			$successiveTbodies.hide();			
			$btn = $('<a href="#" class="btn toggle" id="showAllPrices">Alle prijzen</a>')
				.click(function(e){
					//$btn.fadeOut(200);
					$successiveTbodies.slideToggle(function(){
						var $this = $(this);
						if ($this.is(':hidden')) {
							$btn.text('Alle prijzen');
						}
						else {
							$btn.text('Verbergen');
						}
						//$btn.fadeIn(200);
					});
					e.preventDefault();
				})
				.insertAfter($table)
			;			
		}
	}
};



/**
 * DOM ready stuff
 */
$(function(){

	// body js/jquery is enabled class
	$('body').removeClass('nojs').addClass('jsfx');
	
	// refresh queue (prevent timeout)
	if (typeof Xajax != 'undefined') 
		window.setInterval("xajax_UpdateActivity()", 270000);
	
	/**
	 * cross browser stuff
	 */
	// correct boxmodel input[type="text"] FF<3
	if ($.browser.mozilla && parseFloat($.browser.version) < 1.9) {
		$("body").addClass("FF2");
	}
	// ie6 workarounds for unsupported css
	if ($.browser.msie && parseFloat($.browser.version) < 7) {
		$("body").addClass("IE6");
		$("acronym[title]").addClass('hasTitle'); /* note: ie6 doesn't support abbr element */
	}
	
	
	/**
	 * Anchors
	 *
	 */
	/** 
	 * hover images for certain anchor types
	 */
	/*$('a.more').addClass('more-fx').wrapInner('<span class="hoverHelper" />');
	$('a.next').addClass('next-fx').wrapInner('<span class="hoverHelper" />');
	$('a.prev').addClass('prev-fx').wrapInner('<span class="hoverHelper" />');*/
	
	/**
	 * external (rel="external") and
	 * popup (rel="popup") handling
	 */
	var oPopWin = null;
	$("a[rel='external']").click(function(){
		window.open(this.href);
		return false
	});
	$("a[rel='popup']").click(function(e){
		popWin = new PopupWindow();
		popWin.anchor = $(this);
		popWin.width = 500;
		popWin.height = 500;
		if (popWin.spawn()) {
			e.preventDefault();
		}
	});
	
	
	/**
	 * Drop-down menu (Superfish)
	 */
	if ($.fn.superfish) {
		$("#menu").superfish({
			speed: 0
		});
	}
	
	// auto-submit genre/maand select
	(function(){
		if ($.fn.autoSelect) {
			var $form = $('#genreMaandForm');
			var $enabled = $form.find('select').autoSelect();
			if ($enabled.length) {
				$form.addClass('autoSelect');
			}
		}
	})();
	

	
	
});


// http://ajaxian.com/archives/text-overflow-for-firefox-via-jquery
$.fn.ellipsis = function(enableUpdating){
	var s = document.documentElement.style;
	if (!('textOverflow' in s || 'OTextOverflow' in s)) {
		return this.each(function(){
			var el = $(this);
			if(el.css("overflow") == "hidden"){
				var originalText = el.html();
				var w = el.width();
				
				var t = $(this.cloneNode(true)).hide().css({
                    'position': 'absolute',
                    'width': 'auto',
                    'overflow': 'visible',
                    'max-width': 'inherit'
                });
				el.after(t);
				
				var text = originalText;
				while(text.length > 0 && t.width() > el.width()){
					text = text.substr(0, text.length - 1);
					t.html(text + "&hellip;");
				}
				el.html(t.html());
				
				t.remove();
				
				if(enableUpdating == true){
					var oldW = el.width();
					setInterval(function(){
						if(el.width() != oldW){
							oldW = el.width();
							el.html(originalText);
							el.ellipsis();
						}
					}, 200);
				}
			}
		});
	} else return this;
};
	
	
})(jQuery);


	
	
