$(function () {
	$('#local_list_form > select').change(function (e) {
		$(window).trigger('trackPageview', $('<a href="' + $(this).val() + '" />').get(0));
		window.location = $(this).val();
	});
	
	$('#center img[align][hspace]').each(function () {
		var css = {};
		
		switch (this.align) {
			case 'left':
				css = {
					'margin-right': this.hspace + 'px',
					'margin-left': 0,
					'float': 'left'
				};
				break;
				
			case 'right':
				css = {
					'margin-left': this.hspace + 'px',
					'margin-right': 0,
					'float': 'right'
				};
				break;
		}
		
		$(this).css(css).removeAttr('hspace').removeAttr('align');
	});
});

function unescapeFromPhp (x) {
	if (typeof x == 'object') {
		for (i in x) {
			x[i] = unescapeFromPhp(x[i]);
		}
		return x;
	} else if (typeof x == 'number') {
		return x;
	} else {
		return unescape(x);
	}
}

if (typeof(pageTracker) != 'undefined') {
	$('a').live('click', function () {
		var url = '';
	
		switch (true) {
			case this.hostname != window.location.hostname:
				url = '/_external:' + this.href;
				break;
				
			case !!this.pathname.match(/^\/?files\//):
			case !!this.pathname.match(/\/.*?\.(?!php)\w+$/):
			case !!this.pathname.match(/^\/?redirect\.php/):
				url = '/_internal:' + this.pathname + this.search + this.hash;
				break;
		}
		
		if (url != '') {
			pageTracker._trackPageview(url);
		}
	});
}