$(document).ready(function(){

    ///////////////////////////////////////////////////////////
    // Configure home page gallery
    ///////////////////////////////////////////////////////////

    //remove readmore
    var gallery = '.gallery .gallery-items';
    var readmore = ' a.link-more';
    var link = $(gallery + readmore).each(function(){
      var link = $(this).attr('href');
     
      $box  = $(this).parent().parent().parent();
      $($box).css({cursor:'pointer'});
      $($box).click(function(){
        document.location = link;
        return false;
      });
      $(this).remove();
    })
   


    //initScript();
    //initSideMenu();
    initGooglemaps();

    $('input').keyup(function(){
            var parent = $(this).parent();
            if(this.value.length >= this.maxLength){
                            if ($(this).hasClass('zip_let')) {
                                    $('.zip_num',parent).focus();
                            }
            }
    });

    $('form.form-route').keypress(function(ev){

            if (ev.which == 13) {
                    $('a',this).trigger('click');
            }
    })

})

function initGooglemaps() {
	
	//add contact map
	var myLatlng = new google.maps.LatLng( 52.3408, 4.8724);
	var myOptions = {
	  zoom: 15,
	  center: myLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var baseUrl = $('body').attr('rel');
 
	var map = new google.maps.Map(document.getElementById("googlemaps_contact"), myOptions);
	var marker = new google.maps.Marker({
      position: myLatlng, 
      map: map, 
      icon: baseUrl + '/images/google_pointer.png',
      title:"Businesscreation"
  });   
  
  //add routes
   var zipcode = $('#googlemaps_from_zipcode').attr('rel');     
   if (zipcode) {   	
   		map = new GMap2(document.getElementById("googlemaps_route_canvas"));
   		directionsPanel = document.getElementById("googlemaps_route_textual");
   		map.setCenter(new GLatLng(52.3408, 4.8724), 3);
   		directions = new GDirections(map, directionsPanel);   
   		directions.load("from: " + zipcode + ", nederland to:  Strawinskylaan Amsterdam, nederland");
   }

  
  $('form.form-route a').click(function(){  	  	 
  	 
  	 var zip_let = $('form.form-route input.zip_let').val();
  	 var zip_num = $('form.form-route input.zip_num').val();
  	 if (zip_let.length == 4 && zip_num.length == 2) {
  	 	 $('form.form-route input.zip_let').removeClass('error');
  	 	 $('form.form-route input.zip_num').removeClass('error');
  	 	 $('form.form-route').submit();
  	 } 
  	 else {
  	 	   $('form.form-route input.zip_let').addClass('error');
  	 	   $('form.form-route input.zip_num').addClass('error');
  	 }
  	 return false;
  });
}

 
	 


