function RoutesMap( div ) {
	var routes = new Array();
	var map_div = div
	
	this.render = function(terramain_id)
	{
		this._make_all_inactive();
		
		for (var i=0;i<routes.length; i++)
		{
			var route = routes[i];
			
			// Is this the main departure point?
			if ( route.departure==terramain_id )
			{
				document.getElementById(route.departure).className = 'terramain';
				document.getElementById(route.route).style.display = '';
			}
			// Is it a destination of a main departure point
			else if (route.destination==terramain_id)
				document.getElementById(route.departure).className = '';
		}
	}
	
	this._get_event_target = function( event )
	{
		if (!event)
			event = window.event;
		return event.srcElement==undefined?event.target:event.srcElement;
	}
	
	this._make_all_inactive = function()
	{
		for( var i=0; i<routes.length; i++ )
		{
			var route = routes[i];
			document.getElementById(route.departure).className = 'tile';
			document.getElementById(route.route).style.display = 'none';
		}
	}
	
	
	this.hide = function()
	{
		Element.hide($(map_div));
	}
	
	this.show = function()
	{
		Element.show($(map_div));
	}
	
	this.add = function( departure_id, destination_id, route_id )
	{
		this._add(departure_id, destination_id, route_id);
		this._add(destination_id, departure_id, route_id);
	}
	
	this._add = function( departure_id, destination_id, route_id )
	{
		routes.push({departure:departure_id,destination:destination_id,route:route_id});
	}
	
	this.routes = function() {
		return routes;
	}
}

var intl_routes = new RoutesMap('international_map');

// Almaty
intl_routes.add('ic18','ic02','ir07');
intl_routes.add('ic18','ic01','ir01');
intl_routes.add('ic18','ic07','ir02');
intl_routes.add('ic18','ic11','ir08');
intl_routes.add('ic18','ic12','ir09');
intl_routes.add('ic18','ic09','ir12');
intl_routes.add('ic18','ic10','ir11');
intl_routes.add('ic18','ic08','ir10');
intl_routes.add('ic18','ic05','ir04');
intl_routes.add('ic18','ic06','ir03');
//intl_routes.add('ic18','ic04','ir05');
intl_routes.add('ic18','ic03','ir06');
intl_routes.add('ic18','ic21','ir27');

// Atyrau
intl_routes.add('ic14','ic07','ir17');
intl_routes.add('ic14','ic03','ir16');

// Karaganda
//intl_routes.add('ic17','ic06','ir19');
//intl_routes.add('ic17','ic04','ir18');

// Astana
intl_routes.add('ic13','ic02','ir15');
//intl_routes.add('ic13','ic04','ir14');
intl_routes.add('ic13','ic06','ir13');
intl_routes.add('ic13','ic12','ir23');
intl_routes.add('ic13','ic07','ir25');
intl_routes.add('ic13','ic20','ir26');

// Kostanay
//intl_routes.add('ic16','ic04','ir20');
//intl_routes.add('ic16','ic06','ir21');

//Aktau
//intl_routes.add('ic19','ic02','ir22');
 
var domestic_routes = new RoutesMap('domestic_map');
// Almaty
domestic_routes.add('dc14','dc01','dr00');
domestic_routes.add('dc14','dc15','dr01');
//domestic_routes.add('dc14','dc16','dr02');
domestic_routes.add('dc14','dc12','dr03');
//domestic_routes.add('dc14','dc07','dr04');
domestic_routes.add('dc14','dc10','dr05');
domestic_routes.add('dc14','dc11','dr06');
//domestic_routes.add('dc14','dc09','dr07');
//domestic_routes.add('dc14','dc05','dr08');
domestic_routes.add('dc14','dc04','dr09');
domestic_routes.add('dc14','dc06','dr10');
domestic_routes.add('dc14','dc02','dr11');
domestic_routes.add('dc14','dc03','dr12');
domestic_routes.add('dc14','dc13','dr13');

// Astana
domestic_routes.add('dc10','dc05','dr14');
domestic_routes.add('dc10','dc04','dr15');
domestic_routes.add('dc10','dc06','dr16');
domestic_routes.add('dc10','dc01','dr17');
domestic_routes.add('dc10','dc02','dr18');
domestic_routes.add('dc10','dc03','dr19');
//domestic_routes.add('dc10','dc08','dr20');
domestic_routes.add('dc10','dc09','dr21');
domestic_routes.add('dc10','dc07','dr22');
domestic_routes.add('dc10','dc12','dr23');
domestic_routes.add('dc10','dc16','dr24');
domestic_routes.add('dc10','dc15','dr25');

// Atyrau
domestic_routes.add('dc02','dc01','dr26');
//domestic_routes.add('dc02','dc06','dr27');

function choose_intl()
{
	$('choose_domestic').className = '';
	$('choose_intl').className = 'on';
	domestic_routes.hide();
	intl_routes.show();
	intl_routes.render('ic18');
}

function choose_domestic()
{
	$('choose_intl').className = '';
	$('choose_domestic').className = 'on';
	intl_routes.hide();
	domestic_routes.show();
	domestic_routes.render('dc14');
}

function init_maps()
{			
	// International routes
	var routes = intl_routes.routes();
	for(var i=0;i<routes.length;i++)
		$(routes[i].departure).onmouseover = function() { intl_routes.render(this.id) };
		
	// Domestic routes
	var routes = domestic_routes.routes();
	for(var i=0;i<routes.length;i++)
		$(routes[i].departure).onmouseover = function() { domestic_routes.render(this.id) };
	
	// Choose international
	Event.observe($('choose_intl'),'click', choose_intl );
	
	// Choose domestic
	Event.observe($('choose_domestic'),'click', choose_domestic );
	
	choose_intl();
}

Event.observe(window,'load',init_maps);