// Create the namespace if needed
if (!com) var com={};
if (!com.lastminute) com.lastminute={};
if (!com.lastminute.labs) com.lastminute.labs={};
if (!com.lastminute.labs.radar) com.lastminute.labs.radar={};


/**
 * the hotels need a "locale" parameter, which is set in the gears_col_1_row_1.html component.  This is obviously a placeholder, re-set it in the localised components.
 */
com.lastminute.labs.radar.locale = "en_GB";

/**
 * Holds a single hotel object
 */
com.lastminute.labs.radar.Hotel=function(xmlData)
{
	this.point=null;
	this.marker=null;
	this.icon=null;
	
	// Get the properties for this hotel from the xml
	this.setPropertyFromXml(xmlData, 'corehotelname');
	this.setPropertyFromXml(xmlData, 'accommcode');
	this.setPropertyFromXml(xmlData, 'accommadditional');
	this.setPropertyFromXml(xmlData, 'latitude');
	this.setPropertyFromXml(xmlData, 'longitude');
	this.setPropertyFromXml(xmlData, 'topsecret');
	this.setPropertyFromXml(xmlData, 'mapavailable');
	this.setPropertyFromXml(xmlData, 'distancefromlocation');
	this.setPropertyFromXml(xmlData, 'starratinig');
	this.setPropertyFromXml(xmlData, 'shortdescription');
	this.setPropertyFromXml(xmlData, 'imageurl');
	this.setPropertyFromXml(xmlData, 'goodbuy');
	this.setPropertyFromXml(xmlData, 'minroomprice');

	// Finally, create a default icon
	this.createIcons();
	
	// Create some dynamic properties
	this.url='http://www.lastminute.com/hotels/selectCategoryHotel.do?CATID=4&accommCode='+this.accommcode+'&accommAdditional='+this.accommadditional+'&locale=' + com.lastminute.labs.radar.locale
};

/**
 * Given an xml node, this function will add the contents of the named child node to the Hotel object.
 * If the named child doesn't exist (or there is more than one) this will set the property to ''
 * 
 * @param xmlNode The XmlNode object
 * @param name The name of the child object to read and property that will be set
 * @return The value of the new property
 */
com.lastminute.labs.radar.Hotel.prototype.setPropertyFromXml=function(xmlNode, name)
{	
	var element=xmlNode.getElementsByTagName(name);
	if (undefined==element) return this[name]='';
	if (1!=element.length) return this[name]=''
	element=element[0];
	if (undefined==element.firstChild) return this[name]='';
	element=element.firstChild;
	return this[name]=undefined!=element.nodeValue.toString()?element.nodeValue:'';
}

/**
 * Creates a marker for the hotel for the specific letter
 * 
 * @param The letter to appear on the icons
 * @return Nothing
 */
com.lastminute.labs.radar.Hotel.prototype.createIcons=function(letter)
{
	// Make the google icon
	this.icon=new GIcon(G_DEFAULT_ICON);
	if (undefined!=letter)
	{
		// Create the google image GIcon class
		this.icon.image=com.lastminute.labs.radar.Hotel.image_paths[letter];
		this.icon.shadow=com.lastminute.labs.radar.Hotel.image_paths['shadow'];
		this.icon.iconSize=new GSize(37,36);
		this.icon.shadowSize=new GSize(48,36);
		this.icon.iconAnchor=new GPoint(7, 34);
		this.icon.shadowAnchor=new GPoint();
		this.icon.imageMap=[0,0,35,0,35,14,25,14,25,22,0,22];
		
		// Create a thumb icon url as well
		this.thumbIcon=com.lastminute.labs.radar.Hotel.image_paths[letter+'_thumb'];
	}
}

/**
 * Store the icons in a hash so they can be updated for staging and live frontier sites
 */
com.lastminute.labs.radar.Hotel.image_paths={
	a:'images/hotel_icon_a.png',
	b:'images/hotel_icon_b.png',
	c:'images/hotel_icon_c.png',
	d:'images/hotel_icon_d.png',
	e:'images/hotel_icon_e.png',
	a_thumb:'images/hotel_icon_thumb_a.gif',
	b_thumb:'images/hotel_icon_thumb_b.gif',
	c_thumb:'images/hotel_icon_thumb_c.gif',
	d_thumb:'images/hotel_icon_thumb_d.gif',
	e_thumb:'images/hotel_icon_thumb_e.gif',
	shadow:'images/hotel_icon_shadow.png'
};
 