var Global = {

	init: function(){
		if( $('#my-tele-2-services').length != 0 ){ 
			Global.showBussinesServiceMoreInfo();
		}
		if( $('#my-tele-2-landing').length != 0 ){ 
			Global.showBussinesServiceMoreInfoLanding();
		} 
		if( $('#wholesale-services-login').length != 0 ){
			Global.showLoginBlockMoreInfo();
		}
		if( $('#route-module').length != 0 ){ 
			Global.setRouteSliders();
		} 
		if( $('#availability-results-listing').length != 0 ){
			Global.toggleAvailibilityResults();
		}
		if( $('input#zoek-tele2-zakelijk').length != 0 ){
			$.getScript(oIncludes.autocomplete, function(){
				Global.searchAutocomplete($('input#zoek-tele2-zakelijk'), $('input#searchfield-tele2-zakelijk-submit'), 'ac-result-big');
			});
			Global.initSearchModule();
		}
		if( $('#zoek-tele2-zakelijk-second-field').length != 0 ){
			$.getScript(oIncludes.autocomplete, function(){
				Global.searchAutocomplete($('input#zoek-tele2-zakelijk-second-field'), $('input#searchfield-tele2-zakelijk-submit'), 'ac-result-big');
			});
			Global.initSearchModule();
		}
		if( $('#domain-porting').length != 0 ){ 
			Global.domainPortingMoreInfo();
		}
		if( $('.promotion-set').length != 0 ){ 
			Global.setPromoHeight();
		}
		// set block height
		if( $('.mobile-gallery-2set').length != 0 ){
			Global.setBlockHeight($('.mobile-gallery-2set'), $('.mobile-gallery-promo'));
		}
		if($('#page_home').length != 0){
			interactiveSitemap.init();
		}
		if($('#news-archive').length != 0) {
			$.getScript(oIncludes.newsArchive, function(){
				newsArchiveModule.init();
			});
		}
		if( $('#accordeon-content ul.accordeon').length != 0 ){
			$.getScript(oIncludes.accordion, function(){
				Accordeon.init();
			});
		}
		if( $('#partner-locator-form').length != 0 ){
			$.getScript(oIncludes.partnerLocator, function(){
				partnerLocatorResults.init();
			});
		}
		if( $('#events-calendar').length != 0 ){
			eventCalenderDataSlider.init();
		}
		if( $('form').length != 0 ){
			formValidation.init();
		}
		if( $('#recommended-services').length != 0 ){
			titleToolTip.init($('#recommended-services ul li'));
		}
		if( ( $('.lightbox-video-wrap').length != 0 ) ||
			( $('.general-lightbox').length != 0 ) ){
				$.getScript(oIncludes.simplemodal, function(){});
		}
		if( $('#faq-module').length != 0 ){
			$.getScript(oIncludes.faq, function(){});
		}
		if( $('#searchfield-home').length != 0 ){
			Global.hoverHomeSearchfieldSubmit();
		}
		if($("#commision-table").length != 0){
			$.getScript(oIncludes.tablesorting, function() {
				$.getScript(oIncludes.tablesortingPagination, function() {
					$("#commision-table")
						.tablesorter({widthFixed: true, widgets: ['zebra'], headers: { 0: { sorter: false }, 10: { sorter: false }} })
						.tablesorterPager({container: $("#pagination")});
				});
			});
		}	
		if( $('#domain-checker').length != 0 ){
			Global.checkDomain();
		}
		if( $('#domainregistration-form').length != 0 ){
			$.getScript(oIncludes.hosting, function(){});
		}
		if( $('#domainregistration-overview').length != 0 ){
			Global.initHostingOrderOverview();
		}
		if( $('#propositions').length != 0 ){
			$.getScript(oIncludes.subscriptionSelectors, function(){});
		}
		if($('.text-slider-list').length != 0){
			$.getScript(oIncludes.textslider, function(){
				textSlider.init(); 
			});
		}
		if( $('#coverflow').length != 0 ){
			$.getScript(oIncludes.hotkeys, function(){
				coverflow.initNav(); 
			});
		}
		if( $('#tabbed-content').length != 0 ){
			if( $('#page-specific').hasClass('searchresults') ){}
			else { $.getScript(oIncludes.tabsModuleProducts, function(){}); }
		}
		if( $('.tabbed-content').length != 0 ){
			$.getScript(oIncludes.tabsmodule, function(){});
		}

		if( $('#devices-overview').length != 0 ){
			Global.setMobileDevicesHeight();
		}
		if( $("#webshop-callmeback").length != 0 ){
			Global.initCallMeBackModule();
		}
	},

	initCufon: function(){
		if($('#main-nav li a') != null){
			Cufon.replace('#main-nav li a', { hover: true, textShadow: '1px 1px rgba(0, 0, 0, 0.5)', fontFamily: 'boton_medium' });
		}
		if($('h2') != null){
			Cufon.replace('h2', {  hover: true, fontFamily: 'boton_medium' });
		}
		if($('h3') != null){
			Cufon.replace('h3', {  hover: true, fontFamily: 'boton_medium' });
		}
		if($('.heading-black') != null ){
			Cufon.replace('.heading-black', { fontFamily: 'boton_medium' });
		}
		if($('#subnavigation h3') != null ){
			Cufon.replace('#subnavigation h3', { fontFamily: 'boton_medium' });
		}
		if($('#filter-categories dl dt') != null ){
			Cufon.replace('#filter-categories dl dt', { fontFamily: 'boton_medium' });
		}
		if($('.main-promotion strong') != null ){
			Cufon.replace('.main-promotion strong', { fontFamily: 'boton_medium' });
		}
		if($('#footer-quicklinks dl dt strong a') != null ){
			Cufon.replace('#footer-quicklinks dl dt strong a', { fontFamily: 'boton_medium', hover: 'true' });
		}
		if($('.tabs a') != null ){
			Cufon.replace('.tabs a', { fontFamily: 'boton_medium' });
		}
		if($('.tabs li.active a') != null ){
			Cufon.replace('.tabs li.active a', { fontFamily: 'boton_medium' });
		}
		if($('.account-login legend') != null ){
			Cufon.replace('.account-login legend', { fontFamily: 'boton_medium' });
		}
		if($('#subnavigation .sub-block legend') != null){
			Cufon.replace('#subnavigation .sub-block legend', { fontFamily: 'boton_medium' });
		}
		if($('#login-tele2-partner legend') != null ){
			Cufon.replace('#login-tele2-partner legend', { fontFamily: 'boton_medium' });
		}
		if($('.form-login legend') != null ){
			Cufon.replace('.form-login legend', { fontFamily: 'boton_medium' });
		}
		if($('#aanvraag-mijn-tele2-zakelijk legend') != null ){
			Cufon.replace('#aanvraag-mijn-tele2-zakelijk legend', { fontFamily: 'boton_medium' });
		}
		if($('#aanmelden-partner-form legend') != null ){
			Cufon.replace('#aanmelden-partner-form legend', { fontFamily: 'boton_medium' });
		}
		if($('.partners div.form-element-important legend') != null ){
			Cufon.replace('.partners div.form-element-important legend', { fontFamily: 'boton_medium' });
		}
		if($('#partner-locator-form legend') != null ){
			Cufon.replace('#partner-locator-form legend', { fontFamily: 'boton_medium' });
		}
		if($('#campaigns dt strong') != null ){
			Cufon.replace('#campaigns dt strong', { fontFamily: 'boton_medium' });
		}
		if($('.faq h1') != null ){
			Cufon.replace('.faq h1', { fontFamily: 'boton_medium' });
		}
		if($('.appreciation-form') != null ){
			Cufon.replace('.appreciation-form fieldset legend', { fontFamily: 'boton_medium' });
		}
		if($('.main-product strong.intro') != null ){
			Cufon.replace('.main-product strong.intro', { fontFamily: 'boton_medium' });
		}
		if($('.partners-account-management form legend') != null ){
			Cufon.replace('.partners-account-management form legend', { fontFamily: 'boton_medium' });
		}
		if($('.commission-total-title') != null ){
			Cufon.replace('.commission-total-title span.euro', { fontFamily: 'arial' });
			Cufon.replace('.commission-total-title', { fontFamily: 'boton' });
			Cufon.replace('.commission-total-title span.amount', { fontFamily: 'boton_medium' });
		}
		if($('#tabbed-content .content-wrap .content h3') != null ){
			Cufon.replace('#tabbed-content .content-wrap .content h3', { fontFamily: 'boton_medium' });
		}
		if($('#tabbed-content .content-wrap .content legend') != null ){
			Cufon.replace('#tabbed-content .content-wrap .content legend', { fontFamily: 'boton_medium' });
		}
		if($('#delivery-steps li em') != null ){
			Cufon.replace('#delivery-steps li em', { fontFamily: 'boton_medium' });
		}
		if($('.search-results .result em') != null ){
			Cufon.replace('.search-results .result em', { fontFamily: 'boton_medium' });
		}
		if( $('.device-promo-balloon') ){
			if( $('.euro') ){
				Cufon.replace('.euro', { fontFamily: 'arial' });
			}
			Cufon.replace('.device-promo-balloon', { fontFamily: 'boton_medium' });
		}
		if($('.proposition-heading')){
			Cufon.replace('.proposition-heading', { fontFamily: 'boton_medium' });
		}
		if($('dl.sub-campaign dt em')){
			Cufon.replace('dl.sub-campaign dt em', { fontFamily: 'boton_medium' });
		}
		if($('#domainregistration legend')){
			Cufon.replace('#domainregistration-form legend', { fontFamily: 'boton_medium' });
		}
		if($('#domainregistration-overview table th')){
			Cufon.replace('#domainregistration-overview table th', { fontFamily: 'boton_medium' });
		}	
		if($('.realitycheck .bigtext')){
			Cufon.replace('.realitycheck .bigtext', { fontFamily: 'boton_medium' });
		}
		if($('.device-section')){
			Cufon.replace('.device-section', { fontFamily: 'boton_medium' });
		}
		if($('.promotion .balloon-black')){
			Cufon.replace('.promotion .balloon-black', { fontFamily: 'boton_medium' });
		}
	},

	initSearchModule:function(){
		var elSeachInput = $('.search-module label input');

		elSeachInput.focus(function(){
			sValDefault = $(this).next('input.default-label').val();
			sVal = $(this).attr('value');
			if( sVal != sValDefault ){ $(this).attr('value', sVal); } else { $(this).attr('value', ''); }
		});
		elSeachInput.blur(function(){
			if($(this).attr('value')==''){
				$(this).attr('value', sValDefault);
			}
		});
	},
	
	initCallMeBackModule:function(){
		$("#webshop-callmeback").submit( function() {

			if(formValidation.submitValidation($(this))) {
				$.ajax({
					dataType: 'jsonp',
					url: 'http://formulierverwerking.nl/callmeback_v2/public/tele2soho/index.php',
					jsonp: 'jsonp',
					data: {
						phonenr: $('#telefoon-mijn-tele2-partner', $(this)).val()
					},

					context: $(this),
					
					error: function(data, textStatus, XMLHttpRequest){
						$("p.error", $(this)).html('De aanvraag kon niet worden verstuurd. Probeert u het opnieuw.');
					},
					
					success: function(data, textStatus, XMLHttpRequest){
						if(data == "OK") {
							$("p.error", $(this)).html("");
							$(this).html("<legend>Uw aanvraag is<br/>ontvangen</legend><p>Een van onze medewerkers zal U zo spoedig mogelijk terugbellen.</p>");
							Cufon.replace('#' + $(this).attr('id') + ' legend', { fontFamily: 'boton_medium' });
						} else {
							var error = "Er heeft een fout opgetreden.";
							if(data.error) {
								error = data.error;
							} else if(data.closed) {
								error = data.closed;
							} else if(data.errors.phonenr) {
								error = data.errors.phonenr.join("<br />");
							}
							$("p.error", $(this)).html(error);
						}
					}
				});
			}
			
			return false;
		});
	},
	
	initHostingOrderOverview:function(){
		var elBtn = $('#submitorder');
		var elHref = elBtn.attr('href');
		var elInput = $('#domainregistration-overview-conditions input');

		elBtn.addClass('disabled');
		elBtn.removeAttr('href');

		elInput.bind('click', function(){
				
			if($(this).hasClass('checked')){
				$(this).removeClass('checked');
				elBtn.removeAttr('href');
				elBtn.addClass('disabled');
				
			}
			else {
				elBtn.attr('href', elHref);
				elBtn.removeClass('disabled');
				$(this).addClass('checked');
			}
		});
	}, 

	checkDomain: function(){
		$('#domain-checker input:text').focus(function(){
			sValDefault = $(this).next('input').val();
			sVal = $(this).attr('value');
			if( sVal != sValDefault ){ $(this).attr('value', sVal); } else { $(this).attr('value', ''); }
		});
		$('#domain-checker input:text').blur(function(){
			if($(this).attr('value')==''){
				$(this).attr('value', sValDefault);
			}
		});
	},

	toggleAvailibilityResults: function(){
		$('#availability-results-listing .content').hide();
		$('#availability-results-listing li a').bind('click', function(){			
			var el = $(this);
			var oContentDiv = el.next('div.content');		
			oContentDiv.css({'visibility':'hidden'}); 
			if (el.hasClass('open')) {
				el.removeClass('open');
				oContentDiv.slideUp('fast');
			} else {
				$('#availability-results-listing li div.content').slideUp('fast', function(){
					$('#availability-results-listing li a').removeClass('open');	
				});
				oContentDiv.show('fast', function(){
					el.addClass('open');	
					$(this).css({'visibility':'visible'});
				});
			}
			return false;
		});
	},

	buildCommisionToolTip: function(content, el){
		$('.tooltip-positioner').remove();
		var tooltipHtml = '<div class="tooltip-positioner"><div class="tooltip"><div class="tooltip-wrap"><div class="tooltip-top"></div><div class="tooltip-content"><p>'+content+'</p></div><div class="tooltip-bottom"></div><div class="tooltip-marker"></div></div></div></div>';
			$(tooltipHtml).appendTo(el);
		el.bind('mouseleave', function(){
			$('.tooltip-positioner').remove();
		});
	},

	hoverHomeSearchfieldSubmit: function(){ 
		el = $('#searchfield-home-submit');
		elInput = $('#searchfield-home-input');
		el.bind('mouseenter',function(){
			if( el.hasClass('hover-searchfield-home-submit') ){
				$(this).removeClass('hover-searchfield-home-submit');
			}
			else { $(this).addClass('hover-searchfield-home-submit'); }
		});
		el.bind('mouseleave',function(){
			if( el.hasClass('hover-searchfield-home-submit') ){
				$(this).removeClass('hover-searchfield-home-submit');
			}
			else { $(this).addClass('hover-searchfield-home-submit'); }
		});

		elInput.focus(function(){
			var sVal = $(this).attr('value');
			$(this).attr('value', '');
			$(this).blur(function(){
				if($(this).attr('value')==''){
					$(this).attr('value', sVal);
				}
			});
		});
	},

	initLightbox: function(sContentId){
		var oContent = $('#'+sContentId);
		oContent.modal({
			onOpen :  function(dialog){
				dialog.overlay.fadeIn('fast', function(){
					dialog.container.show();
					dialog.data.show();
					//Cufon.replace('.gen-lightbox-heading', { fontFamily: 'boton_medium' });
				});
			},
			close: true,
			overlayClose: true,
			opacity : 80, 
			position : [120],
			closeClass : 'close-lightbox'
		});
	},
	
	searchAutocomplete: function(searchFieldSelector, searchButtonSelector, resultclass) {
		var language = $(searchFieldSelector).parentFindRecursive('form').attr('lang');
		var qcUrl = 'http://tele2.appliance.siteseeker.se/qc/devel-tele2-nl/';
			$(searchFieldSelector).autocomplete(
				qcUrl, 
					{ 
					  resultsClass: resultclass,
					  cacheLength: 0,
					  extraParams: { ilang: language },
					  delay: 200,
					  selectFirst: false,
					  dataType: 'jsonp',
					  highlight: false,
					  scroll: false,
					  parse: function(data) {
						return $.map(data, function(row) {
						  return {data: row};
						});
					  },
					  formatItem: function(item) {
						if (item) {
						  var nHitString = "<span>" + item.nHits + "</span>";
						  return nHitString + item.suggestionHighlighted;
						}
						return;
					}
				}
			)
			.result(function(event, item) {
				$(searchFieldSelector).val(item.suggestion);
				$(searchButtonSelector).click();
			});
	},

	toggleCommisionTableArchive: function(){
		$('#commision-table-achive').fadeIn('fast', function(){
			$('a.cta-close-window', $(this)).bind('click', function(){
				$('#commision-table-achive').fadeOut('fast');
				$('#commision-table-achive a').unbind('click');
			});	
			/*$('#commision-table-achive a').bind('click', function(){
				$.ajax({
					url: $(this).attr('href'),
					success: function(data) {
						$('#commision-table-achive').fadeOut('fast');
						//$('#commision-table tbody').html(data);
						//$('#commision-table-achive a').unbind('click');
						//$("#commision-table")
						//	.tablesorter({widgets: ['zebra']})
						//	.tablesorterPager({container: $("#pagination")});
					}
				});
				return false;
			});*/
		});
		return false;
	},
	
	printCommisionTable: function() {
		oldsize = table.config.size;
		$.tablesorterPager.setPageSize(table,table.config.totalRows);

		var printhtml = '<style>table {font:normal 12px Arial;} table th {text-align: left;} table th, table td {padding: 0 10px;}</style>';
			printhtml += '<table>';
			printhtml += $('#commision-table').html();
			printhtml += '</table>';

		var newWindow = window.open();
		newWindow.document.open();
		newWindow.document.write(printhtml);
		newWindow.print();
		newWindow.close();

		$.tablesorterPager.setPageSize(table,oldsize);
	},

	initGmapAtOnload: function(sLangUrl){
		$('#google-map').html('<iframe src="'+sLangUrl+'"></iframe>');
	},
	
	setRouteSliders: function(){
		// hide the routes
		$('#route-descriptions ul li div.route').css({'display':'none'});
		$('#route-descriptions ul li a').bind('click', function(){			
			var el = $(this);
			var oContentDiv = el.next('div.route');		
			oContentDiv.css({'visibility':'hidden'}); // looks better in IE if we show the content when the slidedown has finished
			if (el.hasClass('open')) {
				el.removeClass('open');

				oContentDiv.slideUp('fast');
			} else {
				$('#route-descriptions ul li div.route').slideUp('fast', function(){
					$('#route-descriptions ul li a').removeClass('open');	
				});
				oContentDiv.show('fast', function(){
					el.addClass('open');	
					$(this).css({'visibility':'visible'});
				});
			}
			return false;
		});
	},

	printRouteDescription: function(oRouteTrigger){
		var oPrintedRouteId = oRouteTrigger.parent().parent();

		$('a.close-route' ,oPrintedRouteId).css({'display':'none'});
		$('a.print-route' ,oPrintedRouteId).css({'display':'none'});
	
		var sRouteHeadingContent = oPrintedRouteId.prev().text();
		var oRouteHeading = '<h2>Tele2 Zakelijk - '+sRouteHeadingContent+'</h2>';
		var sRouteContents = oPrintedRouteId.html();
		var sRouteHtml = oRouteHeading + sRouteContents;

		var newWindow = window.open();
		newWindow.document.open();
		newWindow.document.write(sRouteHtml);
		newWindow.print();
		newWindow.close();

		$('a.close-route' ,oPrintedRouteId).css({'display':'block'});
		$('a.print-route' ,oPrintedRouteId).css({'display':'block'});
	},

	showBussinesServiceMoreInfo: function(){ 
		// get all service links
		var oTriggers = $('#my-tele-2-services div.login-block a.cta-info');
		oTriggers.removeAttr('href');
		oTriggers.bind('click', function(){
			var sId = $(this).attr('rel');	
			showRelatedInfo(sId);
		});

		function showRelatedInfo(sId){
			$('div.login-additional-info').css({'display':'none'});
			$('div.login-additional-info:gt(2)').css({'top':'275px'});
			oCurrentElement = $('div#'+sId);
			
			oCurrentElement.fadeIn('fast', function(){
				$('a.cta-close-window').removeAttr('href');
				$('a.cta-close-window', $(this)).bind('click', function(){
					oCurrentElement.fadeOut('fast');
				});
			});
		}
	},

	domainPortingMoreInfo: function(){ 
		var oTriggers = $('a.cta-info');
		oTriggers.removeAttr('href');
		oTriggers.bind('click', function(){
			var sId = $(this).attr('rel');	
			
				showRelatedInfo(sId);
			
		});

		function showRelatedInfo(sId){
			$('div.hosting-additional-info').css({'display':'none'});
			$('div.hosting-additional-info:gt(2)').css({'top':'275px'});
			oCurrentElement = $('div#'+sId);
			
			oCurrentElement.fadeIn('fast', function(){
				$('a.cta-close-window').removeAttr('href');
				$('a.cta-close-window', $(this)).bind('click', function(){
					oCurrentElement.fadeOut('fast');
				});
			});
		}
	},

	showBussinesServiceMoreInfoLanding: function(){ 
		var oTriggers = $('#my-tele-2-landing div.service-landing a.cta-info');
		oTriggers.removeAttr('href');
		oTriggers.bind('click', function(){
			var sId = $(this).attr('rel');	
			showRelatedInfo(sId);
		});

		function showRelatedInfo(sId){
			$('div.service-landing-additional-info').css({'display':'none'});
			$('div.service-landing-additional-info:gt(1)').css({'top':'334px'});
			oCurrentElement = $('div#'+sId);
			
			oCurrentElement.fadeIn('fast', function(){
				$('a.cta-close-window').removeAttr('href');
				$('a.cta-close-window', $(this)).bind('click', function(){
					oCurrentElement.fadeOut('fast');
				});
			});
		}
	},

	showLoginBlockMoreInfo: function(){
		var oTriggers = $('#wholesale-services-login div.login-block a.cta-info');
		oTriggers.removeAttr('href');
		oTriggers.bind('click', function(){
			var sId = $(this).attr('rel');	
			showRelatedInfo(sId);
		});

		function showRelatedInfo(sId){
			$('div.login-additional-info').css({'display':'none'});
			$('div.login-additional-info:gt(1)').css({'top':'240px'});
			oCurrentElement = $('div#'+sId);

			oCurrentElement.fadeIn('fast', function(){
				$('a.cta-close-window').removeAttr('href');
				$('a.cta-close-window', $(this)).bind('click', function(){
					oCurrentElement.fadeOut('fast');
				});
			});
		}
	},

	togglePassword: function(el){
		span = el.prev('span.password-default');
		span.hide();
		
		el.blur(function(){
			a = el.parent().find('span.error');
			b = a.height();
			
			if( el.val() == '' ){
				span.css({'top':(b+5)}).show();
			}
		});
	},

	setPromoHeight: function() {
		
		var elPromotionSets = $('.promotion-set');
		
		$.each(elPromotionSets, function(i, a){
			aHeightArray = [];

			var elPromotions = $('.promotion', a);
			
			$.each(elPromotions, function(j, b){
				aHeightArray.push($(b).height());
			});

			aHeightArray.sort(function(a,b){ return a-b; });
			
			var iNewHeight = aHeightArray[aHeightArray.length-1];

			$(elPromotions, a).css({'min-height':iNewHeight, 'height':'auto !important', 'height':iNewHeight});
				
		});
	},

	// same function as promoheight, but this time with vars so we can reuse the function :)
	setBlockHeight: function(element, child) {
		
		var elPromotionSets = $(element);
		
		$.each(elPromotionSets, function(i, a){
			aHeightArray = [];

			var elPromotions = $(child, a);
			
			$.each(elPromotions, function(j, b){
				aHeightArray.push($(b).height());
			});

			aHeightArray.sort(function(a,b){ return a-b; });
			
			var iNewHeight = aHeightArray[aHeightArray.length-1];

			$(elPromotions, a).css({'min-height':iNewHeight, 'height':'auto !important', 'height':iNewHeight});
				
		});
	},

	setMobileDevicesHeight: function() {
		aHeightArray = [];

		var elDevices = $('.device');
		
		$.each(elDevices, function(j, b){
			aHeightArray.push($(b).height());
		});

		aHeightArray.sort(function(a,b){ return a-b; });
		
		var iNewHeight = aHeightArray[aHeightArray.length-1];

		$(elDevices).css({'min-height':iNewHeight, 'height':'auto !important', 'height':iNewHeight});
	}
}

var eventCalenderDataSlider = {
	
	init: function(){
		// hide all more info blocks with js
		$('#events-calendar div.more-information').css({'display':'none'});
	}, 

	toggleEventsInformation: function(oResultId){
		// get the parent item
		oResultParentId = oResultId.parent();
		// use it to find the content
		oResultContentId = oResultParentId.find('div.event div.more-information');
		// check if the current content is already open
		if(oResultParentId.hasClass('open')){
			// close it
			eventCalenderDataSlider.closeEventInformation(oResultParentId, oResultContentId, oResultId);
		}
		else { 
			// open it
			eventCalenderDataSlider.openEventInformation(oResultParentId, oResultContentId, oResultId);
		}
	},

	openEventInformation: function(oResultParentId, oResultContentId, oResultId){
		// close all others first
		$('#events-calendar ul li.open .more-information').slideUp('fast', function(){
			$('#events-calendar li a.trigger').removeClass('trigger-open');
			$('#events-calendar li').removeClass('open');
			$('#events-calendar li a.more-info').text('Meer info & aanmelden');
		});
		// open the current 
		oResultContentId.slideDown('fast', function(){
			oResultParentId.addClass('open');
			$('a.trigger', oResultParentId).addClass('trigger-open');
			$('a.more-info', oResultParentId).addClass('close-info');
			$('a.more-info', oResultParentId).text('Sluiten');
		});

	},

	closeEventInformation: function(oResultParentId, oResultContentId, oResultId){
		oResultContentId.slideUp('fast', function(){
			oResultParentId.removeClass('open');
			$('a.trigger', oResultParentId).removeClass('trigger-open');
			$('a.more-info', oResultParentId).removeClass('close-info');
			$('a.more-info', oResultParentId).text('Meer info & aanmelden');
		});
	}
}

var titleToolTip = {

	sTitleContent: {},
	oToolTip: {},

	init: function(el){
		el.css({'position':'relative'});

		var counter = 1;
		el.each(function(){
			var link = $(this).find('a:first');

			titleToolTip.buildToolTip(link, counter);
			counter++;

			link.mouseenter(function(){
				titleToolTip.showToolTip($(this));
			});

			link.mouseleave(function(){
				titleToolTip.hideToolTip($(this));
			});
		});
		
		
	},

	buildToolTip: function(el, counter){

		titleToolTip.sTitleContent.text = el.parent().find('.tooltip-text').html();
		titleToolTip.oToolTip = $('<div class="tooltip tooltip'+counter+'"><div class="tooltip-wrap"><div class="tooltip-top"></div><div class="tooltip-content">'+titleToolTip.sTitleContent.text+'</div><div class="tooltip-bottom"></div><div class="tooltip-marker"></div></div></div>');
		titleToolTip.oToolTip.insertAfter(el);
		Cufon.refresh('.tooltip .tooltip-wrap .tooltip-content h2', { fontFamily: 'arial' });
		// remove the default title value
		//el.removeAttr('title');
	},
	
	showToolTip: function(el){
		var oCurrentTooltip = el.next('div.tooltip');
		oCurrentTooltip.fadeIn('fast');
	},

	hideToolTip: function(el){
		var oCurrentTooltip = el.next('div.tooltip');
		oCurrentTooltip.hide();
	}

}

var table = { };

var coverflow = {
	initNav: function() {
		$(document).bind('keydown', 'left', coverflow.navPrev);
		$(document).bind('keydown', 'right', coverflow.navNext);
	},

	navPrev: function() {
		var flashMovie =  coverflow.getFlashMovieObject("mediaFlash");

		flashMovie.prevJS();
	},
	
	navNext: function() {
		var flashMovie = coverflow.getFlashMovieObject("mediaFlash");
		
		flashMovie.nextJS();
	},

	showProject: function(code) {
		var flashMovie = coverflow.getFlashMovieObject("mediaFlash");

		flashMovie.showProjectJS(code);
	},
	

	getFlashMovieObject: function(movieName) {
		if (window.document[movieName]) {
			return window.document[movieName];
		}
		if (navigator.appName.indexOf("Microsoft Internet")==-1) {
			if (document.embeds && document.embeds[movieName])
				return document.embeds[movieName]; 
		} else {
		    return document.getElementById(movieName);
		}
	}
}

var interactiveSitemap = {

	init: function(){
	
		$('ul#products input').bind('click', function(){
		
			interactiveSitemap.filterMainCategories($(this).val())	
		});
		
		$('#main-product-all').attr('checked','checked');
		$('#filter-categories dl li a').addClass('active');
	},

	filterMainCategories: function(sCategoryId){

		if(sCategoryId != 'product-all'){
				
			$('#filter-options ul.subcategory').slideUp('fast');
			
			$('#filter-categories ul li a').removeClass('active');

			$('ul#'+sCategoryId+'-services').slideDown('fast', function(){ 
				
				$('input:first', $(this)).attr('checked','checked');

				$('dl#'+sCategoryId+' li a').addClass('active');

				$('input', $(this)).bind('click', function() {
					interactiveSitemap.filterSubCategories($(this).val(), sCategoryId);
				});
			});
		}
		else{ 
			$('#filter-options ul.subcategory').slideUp('medium', function(){
				$('#filter-categories ul li a').addClass('active'); 
			});
		}
	},

	filterSubCategories: function(sSubCategoryId, sCategoryId){
		$('dl#'+sCategoryId+' li a').removeClass('active');
		
		if(sSubCategoryId != 'service-all'){
			$('dl#'+sCategoryId+' li a.'+sSubCategoryId).addClass('active');
		}
		else { $('dl#'+sCategoryId+' li a').addClass('active'); }	
	}
}

jQuery(function($) {
	$.fn.parentFindRecursive = function(selector) {
		var findParent = $(this).parentsUntil(selector).last().parent();
		if(findParent.length < 1) { return $(this).parent(); }
		return findParent;
	}
});

$(document).ready(function(){
	Global.init();
});

