var pro6pp_auth_key = "7ZmzGxwIAcuhbbhL";

function zoeksubmit() {
	if($('#straal').val()!=''&&$('#place').val()!='') {
		var url = "http://api.pro6pp.nl/v1/suggest?auth_key=" + pro6pp_auth_key + "&per_page=1&city=" + escape($('#place').val());
		
		$.getJSON(url + "&callback=?", function(data) {
			
			var straal = parseInt(escape($('#straal').val()));
			
			var url = "http://api.pro6pp.nl/v1/range?auth_key=" + pro6pp_auth_key + "&nl_fourpp="+data.results[0].nl_fourpp+"&per_page=300&range=" +straal;
			
			url = encodeURI(url);
			$.getJSON(url + "&callback=?", function(data) {
				
				var codes='';
				for(i=0;i<data.results.length;i++) {
					codes = data.results[i].nl_fourpp+','+codes;
					
				}
				//alert(codes);
				var url = '&rentaltype='+$('#rentaltype').val()+'&place='+$('#place').val()+'&uitvoering='+$('#uitvoering').val()+'&van='+$('#van').val()+'&tot='+$('#tot').val()+'&pcs='+codes+'&straal='+$('#straal').val();
				document.location=baseurl+tv+'/aanbod/'+url;

			});										
			/*
			if(data.results[0]!=null) {
				$('#addr').val(data.results[0].street);
				$('#adres').val(data.results[0].street);
				$('#city').val(data.results[0].city);
			}
			*/
		});	
	}  else if($('#straal').val()!=''&&$('#place').val()=='') {
		alert('Om te zoeken op straal moet u een stad selecteren.');
	} else {
		
		var url = '&rentaltype='+$('#rentaltype').val()+'&place='+$('#place').val()+'&uitvoering='+$('#uitvoering').val()+'&van='+$('#van').val()+'&tot='+$('#tot').val();
		document.location=baseurl+tv+'/aanbod/'+url;
	}
}
var hoogte = 0;
$(document).ready(function() {
	initialize();

	$(".fancy").lightBox({
		imageLoading: '/lightbox/images/lightbox-ico-loading.gif',
		imageBtnClose: '/lightbox/images/lightbox-btn-close.gif',
		imageBtnPrev: '/lightbox/images/lightbox-btn-prev.gif',
		imageBtnNext: '/lightbox/images/lightbox-btn-next.gif',
   });

	$("#sliderlogos").jcarousel({
		vertical: true,
		scroll: 2,
		auto: 3,
		buttonNextHTML: null,
		buttonPrevHTML: null,
		wrap: 'circular'				
	});
	
	
	

	
	/*$('#slideshow').cycle({ 
		fx:    'fade', 
		speed:  4000,
		timeout:  2000
	 });*/
	
	$('#huizenslides').cycle({ 
		fx:    'fade', 
		speed:  3000,
		timeout:  2500
	 });
	
	
	//scroll_logos();

});

function scroll_logos() {
	

	$('.logos ul').animate({
		'marginTop':'-440px'
		

	},25000,'linear',
	  function() {
			$('.logos ul').css('margin-top','0px');
			scroll_logos();
	  }

	);	

}


var panorama;
var currentYaw = 180;
var currentPitch = 0;
var timer;
var currentZoom = 0;
var zoomingIn = true;

function initialize() {
	
	if($('#address').length>0) {
		var geocoder = new GClientGeocoder();
		var address = $('#address').val();;
		
		var panoClient = new GStreetviewClient();

		var map = new GMap2(document.getElementById("map"));
		
		geocoder.getLatLng(
			address,
			function(point) {
			  	map.setCenter(point, 16);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				
				map.addControl(new GMapTypeControl());
				if($("#map").width()>300) {
					map.addControl(new GSmallMapControl());
					map.addControl(new GOverviewMapControl());
				}
				
				
				panoClient.getNearestPanoramaLatLng(point, function(newPoint) {
                        
						if (newPoint == null) {
                               document.getElementById("streetview").style.display='none';
                                return;
                        }
                        panoramaOptions = { latlng:newPoint};
                        myPano = new GStreetviewPanorama(document.getElementById("streetview"), panoramaOptions);
                });

				
			}
		);
	}

}


function spiral() {
  currentYaw += 1;
  panorama.panTo({yaw:currentYaw, pitch:currentPitch});
}

function stopAndZoom() {
  clearInterval(timer);
  zoomingIn = true;
  timer = window.setInterval(zoom, 500);
}

function zoom() {
  if (zoomingIn) {
    currentZoom++;
  } else {
    currentZoom--;
  }

  panorama.panTo({yaw:currentYaw, pitch:currentPitch, zoom:currentZoom});
  if (currentZoom == 2) {
    zoomingIn = false;
  }
  if (currentZoom == 0) {
    clearInterval(timer);
    timer = window.setInterval(spiral, 200);
  }
}

function get_address() {
	//if($('#straat').val()==''&&$('#city').val()=='') {
		
		
		
		var postcode = $('#pincode').val();
		var huisnummer = $('#huisnummer').val();
		
		if ((postcode.indexOf(' ') == 4 && postcode.length == 7) || (postcode.indexOf(' ') == -1 && postcode.length == 6)) {
			var url = "http://api.pro6pp.nl/v1/autocomplete?auth_key=" + pro6pp_auth_key + "&nl_sixpp=" + escape(postcode) + "&streetnumber=" + escape(huisnummer);
	
			$.getJSON(url + "&callback=?", function(data) {
			
				if(data.results[0]!=null) {
					$('#addr').val(data.results[0].street);
					$('#adres').val(data.results[0].street);
					$('#city').val(data.results[0].city);
				}
			});

		}
	//}
}

function get_address2() {
	//if($('#straat').val()==''&&$('#city').val()=='') {
		
		var pro6pp_auth_key = "7ZmzGxwIAcuhbbhL";
		
		var postcode = $('#hpincode').val();
		var huisnummer = $('#hhuisnummer').val();
		
		if ((postcode.indexOf(' ') == 4 && postcode.length == 7) || (postcode.indexOf(' ') == -1 && postcode.length == 6)) {
			var url = "http://api.pro6pp.nl/v1/autocomplete?auth_key=" + pro6pp_auth_key + "&nl_sixpp=" + escape(postcode) + "&streetnumber=" + escape(huisnummer);
			
			$.getJSON(url + "&callback=?", function(data) {

				if(data.results[0]!=null) {
					$('#hadres').val(data.results[0].street);
					$('#hcity').val(data.results[0].city);
				}
			});

		}
	//}
}
