var regionMapProperties = $H({
								17: $H({'zoom': 500,
									   'posY': -97,
									   'posX': -466,
									   'defaultImage': 'images/HomeMap2/europeDefault.gif',
									   'prefixImage':  'images/HomeMap2/europe',
									   'imageOver':  'images/HomeMap2/europeOver'
									 }),
								22: $H({'zoom': 160,
									   'posY': -9,
									   'posX': -156,
									   'defaultImage': 'images/HomeMap2/asiaDefault.gif',
									   'prefixImage': 'images/HomeMap2/asia',
									   'imageOver':  'images/HomeMap2/asiaOver'
									}),
								16: $H({'zoom': 160,
									   'posY': -58,
									   'posX': -75,
									   'defaultImage': 'images/HomeMap2/africaDefault.gif',
									   'prefixImage':  'images/HomeMap2/africa',
									   'imageOver':  'images/HomeMap2/africaOver'
									}),
								21: $H({'zoom': 1000,
									   'posY': -605,
									   'posX': -360,
									   'defaultImage':  'images/HomeMap2/caribbeanDefault.gif',
									   'prefixImage':  'images/HomeMap2/caribbean',
									   'imageOver':  'images/HomeMap2/caribbeanOver'
									})
							});
							
var SelectionMap = Class.create();

	SelectionMap.prototype = {
		initialize: function(pnlInitial,pnlWaiting,pnlResults,mapClientId,imgMap,imgMapOver,hmpCenterMapOver,
							 hmpCenterMapClick,regionMaps, regions, countriesByRegion, CommandArgument,FuncClientMouseOverRegion, FuncClientClickRegion,appPrefix,FuncHideResults, clientid, clienturl) {
		    this.pnlInitial              = pnlInitial;                 
			this.pnlWaiting              = pnlWaiting;
			this.pnlResults              = pnlResults;
			this.mapClientId			 = mapClientId;
			
			this.regions = regions;
			// Merge the regions parameter with the properties of our map
			var p = this;
			var newRegions = $H();
			this.regions.each(function(x) {
				x.value = x.value.merge(regionMapProperties.get(x.key));
				x.value = x.value.merge(regionMaps.get(x.key));
				newRegions.set(x.key, x.value);
			}, p);
			this.appPrefix	= appPrefix;
			this.regions = newRegions;
			this.countriesByRegion = countriesByRegion;
								
			this.imgMap			         = imgMap;
			this.imgMapOver			     = imgMapOver;

	        this.hmpCenterMapOver        = hmpCenterMapOver;
	        this.hmpCenterMapClick       = hmpCenterMapClick;

			this.highlightClassName = 'hmpHighlight';
			this.selectedRegion = 0; // world
	        this.commandArgument         = CommandArgument;
	        this.funcClientMouseOverRegion = FuncClientMouseOverRegion;
	        this.funcHideResults = FuncHideResults;
	        this.funcClientClickRegion	 = FuncClientClickRegion;
	        this.currentContinent        = this.appPrefix + 'images/HomeMap2/worldDefault.gif';
	        this.currentRegion           = this.appPrefix + 'images/HomeMap2/africaDefault.gif';
	        this.clientid = clientid;
	        this.clienturl = clienturl;
	        	        
	        if (this.funcClientClickRegion.length > 0) {
				var funcClick = eval(this.funcClientClickRegion);
				funcClick(this, this.clientid, $(this.pnlResults), this.clienturl);
	        }
	        if ($(this.pnlInitial) != null)
				$(this.pnlResults).hide();
		},
		showResultPanel: function() {
			if ($(this.pnlInitial) != null)
				$(this.pnlInitial).hide();
			if ($(this.pnlWaiting) != null)
				$(this.pnlWaiting).hide();
			$(this.pnlResults).show();
		},
		showWaitingPanel: function() {
			if ($(this.pnlInitial) != null)
				$(this.pnlInitial).hide();
			if ($(this.pnlWaiting) != null)
				$(this.pnlWaiting).show();
			$(this.pnlResults).hide();
		},
		showInitialPanel: function() {
			if (this.funcHideResults.length > 0) {
				var funcClick = eval(this.funcHideResults);
				funcClick(this.clientid);
			}
			if ($(this.pnlInitial) != null)
				$(this.pnlInitial).show();
			if ($(this.pnlWaiting) != null)
				$(this.pnlWaiting).hide();
			$(this.pnlResults).hide();
		},
		selectContinent: function(continent, obj, eve)
		{
			if (this.regions.get(continent) != null) {
				this.selectedRegion = continent;
	            
				if (this.funcClientClickRegion.length > 0) {
					var funcClick = eval(this.funcClientClickRegion);
					funcClick(this, this.clientid, $(this.pnlResults), this.clienturl);
				}
		        
				if (this.regions.get(this.selectedRegion).get('hasZoom')) {
					this.currentContinent =this.appPrefix +  'images/HomeMap2/worldDefault.gif';
					$(this.imgMap).src = this.currentContinent;
					this.switchContinent(continent);
				} else {
					this.currentContinent =this.appPrefix +  'images/HomeMap2/world' + continent + '.gif';
					$(this.imgMap).src = this.currentContinent;
					this.currentRegion		          = continent;
				}
				this.showResultPanel();
			}
		},
		rollOverContinent: function (continent) {
			$(this.imgMapOver).src =this.appPrefix +  'images/HomeMap2/worldOver' + continent + '.gif';
			if (this.funcClientMouseOverRegion.length > 0) {
				var funcClick = eval(this.funcClientMouseOverRegion);
				funcClick(this, continent, -1,'over', this.clientid);
	        }
		},
		rollOutContinent: function() {
			$(this.imgMap).src = this.currentContinent;
			$(this.imgMapOver).src = this.appPrefix + 'images/blank.gif';
			if (this.funcClientMouseOverRegion.length > 0) {
				var funcClick = eval(this.funcClientMouseOverRegion);
				funcClick(this, -1, -1,'out', this.clientid);
	        }
		},
		rollOverZoomcontinet:function(continent,region)
		{
			if (this.regions.get(continent) != null) {
				$(this.regions.get(continent).get('imgMapOver')).src = this.appPrefix +  this.regions.get(continent).get('imageOver') + region + '.gif';
			}
			if (this.funcClientMouseOverRegion.length > 0) {
				var funcClick = eval(this.funcClientMouseOverRegion);
				funcClick(this, -1, region, 'over', this.clientid);
	        }
		},
		rollOverZoomcontinetBack:function(continent)
		{
			if (this.regions.get(continent) != null) {
				$(this.regions.get(continent).get('imgMapOver')).src =this.appPrefix +  'images/HomeMap2/europeOver0' + '.gif';
			}
		},
		
		rollOutZommContinent:function(continent)
		{
			if (this.regions.get(continent) != null) {
				$(this.regions.get(continent).get('imgMap')).src	  = this.currentRegion;
				$(this.regions.get(continent).get('imgMapOver')).src = this.appPrefix + 'images/blank.gif';
			}
			if (this.funcClientMouseOverRegion.length > 0) {
				var funcClick = eval(this.funcClientMouseOverRegion);
				funcClick(this, continent, -1, 'out', this.clientid);
	        }
		},

		switchContinent:function(continent)
		 {
		 	this.currentRegion = this.appPrefix + this.regions.get(continent).get('defaultImage');
			$(this.hmpCenterMapOver).hide();
			new Effect.Parallel(
				[ new Effect.Scale($(this.imgMap), this.regions.get(continent).get('zoom'),
					{scaleFromCenter: false}),
				new Effect.MoveBy($(this.imgMap),this.regions.get(continent).get('posY'),this.regions.get(continent).get('posX'),
					{})
				],
				{duration: 0.2
				}
			);
			new Effect.Parallel(
				[ 
				new Effect.Fade($(this.hmpCenterMapClick), {to:1}),
				new Effect.Appear($(this.regions.get(continent).get('divOver'))),
				new Effect.Appear($(this.regions.get(continent).get('divClick')), {to:1})
				],
				{duration: 0.2, queue: 'end'
				}
			);			
		  },
		 back: function() {
			if (this.regions.get(this.selectedRegion).get('parent') != 0) {
				this.selectedRegion = this.regions.get(this.selectedRegion).get('parent');
				this.currentRegion = this.appPrefix + this.regions.get(this.selectedRegion).get('defaultImage');
				this.regions.get(this.selectedRegion).get('imgMap').src = this.currentRegion;
				if (this.funcClientClickRegion.length > 0) {
					var funcClick = eval(this.funcClientClickRegion);
					funcClick(this, this.clientid, $(this.pnlResults), this.clienturl);
					this.showResultPanel();
				}
			} else
			if (!this.regions.get(this.selectedRegion).get('hasZoom')) {
				this.selectedRegion = 0;
				this.currentContinent =this.appPrefix +  'images/HomeMap2/worldDefault.gif';
				$(this.imgMap).src = this.currentContinent;
				this.rollOutContinent(0);
				this.showInitialPanel();
			} else {
				this.backToWorld(null, null, this.selectedRegion);
			}
		},
		
		 backToWorld:function(obj, eve,continent)
		 {
			this.selectedRegion = 0;
			this.currentContinent =this.appPrefix +  'images/HomeMap2/worldDefault.gif';
			this.currentRegion    = this.appPrefix + this.regions.get(continent).get('defaultImage');
			this.rollOverZoomcontinet(continent);
			this.rollOutZommContinent(continent);
			$(this.regions.get(continent).get('divOver')).hide();
			new Effect.Parallel(
				[ 
				new Effect.Appear($(this.hmpCenterMapClick)),
				new Effect.Fade($(this.regions.get(continent).get('divClick')))
				],
				{duration: 0.0
				}
			);
			new Effect.Parallel(
				[
				new Effect.Scale($(this.imgMap), 10000 / this.regions.get(continent).get('zoom')),
				new Effect.MoveBy($(this.imgMap), -this.regions.get(continent).get('posY'), -this.regions.get(continent).get('posX'))
				],
				{duration: 0.2, queue: 'end',
				afterFinish: function(eff) {
						$(this.hmpCenterMapOver).show();
						this.showInitialPanel();
					}.bind(this)
				}
				
			);
		 },
		 restartMap:function()
		 {
			this.selectedRegion = 0; // world
	        this.currentContinent        = this.appPrefix + 'images/HomeMap2/worldDefault.gif';
	        this.currentRegion           = this.appPrefix + 'images/HomeMap2/africaDefault.gif';	        	        
			this.showInitialPanel();
		 },
		 selectZoomRegion:function(continent,region, obj, eve)
		 {
		 	if (this.regions.get(region) != null) {
		 		this.currentRegion = this.appPrefix +  this.regions.get(continent).get('prefixImage') + region + '.gif';
		 		$(this.regions.get(continent).get('imgMap')).src	  = this.currentRegion;
		 		this.selectedRegion = region;
				if (this.funcClientClickRegion.length > 0) {
					var funcClick = eval(this.funcClientClickRegion);
					funcClick(this, this.clientid, $(this.pnlResults), this.clienturl);
				}
				this.showResultPanel();
			}
		 }
		}
