// JavaScript Document

$(document).ready(function(){

$("#deelgemeenten").click(function(){
		window.location = "http://www.de-toer-van-frans.nl/deelgemeenten.php";
});

huidigepagina = "toervan";

$(".menu li a, #content4 a").click(function(){
	var content = $(this).attr('id');
	if (huidigepagina != content) {
		$("#content4").load("http://www.de-toer-van-frans.nl/includes/"+content+".php");
		huidigepagina = content;
	}
	return false;
});



	var zIndex = 2;

$('.sleep').click		(function (){ $( this ).css('zIndex', zIndex); zIndex++; })
$('.imghome2').click	(function (){ $( this ).css('zIndex', zIndex); zIndex++; })
$('.imghome').click 	(function (){ $( this ).css('zIndex', zIndex); zIndex++; })
$('.imghome3').click 	(function (){ $( this ).css('zIndex', zIndex); zIndex++; })
$('.imghome4').click 	(function (){ $( this ).css('zIndex', zIndex); zIndex++; })
$('.imghome5').click 	(function (){ $( this ).css('zIndex', zIndex); zIndex++; })


$('.sleep').bind('dragstart',function( event ){
		if ( !$(event.target).is('h2, h1, .header')) return false;
		$( this ).addClass('active');
		$( this ).css('zIndex', zIndex);
		zIndex++;
  })

  .bind('drag',function( event ){
		$( this ).css({
				top: (event.offsetY-document.body.scrollTop),
				left: (event.offsetX-document.body.scrollLeft-$("#wrapper").offset().left)
		});
  })
  .bind('dragend',function( event ){
		$( this ).removeClass('active');
		
  });

$('.imghome')
  .bind('dragstart',function( event ){
		$( this ).addClass('active');
		$( this ).css('zIndex', zIndex);
		zIndex++;
  })

  .bind('drag',function( event ){
		$( this ).css({
				top: (event.offsetY-document.body.scrollTop),
				left: (event.offsetX-document.body.scrollLeft-$("#wrapper").offset().left)
		});
  })
  .bind('dragend',function( event ){
		$( this ).removeClass('active');
		
  });
		$('.imghome2')
  .bind('dragstart',function( event ){
		$( this ).addClass('active');
		$( this ).css('zIndex', zIndex);
		zIndex++;
  })

  .bind('drag',function( event ){
		$( this ).css({
				top: (event.offsetY-document.body.scrollTop),
				left: (event.offsetX-document.body.scrollLeft-$("#wrapper").offset().left)
		});
  })
  .bind('dragend',function( event ){
		$( this ).removeClass('active');
		
  });
  $('.imghome3')
  .bind('dragstart',function( event ){
		$( this ).addClass('active');
		$( this ).css('zIndex', zIndex);
		zIndex++;
  })

  .bind('drag',function( event ){
		$( this ).css({
				top: (event.offsetY-document.body.scrollTop),
				left: (event.offsetX-document.body.scrollLeft-$("#wrapper").offset().left)
		});
  })
  .bind('dragend',function( event ){
		$( this ).removeClass('active');
		
  });
  $('.imghome4')
  .bind('dragstart',function( event ){
		$( this ).addClass('active');
		$( this ).css('zIndex', zIndex);
		zIndex++;
  })

  .bind('drag',function( event ){
		$( this ).css({
				top: (event.offsetY-document.body.scrollTop),
				left: (event.offsetX-document.body.scrollLeft-$("#wrapper").offset().left)
		});
  })
  .bind('dragend',function( event ){
		$( this ).removeClass('active');
		
  });
  $('.imghome5')
  .bind('dragstart',function( event ){
		$( this ).addClass('active');
		$( this ).css('zIndex', zIndex);
		zIndex++;
  })

  .bind('drag',function( event ){
		$( this ).css({
				top: (event.offsetY-document.body.scrollTop),
				left: (event.offsetX-document.body.scrollLeft-$("#wrapper").offset().left)
		});
  })
  .bind('dragend',function( event ){
		$( this ).removeClass('active');
		
  });
		


});

function clearText(thefield){
	if (thefield.defaultValue==thefield.value) thefield.value = ""
} 

function resetText(thefield){
	if(thefield.value=='') thefield.value=thefield.defaultValue 
}

function checkContactForm2() {
	var check = ccscheck('naam', '') + ccscheck('mail','mail');
	if(check==0) return true;
	else return false;
}

function checkContactForm() {
	var check = ccscheck('naam', '') + ccscheck('mail','mail') + ccscheck('postcode','postcode') + ccscheck('adres','') + ccscheck('woonplaats','') + ccscheck('kaart','');
	if(check==0) return true;
	else return false;
}


function ccscheck(inputId, type) {
	var failCSS = 'invalid';
	if(check(inputId,type)==1) {
		document.getElementById(inputId).className = 'goodCSS';
		return 0;
	} else {
		document.getElementById(inputId).className = 'failCSS';
		document.getElementById(inputId).onkeyup = new Function("ccscheck('"+inputId+"', '"+type+"');");
		return 1;
	}
}   
 
function check(inputId, type) {
	var id = document.getElementById(inputId);
	var v = id.value;
	var d = id.defaultValue;
	switch (type) {
		
		case 'mail':
			var atIndex = v.indexOf('@');
			var dotIndex = v.lastIndexOf('.');
			if (atIndex < 1 || atIndex>=(v.length-2) || dotIndex < 1 || dotIndex>=(v.length-2) || atIndex > dotIndex - 1)
				return 0;
			else
				return 1;
			break
	
		case 'postcode':
			var re = new RegExp('(\\d{4})[\\s]*?([A-Z]{2}).*', "i");
			v = v.replace(re, "$1$2");
			v = v.toUpperCase();
			// id.value = v;
			if(v.length == 6 && re.test(v)) return 1; else return 0;
			break

		default:
			var length = v.length;
			if(length >= 2 && d != v) return 1; else return 0;
			break
	}
} 
 
function load() {
     if (GBrowserIsCompatible()) {
       var map = new GMap2(document.getElementById("map"));
	   map.setMapType(G_SATELLITE_MAP);
       map.setCenter(new GLatLng(51.90531, 4.46526), 13);
	   map.disableDragging();
     }
}

//var buffer = new Array();

//function loadContent(elementSelector, sourceUrl) {
	//type = "#"+sourceUrl;
	//if($(type).hasClass('iframe')) {
	//	$(elementSelector).html('<iframe src="http://www.de-toer-van-frans.nl/includes/'+sourceUrl+'.php" border="0" frameborder="0" scrolling="no" height="100%"></iframe>');
	//} else if(typeof buffer[sourceUrl] == "undefined") {
		//$.get("http://www.de-toer-van-frans.nl/includes/"+sourceUrl+'.php',buffer[sourceUrl], function(data) {
			//$(elementSelector).html(data);
			//buffer[sourceUrl] = data;
			//alert("buffer ingeladen");
		//});
	//} else { $(elementSelector).html(buffer[sourceUrl]); alert("uit de buffer gelezen"); }
//}
