Cufon.set('fontFamily', 'DINOT-Regular').replace('h2 .line, .box .date-h3');
Cufon.set('fontFamily', 'DINOT-Medium').replace('#menu a', { textShadow: '1px 1px #051b44' });
Cufon.set('fontFamily', 'DINOT-Bold').replace('.box h3');

var fancyboxDefaults = {
	
	padding			: 20,
	overlayOpacity	: 0.7,
	overlayColor	: '#000',
	titlePosition	: 'inside'
	
}

function confirmMessage() {

	parent.$.fancybox({
		
		padding			: 20,
		overlayOpacity	: 0.7,
		overlayColor	: '#000',
		content			: '<div class="box box-white box-content" style="padding: 0;"><h3>Thank you!</h3><p>Thank you for providing us with your information. After closing this popup you can download all our files.</p></div>',
		onComplete		: renderFancyboxCufon,
		onClosed		: refreshPage
		
	});
	
}

function refreshPage() {
	
	window.location.reload(true);
	
}

function renderFancyboxCufon() {
	
	Cufon.set('fontFamily', 'DINOT-Bold').replace('#fancybox-inner h3');
	
}

function renderGoogleMaps() {
	
	var latlng = new google.maps.LatLng(51.499766912405946, 4.049550890922546);
	
	var myOptions = {
		
		zoom		: 11,
		center		: latlng,
		mapTypeId	: google.maps.MapTypeId.ROADMAP
		
	};
	
	var map = new google.maps.Map($('#fancybox-inner #googlemaps')[0], myOptions);
	
	var marker = new google.maps.Marker({
										
    	position	: latlng,
     	map			: map
		
	});
	
	var arcering;
	
	var arceringCoords = [
						  
    	new google.maps.LatLng(51.499796967408415, 4.048896431922913),
    	new google.maps.LatLng(51.5000674615387, 4.049915671348572),
    	new google.maps.LatLng(51.4997134812415, 4.050151705741882),
    	new google.maps.LatLng(51.49943964554062, 4.049132466316223)
		
  	];
	
	arcering = new google.maps.Polygon({
		
		paths			: arceringCoords,
		strokeColor		: "#29539D",
		strokeOpacity	: 0.8,
		strokeWeight	: 2,
		fillColor		: "#29539D",
		fillOpacity		: 0.35
		
  	});

 	arcering.setMap(map);
	
}

function renderPartnerGoogleMaps() {
	
	var coords = [];
	
	mapId = $('#fancybox-inner .partner-map').attr('id');
	
	switch (mapId) {
		
		case 'partner1-map':
			coords = [ 51.246249, 4.977751 ];
			break;
		case 'partner2-map':
			coords = [ 48.559905, 9.376134 ];
			break;
		case 'partner3-map':
			coords = [ 37.98900, 23.74777 ];
			break;
		case 'partner4-map':
			coords = [ 22.499979, 88.346759 ];
			break;
		case 'partner5-map':
			coords = [ 35.777534, 51.368245 ];
			break;
		case 'partner6-map':
			coords = [ 3.083609, 101.651001 ];
			break;
		case 'partner7-map':
			coords = [ 19.4341, -99.17482 ];
			break;
		case 'partner8-map':
			coords = [ 14.558148, 121.0181 ];
			break;
		case 'partner9-map':
			coords = [ 52.391241, 16.876749 ];
			break;
		case 'partner10-map':
			coords = [ 39.744459, -8.808578 ];
			break;
		case 'partner11-map':
			coords = [ 55.693166, 37.560859 ];
			//coords = [ 55.68226, 37.577459 ];
			break;
		case 'partner12-map':
			coords = [ 39.744459, -8.808578 ];
			break;
		case 'partner13-map':
			coords = [ 13.782759, 100.613697 ];
			break;
		case 'partner14-map':
			coords = [ 41.059765, 29.010381 ];
			break;
		case 'partner15-map':
			coords = [ 52.391241, 16.876749 ];
			break;
		case 'partner16-map':
			coords = [ 25.350988, 55.389687 ];
			break;
		case 'partner17-map':
			coords = [ 10.774305, 106.705138 ];
			break;
		case 'partner18-map':
			coords = [ -34.546577, -58.477545 ];
			break;
		case 'partner19-map':
			coords = [ 3.101907, 101.745265 ];
			break;
		case 'partner20-map':
			coords = [ -6.188507, 106.809187 ];
			break;
		case 'partner21-map':
			coords = [ 1.33092,103.89005 ];
			break;
	}
	
	var latlng = new google.maps.LatLng(coords[0], coords[1]);
	
	var myOptions = {
		
		zoom		: 11,
		center		: latlng,
		mapTypeId	: google.maps.MapTypeId.ROADMAP
		
	};
	
	var map = new google.maps.Map($('#fancybox-inner .partner-map')[0], myOptions);
	
	var marker = new google.maps.Marker({
										
    	position	: latlng,
     	map			: map
		
	});
	
	Cufon.set('fontFamily', 'DINOT-Bold').replace('#fancybox-inner h3');
	
}

function partnerSelectHandler(e) {
	
	var box = $(e).parentsUntil('.box').last().parent();
	
	var button = $(box).find('.button a');
	
	$(button).attr({
		
		href	: $(e).attr('href'),
		title	: $(e).text()
		
	});
	
	var fancyboxSettings = {
		
		autoDimensions	: false,
		width			: 600,
		height			: 355,
		onComplete		: renderPartnerGoogleMaps,
		titlePosition	: 'outside'
		
	}
	
	var settings = $.extend(fancyboxDefaults, fancyboxSettings);
	
	$(button).fancybox(settings);
	
}

$(function() {
	
	if ($('#menu li.active').index() == 1) {
		
		$('.col-side .box:first').prepend('<div class="icon-paper"></div>');
		
	}
	
	$('#menu li:eq(0)').addClass('first');
	
	$('#menu li:eq(5)').addClass('last');
	
	$('.box .item:last').each(function() {
		
		if ($(this).is(':last-child')) {
			
			$(this).addClass('last');
			
		}
		
	});
	
	$('.box-product:odd').addClass('odd');
	
	$('.box-questions input[type=text], .box-questions textarea').each(function() {
		
		var defaultValue = $(this).val();
		
		$(this).focus(function() {
			
			if ($(this).val() == defaultValue) {
				
				$(this).val('');
				
			}
			
		});
		
		$(this).blur(function() {
		
			if ($(this).val() == '') {
				
				$(this).val(defaultValue);
				
			}
			
		});
		
	});
	
	$('.box-questions input[type=text], .box-questions textarea').focus(function() {
		
		$(this).parent().removeClass('error');
		
	});
	
	$('.box-questions .button a').click(function(e) {
		
		e.preventDefault();
		
	});
	
	$('.box-partners .button a').click(function(e) {
		
		e.preventDefault();
		
	});
	
	var fancyboxSettings = {
		
		autoDimensions	: false,
		width			: 500,
		height			: 500,
		onComplete		: renderGoogleMaps,
		titlePosition	: 'outside'
		
	}
	
	var settings = $.extend(fancyboxDefaults, fancyboxSettings);
	
	$('.box-form input[type=text], .box-form textarea').focus(function() {
		
		$(this).parent().removeClass('error');
		
	});
	
	$('.box-contact .button a').fancybox(settings);

	$('.box-gallery .button a').click(function(e) {
		
		e.preventDefault();
		
		$('.box-gallery .gallery li:first a').trigger('click');
		
	});
	
	$('.box-gallery .gallery li a').fancybox({
		
		padding			: 20,
		overlayOpacity	: 0.7,
		overlayColor	: '#000',
		titlePosition	: 'inside'
		
	});

	$('.box-form form select').fakeselect({
				
		defaultValue	: 'Select a country ...',
		countryFlags	: true,
		rows			: 6
				
	});
	
	$('.box-content a[rel="fancybox"]').each(function() {
		
		$(this).removeAttr('rel');
		
		$(this).fancybox({
		
			titlePosition	: 'inside'
			
		});
		
	});
	
	$('.blockContent a[rel]').fancybox({
		
		titlePosition	: 'inside'
		
	});
	
	$('.box-downloads .youtube a').click(function() {
		
		$.fancybox({
			
			padding			: 20,
			overlayOpacity	: 0.7,
			overlayColor	: '#000',
			autoScale		: false,
			transitionIn	: 'none',
			transitionOut	: 'none',
			title			: this.title,
			width			: 680,
			height			: 495,
			href			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			type			: 'swf',
			swf				: {
				wmode			: 'transparent',
				allowfullscreen	: 'true'
			}
			
		});
	
		return false;
		
	});
	
	$('.box:not(.box-downloads) a').click(function() {
		
		if ($(this).attr('href').match(/http:\/\/(?:www\.)?youtube.*watch\?v=([a-zA-Z0-9\-_]+)/)) {
			
			$.fancybox({
				
				padding			: 20,
				overlayOpacity	: 0.7,
				overlayColor	: '#000',
				autoScale		: false,
				transitionIn	: 'none',
				transitionOut	: 'none',
				title			: this.title,
				width			: 680,
				height			: 495,
				href			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				type			: 'swf',
				swf				: {
					wmode			: 'transparent',
					allowfullscreen	: 'true'
				}
				
			});
		
			return false;
			
		}
		
	});
	
	$('.box-downloads li:not(.youtube) a.disabled').click(function(e) {
		
		e.preventDefault();

		var sFileLink = e.target.href;
		var aFileLink = sFileLink.split('/');
		var iFileLinkLength = aFileLink.length;
		var iFileId = aFileLink[(iFileLinkLength - 1)];

		$.fancybox({
			
			autoScale		: false,
			padding			: 20,
			overlayOpacity	: 0.7,
			overlayColor	: '#000',
			width			: 620,
			height			: 550,
			type			: 'iframe',
			scrolling		: 'no',
			href			: 'http://www.meaf.nl/form/form-download?iFileId=' + iFileId
			
		});
		
	});

	// Submit questions form at homepage.
	$('.box-questions a').bind('click', function() {
		$('.box-questions form').submit();
	});

	// Submit contact form.
	$('.blockContact a.contactSubmit').bind('click', function() {
		$('.blockContact form').submit();
	});

});
