var delayedMap = new Class({
	initialize: function() {
		this.count = 0;
		this.regions = {
			0: "eur",
			1: "can",
			2: "usa",
			3: "aus",
			4: "nzl",
			5: "rsa",
			6: "chn"
		};
		
		this.delayTimer = this.startSlideShow.periodical(750, this);
	},
	
	startSlideShow: function() {
		this.hideRegion();
		if(this.regions[this.count]) {
			this.showRegion();
			return (this.regions[this.count++] ? this.count : false);
		}
		
		$clear(this.delayTimer);
	},
	
	stopSlideShow: function() {
		return false;
	},
	
	showRegion: function() {
		if(this.regions[this.count]) {
			extAreaOver('country-map', this.regions[this.count]);
		}
		return this;
	},
	
	hideRegion: function() {
		if(this.regions[this.count-1]) {
			extAreaOut('country-map', this.regions[this.count-1]);
			return this;
		}
		return false
	}
});

document.addEvent('domready', function() {
	
	function showWindow(winID) {
		
		winID.setStyle('display','block');
		winID.addEvent("mouseenter",function() {
			if(timeout) {
				clearTimeout(timeout);
				timeout = false;
			}
		});
		winID.addEvent("mouseleave",function(){
			var re = new RegExp(/([a-z]+)\-/);
			var m = re.exec(winID.id);
			setAreaOut(this, "country-map_canvas", false, 0);
			$(m[1]).onmouseout = function(event){
				hideWindow();
				setAreaOut(this, "country-map_canvas", false, 0);
			};
			hideWindow(this);
		});
		
	}
	
	function hideWindow() {
		$$(".body").each(function(item,index){
			item.setStyle('display','none');
		});
	}
	
	function switchWindow(winID) {
		if(winID.getStyle('display') == 'none') {
			hideWindow();
			showWindow(winID);
		} else {
			hideWindow();
		}
	}
	
	cvi_map.defaultRadius = 0;
	cvi_map.defaultOpacity = 95;
	cvi_map.defaultBordercolor = '#FFFFFF';
	cvi_map.defaultAreacolor = '#F88017';
	cvi_map.defaultNoborder = false;
	cvi_map.defaultNofade = false;
	cvi_map.defaultShowcoords = true;
	cvi_map.defaultDelayed = false;
	cvi_map.defaultImgsrc = '';
	cvi_map.defaultMapid = '#countries';
	
	cvi_map.add($('country-map'), {});
	
	$$(".body").each(function(item,index){
		item.setOpacity(0.95);
	});
	var timeout = false;
	$$('area').each(function(item,index){
		if(item.href == location.href) {
			item.onmouseover = function(){
				extAreaOver("country-map", this.id);
				$(item.id).onmouseout = function(event){
					if(!timeout) {
						timeout = window.setTimeout(function(item){
							hideWindow();
							setAreaOut(item, "country-map_canvas", false, 0);
						}, 1000);	
					}
				};
				showWindow($(item.id + "-body"));
				return false;
			};
		}
	});
});