$(function init(){
	$('#leftColGallery a').lightBox({fixedNavigation: true});
	
	gMap.init();
	
	$('table.prices tr:even').addClass('even');

	$('.renderVisible').removeClass('renderVisible');
	$('.renderHidden').removeClass('renderHidden');
	
	/* GA tracking */
	try {
		var pageTracker = _gat._getTracker("UA-13010835-1");
		pageTracker._trackPageview();
	} catch(err) {
		
	}
});

var gMap = {
	init: function () {
		var gmap = $('#gMap');
		if (gmap.length == 0) return;
		
		if (GBrowserIsCompatible()) {
			var map = new GMap2(gmap[0]);
			var latlng = new GLatLng(50.591797, -4.832159);
			map.setCenter(latlng, 9);
			map.setUIToDefault();
			
			var marker = new GMarker(latlng);
			map.addOverlay(marker);
			
			// GEvent.addListener(marker, "click", function() {
			// 	map.openInfoWindow(latlng, $('<div class="info-content"><h3>Courtenay House</h3><img src="/assets/images/gallery/medium/front-view.jpg" alt="" /><a href="/#leftColGallery">See more images</a></div>')[0]);
			// });
		}
	
	}
}

/* simple template */
String.prototype.tpl = function (o) {
    return this.replace(/{\$([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
        }
    );

};


/* test for empty object */
function emptyObject(o) {
	for (var i in o) { 
		return false;
	}
	return true;
}

/* link blurring extends jQ */
$.fn.nb = function() {
	this.blur();
	return this.focus(function(){
		this.blur();
	});
}

/* replaces DOM element and returns the new jQuery object*/
jQuery.fn.replace = function() {
    var stack = [];
    return this.domManip(arguments, true, 1, function(a){
        this.parentNode.replaceChild( a, this );
        stack.push(a);
    }).pushStack( stack );
};

function preloadImages() {
	var a = (typeof arguments[0] == 'object')? arguments[0] : arguments;
	for(var i = a.length -1; i >= 0; i--) {
		$("<img>").attr("src", a[i]);
	}
}

function log(a) {
	console.log(a);
}
