imgPreloader = new Image();
imgPreloader.src = '/_img/loading.gif';

function display_submenu(id, rid) {
	divs = $("LI", ".m_right");
	for (i=0;i<divs.length;i++) {
		/*if ($(divs[i]).attr("class")=="activ") {
			$("#sub_"+$(divs[i]).attr("id")).animate({height: "hide"}, 300);
		}*/
		$(divs[i]).attr("class", "");
		//$("#sub_"+$(divs[i]).attr("id")).animate({height: "hide"}, 300);
		$("#sub_"+$(divs[i]).attr("id")).hide();
		
	}
	$("#"+id).attr("class", "activ");
	$("#sub_"+id).animate({height: "show"}, 300);
	//$("#sub_"+id).show();
	
	update_contacts_at_bottom(rid);

	$('.m2410 .country_block').hide();
	$('#country_'+rid).show();
}

function show_mailer_window(mailto) {
	var height_frame = document.getElementById("mailer_window").clientHeight;
	$("#mailer_window").css("top", document.body.scrollTop+((document.body.clientHeight-height_frame)/2));
	$("#mailer_window").css("visibility", "visible");
	$("#q_tomail").val(mailto);
	
}
function hide_mailer_window() {
	$("#mailer_window").css("visibility", "hidden");
}

$(document).ready(function() {
	$('a').each(function() {
		var href = $(this).attr('href');
		if (href.substring(0, 7) == 'mailto:') {
			$(this).click(function() {
				show_mailer_window(href.substring(7));
				return false;
			});
		}
	});
});

function update_contacts_at_bottom(id) {
	$('.top_center').html('<img src="/_img/loading.gif"/>');
	$('.top_right').html('');

	$.ajax({
		url: '/ajax_country_contacts.php',
		type: 'GET',
		data: 'lang=' + cur_lang + '&country=' + id,
		success: function(data) {
			var contacts = data.split('$-SEPARATOR-$');
			$('.top_center').html(contacts[0]);
			$('.top_right').html(contacts[1]);
		}
	});
}

function update_mini_map() {
	var center = map.getCenter();
	var zoom = map.getZoom();
	var centerMarker = placeMarker.getLatLng();
	
	$('#print_contact_map').attr(
		'src',
		'http://maps.google.com/staticmap?center=' + center.lat() + ',' + center.lng() +
		'&zoom=' + (zoom + 1) + '&size=512x512&markers=' + centerMarker.lat() + ',' + centerMarker.lng() +
		',white&maptype=hybrid&key=' + gmapsKey + ''
	);
}

