
jQuery(function($) {
// Show the print button when the user can print
	if(window.print && $('#print-btn').length > 0) { $('#print-btn').show(); }
	
// initialize youtube videos in content pages
	$('#content-youtube-album a.tube').nvsTube();
	
// initialize photoalbums in content pages.
	$('#content-fotoalbum a.photo').nvsAlbum({overlayTransparancy: '0.7'});


	$('#ingestuurd .image a').nvsAlbum({overlayTransparancy: '0.7', jsonEnabled:	false, jsonUrl: "/json/fotoalbum.php?id=" });
	$('#ingestuurd .lnk a').nvsAlbum({overlayTransparancy: '0.7', jsonEnabled:	false, jsonUrl: "/json/fotoalbum.php?id=" });

// initialize photocarrousel
	init_carrousel();
	
	$('#footer-banners img').hover(
		function() { 
			$(this).attr("oldsrc", $(this).attr("src"));
			nSrcSuf = $(this).attr("src").substr($(this).attr("src").length-4,4);
			nSrcPref = $(this).attr("src").substr(0,$(this).attr("src").length-4);
			nSrc =nSrcPref+"_cl"+ nSrcSuf;
			$(this).attr("src", nSrc);
		},
		function() {
			$(this).attr("src", $(this).attr("oldsrc"));
		}
	)
	
// login functions 
	$('#frm-login .password_bg').addClass('txt');
	$('#login_password').focus(function () { $('#frm-login .password_bg').removeClass('txt'); });
	$('#login_password').blur(function () {
		if($('#login_password').val() == '') { 	
			$('#frm-login .password_bg').addClass('txt')
		}
	});
	
	$('#login_username').attr('oldval','Inlognaam');
	$('#login_username').focus(function () { 
		if($('#login_username').val() == $('#login_username').attr('oldval')) { 
			$('#login_username').val('');
		}	
	});
	$('#login_username').blur(function () {
		if($('#login_username').val() == '') { 	
			$('#login_username').val($('#login_username').attr('oldval'));
		}
	});


// newsletter archive clear input functions 
	$("#frm_newsletter_subscribe input[value!=''][type!='submit']").focus(function () { 
		if(!$(this).attr("startvalue")) {  
			$(this).attr("startvalue", $(this).val());
		} 
		if($(this).val() == $(this).attr("startvalue")) {
			$(this).val('');	
		}
	});
	$("#frm_newsletter_subscribe input[value!='']").blur(function () { 
		if($(this).val() == '') {
			$(this).val($(this).attr("startvalue"));
		}
	});
	
	if($("#googleMap").length > 0) {
		init_googlemap();
	}
	if($("#busGoogleMap").length > 0) {
		init_busGooglemap();
	}

	$('#scroller div').slider();
	
	if(typeof(tfb) != 'undefined') {
		tfb.account = 'debeepnl';
		tfb.label = 'follow-us';
		tfb.color = '#92278f';
		tfb.side = 'r';
		tfb.top = 136;
		tfb.showbadge();
	}
});



var map = null;
var geoXml =null;
var KMLoverlays = new Array();

function init_googlemap() {
    map = new GMap2(document.getElementById("googleMap"));
    var center = new GLatLng(52.168457,5.412827); 
	map.setCenter(center, 11);
	map.setMapType(G_NORMAL_MAP);
   
	var mt = map.getMapTypes();
	for (var i = 0; i < mt.length; i++) {
		// Overwrite the getMinimumResolution() and getMaximumResolution() methods
		mt[i].getMinimumResolution = function() {return 11;}
		mt[i].getMaximumResolution = function() {return 15;}
	}
	
	map.enableDragging();	
	map.addControl(new GLargeMapControl());

    /**
   * Listener die ervoor zorgt dat bij het aanklikken van een
   * placemark (en dus openen van de balloon) de KML niet opnieuw
   * ingeladen wordt.
   * Daarnaast een fix om de links in de balloon niet in een nieuw
   * venster te laten openen
   */          

	GEvent.addListener(map, "infowindowopen", function() {
		$('#googleMap a').each(function(e){
				$(this).attr("target","_self");
		});
	});
	KMLoverlays['beeps']  = load_KML('http://www.debeep.nl//kml/beeps.kml.php', "beeps");
}
	
function init_busGooglemap() {
    map = new GMap2(document.getElementById("busGoogleMap"));
    var center = new GLatLng(52.178457,5.392827);
	map.setCenter(center, 11);
	map.setMapType(G_NORMAL_MAP);

	var mt = map.getMapTypes();
	for (var i = 0; i < mt.length; i++) {
		mt[i].getMinimumResolution = function() {return 11;}
		mt[i].getMaximumResolution = function() {return 15;}
	}

	map.enableDragging();
	map.addControl(new GLargeMapControl());

	GEvent.addListener(map, "infowindowopen", function() {
		$('#busGoogleMap a').each(function(e){
				$(this).attr("target","_self");
		});
	});


	KMLoverlays['beeps']  = load_KML('http://www.debeep.nl//kml/bibilobus.kml.php', "beeps");
}

function load_KML(UrlOfKml,overlay) {
	if (UrlOfKml != null) {
		var _d = new Date();
		var _d = _d.getMilliseconds();
		UrlOfKml = UrlOfKml+"?"+_d;
		
		return new GGeoXml(UrlOfKml,function() { _show_kmlOverlay(overlay) } );
	}
}

function _show_kmlOverlay(overlay) {
	if (KMLoverlays[overlay].loadedCorrectly()){ 
		map.addOverlay(KMLoverlays[overlay]);
	}  else {
		_show_kmlOverlay(overlay);
	}

}
(function($) {
		$.fn.slider = function(options) {
			var defaults = {
				speed: 			4000,
				fadeSpeed: 		1000,
				curTop:			0,
				StarScrollTop:	0,

				activeLi:		0,
				liCount:		0,

				maxCount:		0
			};

			var options = $.extend(defaults, options);
			var jQueryMatchedObj = this;
			options.liCount = jQueryMatchedObj.length;

			options.StartScrollTop = 0;
			options.curTop = options.StartScrollTop;

			$('#scroller div:first').clone().appendTo('#scroller');
			$('#scroller').css({top: options.StartScrollTop});

			$('#scroller img').hover(
					function() {
						pauze();
						$(this).attr("oldsrc", $(this).attr("src"));
						nSrcSuf = $(this).attr("src").substr(($(this).attr("src").length-4),4);
						nSrcPref = $(this).attr("src").substr(0,($(this).attr("src").length-4));
						
						if((nSrcPref+nSrcSuf).indexOf("_cl") == -1){
						    nSrc = nSrcPref+"_cl"+ nSrcSuf;
						}
						$(this).attr("src", nSrc);
					},
					function() {
						options.TO = window.setTimeout(function() { animate() }, options.speed);
						$(this).attr("src", $(this).attr("oldsrc").replace('_cl',''));
					}
				)

			function pauze() {
				window.clearTimeout(options.TO);
			}

			function start() {
				window.clearTimeout(options.TO);
				options.TO = window.setTimeout(function() { animate() }, options.speed);
			}

			function animate() {
				if(options.liCount > 1) {
					nTop = options.curTop - 45;
					options.curTop = nTop;

					$("#scroller").animate(
						{ top: nTop },
						options.fadeSpeed,
						endAnimation
					);
				}
			}

			function endAnimation() {
				if(options.activeLi +1 < options.liCount) {
					options.activeLi++;
					start();
				} else {
					options.activeLi = 0;
					options.curTop = options.StartScrollTop;
					$("#scroller").css({ top: options.StartScrollTop });
					start();
				}
			}

		 	start(jQueryMatchedObj);
		}
})(jQuery);

