var ns = NUSA.namespace("Maps.Models");


ns.Map = function(state) {
	
	this.id;
		
	this.currentState = null;
	this.state = null;
	
	this.topicID = null;
	this.viewByEntityTypeID = null;
	this.subjectEntity = null;
	this.parentEntity = null;
	this.parents = null;
	
	this.largeImageSource = null;
	this.smallImageSource = null;
	this.vectors = null;
	this.summaryText = null;
	this.rank=null;
	
	this.entities = [];
	this.currentEntity = {};	
	
	this.imageMapHolder = null;
	this.imageMapElement = null;
	
	this.stateLarge = new NUSA.Maps.Models.StateLarge(this);
	this.stateSmall = new NUSA.Maps.Models.StateSmall(this);
	
	this.setState(state);
	this.init();
	
	this.mouseIsOver = false;
		
	this.onMapLoad;
		
};

ns.Map.prototype.init = function(){
	
	this.imageMapHolder = document.createElement('DIV');
	
	var repositionBubbleDelegate = new NUSA.Utils.Delegate(this,this.repositionBubble);
	var bubbleFadeOutDelegate = new NUSA.Utils.Delegate(this,this.bubbleFadeOut);
	//$("#hoverBubble").bind("mouseover",repositionBubbleDelegate);
	//$("#mapImage").bind("mousemove",repositionBubbleDelegate);
	//$("#mapImage").bind("mouseout",bubbleFadeOutDelegate);
	
};

ns.Map.prototype.setState = function(state){
	
	switch(state) {
		
		case "large":
			this.state = this.stateLarge;
			if (this.id) {
				this.state.checkImageMap();
			}
			break;
			
		case "small":
			this.state = this.stateSmall;
			
	}
	
};

ns.Map.prototype.load = function(subjectID, topicID, viewByID){
	
	
	if (subjectID && topicID && viewByID) {
	
	var restPath = 'mapData/'+topicID+'/'+subjectID+"-"+viewByID+"-"+topicID+".json";
    var pars = '';
	
	// The delegate is needed for binding reasons.
	var mapLoadedDelegate = new NUSA.Utils.Delegate(this.state,this.state.mapLoaded);
    $.getJSON(restPath,0,mapLoadedDelegate);
    
	}
	
	else {
		this.state.invalidData();	
	}

    
};

ns.Map.prototype.repositionBubble = function(e){
	this.state.repositionBubble(e);		 
};

ns.Map.prototype.bubbleFadeIn = function(e){
	this.state.bubbleFadeIn(e); 
};

ns.Map.prototype.bubbleFadeOut = function(e){
	this.state.bubbleFadeOut(e);
};

ns.Map.prototype.deadEnd = function(e){
	this.state.deadEnd(e);
};

ns.Map.prototype.mouseIsOff = function(e){
	this.state.mouseIsOff(e);
};





