$(document).ready(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');
	});
	
	// Randomize ads right
	// $('div.banner_right').randomize('div.ad');
	//$('div.banner_right>p.banner_annonser').insertAfter('div.ad:last');
	
});

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);
		}
	});
}

// Randomize divs; used for banner right
/*(function($) {

$.fn.randomize = function(childElem) { 
  return this.each(function() {
      var $this = $(this);
      var elems = $this.children(childElem);
      
      console.log(elems);
 
      elems.sort(function() { return (Math.round(Math.random())-0.5); });  
		
		console.log('ELEMS sorted');
		
      // $this.empty();  
		
		console.log($this);
		
      for(var i=0; i < elems.length; i++) {
      	console.log(elems[i]);
        //$this.append(elems[i]);
      }

  });   
}
})(jQuery);*/

