/* ------------------------------------------------- */
/* On document ready
/* ------------------------------------------------- */
jQuery(document).ready(function($) {
	/* ------------------------------------------------- */
	/* Animate sub menu ... joy joy
	/* ------------------------------------------------- */
	$('#sub-menu a').hover(function() {
		if(!$(this).parent().hasClass('current')) {
			$(this).animate({
				'height':30,
				'line-height':30,
				'font-size':14
			}, {
				duration:100,
				queue:false
			});
		}
	}, function() {
		if(!$(this).parent().hasClass('current')) {
			$(this).animate({
				'height':22,
				'line-height':22,
				'font-size':12
			}, {
				duration:300,
				queue:false
			});
		}
	});

	$('#menu a').hover(function() {
		$(this).animate({
			'height':70,
			'line-height':70,
			'font-size':20
		}, {
			duration:100,
			queue:false
		});
	}, function() {
		$(this).animate({
			'height':35,
			'line-height':35,
			'font-size':15
		}, {
			duration:300,
			queue:false
		});
	});
	/* ------------------------------------------------- */
	/* Expand click target
	/* ------------------------------------------------- */
	$('.expand').each(function() {
		$(this).css({
			'cursor':'pointer'
		});
		$(this).click(function() {
			window.location = $('a', $(this)).attr('href');
		});
		$(this).hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
	});
	/* ------------------------------------------------- */
	/* JQuery Listify
	/* ------------------------------------------------- */
	$('table tbody tr').each(function() {
		// Get voorstelling link
		var anchor = $(this).find('td.titel a');
		var href = anchor.attr('href');
		// Hide link
		var text = anchor.html();
		anchor.after(text).hide();
		// Set Cursor
		$(this).css('cursor', 'pointer');
		// Add hover
		$(this).hover(function() {
			$(this).addClass('hover');
		}, function () {
			$(this).removeClass('hover');
		});
		// Add click but not to td.tickets
		$("td:not('.tickets')", $(this)).click(function(e) {
			e.preventDefault();
			window.location = href;
		});
	});
	
	$('table tbody tr.uitverkocht').mouseover(
		function() {
			var tr = $(this);
			var pos = $(this).offset();
			$('<div></div>', {
				'id':'uitverkocht',
				'class':'accented-bg',
				'css':{
					'top':pos.top,
					'left':pos.left,
					'width':tr.width(),
					'cursor':'pointer',
					'height':tr.height(),
					'line-height':tr.height() + 'px'
				},
				'html':'<p>uitverkocht / <span>uitverkocht</span> / uitverkocht / <span>uitverkocht</span> / uitverkocht / <span>uitverkocht</span> / uitverkocht / <span>uitverkocht</span> / uitverkocht / <span>uitverkocht</span> / uitverkocht / <span>uitverkocht</span> / uitverkocht / <span>uitverkocht</span> / uitverkocht / <span>uitverkocht</span> / uitverkocht / <span>uitverkocht</span> / uitverkocht / <span>uitverkocht</span></p>',
				'mouseout': function() {
					$(this).fadeOut('fast', function() {
						$(this).remove();
					})
				},
				'click': function() {
					window.location = $('a', tr).attr('href');
				}
				}).appendTo('body');
			}
		);

		$('table tbody tr:not(".uitverkocht")').each(function() {
			var pos = $(this).offset();
			var img = $('td.image img', $(this));
			var id = 'over-' + img.attr('id');
			if(!$('#' + id).length) {
				$('<img/>', {
					'id': id,
					'class':'over-image',
					'css':{
						top:pos.top - 110,
						left:pos.left,
						'position':'absolute',
						'display':'none'
					},
					'src': img.attr('src')
					}).appendTo('body');
				}
				/* ------------------------------------------------- */
				/* INTERACTIVITY
				/* ------------------------------------------------- */
				$(this).hover(function() {
					pos = $(this).offset();
					$('#' + id).css({
						top:pos.top - 110,
						left:pos.left
						}).fadeIn(150);
					}, function() {
						$('#' + id).fadeOut(300);
					});
				});

				/* ------------------------------------------------- */
				/* VALIDATION FORM
				/* ------------------------------------------------- */
				if($('#form-subscribe').size() > 0) {
					$("#form-subscribe").validate({
						submitHandler: function(form) {
							jQuery(form).ajaxSubmit({
								target: "#subscribe"
							});
						}
					});
				}
				
				/* ------------------------------------------------- */
				/* jQuery Cycle
				/* ------------------------------------------------- */
				if($('#idk-wrapper div.idk').length) $('#idk-wrapper').cycle({
					fx:'scrollLeft',
					sync:true,
					timeout:5000,
					speed:1000
				});
				/* ------------------------------------------------- */
				/* Calendar
				/* ------------------------------------------------- */
				$('#calendar-wrapper li:even').each(function() {
					$(this).addClass('even');
				});
				/* ------------------------------------------------- */
				/* Search-box
				/* ------------------------------------------------- */
				if($('#search-box').length) {
					$('#search-box').hide();
					$('#search-box a').click(function(e) {
						e.preventDefault();
						$('#search-box').fadeOut('fast');
					});
					$('#search-box input').focus(function() {
						if($(this).val() == 'Zoek op onze website') {
							$(this).val('');
						}
					});
					$('#search-box input').blur(function() {
						if($(this).val() == '') {
							$(this).val('Zoek op onze website');
						}
					});
					$('li.search-btn a').click(function(e) {
						e.preventDefault();
						var pos = $(this).offset();
						$('#search-box').css({
							'top':pos.top
						});
						$('#search-box').fadeIn('fast');
					});
				}
				/* --------------------------------------------------------- */
				/* Tool tips
				/* --------------------------------------------------------- */
				if($('li.media-btn').length) {
					$('li.media-btn').each(function() {
						// Build tooltips
						var pos = $(this).offset();
						var txt = $('a', $(this)).attr('title');
						$('<div></div>', {
							'id': 'tooltip-' + $(this).attr('id'),
							'class': 'tooltip',
							'css': {
								'top':pos.top + 40,
								'left':pos.left,
								'position':'absolute'
							},
							'html': '<span>' + txt + '</span>'
							}).appendTo('body');
							// Add tooltip interactivity
							var tooltip = $('#tooltip-' + $(this).attr('id'));
							$('a', $(this)).mousemove(function(e) {
								tooltip.css({
									'top':e.pageY+20,
									'left':e.pageX - (tooltip.width() / 2)
								});
								tooltip.fadeIn('fast');
							});
							// Hide on mouseout
							$('a', $(this)).mouseout(function(e) {
								tooltip.fadeOut('fast');
							});
						});
					}
					/* --------------------------------------------------------- */
					/* Scrollable inits
					/* --------------------------------------------------------- */
					$('.scrollable').scrollable({
						mousewheel:false,
						circular:true
					}).autoscroll({
                                                autoplay:true,
                                                interval:6500
                                        });
					/* --------------------------------------------------------- */
					/* Scrollpane inits
					/* --------------------------------------------------------- */
					if($('.scrollpane').length) $('.scrollpane').jScrollPane();
					/* --------------------------------------------------------- */
					/* Scrollpane inits
					/* --------------------------------------------------------- */
					if($('#column-2').length) {
						
						$('ol', $('#column-2')).addClass("dontsplit");
						$('li', $('#column-2')).addClass("dontsplit");
						
						$('h2', $('#column-2')).addClass("dontend");
						$('h3', $('#column-2')).addClass("dontend");
						
						$('#column-2').columnize({
							'columns':2,
							lastNeverTallest:true
						});
					}
					/* --------------------------------------------------------- */
					/* External links
					/* --------------------------------------------------------- */
					$('a[rel*=external]').click(function(e) {
						window.open(this.href);
						e.preventDefault();
					});
					/* --------------------------------------------------------- */
					/* Colorbox
					/* --------------------------------------------------------- */
					if($('div.fotos ul li').length) $('div.fotos ul li').click(function() { $.colorbox({'href':$('a', $(this)).attr('href'),'rel':$('a', $(this)).attr('rel')}); });
					if($('div.nieuws ul li div.slideshow a').length) { $('div.nieuws ul li div.slideshow').cycle(); }
					$('a.colorbox').colorbox();
				});

