window.addEvent('domready', function(){

	if ($('LocationSelector')) {
		new LocationSelector($('LocationSelector'));
	}

	// Activate all date pickers
	$$('input.DatePicker').each( function(el){
		new DatePicker(el);
	});
	$$('label.phantom').each( function(el){
		new PhantomLabels(el);
	});
	$$('#breadcrumbs .bookmarks').each( function(el){ insertBookmarks(el); });

	// Get Live Fors
	$$('.getlivefors').each( function(el){
		new Ajax('/livefor/recenttwo', { method: 'get', update: el }).request();
	});

	// Google Analytics
	if(typeof urchinTracker == "function"){
		_uacct = "UA-356557-4";
		urchinTracker();
	}
});

function alternate(hideDiv, showDiv){
	$(hideDiv).style.display = "none";
	$(showDiv).style.display = "block";
}

function insertBookmarks(el){
	var url = escape(window.location.href);
	var title = escape(document.title);
	new Ajax('/bookmarkme.html', {
		method: 'get',
		update: el,
		onComplete: function(){
			el.getElements('a').each( function(link){
				link.href = link.href.replace('[[[url]]]', url).replace('[[[title]]]', title);
			});
			if (el.hasClass('bacon')) {
				var baconlink = new Element('a', {
					'href': '/index_bacon.aspx',
					'title': 'enable baconification'
				}).setHTML('<img alt="enable baconification" src="/imgs/find/baconification.gif" />').injectInside(el);
			}
		}
	}).request();
}
