function SetHorizon(){
	$(document).scrollLeft(Math.abs($(window).width()/2 - 1284/2), 0);
// 	window.scrollBy(Math.abs($(window).width()/2 - 1284/2), 0);
}

function preloadImages(){
	for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	}
}

$(document).ready(function(){
	var img_path = "images/";
	SetHorizon();
	preloadImages(
		img_path+'btn_nieuwer.png',
		img_path+'btn_nieuwer.png',
		img_path+'btn_ouder.png',
		img_path+'btn_scroll_down.png',
		img_path+'btn_scroll_up.png',
		img_path+'btn_scroll_up.png',
		img_path+'img_kika_hover.png',
		img_path+'img_logo_caar_hover.png',
		img_path+'img_logo_total_hover.png',
		img_path+'img_pen_hover.png',
		img_path+'img_tab_auto_hover.jpg',
		img_path+'img_tab_home_hover.jpg',
		img_path+'img_tab_route_hover.png',
		img_path+'img_tab_team_hover.jpg',
		img_path+'img_rally_nieuws_hover.png',
		img_path+'img_sleutel_hover.png',
		img_path+'img_webdesign_hover.png'
	);

	$(".RO-link-jpg img").hover(
		function(){
			this.src = this.src.replace(".jpg", "_hover.jpg");
		},
		function(){
			this.src = this.src.replace("_hover.jpg",".jpg");
		}
	);

	$(".RO-link img").hover(
		function(){
			this.src = this.src.replace(".png", "_hover.png");
		},
		function(){
			this.src = this.src.replace("_hover.png",".png");
		}
	);

	var runOnLoad = new Array();
	window.onload = function() {
		for(var i = 0; i < runOnLoad.length; i++) runOnLoad[i]() 
	}
	if(document.getElementsByTagName)
	for(var i in a = document.getElementsByTagName('a')) {
		a[i].onmousedown = function() { 
			this.blur();                 // most browsers 
			this.hideFocus = true;       // internet explorer
			this.style.outline = 'none'; // mozilla
		}   
		a[i].onmouseout = a[i].onmouseup = function() { 
			this.blur();                 // most browsers 
			this.hideFocus = false;      // internet explorer    
			this.style.outline = null;   // mozilla 
		}
	}

	if(jQuery.browser.msie && (jQuery.browser.version == '5.5' ||jQuery.browser.version == '6.0')){
		supersleight.init();
	}

			function Tooltip(marker, text, padding){
				this.marker_ = marker;
				this.text_ = text;
				this.padding_ = padding;
			}

			Tooltip.prototype = new GOverlay();

			Tooltip.prototype.initialize = function(map){
				var div = document.createElement("div");
				div.appendChild(document.createTextNode(this.text_));
				div.className = "tooltip";
				div.style.position = "absolute";
				div.style.visibility = "hidden";
				map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
				this.map_ = map;
				this.div_ = div;
			}

			Tooltip.prototype.remove = function(){
				this.div_.parentNode.removeChild(this.div_);
			}

			Tooltip.prototype.copy = function(){
				return new Tooltip(this.marker_,this.text_,this.padding_);
			}

			Tooltip.prototype.redraw = function(force){
				if (!force) return;
				var markerPos = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
				var iconAnchor = this.marker_.getIcon().iconAnchor;
				var xPos = Math.round(markerPos.x - this.div_.clientWidth / 2);
				var yPos = markerPos.y - iconAnchor.y - this.div_.clientHeight - this.padding_;
				this.div_.style.top = yPos + "px";
				this.div_.style.left = xPos + "px";
			}

			Tooltip.prototype.show = function(){
				this.div_.style.visibility = "visible";
			}

			Tooltip.prototype.hide = function(){
				this.div_.style.visibility = "hidden";
			}


	function createMarker(latlng, title,url){
		var marker = new GMarker(latlng);
		var tooltip = new Tooltip(marker,title,4); 
		marker.tooltip = tooltip; 
		map.addOverlay(tooltip);
		map.addOverlay(marker);
		GEvent.addListener(marker,"mouseover",function(){ this.tooltip.show(); });
		GEvent.addListener(marker,"mouseout",function(){ this.tooltip.hide(); });
		GEvent.addListener(marker,"click",function(){ window.location.href=url; });
		return marker;
	}
	
	function dropPinsClicked(onoroff){

		map.clearOverlays();
		var center = new GLatLng(52.0779734, 4.3123713);
		map.setCenter(center, 15);
	
		var marker = new GMarker (center);
		map.addOverlay(marker);
		dropMarker(marker, Math.round(Math.random()*100+200));
		if(onoroff){
			var latlng = map.getCenter();
			for(var i=0; i<points.length; i++){
				var lat = points[i].lon;
				var lng = points[i].lat;
				var marker = createMarker(new GLatLng(lat, lng),points[i].title,points[i].url);
				map.addOverlay(marker);
				dropMarker(marker, Math.round(Math.random()*100+200));
			}
			map.setZoom(12) ;
		}
	}
	function createpoint (lon, lat,title,url)
	{
		var newObject = new Object ();

		newObject.lon = lon;
		newObject.lat = lat;
		newObject.title = title;
		newObject.url = url;
		
		points.push(newObject);
	}


	function dropMarker(marker, height){
		// Make bouncable
		if (!marker.Xa)
		{
			marker.Xa = true;
			marker.qo(false);
		}
		marker.Pa = height;	// Current height
		marker.ri = height;	// Max height
		marker.av = 1;		// Direction (+ = down)
		marker.tc();		// Go baby!
	}


});