// -----------------------------------------------------------------------------
window.addEvent('domready',function() {
	// minimal-height for MSIE versions < IE 7.0
  if(navigator.userAgent.toLowerCase().indexOf('msie') > 0 && $('tekst').getStyle('height').toInt() < 550) {
    $('tekst').setStyle('height','550px')
  }
	// Make png's transparent
	$$('img[src$=.png]').each(function(png) {
		png.setStyle('behavior','url(/_include/pngFix.htc)');
	}); 
	// changes "target='_blank'" into "rel='external'"
  $$('a[rel=external]').each(function(extLink) {
    extLink.setProperty('target','_blank');
  });
  
  if($('sendForm')) {
    var missingField;
    $('sendForm').addEvent('submit',function(ev) {
      var e = new Event(ev);
      e.stop();
      missingField = false;
      
      $$('.reqFld').each(function(field) {
        field.removeClass('reqFldEmpty');
        if(field.getValue() == '') {
          field.addClass('reqFldEmpty');
          missingField =  true;
        }
      });
      
      if(missingField == true) {
        alert('De gekleurde velden zijn verplicht');
      } else{
        $("sendForm").submit();
      }
    });
  }
  
  $$('a[href$=.pdf]').each(function(pdf){
	pdf.setProperty('onclick','_gaq.push(["_trackEvent","Download","Prijslijst"]);');
  });
  
  // Route popup
  if($('routeform')) {
    $('routeform').addEvent('submit',function(ev) {
      var e = new Event(ev);
      e.stop();

      // Haal het vertrekpunt uit het formulier en vervang de spaties door + tekens
      var vertrekpunt = $('google_postcode').getValue();

      // Adres
      var straat = 'Hoogeweg+22';
      var postcode = '2231+ms'
      var plaats = 'rijnsburg'
      var adres = straat+','+postcode+'+'+plaats
    
      // Open een nieuw venster met de routebeschrijving
      window.open("http://maps.google.nl/maps?f=d&hl=nl&saddr="+ vertrekpunt +"&daddr="+ adres +"&ie=UTF8&om=1","_blank","directories=0, location=0, menubar=0, status=0, toolbar=0, resizable=1, height=750, width=1000")
    });
  }
});


function googleMaps() {
  var map = new GMap2($('maps'));

  map.addControl(new GLargeMapControl());
  map.setCenter(new GLatLng(52.209350, 4.456363), 12);
	map.setMapType(G_HYBRID_MAP);
	
  var point = new GLatLng(52.209350, 4.456363);
  var marker = new GMarker(point);
  map.addOverlay(marker);
  GEvent.addListener(marker,'click',function() { 
    this.openInfoWindowHtml('<h3>Vianen Kwekerijen</h3><p>Hoogeweg 22<br/>2231 MS Rijnsburg</p>');
  });
}

/* ------------------------------------------------------------ */
/*
Simple SlideShow Class
version: 0.1
copyright 2007 11 01 - Huug Helmink, Ace Group bv

Usage:
  var mySlideShow = new simpleSlide([images::array]);
  mySlideShow.displayImage();
    or
  mySlideShow.displayImage.periodical([time::integer],mySlideShow);
*/
var simpleSlide = new Class({
  initialize: function(imageArray) {
    this.images = imageArray;
    this.active = 0;
    this.max = this.images.length;
    this.images.setStyle('display','none');
    this.images[this.active].setStyle('display','block');
  },
  
  displayImage: function() {
    this.images[this.active].setStyle('display','none');
    if(this.active < this.max-1)  this.active++;
    else this.active = 0;
    this.images[this.active].setStyle('display','block');
  }
});

if($('fotoslide')) {
  var mySlideShow = new simpleSlide($$('#fotoslide span'));
  mySlideShow.displayImage.periodical(3000,mySlideShow);
}

