W.Map = function(map)
{
	//this.map		= W.$(map);
	var self		= this;

	W.Event.add(window, 'load', function() { self.init(map); });
}



W.Map.prototype = {

	map			: null,
	tweens		: {},
	duration	: 10,
	_open		: false,
	
	
	
	init : function(map)
	{
		//topnav.onOpen 	= this.open.bind(this);
		//topnav.onClose	= this.close.bind(this);
		//topnav.onOver	= this.highlight.bind(this);
		
		//this.duration	= topnav.duration;
		
		this.map	= W.$(map);
	},
	
	
	
	open : function()
	{
		if (this._open) return;
		
		topnav_rollover.rollover('topnav_photogallery', true);
		topnav_rollover.select('topnav_photogallery'); 
		
		var map		= this.map;
		
		var start	= parseInt(W.Dom.getStyle(map, 'top'));
		var end		= 0;
		var close	= null;
		
		if ((close = this.tweens.closing) !== undefined) {
			close.stop();
			this.closed();
		}
		
		map.parentNode.style.zIndex		= 100;
		
		//console.log('start: ' + start + ', end: ' + end + ', duration: ' + this.duration);
		this.tweens.opening		= new W.Tween({start: start, end: end, duration: this.duration, obj:this, bind: 'animate', method: 'easeInOutQuad', callback: 'opened'});
		this._open	= true;
		
		if (window.fader) fader.pause();
	},
	
	
	
	close : function()
	{
		if (!this._open) return this.open();
		
		if (this.tweens.opening) {
			topnav_rollover.rollover('topnav_photogallery', true);
			return;
		}

		var map		= this.map;
		
		var start	= parseInt(W.Dom.getStyle(map, 'top'));
		var end		= -map.offsetWidth;
		var open	= null;
		
		/*
		if ((open = this.tweens.opening) !== undefined) {
			open.stop();
			this.opened();
		}
		*/
		
		//console.log('start: ' + start + ', end: ' + end + ', duration: ' + this.duration);
		this.tweens.closing		= new W.Tween({start: start, end: end, duration: this.duration, obj:this, bind: 'animate', method: 'easeInOutQuad', callback: 'closed'});
		this._open	= false;
		
		if (window.fader) fader.resume();
	},
	
	
	
	animate : function(num)
	{
		this.map.style.top		= num + 'px';
	},
	
	
	
	highlight : function(el)
	{
		//el	= W.Event.source(e);
		if (el) {
			if (el.tagName.toUpperCase() != 'LI' || el.tagName.toUpperCase() != 'BODY') {
				el = el.parentNode;
			}
			
			if (el.tagName.toUpperCase() == 'LI') {
				for (var i = 0, max = el.childNodes.length; i < max; ++i) {
					if (el.childNodes[i].nodeType == 1) {
						el = el.childNodes[i];
						break;
					}
				}
			}
			
			if (el.href) {
				var id	= el.href.substr(el.href.lastIndexOf('=') + 1);
			}
		}
		
		// turn off dots
		var dots	= W.Dom.getElementsByClassName('selected', 'li', W.$('map'));
		for (var i = dots.length; --i >= 0; ) {
			W.Dom.removeClassname(dots[i], 'selected');
		}
		
		// turn on dots
		var dots	= W.Dom.getElementsByClassName(id, 'li', W.$('map'));
		for (var i = dots.length; --i >= 0; ) {
			W.Dom.addClassname(dots[i], 'selected');
		}
	},
	
	
	
	opened : function()
	{
		delete this.tweens.opening;
	},
	
	
	
	closed : function()
	{
		delete this.tweens.closing;
		
		topnav_rollover.unselect();
		topnav_rollover.rollover('topnav_photogallery', false);
		
		this.map.parentNode.style.zIndex		= 0;
	}
}