Event.observe(window, 'load', function()
{
	if ($('hide_button'))
	{
		
		Event.observe($('hide_button'), 'click', function()
		{ 
			if ($('map').visible())
			{
				$('map').hide();
				$('nav_country').hide();
				$('hide_button').src = '/images/projecten/show.png';
				$('hide_text').innerHTML = 'Toon wereldkaart';
				$('worldmap').style.height = '60px';
			}
			else
			{
				$('map').show();
				$('nav_country').show();
				$('hide_button').src = '/images/projecten/hide.png';
				$('hide_text').innerHTML = 'Verberg wereldkaart';
				$('worldmap').style.height = '481px';
			}
			
		}.bind(this));
	}
	
	if ($('hide_button2'))
	{
		Event.observe($('hide_button2'), 'click', function()
		{ 
			if ($('worldmap').style.height == '481px')
			{
//				$('worldmap').hide();
//				$('nav_country').hide();
				$('hide_button2').src = '/images/projecten/show2.png';
				$('hide_text').innerHTML = 'Toon kaart';
				$('worldmap').style.height = '0px';
				$('worldmap').style.padding = '0';
//				google.maps.event.trigger(map, 'resize')
				$('worldmap').style.overflow = 'hidden';
			}
			else
			{
//				$('worldmap').show();
//				$('nav_country').show();
				$('hide_button2').src = '/images/projecten/hide2.png';
				$('hide_text').innerHTML = 'Verberg kaart';
				$('worldmap').style.height = '481px';
				$('worldmap').style.padding = '1px 18px';
				$('worldmap').style.position = 'relative';
				$('worldmap').style.zIndex	= '2';
				$('worldmap').style.overflow = 'visible';
				
				
//				
//				  var center = map.getCenter(); 
//			      google.maps.event.trigger(map, 'resize'); 
//			      map.setCenter(center); 
			}
			
		}.bind(this));
	}

	
});

var MarkerCollection = Class.create(
{
		initialize: function() 
		{
			this.collection   = new Array();
		},
		addProject: function(markerobj)
		{
			this.collection.push(markerobj);	
		},
		clearMarkers:function()
		{
			this.collection.each(function(item){
			if (item.infowindow != undefined)
			{
			  item.infowindow.close();
			}
		});
	}
});

var googleMapObject = Class.create(
{
	initialize: function() 
	{
		
		var latlng = new google.maps.LatLng(32.876174, 13.187507); // libya
	    var myOptions = {
	      scrollwheel: false,
	      zoom: 2,
	      center: latlng,
	      mapTypeId: google.maps.MapTypeId.ROADMAP
	    };
	    this.map = new google.maps.Map($('map'), myOptions);
	},
	getMap: function()
	{
		return this.map;
	},
	zoomCountry: function(lat_x, long_x, lat_y, long_y)
	{
//		this.map.setCenter(new google.maps.LatLng(52.0912623,5.1227478));
//        this.map.setZoom(7);

 		var myOptions = { scrollwheel: false, mapTypeId: google.maps.MapTypeId.ROADMAP }; 
      	//var map = new google.maps.Map($('map'), myOptions); 
    
		var bounds = new google.maps.LatLngBounds();
		var point1 = new google.maps.LatLng(long_x,lat_x);
		var point2 = new google.maps.LatLng(long_y,lat_y);

		bounds.extend(point1);
		bounds.extend(point2);
		map.fitBounds(bounds); 
		
			
		
 
	}
});

var markerObject = Class.create(
{
	
	initialize: function(map, x, y, img, title, country, programma) 
	{
		this.x 			= x;
		this.y 			= y;
		this.img		= img;
		this.title		= title;
		this.country	= country;
		this.programma	= programma;
		this.map 		= map;
		this.icon 		= '/images/projecten/marker.png';
		this.infowindows= null;
		this.addMarker();
		
	},
	addMarker: function()
	{
		var self = this;
		
		var marker = new google.maps.Marker({
	        position: new google.maps.LatLng(self.x, self.y),
	        icon: self.icon,
	        map: self.map
	    });
	
	    google.maps.event.addListener(marker, "click", function(e)     
	    {
	    	projectcollection.clearMarkers();
	    	
	    	var html  = '<div class="google_projectimage">';
	    		html += '	<p>'+ self.img +'</p>';
	    		html += '	<p class="title">'+ self.title +'</p>';
	    		html += '	<p>Land: '+ self.country +'</p>';
	    		html += '	<p>Programma: '+ self.programma +'</p>';
	    		html += '</div>';
	    	
	    	var infowindowOptions = 
	    	{
				content: html,
				maxWidth: 285
			};
			
			
			
			self.infowindow = new google.maps.InfoWindow(infowindowOptions);
			self.infowindow.open(map, marker);
			
			
	    });
	    
		
		   
	    
	}
});

