var office = null;

MAG.change_offices_map = function(city_id){
	try{
		var office = MAG.offices[city_id];
	}catch(e){
		return;
	}

	var blueIcon = new GIcon(G_DEFAULT_ICON);
	blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
	markerOptions = { clickable:false };

	if(!MAG.change_offices_map.map) {
		MAG.change_offices_map.map = new google.maps.Map2(document.getElementById('google_map'));
		MAG.change_offices_map.map.setUIToDefault();
	}

	// #2a -- calculate center
	var markersBounds = new GLatLngBounds( );

	if(office.length > 0) {

		for(i=0; i < office.length; i++){

			$('#data_content').append('<div>'+office[i].description+'</div>');
			if(office.length != 1 && i < office.length-1) {
				$('#data_content').append('<div class="sep sep_small"></div>');
			}

			if(!office.point){
				office[i].point = new GLatLng(office[i].latitude, office[i].longitude);
			}

			if(!office[i].marker){
				office[i].marker= new GMarker(office[i].point, markerOptions);
				MAG.change_offices_map.map.addOverlay(office[i].marker);
			}

			markersBounds.extend( office[i].point );
			//MAG.change_offices_map.map.setCenter(office.point,[13-15]);
		}

			var markersCenter = markersBounds.getCenter();
			var markersZoom = G_HYBRID_MAP.getBoundsZoomLevel(markersBounds,new GSize(271, 167));
			markersZoom = (office.length == 1) ? 16 : markersZoom;

			MAG.change_offices_map.map.setCenter(markersCenter, markersZoom);
	}
}

$(document).ready(function(){
	$('#home_deposit_amount, #home_deposit_rate').bind('focus', function(){
		if(this.value == this.getAttribute('title')){
			$(this).val('').removeClass('empty');
		}
	}).bind('blur', function(){
		if(!this.value.length){
			$(this).val(this.getAttribute('title')).addClass('empty');
		}
	});

	$('#home_deposit_days').bind('change keyup', function(){
		if(this.value){
			$(this).removeClass('empty');
		}else{
			$(this).addClass('empty');
		}
	});

	//news
	$('.news_index li:odd').addClass('odd');

	$('#subscribe').click(function(){
		var email = $('#email').val();
		var name = $('#name').val();
		var parameters	= {'method' : 'subscribe', 'mail' : email, 'name' : name};
		var url			= MAG.controller_url + MAG.ajax;

		$.get(url, parameters, function(html){
			$('#subscr').html(html);
		});
	});

	MAG.change_offices_map($('#clone_network_select').val());

	$('#clone_network_select').change(function(){
		$('#data_content').html('')
		MAG.change_offices_map(this.value);
		;
	});
});


