$(function(){
	$('body').removeClass('js-disabled').addClass('js-enabled');
	Shadowbox.init();
	
	$('#body_contact_us').initMap();
	
	$('#body_calculator').initCalculatorLaunch();
	
	$('#quotes').flashQuotes();
});

$.fn.initMap = function() {
	return this.each(function(){
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map_sleeve"));
			ll = new GLatLng(51.513339738074784, -0.07725298404693604);
			map.setCenter(ll, 16);
			map.addOverlay(new GMarker(ll));
			map.addControl(new GLargeMapControl());
			map.enableScrollWheelZoom()
		}
	});
}

$.fn.initCalculatorLaunch = function() {
	return this.each(function(){
		runTrigger();
	});
}

$.fn.flashQuotes = function(){
	return this.each(function(){
		var quotes = $('>li',this);
		var randomEntry = $(this).randomChild();
		
		var timer = window.setInterval(function(){
			quotes.filter(':visible').fadeOut(function(){
				if ($(this).is(':last-child')) {
					quotes.eq(0).fadeIn();
				} else {
					$(this).next('li').fadeIn();
				}
			});
		},5000);
	});	
}

$.fn.randomChild = function(settings) {
	return this.each(function(){
		var c = $(this).children().length;
		var r = Math.ceil(Math.random() * c);
		$(this).children().hide().parent().children(':nth-child(' + r + ')').show();
	});
};