// Countrybox class
var g_countrybox_id = 0;

function Countrybox( id, url, position )
{
	this.id 		= id;			// the id of the country box
	this.url 		= url;			// the url of the page to redirect to
	this.position 	= position;		// whether the box appears aligned to the "left" or "right" of the image
	this.active	= 0;				// indicates whether the countrybox has been created/activated yet 
}

function show_countrybox()
{
	TogglePopup( this.id, this.id + '_flag', this.position, 1 ); // show the countrybox 
	ToggleDiv( 'click' ); // show the background
	
	// Check whether we need to create the countrybox for the first time...
	if( this.active == 0 )
	{
		g_countrybox_id = this.id;
		request = create_xml_http_request();
		
		var url = "ajax/countrybox.php"; // creates the XML document url
		url = url + "?id=" + this.id + "&url=" + this.url;
		
		request.onreadystatechange = countrybox_state_changed;
		request.open("GET",url,true);
		request.send(null);
		
		this.active = 1; // mark the countrybox as being active so that it is not recreated again (waste of bandwidth!)	
	}
}

// Retrieves the XML data 
function countrybox_state_changed( id )
{
	if( request.readyState == 4 )
	{
		var xml_doc = request.responseXML.documentElement;
		var content = get_xml_node( xml_doc, "content", 0 );
		document.getElementById( g_countrybox_id + "_countries" ).innerHTML = content;
	}
}

Countrybox.prototype.show_countrybox			=show_countrybox;