var DivSet = new Class({
	
	imagesLoaded : false,
	
	initialize: function(id, cat) {
		this.id = id;
		this.div = $(id);
		this.cat = cat;
		this.shortName = divAbbrev(id, cat);
		this.shortNameCamel = divAbbrevCamel(id, cat);
		this.selected = this.div.hasClass('sel');
		this.div.setStyle('display', 'block');
		
		if (this.cat == 'page') {
			this.leftNavDims  = { left: 15 , top: 157, width: 150, height: 400 };
			this.mainPaneDims = { left: 165, top: 157, width: 0  , height: 0   };

			this.mainPaneDiv = $(this.shortNameCamel + 'MainPane_div');
			if (this.shortNameCamel == 'whoWeAre') {
				this.bioDims           = { left: 0  , top: 0  , width: 0, height: 0 };
				this.bioImgDims        = { left: 0  , top: 0  , width: 0, height: 0 };
				this.bioTitleDims      = { left: 0  , top: 0  , width: 0, height: 0 };
				this.bioDetailDims     = { left: 0  , top: 0  , width: 0, height: 0 };
				this.portfolioDims     = { left: 0  , top: 300, width: 0, height: 0 };
			}
		}
		
		if (this.selected) {
			current[cat] = this.shortName;
			this.show();
		} else {
			this.hide();
		}
	},
	
	show:    function() {
		this.div.fade('show');
//		this.div.setStyle('display', 'block');

		switch (this.div.id) {
			case 'pageWhatWeveDone_div':
				setReelsSubIndexes();
				
				if (stat['chooseReel']) {
					$('chooseReel_div').setStyle('display', 'block');
					this.div.removeClass('theater');
				} else {
					$('chooseReel_div').setStyle('display', 'none');
					stat['chooseReel'] = false;
					this.div.addClass('theater');
				}
				
			break;
			
			case 'pagePost_div':
				$('postMainPane_div' ).setStyle('display', 'block');
			break;
			
			case 'pageMusic_div':
				$('musicMainPane_div').setStyle('display', 'block');
			break;
			
			case 'pageWhoWeAre_div':
				$('aboutBioDiv_div'  ).setStyle('display', 'block');
			break;
		}
		
		if (this.div.hasClass('theater')) {
			if (isSet(aPlayers['theater'])) aPlayers['theater'].show();
		} else {
			if (isSet(aPlayers['theater'])) aPlayers['theater'].hide();
		}
		
		if (!this.imagesLoaded) {
//			alert ('loading class ' + this.div.id.replace('_div', '_img'));
			$$('.' + this.div.id.replace('_div', '_img')).each( function(item) {
				item.src = item.get('imgSrc');
			});
			this.imagesLoaded = true;
		}
		
	},
	
	hide:    function() {
		this.div.fade('hide');
//		this.div.setStyle('display', 'none');
			switch (this.div.id) {
				case 'pagePost_div':
					$('postMainPane_div' ).setStyle('display', 'none');
				break;
				
				case 'pageMusic_div':
					$('musicMainPane_div').setStyle('display', 'none');
				break;
				
				case 'pageWhoWeAre_div':
					$('aboutBioDiv_div'  ).setStyle('display', 'none');
				break;
			}
//		this.div.setStyle('z-index', 1);
	}, //this.div.setStyle('display', 'block'); },
	
	fadeIn:  function() { this.div.fade('in'); },
	fadeOut: function() { this.div.fade('out'); },
	
	selectDS: function() {
		this.selected = true;
		this.div.addClass('sel');
		current[this.cat] = this.shortName;
	},
	
	deselectDS: function() {
		this.selected = false;
		this.div.removeClass('sel');
		current[this.cat] = 'none';
	},
	
	choose: function() {
		if (!this.selected) {
			switch (this.cat) {
				case 'page':
					var currPage = aObjs['page'][current['page']];
					if (current['page'] != 'none') {
						currPage.deselectDS();
						currPage.hide();
					}
					this.selectDS();
					
					if (isSet(aPlayers['theater'])) {
						if (aPlayers['theater'].visible) aPlayers['theater'].stop();
					}
					
					this.resize();
					this.show();
					
					switch (this.shortNameCamel) {	// Display the 'theater' and load portfolio slots if necessary
						case 'home':
							stat['chooseReel'] = true;
//							aPlayers['theater'].show();
//							aPlayers['theater'].load( 'v', '', featuredSpotPath, 'false' );
							aPlayers['theater'].load( { mode      : 'v',
														path      : featuredSpotPath,
														autoStart : 'false' } );
						break;
						
						case 'whoWeAre':
//							aPlayers['theater'].hide();
							if (!stat['portfolioFilled']) {
								for (var i=0; i<numPortfolioSlots; i++) {
									aObjs['portfolioSlot'][i].ajaxFill();
								}
								stat['portfolioFilled'] = true;
							}
						break;
						
						default:
//							if (isSet(aPlayers['theater'])) {
//								aPlayers['theater'].hide();
//							}
						break;
					}
					
					SWFAddress.setTitle (siteName + ' - ' + aPageTitles[this.shortName]);
				break;
				
				case 'aboutBioDiv':
					var currBio = aObjs['aboutBioDiv'][current[this.cat]];  // This is the bio we're moving away from
					if (current[this.cat] != 'none') {
						currBio.deselectDS();
						currBio.fadeOut();
					}
					this.selectDS();
					this.fadeIn();
				break;
				
				case 'postContentDiv':
					if (isSet(current[this.cat])) {
						aObjs[this.cat][current[this.cat]].hide();
						aObjs[this.cat][current[this.cat]].deselectDS();
					}
					aObjs[this.cat][this.shortName].selectDS();
					aObjs[this.cat][this.shortName].show();
				break;
	
				case 'musicContentDiv':
					if (isSet(current[this.cat])) {
						aObjs[this.cat][current[this.cat]].hide();
						aObjs[this.cat][current[this.cat]].deselectDS();
					}
					aObjs[this.cat][this.shortName].selectDS();
					aObjs[this.cat][this.shortName].show();
				break;
	
				default:
					aObjs[this.cat][current[this.cat]].hide();
					aObjs[this.cat][current[this.cat]].deselectDS();
					aObjs[this.cat][this.shortName].selectDS();
					aObjs[this.cat][this.shortName].show();
				break;
			}
		}
	},
	
	resize: function (){
		if (this.cat == 'page') {
			this.leftNavDims.height = container.height-157-2;
			$(this.shortNameCamel + 'LeftNav_div').setStyles (this.leftNavDims);
//			$('mainPlayer_div').setStyles (this.mainPaneDims);

			this.mainPaneDims.width  = container.width - 165 - 2;
			this.mainPaneDims.height = container.height - 157 - 2;
			this.mainPaneDiv.setStyles ( { width : this.mainPaneDims.width, height : this.mainPaneDims.height } );
			
			if (isSet(aPlayers['theater'])) aPlayers['theater'].resize();
									
			switch (this.shortNameCamel) {
				case 'home':
					$('theater_div').setStyles ( { left   : leftNavWidth,
												   top    : topNavHeight,
												   width  : container.width  - leftNavWidth - 2,
												   height : container.height - topNavHeight - 2 } );
												 
	//				$('reelsIndexes_div').setStyles ( { width : 150 } );
					$('theaterPlayer_div').setStyles ( { left   : reelsPlayerHBorder + 50,
													     top    : reelsPlayerVBorder + 100,
													     width  : container.width  - leftNavWidth - (reelsPlayerHBorder*2) - 2 - 100,
													     height : container.height - topNavHeight - (reelsPlayerVBorder*2) - 2 - 150 } );
					break;
					
				case 'whoWeAre':
//					$('whoWeAreLeftNav_div').setStyle ('height', this.leftNavDims.height - 300);
					this.bioDims.width  = this.mainPaneDims.width;
					this.bioDims.height = parseInt((container.height - 157 - 4) / 3);
					
					this.bioImgDims.width = this.bioDims.width / 4;
					this.bioImgDims.height = this.bioDims.height;
					
					this.bioTitleDims.left = (this.bioDims.width / 4) + 30;
					this.bioTitleDims.top = 10;
					this.bioTitleDims.width = (this.bioDims.width * 3/4) - 30;
					this.bioTitleDims.height = 40;
					
					this.bioDetailDims.left = (this.bioDims.width / 4) + 30;
					this.bioDetailDims.top = 50;			
					this.bioDetailDims.width  = (this.bioDims.width * 3 / 4) - 50;
					this.bioDetailDims.height = this.bioDims.height - 70;
					
					$('aboutBioDiv_div').setStyles ( this.bioDims );
					$$('.bioImg'    ).each(function(item) {item.setStyles(this.bioImgDims) }.bind(this));
					$$('.bioTitle'  ).each(function(item) {item.setStyles(this.bioTitleDims) }.bind(this));
					$$('.bioDetails').each(function(item) {item.setStyles(this.bioDetailDims) }.bind(this));
		
					this.portfolioDims.top    = this.bioDims.height;
					this.portfolioDims.width  = this.mainPaneDims.width;
					this.portfolioDims.height = parseInt((container.height - 157 - 4) * 2 / 3);
					$('portfolio_div').setStyles( this.portfolioDims );
		//			$('portfolioSlotDetails_div').setStyle('height', 150); //this.portfolioDims.height);    Moved to CSS
					
					var slotTop    = 50;
					var slotWidth  = parseInt(this.mainPaneDims.width / numPortfolioSlots);
					var slotHeight = this.portfolioDims.height - slotTop;
					
					for (var i=0; i<numPortfolioSlots; i++) {
						var slotDims = { left: i * slotWidth , top: slotTop  , width: slotWidth, height: slotHeight };
						aObjs['portfolioSlot'][i].resize(slotDims);
					}
					break;
					
				case 'whatWeveDone':
					$('theater_div').setStyles ( { left   : leftNavWidth,
												   top    : topNavHeight,
												   width  : container.width  - leftNavWidth - 2,
												   height : container.height - topNavHeight - 2 } );
												 
	//				$('reelsIndexes_div').setStyles ( { width : 150 } );
					$('theaterPlayer_div').setStyles ( { left   : reelsPlayerHBorder,
													     top    : reelsPlayerVBorder,
													     width  : container.width  - leftNavWidth - (reelsPlayerHBorder*2) - 2,
													     height : container.height - topNavHeight - (reelsPlayerVBorder*2) - 2 } );
					break;
					
				case 'post':
					$$('.' + this.shortName + 'ContentDiv').each(function(item) {
							$(item.id).setStyles ( { width   : this.mainPaneDims.width - 40,
													 height  : this.mainPaneDims.height - 40 } ); }.bind(this));
					break;
					
				case 'music':
					$$('.' + this.shortName + 'ContentDiv').each(function(item) {
							$(item.id).setStyles ( { width   : this.mainPaneDims.width - 40,
													 height  : this.mainPaneDims.height - 40 } ); }.bind(this));
					break;
					
				default:
					break;
					
	//			players['theater'].resize();
			}
		}
	}
}); 

