/*
	prodosa javascript
*/

var leftcolumnScrollTop = 0;


$(document).ready(function() {
    /*	World Map:
		Initialise the worldmap */
	worldmap.init();
	$("#worldmap").mousemove(function(e){
		worldmap.mouseX = e.pageX;
		worldmap.mouseY = e.pageY;
	});
	
});

var adjustContentHeight = function() {

	var outerHeight = $('#outercontent').height();
	var horsesHeight = $('#horses').height() - 20;
	//alert(horsesHeight + ' - ' + outerHeight);
	
	//return;
	
	if (horsesHeight > outerHeight) {
		var diff = horsesHeight - outerHeight;
		var $innerContent = $('#innercontent');
		$innerContent.height($innerContent.height() + diff + 9);
	}
	
}
function alerttypeof(obj) {
	alert(typeof(obj));
}

var worldmap = {

	mouseX: 0,
	mouseY: 0,
	currentPopup: null,
	
	init: function() {
		/*	Click on a continent:
			Popup the list with cities for that continent */
		$("#worldmap li").click(function() {
			$('.worldmappopup').hide();
			worldmap.currentPopup = null;
			var popup = $('#' + $(this).attr('id') + '-popup');
			popup.css({"left": worldmap.mouseX + 1 + "px", "top": worldmap.mouseY + 1 + "px"});
			popup.show('fast');
			worldmap.currentPopup = popup;
			return false;
		});
		
		
		/*	Click on a city name:
			Open the region page for that city */
		$(".cityname").click(function() {
			worldmap.currentPopup.hide();
			worldmap.currentPopup = null;
			//alert($(this).attr('href'));
			window.location.href = WS_ROOT + '?p=regions&regid='+$(this).attr('href');
			/*	TODO:
				Find out how Google can follow these generated links :) */
			return false;
		});
	}
	
	
	/*
	<ul id="worldmap"> 
		<li id="na"><a href="#" onclick="displayPopup('na');"><span>North America</span></a></li> 
		<li id="sa"><a href="#"><span>South America</span></a></li> 
		<li id="af"><a href="#"><span>Africa</span></a></li> 
		<li id="as"><a href="#"><span>Asia</span></a></li> 
		<li id="eu"><a href="#"><span>Europe</span></a></li> 
		<li id="me"><a href="#"><span>Middle East</span></a></li> 
		<li id="oc"><a href="#"><span>Oceania</span></a></li> 
	</ul> 
	*/
}


function AjaxLoadModule(module, params, target) {
	var elm = $('#'+target);
	elm.html('<p>Loading. Please, wait...</p>');
	elm.load('../includes/AjaxLoadModule.php?module='+module+'&'+params, function() {
		//elm.hide();
		//elm.fadeIn();
	});
}

// collecting error message for client validation
var errmsg = {
	
	messages: new Array(),
	title: 'Oops,... the following problems occurred:\n\n',
	separator: '\n',
	
	add: function(msg) {
		this.messages.push(msg);
		// errmsg.messages[errmsg.messages.length] = msg;
	},
	
	all: function() {
		return this.messages.join(this.separator);
	},
	
	display: function() {
		alert(this.title + this.all());
		this.reset();
	},
	
	error: function() {
		return (this.messages.length>0);
	},
	
	reset: function() {
		this.messages = new Array();
	}
	
}

