 jQuery.noConflict();

// TRIGGER ROUTEPLANNER FOR HEADER
	function calculateRoute(chain){
		jQuery("#calculate-route").trigger("click");
	}
	//
	function calculateFuel()
	{
		jQuery("#calculate-fuel").trigger("click");
	}
	

jQuery(document).ready(function() {

	jQuery(".fancybox").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 660,
		'height'			: 580,
		'scrolling'   		: 'no'
			});
	
	jQuery(".videopopup").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 580,
		'height'			: 350,
		'scrolling'   		: 'no'
			});
		
	jQuery(".notice").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 660,
		'height'			: 300,
		'scrolling'   		: 'no'
			});
			
	jQuery(".popup").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 660,
		'height'			: 580,
		'scrolling'   		: 'auto'
			});
			
			jQuery(".bigpopup").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 960,
		'height'			: 580,
		'scrolling'   		: 'auto'
			});
	
	jQuery(".routeplan").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 960,
		'height'			: 580,
		'scrolling'   		: 'no'
			});
	
	jQuery(".fancypic").fancybox({
		'titleShow'     : false,
		'transitionIn'	: 'none',
		'overlayColor'	: '#FFFFFF',
		'autoScale'     	: false,
		'scrolling'   		: 'no',
		'transitionOut'	: 'none'

			});

	jQuery(".person a").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayColor'		: '#362B24',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				:  822,
		'height'			: '95%',
		'scrolling'   		: 'auto'
	});	
	
	jQuery("#linkedingroup").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayColor'		: '#362B24',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				:  '90%',
		'height'			: '95%',
		'scrolling'   		: 'auto'
	});
	
	jQuery(".notice").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayColor'		: '#362B24',
		'autoScale'     	: false,
		'type'				: 'iframe',
		'width'				: 600,
		'height'			: 300,
		'scrolling'   		: 'no'
	});	
		
	// SUBCRIBE TO MAILINGLIST	
  	function checkEmail(email)
	{	
		var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailVal = jQuery("#" + email).val();
		return pattern.test(emailVal);
	}
	
	jQuery(function()
	{
		jQuery("#subForm input:submit").click(function() 
		{		
			// First, disable the form from submitting
			jQuery('form#subForm').submit(function() { return false; });
			
			// Grab form action
			var formAction = jQuery("form#subForm").attr("action");
			
			// Hacking together id for email field
			var id = "iykrp";
			var emailId = id+"-"+id;
			
			// Validate email address with regex
			if (!checkEmail(emailId)) 
			{
				jQuery("#error").trigger('click');
				return false;
				
			}
			
			// Serialize form values to be submitted with POST
			var str = jQuery("form#subForm").serialize();
			
			// Add form action to end of serialized data
			var serialized = str + "&action=" + formAction;
			
			jQuery.fancybox.showActivity();

			// Submit the form via ajax
			jQuery.ajax({
				url: "http://www.lavagraphics.be/includes/proxy.php",
				type: "POST",
				data: serialized,
				success: function(data){
					// Server-side validation
					if (data.search(/invalid/i) != -1) {
						//alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
						jQuery("#error").trigger('click');
						jQuery("#" + emailId).val() = '';
					}
					else
					{
						jQuery("#ok").trigger('click');
						jQuery("#" + emailId).val() = '';
					}
				}
			
			});
		});
	});


	
});


