/***********************************************************************

Author:     Sander Tiekstra
Company:    Tiekstramedia
URL:        http://www.tiekstramedia.nl

***********************************************************************/

$(function (){
	
	// mail rewrite (href: '[a]' > '@')
	// ----------------------------------------------------------------------------------------------------
	$('a[href*="mailto:"]').each(function() {
		var mailto = $(this).attr('href').split('[at]');
		$(this).attr("href", mailto[0] + "@" + mailto[1]);
	});
	// ----------------------------------------------------------------------------------------------------

	// mail rewrite (text node: '[a]' > '@')
	// ----------------------------------------------------------------------------------------------------
	$('a:contains("[at]")').each(function() {
		var mailto = $(this).text().split('[at]');
		$(this).text(mailto[0] + "@" + mailto[1]);
	});
	// ----------------------------------------------------------------------------------------------------
	
	
	// Toggle
	// ----------------------------------------------------------------------------------------------------
	$('div.toggle>*')
	.not('div')
	.hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	})
	.click(function() {
		$(this).parent().find('.wrapper').slideToggle();
	})
	.parent()
	.find('.wrapper')
	.hide();
	// ----------------------------------------------------------------------------------------------------
	
	
	// Positioning the main navigation items
	// ----------------------------------------------------------------------------------------------------
	/*
	if ( $('#nav-main>ul>li').length >0 ) {
		var $mainNav = $('#nav-main>ul');
		var padding = ( $mainNav.outerWidth() - $mainNav.width() ) * 2;
		var minimalWidth = function () {
			var w = 0;
			$('#nav-main>ul>li').each(function(index) {
				w += $(this).width();
				i = index;
			});
			return w;
		};
	
		$('#nav-main>ul>li').not(':last').css({
			marginRight: ( $mainNav.outerWidth() - padding - minimalWidth() ) / i
		});
	};
	*/
	
	// ----------------------------------------------------------------------------------------------------
	
	// show submenu in IE6
	// ----------------------------------------------------------------------------------------------------
	/*
	if ($.browser.msie){
		$('#nav-main>ul>li').hover(function() {
			$(this).addClass('over');
		}, function() {
			$(this).removeClass('over');
		})
		.mouseover(function() {
			$('ul', this).css("width", $('ul', this).width());
		});
	}
	*/
	
	// ----------------------------------------------------------------------------------------------------

	$.fn.vTabs = function () {
		var container = this;
		
		$(this).find('ul.tabs li a').click(function () {
			var link = this;
			var href = $(link).attr('href');
			href = '#' + href.split('#')[1];
			$(this).closest('ul.tabs').find('li.active').removeClass('active');

			if ($(container).find('div.tabContent.active').length > 0) {
				$(container).find('div.tabContent.active').slideUp(400,function () {
					$(this).removeClass('active');
					showContent(href, link)
				});
			} else {
				showContent(href, link)
			}
		});
		
		$(this).find('ul.tabs li:first a').trigger('click');
		
		function showContent(contentElement, link) {
			$(link).parent().addClass('active');

			$(contentElement).slideDown(400, function () {
				$(this).addClass('active');
			});
			
		}
	}
/**/
	$(document).ready(function () {
    	Shadowbox.setup("a.video", {
			autoplayMovies: true,
			width: 1024,
			height: 576,
			displayNav: true,
			onOpen: moveCloseLink 
	    });
	    
	    if ($('div.vTabs').length > 0) {
	    	$('div.vTabs').vTabs();
	    }
	});
/**/	
	function moveCloseLink()
	{
	    cb=document.getElementById( 'sb-nav-close' );
    	tb=document.getElementById( 'sb-title' );

	    if( tb )
    	    tb.appendChild(cb);
	} 
});	

(function ($){	
	$.faqOptions = {page: 1, category: null};
	
	// FAQ
	// ----------------------------------------------------------------------------------------------------
	$.fn.faq = function () {
		$.faqOptions.faq = this
		
		$(this).find('div.categories ul li a').click(function () {
			$(this).selectCategory();
		});
		
		$(this).find('div.questions div.categoryQuestions div.question a').click(function () {
			$(this).selectQuestion();
		});
		
		
		var hash = window.location.hash;
	
		var arrFaq = hash.split("/");
		
		var catLink = $(this).find('div.categories a[href='+arrFaq[0]+']');
		var questionLink = $(this).find('div.questions a[href='+hash+']');
		
		if (hash == "" || $(catLink).length <= 0) {
			$(this).find('div.categories ul li:first a').selectCategory();
		} else {
			$(catLink).selectCategory();
			if ($(questionLink).length > 0) {
				setTimeout(function () {
					$(questionLink).selectQuestion();
				}, 400);			
			}
		}
	}
	
	$.fn.selectCategory = function () {
		var faq = $.faqOptions.faq;
		
		$(this).closest('ul').find('li.active').removeClass('active');
		$(this).closest('li').addClass('active');

		var cat = $(this).attr('href');
		cat = cat.replace("#", "");
	
		$.closeActiveCategory();
		
		setTimeout(function () {
			$.faqOptions.page = 1;
			$.faqOptions.category = cat;			
			
			$.setPaginate();
			
			$(faq).find('div.questions div#questions-'+cat+' div.question.show').removeClass('show');
			$(faq).find('div.questions div#questions-'+cat+' div.question:lt(10)').addClass('show');
		
			$(faq).find('div.questions div#questions-'+cat).show(0).addClass('active');					

			var questionsHeight = $(faq).find('div.questions div#questions-'+cat).height()+$(faq).find('div.questions div.paginate').height();
			$(faq).find('div.questions').animate({height: questionsHeight+'px', width: '450px'}, 400);
		}, 450);
		
		$(faq).find('div.answerBoxWrapper').removeClass('active');			
		$(faq).find('div.questions div.categoryQuestions div.question.current').removeClass('current');
		$(faq).find('div.answerBox').slideUp(400);
	}

	$.closeActiveCategory = function () {
		$($.faqOptions.faq).find('div.questions div.categoryQuestions.active').closeCategory();
	}
	
	$.fn.closeCategory = function () {
		if ($(this).length > 0) {
			$($.faqOptions.faq).find('div.questions').animate({width: 0}, 400, function () {
				$(this).find('div.categoryQuestions.active').hide(0).removeClass('active');
			});
		}
	}
	
	$.fn.selectQuestion = function () {
		var faq = $.faqOptions.faq;
	
		var question = $(this).text();
		var answer = $(this).closest('div.question').find('div.answer').html();
		
		$(this).closest('div.categoryQuestions').find('div.question.current').removeClass('current');
		$(this).closest('div.question').addClass('current');
		
		var delay = 0;
		
		if ($(faq).find('div.answerBoxWrapper').hasClass('active')) {
			$(faq).find('div.answerBox').slideUp(400);
			delay = 400;
		}
		
		setTimeout(function () {
			$(faq).find('div.answerBox h4').html(question);
			$(faq).find('div.answerBox div.answerContent').html(answer);	
			
			$(faq).find('div.answerBoxWrapper').addClass('active');			
			$(faq).find('div.answerBox').slideDown(400);			
		}, delay);
		
		$.refreshCurrentPage();
	}
	
	$.refreshCurrentPage = function () {
		if ($.faqOptions.category != null) {
			var faq = $.faqOptions.faq;
		
			var page = $.faqOptions.page;
		
			var totalQuestions = $(faq).find('div.questions div#questions-'+$.faqOptions.category+' div.question.active').length;
			var totalPages = Math.ceil(totalQuestions/10);
			
			if (page > totalPages || page < 1) {
				page = 1;
			}
	
			$(faq).find('div.questions div#questions-'+$.faqOptions.category+' div.question.show').removeClass('show');
	
			var condition = '';
			if (page == 1) {
				condition = 'div.question.active:lt(10)';
			} else {
				var gt = (page*10)-11;
				condition = 'div.question.active:gt('+gt+'):lt(10)';
			}
			
			$(faq).find('div.questions div#questions-'+$.faqOptions.category+' '+condition).addClass('show');
	
			$.faqOptions.page = page;			
			$.setPaginate();
			
			var questionsHeight = $(faq).find('div.questions div#questions-'+cat).height()+$(faq).find('div.questions div.paginate').height();
			$(faq).find('div.questions').animate({height: questionsHeight+'px'}, 400);
		}
	}
	
	$.goToPage = function (page) {
		var faq = $.faqOptions.faq;
		
		$(faq).find('div.questions div.questionsInner').animate({width: 0}, 400, function () {
			page = parseInt(eval($.faqOptions.page+page));

			var totalQuestions = $(faq).find('div.questions div#questions-'+$.faqOptions.category+' div.question.active').length;
			var totalPages = Math.ceil(totalQuestions/10);
			
			if (page > totalPages || page < 1) {
				page = 1;
			}
			
			$(faq).find('div.questions div#questions-'+$.faqOptions.category+' div.question.show').removeClass('show');
			
			var condition = '';
			if (page == 1) {
				condition = 'div.question.active:lt(10)';
			} else {
				var gt = (page*10)-11;
				condition = 'div.question.active:gt('+gt+'):lt(10)';
			}
			
			$(faq).find('div.questions div#questions-'+$.faqOptions.category+' '+condition).addClass('show');
			$(faq).find('div.questions div.questionsInner').animate({width: '465px'}, 400);

			var questionsHeight = $(faq).find('div.questions div#questions-'+$.faqOptions.category).height()+$(faq).find('div.questions div.paginate').height();
			$(faq).find('div.questions').animate({height: questionsHeight+'px'}, 400);

			$.faqOptions.page = page;			
			$.setPaginate();
		});
	}
	
	$.setPaginate = function () {
		var faq = 	$.faqOptions.faq;
		var cat = 	$.faqOptions.category;
		var page = 	$.faqOptions.page;
		
		
		var totalQuestions = $(faq).find('div.questions div#questions-'+cat+' div.question.active').length;
		var totalPages = Math.ceil(totalQuestions/10);
		
		if (totalPages > 1) {
			$(faq).find('div.questions div.paginate.hide').removeClass('hide');

			$(faq).find('div.questions div.paginate a.prev.hide, div.questions div.paginate a.next.hide').removeClass('hide');
			
			if (page == 1) {
				$(faq).find('div.questions div.paginate a.prev').addClass('hide');
			} else if (page == totalPages) {
				$(faq).find('div.questions div.paginate a.next').addClass('hide');
			}
			
			$(faq).find('div.questions div.paginate span.currentPage').text(page);
			$(faq).find('div.questions div.paginate span.totalPages').text(totalPages);
			
		} else {
			$(faq).find('div.questions div.paginate').addClass('hide');
		}
	}
	
	$(document).ready(function () {
		if ($('#faq').length > 0) {
			$('#faq').faq();
		}
	});
	// ----------------------------------------------------------------------------------------------------
})(jQuery);


(function ($){	
	// Eventlist
	// ----------------------------------------------------------------------------------------------------
	$.fn.eventList = function (type) {
		$(this).load('/backend/events/events/formlist/', {type: type});
	}
	
	$.eventItemClick = function (event) {
		if ($(event).hasClass('active')) {
			$(event).removeClass('active');
			$(event).find('input.checkEvent').attr('checked', false);
		} else {
			$(event).addClass('active');
			$(event).find('input.checkEvent').attr('checked', true);				
		}
	}
	
	$.submitSubscription = function (form, type) {
		var action = $(form).attr('action');
	
		$.ajax({
			type: 	'POST',
			url: 	action,
			data: 	$(form).serialize(),
			dataType: 'json',
			success: function (data) {
				$("input[id*='LynxEventsSubscribers_'], div.radiolist.error").removeClass('error');

				if (data.errors != undefined) {
					var errors = data.errors;
					for (k in errors) {
						var input = $("input[id*='LynxEventsSubscribers_"+k+"']").addClass('error');
						
						if ($(input).closest('div.radiolist').length > 0) {
							$(input).closest('div.radiolist').addClass('error');
						}
					}
				} else {
					if (type == "seminars") {
						location.href = "seminarbedankt/";
					} else {
						location.href = "webinarbedankt/";
					}
				}

			}
		});
		
		return false;
	}

	// ----------------------------------------------------------------------------------------------------
})(jQuery);

(function ($){	
	// Library
	// ----------------------------------------------------------------------------------------------------
	$.fn.showLibraryBook = function () {
		var url = $(this).attr('href');
		Shadowbox.open({
			content:    url,
			player:     'iframe',
			height:     410,
			width:      660
		});
		
		return false;
	}

})(jQuery);

// Sifr
// ----------------------------------------------------------------------------------------------------
var HelveNeuConBol = {
	src: 'http://www.lynx.be/layout/sifr/helvetica-neue-bold-condensed.swf'
	,ratios: [6,1.41,9,1.35,15,1.29,21,1.25,22,1.22,27,1.24,28,1.23,34,1.22,38,1.21,39,1.22,51,1.21,80,1.2,82,1.19,87,1.2,88,1.19,89,1.2,93,1.19,94,1.2,1.19]
};

sIFR.activate(HelveNeuConBol);

sIFR.replace(HelveNeuConBol, {
	selector: 'body.home ul.nav-sub li.special'
	,css: [
		'.sIFR-root { color: #009b3a; leading: -21; letter-spacing: -3.5; text-transform: uppercase; }'
		,'a:link { color: #009b3a; text-decoration: none; }'
		,'a:hover { color: #353535; text-decoration: none; }'
	]
	,offsetLeft: '2'
	,offsetTop: '-15'
	,tuneHeight: '-15'
	,wmode: 'transparent'
});

sIFR.replace(HelveNeuConBol, {
	selector: 'body.home ul.nav-sub li'
	,css: [
		'.sIFR-root { leading: -21; letter-spacing: -4; letter-spacing: -3.5; text-transform: uppercase; }'
		,'a:link { color: #353535; text-decoration: none; }'
		,'a:hover { color: #009b3a; text-decoration: none; }'
		
	]
	,offsetLeft: '2'
	,offsetTop: '-13'
	,tuneHeight: '-13'
	,wmode: 'transparent'
});


//sIFR.replace(HelveNeuConBol, {
//	selector: '#content h1'
//	,css: ['.sIFR-root { color: #009b3a; leading: -22; letter-spacing: -3; text-transform: uppercase; }' ]
//	,offsetTop: '-16'
//	,tuneHeight: '-16'
//	,wmode: 'transparent'
//
//});

sIFR.replace(HelveNeuConBol, {
	selector: '#content h2.subheading'
	,css: ['.sIFR-root { color: #009b3a; leading: -22; letter-spacing: -2; text-transform: uppercase; }' ]
	,wmode: 'transparent'
});

sIFR.replace(HelveNeuConBol, {
	selector: '#content blockquote p'
	,css: [
		'.sIFR-root { color: #009b3a; leading: -16; letter-spacing: -2; text-transform: uppercase; }'
		,'em { color: #353535; font-style: normal; }'
		,'strong { color: #353535; font-weight: normal; }'
	]
	,offsetTop: '-11'
	,tuneHeight: '-11'
	,wmode: 'transparent'
});


sIFR.replace(HelveNeuConBol, {
	selector: '.home .sub-02 .euro-front'
	,css: [
		'.sIFR-root { color: #2F2F2F; leading: -21; letter-spacing: -4; letter-spacing: -3.5; text-transform: uppercase; font-size:53px; }'
		,'a:link { color: #353535; text-decoration: none; }'
		,'a:hover { color: #009b3a; text-decoration: none; }'
		
	]
	,offsetLeft: '2'
	,offsetTop: '0'
	//,tuneHeight: '-1'
	,wmode: 'transparent'
});
// ----------------------------------------------------------------------------------------------------

/*
// Google Search (disabled)
// ----------------------------------------------------------------------------------------------------
google.load('search', '1');

function OnLoad() {
	// Create a search control
	var searchControl = new google.search.SearchControl();

	// Add in a WebSearch
	lynxSearch = new google.search.WebSearch();

	// Restrict our search to pages from the Lynx
	lynxSearch.setSiteRestriction('www.lynx.nl');

	// create a search control
	var searchControl = new google.search.SearchControl();

	// web search, open
	var options = new google.search.SearcherOptions();
	options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
	options.setRoot(document.getElementById("searchresult"));
	searchControl.addSearcher(lynxSearch, options);

	// tell the searcher to draw itself and tell it where to attach
	searchControl.draw(document.getElementById("search"));
	
	//change the text of the search button
	$('.gsc-search-button').attr("value", "ZOEK");
	
	function searchComplete(a, response) {
		$('#searchresult .found, span.back').remove();
		$('.gsc-all-results').trigger('click');
		$('#searchresult').show();
		$('#content').hide();
		$('#searchresult div.gsc-trailing-more-results').hide();

		if ($('#searchresult div.gsc-cursor-page').length == 1) {
			$('#searchresult div.gsc-cursor').hide();
		};

		//show the user the results of their search
		if (response.results.length < 1) {
			$('#searchresult').append("<span class='back'>&#60; Terug</span><p class='found error'>Uw zoekopdracht '" + a.input.value + "' heeft geen resultaten opgeleverd");
		 } else if(response.cursor != null && response.cursor.estimatedResultCount == '1') {
			$('#searchresult').prepend("<span class='back'>&#60; Terug</span> <p class='found'>Uw zoekopdracht '" + a.input.value + "' heeft &eacute;&eacute;n resultaat opgeleverd.");
		} else if (response.cursor != null){
			$('#searchresult').prepend("<span class='back'>&#60; Terug</span> <p class='found'>Uw zoekopdracht '" + a.input.value + "' heeft de volgende resultaten opgeleverd.");
		}
	}

	
	$('span.back').live("click", function(event) {
		$('#content').show();
		$('#searchresult').hide();
	});
	
	searchControl.setSearchCompleteCallback(this, searchComplete, null);
	

}
google.setOnLoadCallback(OnLoad);
// ----------------------------------------------------------------------------------------------------
*/
