var FloorNavigatorPopup = {
	container: null,
	updateContainer: function(oData) {
		if (!$defined(FloorNavigatorPopup.container))
		{
			FloorNavigatorPopup.container = FloorNavigatorPopup.createTemplate();
		}
		FloorNavigatorPopup.container.getElement('.fn-Popup-title').setHTML(oData['title']);
		FloorNavigatorPopup.container.getElement('.fn-Popup-content').setHTML(oData['content']);

		refel = $(oData['ref']);
		refcoords = refel.getCoordinates();
		coords = {'left': (refcoords['left']+refcoords['width'])-21,
		          'top':  (refcoords['top']-6),
				  'display':'block'};		
		
		FloorNavigatorPopup.container.setStyles(coords);
	},
	
	close: function() {
		if ($defined(FloorNavigatorPopup.container))
			FloorNavigatorPopup.container.setStyle('display','none');
	},
	
	createTemplate: function() {
		ret =
			new Element('div',{'id':'fnFeaturesPopup','events':{
				'mouseenter': function() {this.over=true;},
				'mouseleave': function() {this.over=false;}
			}}).adopt(
				new Element('img',{'src':'/assets/images/FloorNavigator/sidebar.Popup.left-arrow.png',
				                   'class':'fn-Popup-leftarrow'}),
				new Element('div',{'class':'fn-Popup-chrome'}).adopt(
					new Element('div',{'class':'fn-Popup-close',
										'events':{
											'click': function(e) {
												FloorNavigatorPopup.close();
											},
											'mouseenter': function(e) {
												//this.setStyle('color','#000');
												this.addClass('hover');
											},
											'mouseleave': function(e) {
												this.removeClass('hover');
											}
										}}).setText('X'),
					new Element('div',{'class':'fn-Popup-frame'}).adopt(
						new Element('h6',{'class':'fn-Popup-title'}),
						new Element('div',{'class':'fn-Popup-content'})
					)
				)
			);
		ret.setProperty("over",false);
		
		/*document.addEvent('mousedown',function(e) {
			if (FloorNavigatorPopup.container.over==true) return;
			FloorNavigatorPopup.close();
		});*/
		$(document.body).adopt(ret);
		return ret;
	},
	
	getFeatures: function(ref, material, feature) {
		
		var FN = 'Material:'+material;
		var FeatureName = feature;
		var url = '/applications/FloorNavigator/controllers/feature-values.php?FN='+FN+'&FeatureName='+FeatureName;
		var ajaxRequest = new Ajax(url, {'method':' get',
		                                 onComplete: function(responseString){
			//data = Json.evaluate(responseString);
			//data['ref'] = $(ref);
			data = {'ref':$(ref),
			        'title':FeatureName,
			        'content':responseString};
					
			FloorNavigatorPopup.updateContainer(data);
		}}).request();
	}
};

