function drawAllLinks (aLinks) {alert ('got ' + aLinks);
	aLinks.each(function(item) { alert ('each is ' + item); item.draw(); });
}

var Link = new Class({

	aImages: new Array(),
	over: false,
	hasSub: false,
	inSub: false,
	
	left  : 0,
	top   : 130,
	width : 20,
	height: 27,
	
	initialize: function(id, cat){
		this.id = id;
		this.div = $(id);
		this.cat = cat;
		this.shortName = divAbbrev(id, cat);
		this.mouseOver = false;
		this.selected = this.div.hasClass('sel');
		this.imgStat = this.selected ? '_on' : '_off';
		this.imgMStat = '_out';
		if (this.selected) current[cat] = this.shortName;
		
		this.aTag = this.div.getChildren('a')[0];

		if (isSet(this.aTag)) {
			this.wrapperObj = this.aTag;
		} else {
			this.wrapperObj = this.div;
		}
		
		if (isSet(aAttr[this.cat])) {
		} else {
			this.loadImages();
		}
		
		this.subDiv = this.div.getChildren('.pageSubMenu')[0];
		if (isSet(this.subDiv)) {
			this.hasSub = true;
			
			this.subBlackBox = new Element ('div');
			this.subBlackBox.addClass('blackBox');
			this.subBlackBox.inject (this.subDiv, 'top');
			
			this.subFX = new Fx.Tween (this.subDiv, {link: 'cancel'} );
			
			this.hideSub();
		}
		
		this.inSub = this.div.hasClass('inSub') ? true : false;		// Is this a link in a sub-menu?
		
		if (isSet(aPageNavLinks[this.shortName])) {
			var attribs = aPageNavLinks[this.shortName];
			this.left   = attribs.left;
			this.top    = attribs.top;
			this.width  = attribs.width;
			this.height = attribs.height;
		}
		
		this.draw ();

		this.div.addEvent('mouseenter', function() { this.mouseenter() }.bind(this) );
		this.div.addEvent('mouseleave', function() { this.mouseleave() }.bind(this) );
	},
	
	loadImages: function() {
		this.numStates = aNavImgData[this.cat].states.length;
		this.imgPath   = aNavImgData[this.cat].path;
		this.imgPrefix = aNavImgData[this.cat].prefix;
		this.imgSuffix = aNavImgData[this.cat].suffix;
		
		for (var i=0; i<this.numStates; i++) {
			var imageCat = aNavImgData[this.cat].states[i];
			var fullPath = this.imgPath + this.imgPrefix + this.shortName + imageCat + this.imgSuffix;

//			alert ('the imageCat is ' + imageCat + ', path: ' + fullPath);
			this.aImages[imageCat] = new Image ();
			this.aImages[imageCat].src = fullPath;
		}
		

	},
	
	draw: function() {
		if (isSet(aAttr[this.cat])) {
			var attr = this.div.hasClass('sel') ? aAttr[this.cat]['onover'] : aAttr[this.cat]['offout'];
			this.wrapperObj.setStyles (attr);
		} else {
			this.resize();
			
			var img = this.wrapperObj.getChildren('img')[0];
			img.src = img.src.replace('_off',  this.imgStat);
			img.src = img.src.replace('_on',   this.imgStat);
			img.src = img.src.replace('_out',  this.imgMStat);
			img.src = img.src.replace('_over', this.imgMStat);
		}
	},
	
	mouseenter: function() {
		this.mouseOver = true;
		this.imgMStat = '_over';
		if (isSet(aAttr[this.cat])) {
			var attr = this.div.hasClass('sel') ? aAttr[this.cat]['onover'] : aAttr[this.cat]['offover'];
			this.wrapperObj.setStyles (attr);
		} else {
			var img = this.wrapperObj.getChildren('img')[0];
			img.src = img.src.replace('_out', '_over');
		}

		if (this.hasSub) this.showSub();
	},
	
	mouseleave: function() {
		this.mouseOver = false;
		this.imgMStat = '_out';
		if (isSet(aAttr[this.cat])) {
			var attr = this.div.hasClass('sel') ? aAttr[this.cat]['onout'] : aAttr[this.cat]['offout'];
			this.wrapperObj.setStyles (attr);
		} else {
			var img = this.wrapperObj.getChildren('img')[0];
			img.src = img.src.replace('_over', '_out');
		}

		if (this.hasSub) this.hideSub();
	},
	
	resize: function() {
		if (this.cat == 'pageNavLink') {
			this.div.setStyles ({ left: this.left, top: this.top, width: this.width, height: this.height });
		}
	},
	
	selectLink: function() {
		this.selected = true;
		this.imgStat = '_on';
		this.div.addClass('sel');
		current[this.cat] = this.shortName;
		this.draw();
		
		if (isSet(current['subDown'])) {
			if (this.inSub) current['subDown'].hideSub();	// If we've clicked a link in a sub-menu, hide sub-menu
		}
	},
	
	deselectLink: function() {
		this.selected = false;
		this.imgStat = '_off';
		this.div.removeClass('sel');
		this.draw();
	},
	
	choose: function() {	// alert ('trying to deselect [' + this.cat + '][' + current[this.cat] + ']');
		if (isSet(current[this.cat])) aObjs[this.cat][current[this.cat]].deselectLink();
		this.selectLink();
	},
	
	showSub: function() {
		this.subBlackBox.set('opacity', .7);
//		this.subDiv.setStyle('visibility', 'visible');
		this.subFX.start ('height', 207);
		current['subDown'] = aObjs['pageNavLink'][this.shortName];
	},
	
	hideSub: function() {
//		this.subBlackBox.set('opacity', 0);
//		this.subDiv.setStyle('visibility', 'hidden');
		this.subFX.start ('height', 0);
	}
});

var NavLink = new Class ({		// Left Nav Link on the About page
	Extends: Link,
	initialize: function(id, cat) {
		this.parent (id, cat);
		if (!this.div.hasClass('noJump')) {
			this.div.addEvent('mousedown', function(e) {
	//			alert ('Which is ' + this.div.id + ' and this.cat is ' + this.cat);
				if (!this.selected) {
					switch (this.cat) {
/*						case 'pageNavLink':
							this.choose();
							aObjs['page'][this.shortName].choose();
							return false;
						break;
						
*/						case 'aboutNavLink':
	//						players['theater'].hide();
							aObjs['aboutNavLink'][current[this.cat]].deselectLink();
							this.selectLink();
							SWFAddress.setValue(aLinkShortcuts[this.shortName]);
							SWFAddress.setTitle (siteName + ' - ' + aPageTitles[this.shortName]);
							aObjs['aboutBioDiv'][this.shortName].choose();
						break;
						
						case 'reelsNavLink':
							if (isSet(current[this.cat])) {
								aObjs['reelsNavLink'][current[this.cat]].deselectLink();
								aObjs['reelsIndexes'][current[this.cat]].hide();
							}
							this.selectLink();
							SWFAddress.setValue(this.shortName);
							SWFAddress.setTitle (siteName + ' - ' + aPageTitles[this.shortName]);
							aObjs['reelsIndexes'][this.shortName].show();
						
							this.loadReel();
						break;
						
						case 'musicNavLink':
							this.choose();
							aObjs['musicContentDiv'][this.shortName].choose();
							SWFAddress.setValue('music' + this.shortName);
							SWFAddress.setTitle (siteName + ' - ' + aPageTitles['music' + this.shortName]);
						break;
						
						case 'postNavLink':
							this.choose();
							aObjs['postContentDiv'][this.shortName].choose();
							SWFAddress.setValue('post' + this.shortName);
							SWFAddress.setTitle (siteName + ' - ' + aPageTitles['post' + this.shortName]);
						break;
					}
				}
	// Show correct thing
			}.bind(this));
		} else {
			this.div.addEvent('mousedown', function(e) {
//				alert ('No Jump');
			}.bind(this));
		}
	},
	
	jump: function() {
		this.choose();
		aObjs['page'][this.shortName].choose();
	},
	
	loadReel: function() {
		$('chooseReel_div').setStyle('display', 'none');
		stat['chooseReel'] = false;
		aPlayers['theater'].show();
		aPlayers['theater'].load( { mode      : 'v',
									path      : aReels[this.shortName].src,
									autoStart : 'true' } );
	}
	
});

