$(document).ready(function(){
	$('#mailoverlay').hover(function() {
		var offset = $("#mailoverlay").offset();
		if(offset.left == -180){
			$("#mailoverlay").stop().animate({"left": "+=180px"}, "slow");
		}
	}, function(){
		window.setTimeout(function() {
			var offset = jQuery("#mailoverlay").offset();
			if(offset.left == 0){
				jQuery("#mailoverlay").stop().animate({"left": "-=180px"}, "slow");
			}
		}, 4000);
	});
	
	window.setTimeout(function() {
		$("#mailoverlay").animate({"left": "-=180px"}, "slow");
	}, 4000);
	$(".btn_submit").mouseover(function(){
		$(this).attr('class','btn_submita');
	});
	$(".btn_submit").mouseout(function(){
		$(this).attr('class','btn_submit');
	});
	var flashvars = {};
	var params = {
		scale: "noscale",
		wmode: "transparent",
		align: "center",
		salign: "center"		
	};
	var attributes = {};
	swfobject.embedSWF("/media/movies/henry.swf", "player1", "263", "176", "9.0.0", "/else/includes/js/swfobject/expressInstall.swf",flashvars,params,attributes);
	swfobject.embedSWF("/media/movies/mark.swf", "player2", "263", "176", "9.0.0", "/else/includes/js/swfobject/expressInstall.swf",flashvars,params,attributes);
	swfobject.embedSWF("/media/movies/jeroen.swf", "player3", "263", "176", "9.0.0", "/else/includes/js/swfobject/expressInstall.swf",flashvars,params,attributes);
	
	
	
	var attributes = {styleclass: "flashdiv"};
	swfobject.embedSWF("/media/movies/flash.swf", "flash1", "1200", "429", "9.0.0", "/else/includes/js/swfobject/expressInstall.swf",flashvars,params,attributes);
	
	var attributes = {styleclass: "flashdiv"};
	swfobject.embedSWF("/media/movies/flash2.swf", "flash2", "1200", "429", "9.0.0", "/else/includes/js/swfobject/expressInstall.swf",flashvars,params,attributes);
	
	var random = Math.floor(Math.random()*8);
	$('#headpic').css({ 'background-image' : 'url(/media/basic/images/homepage/'+random+'.jpg)' });
	
	
	$("#contact_button").click(function(){
		var name = $("#naam").val();
		var company = $("#bedrijf").val();
		var email = $("#email").val();
		var code = $("#code").val();
		var message = $("#bericht").val();
		if((name != 'Naam' && name != '') && (email != 'E-mail' && email != '') && (code != 'hier' && code != '' && code == 'i-Solve') && (message != 'Bericht' && message != '') && validateMail(email)){
			$.post('../media/basic/ajax/mail.php',{
				action : 'mail',
				name : name,
				company: company,
				email: email,
				code : code,
				message : message
			},function(data){
				if(data == "SUCCESS"){
					//$("#contact_container").fadeOut('slow', function() {
						$("#contactform").html("<div style=\"padding-right: 25px;\"><br /><h2>Bedankt</h2>Wij hebben jou gegevens ontvangen en zullen hier zo spoedig mogelijk op terug komen.</div>");
					//	$("#contact_container").fadeIn('slow');
					//});
				}
			});
		}if((name == 'Naam' || name == '')){
			$("#naam").css({ 'border' : '1px solid #ed1066' });
		}else{
			$("#naam").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((email == 'E-mail' || email == '') || !validateMail(email)){
			$("#email").css({ 'border' : '1px solid #ed1066' });
		}else{
			$("#email").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((code == 'hier' || code == '') || code != 'i-Solve'){
			$("#code").css({ 'border' : '1px solid #ed1066' });
		}else{
			$("#code").css({ 'border' : '1px solid #B3B3B3' });
		}
		if((message == 'Bericht' || message == '')){
			$("#bericht").css({ 'border' : '1px solid #ed1066' });
		}else{
			$("#bericht").css({ 'border' : '1px solid #B3B3B3' });
		}
	});
});

var latv;
var lngv;
var address='\'t veld 3 Heteren nederland';
var map;
function load() {
	if(GBrowserIsCompatible()){
		map = new GMap2(document.getElementById("maps"));
		var customUI = map.getDefaultUI();
		customUI.maptypes.normal = false;
		customUI.maptypes.physical = false;
		customUI.maptypes.hybrid = false;
		customUI.maptypes.satellite = false;
		customUI.zoom.scrollwheel = true;
		customUI.zoom.doubleclick = true;
		customUI.keyboard = true;
		
		customUI.controls.largemapcontrol3d = false;
		customUI.controls.smallzoomcontrol3d = false;
		customUI.controls.maptypecontrol = false;
		customUI.controls.menumaptypecontrol = false;
		customUI.controls.scalecontrol = false;
	
		map.setUI(customUI);
		
		geocoder = new GClientGeocoder();
		var custIcon = new GIcon(G_DEFAULT_ICON);
		custIcon.image = "/media/basic/images/gmarker.png";
		custIcon.shadow = "/media/basic/images/shadow.png";
		custIcon.iconSize = new GSize(124, 58);
		custIcon.shadowSize = new GSize(0, 0);
		custIcon.iconAnchor = new GPoint(60, 55);
		markerOptions = { icon:custIcon };

		geocoder.getLocations(address, function(point) {
			latv=point.Placemark[0].Point.coordinates[1];
			lngv=point.Placemark[0].Point.coordinates[0];
			map.setCenter(new GLatLng(latv,lngv), 15, G_PHYSICAL_MAP);
			var point = new GLatLng(latv,lngv);
			var marker = new GMarker(point,markerOptions);
			var html = "";
			map.addOverlay(marker);
		});
	}
}

var directionsPanel;
var directions;

function getDirections() {
	$("#directions").html("<br /><h2>Routebeschrijving</h2><a href=\"javascript:void(0)\" onclick=\"showFormulier()\" class=\"btnbericht\">Stuur bericht</a>");
  	map = new GMap2(document.getElementById("maps"));
	geocoder = new GClientGeocoder();
	directionsPanel = document.getElementById("directions");
	var customUI = map.getDefaultUI();
	customUI.maptypes.normal = false;
	customUI.maptypes.physical = false;
	customUI.maptypes.hybrid = false;
	customUI.maptypes.satellite = false;
	customUI.zoom.scrollwheel = true;
	customUI.zoom.doubleclick = true;
	customUI.keyboard = true;
	
	customUI.controls.largemapcontrol3d = false;
	customUI.controls.smallzoomcontrol3d = false;
	customUI.controls.maptypecontrol = false;
	customUI.controls.menumaptypecontrol = false;
	customUI.controls.scalecontrol = false;

	map.setUI(customUI);
		
		geocoder = new GClientGeocoder();
		var custIcon = new GIcon(G_DEFAULT_ICON);
		custIcon.image = "/media/basic/images/gmarker.png";
		custIcon.shadow = "/media/basic/images/shadow.png";
		custIcon.iconSize = new GSize(124, 58);
		custIcon.shadowSize = new GSize(75, 84);
		custIcon.iconAnchor = new GPoint(0, 30);

		markerOptions = { icon:custIcon };
	geocoder.getLocations(address, function(point) {
		latv=point.Placemark[0].Point.coordinates[1];
		lngv=point.Placemark[0].Point.coordinates[0];
		map.setCenter(new GLatLng(latv,lngv), 15, G_PHYSICAL_MAP);
			var point = new GLatLng(latv,lngv);
			var marker = new GMarker(point,markerOptions);
			var html = "";
			map.addOverlay(marker);
		directions = new GDirections(map, directionsPanel);
		fromadd=$('#dir-address').val()+" nederland";
		directions.load("from: "+fromadd+" to:"+address,{ locale: 'nl' });
		
	});
	$("#directions").css({display: 'block'});
	$("#contactform").css({display: 'none'});
}

function showFormulier(){
	$("#directions").css({display: 'none'});
	$("#contactform").css({display: 'block'});
}

function validateMail(email){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email) == false) {
		return false;
	}else{
		return true;
	}
}
