/****************************************
|
| LHBA Neighbourhoods
| Created by: Kevin Biskaborn
| Copyright 2008 ScriptReaction
| http://www.scriptreaction.com
|
****************************************/

var mapManager = {
	launch: function ( startId ){
		if(mapManager.hoodList.activeItemId < 0 && startId >= 0){
			//no item selected
			//go ahead with requested start
			mapManager.hoodList.actions.activate( startId );
		}
	},
	icons: {
		actions: {
			over: function ( id ){
				mapManager.icons.apply.doOver( id );
			},
			out: function ( id ){
				mapManager.icons.apply.doOut( id );
			},
			activate: function ( id ){
				this.out( id );
				//mapManager.focusBoxes.start( id );
				mapManager.hoodList.actions.activate( id );
			}
		},
		apply: {
			getIconElement: function ( id ){
				return document.getElementById("mapIcon_" + id).getElementsByTagName("a")[0];
			},
			getDescElement: function ( id ){
				return document.getElementById("mapDesc_" + id);
			},
			doOver: function ( id ){
				this.getDescElement( id ).style.display = "block";
				this.getIconElement( id ).style.backgroundPosition = "0px -24px";
			},
			doOut: function ( id ){
				this.getDescElement( id ).style.display = "none";
				this.getIconElement( id ).style.backgroundPosition = "0px 0px";
			}
		}
	},
	focusBoxes: {
		activeId: -1,
		start: function ( id ){
			this.actions.activate( id );
		},
		end: function (){
			this.apply.hideFocusBox( this.activeId );
			mapManager.hoodList.actions.deactivateAll();
			mapManager.hoodList.activeItemId = -1;
		},
		actions: {
			activate: function ( id ){
				mapManager.focusBoxes.activeId = id;
				mapManager.focusBoxes.apply.showFocusBox( id );
			}
		},
		apply: {
			getFocusElement: function ( id ){
				return document.getElementById("focusBox_" + id);
			},
			showFocusBox: function ( id ){
				this.showFadeBg();
				this.getFocusElement( id ).style.display = "block";
			},
			hideFocusBox: function ( id ){
				this.hideFadeBg();
				this.getFocusElement( id ).style.display = "none";
			},
			getFadeBgElement: function (){
				return document.getElementById("focusFader");
			},
			showFadeBg: function (){
				this.getFadeBgElement().style.display = "block";
			},
			hideFadeBg: function (){
				this.getFadeBgElement().style.display = "none";
			}
		}
	},
	
	hoodList: {
		itemCount: 0,
		activeItemId: -1,
		actions: {
			path: {},
			over: function ( id ){
				mapManager.hoodList.apply.doOver( id );
			},
			out: function ( id ){
				mapManager.hoodList.apply.doOut( id );
			},
			activate: function ( id ){
				this.deactivateAll();
				mapManager.hoodList.apply.doActivate( id );
			},
			deactivateAll: function (){
				this.path = mapManager.hoodList;
				for(var i = 0; i < this.path.itemCount; i++)
					this.path.apply.doDeactivate( i );
			}
		},
		apply: {
			getListItem: function ( id ){
				return document.getElementById("hoodListItem_" + id);
			},
			doOver: function ( id ){
				mapManager.icons.apply.doOver( id );
			},
			doOut: function ( id ){
				mapManager.icons.apply.doOut( id );
			},
			doActivate: function ( id ){
				if( id == mapManager.hoodList.activeItemId){ //already selected
					this.doDeactivate( id );
					mapManager.hoodList.activeItemId = -1;
				} else { //new selection
					mapManager.hoodList.apply.newClassTo( this.getListItem( id ), "active" );
					mapManager.hoodList.activeItemId = id;
					mapManager.focusBoxes.start( id );
				}
				mapManager.icons.actions.over( id ); //on open/close details, rehighlight on map
			},
			doDeactivate: function ( id ){
				mapManager.hoodList.apply.newClassTo( this.getListItem( id ), "" );
				this.doOut( id );
				mapManager.focusBoxes.apply.hideFocusBox( id );
			},
			newClassTo: function ( listItem, newClass ){
					if(listItem.className.slice(0,3) == "alt"){
						addClass = "alt";
						if(!newClass.length == "") addClass += " " + newClass;
						listItem.className = addClass;	
					}
					else
						listItem.className = newClass;
			}
		}
	},
	
	actions: {
		doprint: function (){
			window.print();	
		}
	}
	
}