$(document).ready(function(){

	is_compatible = jQuery.support.boxModel;

	if ( is_compatible ) {
		$('.c_nw, .c_ne, .c_sw, .c_se').show();
	}
	else {
		$("#incompatible").show();
	};
	
	$.ajaxSetup({
		cache:		false,
		datatype:	'xml',
		timeout:	10000
	});

	setup_navigation();

	if ( typeof local_init_functions == 'function' ) {
		var local_functions = local_init_functions();
		var page_name = $('#page_name').text();
		run_local_function( page_name, local_functions );
	};

});

function run_local_function( page_name, local_functions ) {

	if ( local_functions.length > 0 ) {
		var current_function = local_functions.shift();
		var current_function_name = current_function.toString().match( /function\s*([\w\$]*)\s*\(/ )[1];

		var ms1 = new Date().getTime().toString();
		current_function();
		var ms2 = new Date().getTime().toString();
		var loading_time = ms2 - ms1;

		if ( _gaq ) { _gaq.push([ '_trackEvent', 'profiling', page_name, current_function_name, loading_time ]) };

		setTimeout( function(){ run_local_function( page_name, local_functions ) }, 50 );
	};

};

function setup_navigation() {
	$("#navi_top_city_chooser").click(function(){
		$(this).hide();
		$(".navi_top_city").show().click(function(){
			var city_id = $(this).attr("city_id");
			$.cookie('user_geo_city', city_id, { path: '/', expires: 1000 } );
			window.location.reload(true);
		});;
	});
};
