Cufon.replace('#header', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});
Cufon.replace('#navigation ul li a', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});
Cufon.replace('#slogan', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});
Cufon.replace('#newsletter', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});
Cufon.replace('#content h1', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});
Cufon.replace('#content h2', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});
Cufon.replace('#content h3', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});
Cufon.replace('#content h4', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});
Cufon.replace('#content h5', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});
Cufon.replace('#content h6', { fontFamily: 'LexiconNo2A-RomanTxt', hover: true});

var StartOffset 	= 860;
var OverlapOffset = 361;

$(document).ready( function() {
	SetInformationBlock();
	$("#slogan .slide:first").fadeIn(700);
	
	if($("#inline").length > 0) {
		$("#inline").click(function() {
			$.fancybox({
				'href'		: '#taf'
			});
			return false;
		});
	}
  
  if($(".peoplelist").length > 0) {
    $(".peoplelist a").each( function() {
      var DefaultSrc = $("img", $(this)).attr("src");
      $(this).hover(
        function () {
          $("img", $(this)).attr("src", $(this).attr("hover"));
        }, 
        function () {
          $("img", $(this)).attr("src", DefaultSrc);    
        }
      );  
    });
    

  }
	
	if($("#map").length > 0) {
		SetMapStart();

		$("#fromAddress").keyup(	function() { SetMapStart(); });		
		$("#fromAddress").change(	function() { SetMapStart(); });	
		$("#fromAddress").blur(		function() { SetMapStart(); });	
		$("#fromCountry").keyup(	function() { SetMapStart(); });
		$("#fromCountry").change(	function() { SetMapStart(); });	
		$("#fromAddress").blur(		function() { SetMapStart(); });	
		
	 	$("#map").GoogleMaps3({width: '362px', 
	    										 height: '340px', 
	    										 centerpoint: 'Sterksel, NL',
	    										 zoomlevel: 8,
	    										 directions:{
	    										 div:'#directions',
	    										 start:'#start',
	    										 end:'#end',
	    										 button:'#getdirections' },
	    										    controls:{
												        TypeControls       : 'DROPDOWN_MENU'
												      }
	    										}); 

	  var MapIcon = new google.maps.MarkerImage('/pics/logo_google.png', 
	  							new google.maps.Size(60,71), 
	  							new google.maps.Point(0,0), 
	  							new google.maps.Point(23,71));
	  					
	  $("#map").GoogleMaps3.AddMarkerByAddress('St. Hubertuslaan 2, Maastricht, NL',{icon: MapIcon}); 
    $("#map").GoogleMaps3.AddMarkerByAddress('Boschdijk 133, Eindhoven, NL',{icon: MapIcon}); 
	  $("#map").GoogleMaps3.AddMarkerByAddress('Venrayseweg 53a, Venlo, NL',{icon: MapIcon}); 
	}


});

/*
$(window).load(function() {
	if($("#scroller").length > 0) {
		$("#scroller img").each(function() {
	    if($.browser.msie){
	        grayscaleImageIE(this);
	    } else {
	      this.src = grayscaleImage(this);
	    }
		});
	} 
});
*/

$(window).resize(function(){
	SetInformationBlock();
});

function SetMapStart()
{
	var FromValue = $("#fromAddress").val();
	var FromCountryValue = $("#fromCountry").val();
			
	$("#start").val(FromValue + ", " + FromCountryValue);
}

function SetInformationBlock() {
	$("#navigation a").each( function() {
		var CurrentElement = $(".info", $(this));
		var WindowWidth 	 = parseInt($(window).width());
		var PositionLeft	 = "-123";
    var isiPad         = navigator.userAgent.match(/iPad/i) != null;
    var isiPhone       = navigator.userAgent.match(/iPhone/i) != null;
  		
		if(WindowWidth < (990 + 113)) {
			PositionLeft = "123";
		}
    
    if(!isiPad && !isiPhone){
		  if(CurrentElement.length > 0) {
			  $(this).hover(
				  function() { 
					  CurrentElement.css({"left" : PositionLeft + "px"});
					  CurrentElement.animate({ 
						  "height" : "160px",
						  "border-top" : "1px solid #231F20"
					  }, 1000);		
				  },
				  function() {
					  CurrentElement.stop(true);
					  CurrentElement.css({ 
						  "height" : "0px",
						  "border-top" : "0px solid #231F20"
					  });		
				  }	
			  );
		  }
    }
	});
}

var GeneralCounter = 0;
function PlaceImages() {     
	$("#slideshow .double").each(
		function() {
			var leftoffset = StartOffset;
			var opacity = 1;
			if(GeneralCounter == 0) {
				leftoffset = 0; 
				opacity = 1;
        imageopacity = 0;
				imageieopacity = 0;
			} else {
				if(GeneralCounter == 1) {
          imageopacity = 1;
					imageieopacity = 100;
					leftoffset = OverlapOffset; 
				}
			}
			
			$(this).css({
			//	"z-index" : (10000 - GeneralCounter),
				"left" 		: leftoffset + "px"
			});        
          
			

			if($.browser.msie) {
				if(GeneralCounter == 0) {
					$(this).find(".imagefirst").css("display", "none");
				}
				
				$(this).find(".imagefirst").css({
					"z-index" : (900 - GeneralCounter)
				}); 
				
				$(this).find(".imagelast").css({
					"z-index" : (800 - GeneralCounter)
				});   
			} else {
				$(this).find(".imagefirst").css({
					"z-index" : (900 - GeneralCounter),
					"opacity"	: imageopacity
				});  
				
				$(this).find(".imagelast").css({
					"z-index" : (800 - GeneralCounter),
					"opacity"  : 1
				});     
			}
              
			GeneralCounter++;
		}
	);
	
	$("#slogan .slide:first").fadeIn(700);
	
	var TimeOutCount = 8000;
	if(typeof bSlideOnHomepage != "undefined") {
		if($.browser.msie) {
			var Flash = new CFlashObj("/media/Slider.swf", 856, 347, "");
			Flash.SetTargetDiv("slideshow");
			Flash.Write();
			
			TimeOutCount = 5000;
			setInterval(function(){ SlideSlogan(); }, TimeOutCount);
		} else {
			TimeOutCount = 5000;
			setTimeout(function(){ GoSlide(); }, TimeOutCount);
		}
	}
	
}

function SlideSlogan() {
	$("#slogan .slide:first").fadeOut(700, function() {
		$(this).appendTo($("#slogan .smallhead"));
		$("#slogan .slide:first").fadeIn(700);
	});
}

function GoSlide()
{
	$("#slideshow .double:first").fadeOut(700, function() {
		$(this).appendTo($("#slideshow"));
		$(this).css("left", StartOffset + "px");
		//$(this).css("z-index", (10000 - GeneralCounter));
		$(this).find(".imagefirst").css("display","block");
		$(this).find(".imagelast").css("display","block");
		$(this).show();
	});
	
	GeneralCounter++;

	$("#slideshow .double:first .imagefirst").delay(200).animate({"left":"0px", "opacity":"0"},1000); 
	$("#slideshow .double:first .imagelast").delay(300).animate({"left":"0px", "opacity":"1"},1000);
	$("#slideshow .double:first").delay(200).animate({"left":"0px"},1000);
	                                       
  $("#slideshow .double:first").next().delay(1000).animate({"left": OverlapOffset + "px"},1000);
  $("#slideshow .double:first").next().find(".imagefirst").delay(200).animate({"opacity":"1"},1000);
  
  $("#slogan .slide:first").fadeOut(700, function() {
		$(this).appendTo($("#slogan .smallhead"));
		$("#slogan .slide:first").fadeIn(700);
	});
	
	var counter = 0;
  $("#slideshow .double").each(
		function() {
			$(this).find(".imagefirst").css({
				"z-index" : (900 - counter),
				"opacity"	: imageopacity
			});
			
			$(this).find(".imagelast").css({
				"z-index" : (800 - counter),
				"opacity"	: 1
			});
			counter++;
		}
	);
	
  var TimeOutCount = 8000;
	if(typeof bSlideOnHomepage != "undefined") {
		TimeOutCount = 5000;
		setTimeout(function(){ GoSlide(); }, TimeOutCount);
	}
	
}

function checkValueFocus(field){
	
	var FieldValue = field.value;
	switch(FieldValue){
		case 'straatnaam, postcode, plaats':
			field.style.color = '#515253';
			field.value = '';
		break;
	}	
} 		

function checkValueBlur(field){
	
	var FieldValue = field.value;
	
	switch(FieldValue){
		case '':
			field.style.color = '#c0c0c0';
			field.value = 'straatnaam, postcode, plaats';
		break; 			
	}	
}

function grayscaleImageIE(imgObj)
{
    imgObj.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayScale=1)';
}

function grayscaleImage(imgObj)
{
    var canvas = document.createElement('canvas');
    var canvasContext = canvas.getContext('2d');
    
    var imgW = imgObj.width;
    var imgH = imgObj.height;
    canvas.width = imgW;
    canvas.height = imgH;
    
    canvasContext.drawImage(imgObj, 0, 0);
    var imgPixels = canvasContext.getImageData(0, 0, imgW, imgH);
    
    for(var y = 0; y < imgPixels.height; y++){
        for(var x = 0; x < imgPixels.width; x++){
            var i = (y * 4) * imgPixels.width + x * 4;
            var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
            imgPixels.data[i] = avg; 
            imgPixels.data[i + 1] = avg; 
            imgPixels.data[i + 2] = avg;
        }
    }

    canvasContext.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
    return canvas.toDataURL();
}

