$(document).ready(function() {
	$("#menu_top li.world").click(function(){
		showWorldMapLayer();
		return false;	
	});
	
	$("#worldmap_fadeout").click(function(){
		hideWorldMapLayer();
	});
	
	$("#data-worldmap-overlay").click(function(){
		$('.worldmap-continent').hide();
		$("#data-worldmap-overlay").hide();
		$("#data-info-text").hide();
	});
	
	$("img.overlay-image").click(function(){
		var overlay_id = this.id;
		var id = overlay_id.split("-");
		var output = id[1];
		if (id[2]) output += "-"+id[2];
		$("div.worldmap-continent").hide();
		$("#data-worldmap-overlay").show();
		$("#data-info-text").show();
		$('#data-' + output).show();
	});
	
	$('#worldmap area').mouseenter(function(){
		/*
		$('img#overlay-' + this.id).appendTo('.tx-pxmcworldmap-pi1');
		$('img#overlay-' + this.id).show();
		console.log(this.id);
		*/
		$('#worldmap-image').addClass('overlay-' + this.id + '_neu');
		$(this).mouseleave(function(){
		    /*
			$('img#overlay-' + this.id).mouseenter(function(){
				return 'on';
			});
			$('img#overlay-' + this.id).mouseleave(function(){
				$('img#overlay-' + this.id).appendTo('.tx-pxmcworldmap-pi1 #img-container');
				$('img#overlay-' + this.id).hide();
			});
			*/
			$('#worldmap-image').removeClass('overlay-' + this.id + '_neu');
			/*$('img#overlay-' + this.id).appendTo('.tx-pxmcworldmap-pi1 #img-container');
			$('img#overlay-' + this.id).hide();
			*/
		});
	});
	
	
	$('img.overlay-image').mouseenter(function(){
		$(this).appendTo('.tx-pxmcworldmap-pi1');
		$(this).show();
		
		
		$(this).mouseleave(function(){
			$(this).appendTo('.tx-pxmcworldmap-pi1 #img-container');
			$(this).hide();
		});
	});
	
	if($('#worldmap')){
		var areas = $('#worldmap area');
		for(var i = 0; i < areas.length; i++) {
			$(areas[i]).bind('click', showRegionsOfArea);
			//$(areas[i]).bind('mouseover', showAreaLabel);
			//$(areas[i]).bind('mouseout', hideAreaLabel);
		}

		var openers = $('.tx-pxmcworldmap-pi1 span.country-title');
		for(var i = 0; i < openers.length; i++) {
			$(openers[i]).parent('li').bind('mouseenter', showLanguageOptions);
			$(openers[i]).parent('li').bind('mouseleave', hideLanguageOptions);
		}
	}
});

var showWorldMapLayer = function() {
	$("#worldmap_fadeout").show();
	$("#worldmap_overlay").fadeIn();
}

var hideWorldMapLayer = function() {
	$("#worldmap_fadeout").hide();
	$("#worldmap_overlay").hide();
}

var showLanguageOptions = function(){
	/*$(this).children('ul').show();*/
}

var hideLanguageOptions = function(){
	/*$(this).children('ul').hide();*/
}

var showRegionsOfArea = function(){
	$("div.worldmap-continent").hide();
	$("#data-worldmap-overlay").show();
	$("#data-info-text").show();
	$('#data-' + this.id).show();
	
	return false;
}

var closeWindow = function(pObj){
	$('.worldmap-continent').hide();
	$("#data-worldmap-overlay").hide();
	$("#data-info-text").hide();
}
