
$(function(){

	// Hide track at <960
	function toggleTrack(){ $('div.track').toggle($(window).width()>=960) }
	$(window).bind('load resize',toggleTrack);
	toggleTrack();

	// Input placeholders (use class="placeholder" on associated label)
	$('label.placeholder').inputPlaceholder();

	// Theme menu
	var themeTimer;
	$('#theme-menu-content').addClass('js');
	$('#theme-menu-toggle').add('#theme-menu-content').hover(function(e){
		if (e.type == 'mouseenter') {
			clearTimeout(themeTimer);
			$('div#theme-menu-content').stop(true,true).slideDown(300);
		} else {
			clearTimeout(themeTimer);
			themeTimer = setTimeout(closeThemeMenu,300);
		}
	});

	function closeThemeMenu() {
		$('div#theme-menu-content').stop(true,true).slideUp(300);
	}


	// Channel/contact
	$('h3.channel').addClass('js').each(function(){
		if (!$(this).hasClass('active'))
			$(this).next('div.channel-content').hide();

		$(this).click(function(){
			$(this).toggleClass('active')
				.next('div.channel-content').toggle();
		});
	});

	// Video's
	$('a.video-fancybox').find('span.play').css('opacity',0.6).end().hover(function(e){
		$(this).find('span.play').css('opacity',(e.type == 'mouseenter') ? 1 : 0.6);
		$(this).find('span.description').toggle();
	}).find('span.description').hide().end()
	.click(function(e){
		e.preventDefault();
		$.fancybox({
			type: 'iframe',
			href: $(this).attr('href'),
			orig: this,
			transitionIn: 'elastic',
			titleShow: false,
			overlayColor: '#000',
			overlayOpacity: 0.6,
			width: 620,
			height: 350
		});
	});


	// Supertag definitions
	$('a.supertag-event-chat').click(function(){
		_supertag.event = 'kanaalsturing/chat';
		_supertag.submit();
	});

	$('a.supertag-event-mail').click(function(){
		_supertag.event = 'kanaalsturing/mail';
		_supertag.submit();
	});

	$('a.supertag-event-locatie').click(function(){
		_supertag.event = 'kanaalsturing/locatie';
		_supertag.submit();
	});

	$('a.link_reactieoppagina2').click(function(){
		_supertag.event = 'vraag_en_antwoord/geholpen_ja';
		_supertag.submit();
	});

	$('a.link_mailuwvraag2').click(function(){
		_supertag.event = 'vraag_en_antwoord/geholpen_nee';
		_supertag.submit();
	});

	$('a.video-fancybox').click(function(){
		_supertag.event = 'video/start';
		_supertag.submit();
	});


});



(function($){

	$.fn.inputPlaceholder = function() {
		return this.each(function(){
			var input = $('#'+$(this).attr('for'));
			var text = $(this).text();
			var val = input.val();
			if (val == '' || val == text) input.val(text).addClass('init');
			input.focus(function(){
				if ($(this).val() == text) $(this).val('').removeClass('init');
			}).blur(function(){
				if ($(this).val() == '') $(this).val(text).addClass('init');
			});
		});
	};

})(jQuery);
