/*

	# -------------------------------------------------------------------------------------------- #
	#																			#
	# DC.FrameSet.class.js															#
	#																			#
	# MySpinalCord.com																#
	# Copyright 2011 Thommy Morgan													#
	# All Rights Reserved															#
	#																			#
	# -------------------------------------------------------------------------------------------- #
	
		
*/


/*
# ----------------------------------------------------------------------------- #
# DC.FrameSet Class Constructor										#
# ----------------------------------------------------------------------------- #*/


DC.FrameSet = function(title, content, dimensions, transitionIn, transitionOut, settings) {
	
	
	/*
	# ----------------------------------------------------------------------------- #
	# Private Variables													#
	# ----------------------------------------------------------------------------- #*/
	
	this.superClass 			= DC.Object;
	this.superClass();
	
	this.index			= DC.FrameSet.frameSets.length;
	this.delegate			= null;
	
	this.title 			= title
	this.content 			= (content != null) ? 
						content : 
						'<div style="text-align: center">' +
						'<img src="http://static.myspinalcord.com/Images/loading.gif" width=100 />' +
						'<div style="text-align: center">Loading...</div></div>';
	
	this.dimensions 		= (dimensions) 	? dimensions 		: new CGDim(400, 300);	// default dimensions are 400 x 300
	this.initialOrigin		= CGNullPoint;
	this.finalDimensions	= CGNullDim;
	this.transitionIn		= (transitionIn) 	? transitionIn 	: TransitionTypeFadeIn;
	this.transitionOut		= (transitionOut) 	? transitionOut 	: TransitionTypeFadeOut;
	this.settings 			= settings;
	this.maxSize			= new CGDim(800, 455);
	
	// Define Boolean Setting Flags
	
	this.onlyVisible = NO;
	this.isDraggable = NO;
	this.autoResizes = NO;
	this.resizeTitle = NO;
	this.maximizable = NO;
	this.minimizable = NO;
	this.purgeOnHide = NO;

	with(this) {
		
		if(settings & FrameSetSettingsDefault) {
			onlyVisible = YES;
			isDraggable = YES;
			autoResizes = YES;
			resizeTitle = YES;
			maximizable = NO;
			minimizable = NO;
			purgeOnHide = YES;
		}
		
		onlyVisible = (settings & FrameSetSettingsOnlyVisible) ? YES : onlyVisible; // Default NO
		isDraggable = (settings & FrameSetSettingsIsDraggable) ? YES : isDraggable; // Default YES
		resizeTitle = (settings & FrameSetSettingsResizeTitle) ? YES : resizeTitle; // Defualt YES
		autoResizes = (settings & FrameSetSettingsAutoResizes) ? YES : autoResizes; // Default YES
		maximizable = (settings & FrameSetSettingsMaximizable) ? YES : maximizable; // Default NO
		minimizable = (settings & FrameSetSettingsMinimizable) ? YES : minimizable; // Default NO
		purgeOnHide = (settings & FrameSetSettingsPurgeOnHide) ? YES : purgeOnHide; // Default YES
		
	}
	
	// Define Boolean Attribute Flags
	
	this.isAnimating		= NO;	// YES if the object is undergoing some kind of animation
	this.isAdjusting		= NO;	// YES if the object has supposedly finished it's animation and is auto-adjusting to content size
	this.isHidden			= YES;	// YES if the object is not being show
	this.isMaximized		= NO;	// YES if the object is at its maximum size
	this.isMinimized		= NO;	// YES is the object is tacked to the minimize bar
	this.isRestored		= YES;	// YES if the object is in its default size
	
	// Layer Objects
	
	this.frameLayerObject 	= new DC.Layer(); // The main HTML object controller that represents the entire frame
	
	this.buttonCont		= new DC.Layer(); // The element that contains the frame position controls
	this.mainCont			= new DC.Layer(); // The center piece that contains all of the content
	
	this.closeButton		= new DC.Layer("button"); // Closes frame (ALL frames must have this)
	this.maximButton		= new DC.Layer("button"); // Maximizes the frame or restores it
	this.minumButton		= new DC.Layer("button"); // Minimizes the frame

	this.dragLayer			= new DC.Layer(); // The content box that represents the drag area	
	this.titleLayer		= new DC.Layer(); // Layer object containing the title portion of the frame
	this.contentLayer		= new DC.Layer(); // Layer object containt the main content of the frame

	this.cursorCoors 		= CGNullPoint; // Current cursor position
	this.origin 			= CGNullPoint; // Container origin
	this.innerOrigin		= CGNullPoint; // Inner container origin
	this.dragActivated 		= NO;		// Drag enabler
	
	this.maximFunc			= function() {};
	this.minimFunc			= function() {};
	
	this.initializeContent();
	
	DC.FrameSet.frameSets.push(this);
	
	
}
DC.FrameSet.prototype = new DC.Object;


DC.FrameSet.prototype.setMaximFunc = function(func) {
	this.maximFunc = func;	
}


DC.FrameSet.prototype.setMinimFunc = function(func) {
	this.minimFunc = func;	
}


/*
# ----------------------------------------------------------------------------- #
# Class Constants												 	#
# ----------------------------------------------------------------------------- #*/


enumerate([

	"FrameSetSettingsNone",			// 1 << 0
	"FrameSetSettingsDefault",		// 1 << 1
	"FrameSetSettingsOnlyVisible",	// 1 << 2
	"FrameSetSettingsIsDraggable",	// 1 << 3
	"FrameSetSettingsAutoResizes",	// 1 << 4
	"FrameSetSettingsResizeTitle",	// 1 << 5
	"FrameSetSettingsMaximizable",	// 1 << 6
	"FrameSetSettingsMinimizable",	// 1 << 7
	"FrameSetSettingsPurgeOnHide",	// 1 << 8
	"FrameSetSettingsSmallTitle",		// 1 << 9
	
], YES);


DC.FrameSet.enableWindowAlert = NO;
DC.FrameSet.enableSingleEventAlert = YES;
DC.FrameSet.alertDialog = null;
DC.FrameSet.messageDialog = null;
DC.FrameSet.hiddenLayer = null;
DC.FrameSet.frameSetContainer = null;
DC.FrameSet.isAnimating = NO;
DC.FrameSet.frameSets = [];
DC.FrameSet.visibleFrameSets = [];


/*
# ----------------------------------------------------------------------------- #
# Class Functions												 	#
# ----------------------------------------------------------------------------- #*/


DC.FrameSet.frameSetContainerCheck = function() {
	if(DC.FrameSet.frameSetContainer == null) {
		DC.animCheck(); // Check for animation layer
		DC.FrameSet.frameSetContainer = new DC.Layer();
		DC.anim.addChild(DC.FrameSet.frameSetContainer);
	}
}


DC.FrameSet.minimizeAllDialogs = function() {
	for(var i = 0; i < DC.FrameSet.frameSets.length; i++) {
		DC.FrameSet.frameSets[i].hide();
	}
}


DC.FrameSet.checkForAnyAnimation = function() {
	for(var i = 0; i < DC.FrameSet.frameSets.length; i++) {
		if(DC.FrameSet.frameSets[i].isAnimating) return YES;
	}
	return NO;
}


DC.FrameSet.functionToCallAfterClear = null;


DC.FrameSet.displayAlert = function(msg, title) {
	msg = "<div style=padding:10px>" + msg + "</div>";
	msg += "<div><input type=submit class=submitInput onclick=DC.FrameSet.closeAlert() value=close /></div>";
	if(!title) title = "Alert!";
	DC.FrameSet.alertDialog = new DC.FrameSet(
		title,
		msg,
		new CGDim(300, 60),
		TransitionTypeFadeIn,
		TransitionTypeFadeOut,
		FrameSetSettingsDefault
	);
	DC.FrameSet.alertDialog.title = title;
	DC.FrameSet.alertDialog.frameLayerObject.setClass("frameSetDialog errorDialog");
	DC.FrameSet.alertDialog.show();
}


DC.FrameSet.closeAlert = function() {
	tryout(function() {
		DC.FrameSet.alertDialog.hide();
	});
}


DC.FrameSet.displayMessage = function(msg, title) {
	msg = "<div style=padding:10px>" + msg + "</div>";
	msg += "<div><input type=submit class=submitInput onclick=DC.FrameSet.closeMessage() value=close /></div>";
	if(!title) title = "Just a Message!";
	DC.FrameSet.messageDialog = new DC.FrameSet(
		title,
		msg,
		new CGDim(500, 60),
		TransitionTypeFadeIn,
		TransitionTypeFadeOut,
		FrameSetSettingsDefault + ((title.length > 15) ? FrameSetSettingsSmallTitle : 0)
	);
	DC.FrameSet.messageDialog.title = title;
	DC.FrameSet.messageDialog.frameLayerObject.setClass("frameSetDialog messageDialog");
	DC.FrameSet.messageDialog.show();
}


DC.FrameSet.closeMessage = function() {
	tryout(function() {
		DC.FrameSet.messageDialog.hide();
	});
}


/*
# ----------------------------------------------------------------------------- #
# Private functions												 	#
# ----------------------------------------------------------------------------- #*/


DC.FrameSet.prototype.setDelegate = function(delegate) {
	this.delegate = delegate;
}


DC.FrameSet.prototype.setContent = function(content, override) {
	
	var self = this;
	
	if(!override && (self.isAnimating || !self.isHidden)) return NO;
	
	self.content = content;

	/*
	# ----------------------------------------------------------------------------- #
	# Change content													#
	# ----------------------------------------------------------------------------- #*/
	
	with(self) {
	
		frameLayerObject.reset(YES);
		frameLayerObject.setStyle("display", "none");
		
		frameLayerObject.setClass("frameSetDialog");
		frameLayerObject.setSize(dimensions.width, dimensions.height);
		frameLayerObject.moveTo(window_width() / 2 - dimensions.width / 2, 80);
		
		buttonCont = new DC.Layer();
		buttonCont.setClass("buttonContainer");
		
		closeButton = new DC.Layer("button");
		closeButton.setClass("closeButton");
		closeButton.addEventTo("click", function() { hide(); });
		buttonCont.addChild(closeButton);
		
		if(maximizable) {
			maximButton = new DC.Layer("button");
			maximButton.setClass("maximButton");
			maximButton.addEventTo("click", function() { maximize(); });
			buttonCont.addChild(maximButton);
		}
		
		if(minimizable) {
			minimButton = new DC.Layer("button");
			minimButton.setClass("minimButton");
			minimButton.addEventTo("click", function() { minimize(); });
			buttonCont.addChild(minimButton);
		}
		
		frameLayerObject.addChild(buttonCont);
		
		mainCont = new DC.Layer();
		mainCont.setClass("frameSetContent");
		
		frameLayerObject.addChild(mainCont);
		
		titleLayer = new DC.Layer();
		titleLayer.setClass("frameSetTitle" + (((settings & FrameSetSettingsSmallTitle) || (resizeTitle && title.length > 20)) ? " frameSetSmallTitle" : ""));
		titleLayer.setHTML(title);
		
		mainCont.addChild(titleLayer);
		
		contentLayer = new DC.Layer();
		contentLayer.setHTML(content);
		contentLayer.setClass("frameSetInnerContent");
		
		mainCont.addChild(contentLayer);
		
		frameLayerObject.setSize(dimensions.width, dimensions.height)
		frameLayerObject.moveTo(window_width() / 2 - dimensions.width / 2, 80);
	
	
		/*
		# ----------------------------------------------------------------------------- #
		# Drag Effect														#
		# ----------------------------------------------------------------------------- #*/
		
		
		makeDraggable(isDraggable);
	
	
		/*
		# ----------------------------------------------------------------------------- #
		# Finalize Initialization											#
		# ----------------------------------------------------------------------------- #*/
	
	
		DC.FrameSet.frameSetContainerCheck();	// Check for animation and popup layer
		DC.FrameSet.frameSetContainer.addChild(frameLayerObject);
	
	}
	
	
}
DC.FrameSet.prototype.initializeContent = function() { this.setContent(this.content); }


DC.FrameSet.prototype.makeDraggable = function(yesOrNo) {
	
	var self = this;
	
	if(yesOrNo) {
		
		self.titleLayer.setStyle("cursor", "move");
	
		self.frameLayerObject.addEventTo("mousedown", function(event) {
			with(self) {
				if(!dragActivated) {
					
					cursorCoors 	= new CGPoint(event.x, event.y);
					origin 		= new CGPoint(frameLayerObject.getLeft(YES), frameLayerObject.getTop(YES));
	
					titleObject	= frameLayerObject.obj.children[1].children[0];
					innerOrigin	= new CGPoint(
									titleObject.getLeft(YES)	- titleObject.getAttr("margin-left").replace("px", "").toInt(),
									titleObject.getTop(YES)	- titleObject.getAttr("margin-top").replace("px", "").toInt() - document.body.scrollTop
								);
	
					var w = 	titleObject.getWidth() 									+
							titleObject.getAttr("padding-left").replace("px", "").toInt() 	+
							titleObject.getAttr("padding-right").replace("px", "").toInt();
					var h = 	titleObject.getHeight()									+
							titleObject.getAttr("padding-top").replace("px", "").toInt() 	+
							titleObject.getAttr("padding-bottom").replace("px", "").toInt();
							
					targetArea	= [
						{x: innerOrigin.x, 		y: innerOrigin.y		},
						{x: innerOrigin.x,	 	y: innerOrigin.y + h	},
						{x: innerOrigin.x + w,	y: innerOrigin.y + h	},
						{x: innerOrigin.x + w, 	y: innerOrigin.y		}
					];
					
					if(cursorCoors.isInPoly(targetArea)) {
						dragActivated = YES;
						disableSel(document.body);
					}
					
				}
			}
		});
		
		self.frameLayerObject.addEventTo("mousemove", function(event) {
			with(self) {
				if(dragActivated) {
					var dx = event.x - cursorCoors.x;
					var dy = event.y - cursorCoors.y;
					frameLayerObject.moveTo(origin.x + dx, origin.y + dy);
				}
				// Prevent From Crossing Page Boundaries
				with(frameLayerObject) {
					if(getLeft() < 0) 						moveTo(0, 						getTop(YES));
					if(getTop() < 0) 						moveTo(getLeft(YES), 				0);
					if(getLeft() + getWidth() > window_width()) 	moveTo(window_width() - getWidth(), 	getTop(YES));
					if(getTop() + getHeight() > doc_height()) 	moveTo(getLeft(YES), 				doc_height() - getHeight());
				}
			}
		});
		
		var clearOutDrag = function() {
			with(self) {
				dragActivated	= NO;
				cursorCoors 	= CGNullPoint;
				origin 		= CGNullPoint;
				enableSel(document.body);
			}	
		}
		
		document.body.addEventTo(new Array("mouseup", "mouseout"), function(event) {
			clearOutDrag();
		});
		
		self.dragLayer.addEventTo(new Array("mouseout"), function(event) {
			if((event.x < cursorCoors.x - 50 || event.x > cursorCoors.x + 50) ||
				(event.y < cursorCoors.x - 50 || event.y > cursorCoors.y + 50))
			clearOutDrag();
		});
	
	}
	else {
		
		self.titleLayer.setStyle("cursor", "default");
	
		self.frameLayerObject.removeEventFrom("mousedown", function(event) {
			with(self) {
				if(!dragActivated) {
					
					cursorCoors 	= new CGPoint(event.x, event.y);
					origin 		= new CGPoint(frameLayerObject.getLeft(YES), frameLayerObject.getTop(YES));
	
					titleObject	= frameLayerObject.obj.children[1].children[0];
					innerOrigin	= new CGPoint(
									titleObject.getLeft(YES)	- titleObject.getAttr("margin-left").replace("px", "").toInt(),
									titleObject.getTop(YES)	- titleObject.getAttr("margin-top").replace("px", "").toInt() - document.body.scrollTop
								);
	
					var w = 	titleObject.getWidth() 									+
							titleObject.getAttr("padding-left").replace("px", "").toInt() 	+
							titleObject.getAttr("padding-right").replace("px", "").toInt();
					var h = 	titleObject.getHeight()									+
							titleObject.getAttr("padding-top").replace("px", "").toInt() 	+
							titleObject.getAttr("padding-bottom").replace("px", "").toInt();
							
					targetArea	= [
						{x: innerOrigin.x, 		y: innerOrigin.y		},
						{x: innerOrigin.x,	 	y: innerOrigin.y + h	},
						{x: innerOrigin.x + w,	y: innerOrigin.y + h	},
						{x: innerOrigin.x + w, 	y: innerOrigin.y		}
					];
					
					if(cursorCoors.isInPoly(targetArea)) {
						dragActivated = YES;
						disableSel(document.body);
					}
					
				}
			}
		});
		
		self.frameLayerObject.removeEventFrom("mousemove", function(event) {
			with(self) {
				if(dragActivated) {
					var dx = event.x - cursorCoors.x;
					var dy = event.y - cursorCoors.y;
					frameLayerObject.moveTo(origin.x + dx, origin.y + dy);
				}
				// Prevent From Crossing Page Boundaries
				with(frameLayerObject) {
					if(getLeft() < 0) 						moveTo(0, 						getTop(YES));
					if(getTop() < 0) 						moveTo(getLeft(YES), 				0);
					if(getLeft() + getWidth() > window_width()) 	moveTo(window_width() - getWidth(), 	getTop(YES));
					if(getTop() + getHeight() > doc_height()) 	moveTo(getLeft(YES), 				doc_height() - getHeight());
				}
			}
		});
		
		var clearOutDrag = function() {
			with(self) {
				dragActivated	= NO;
				cursorCoors 	= CGNullPoint;
				origin 		= CGNullPoint;
				enableSel(document.body);
			}	
		}
		
		document.body.removeEventFrom(new Array("mouseup", "mouseout"), function(event) {
			clearOutDrag();
		});
		
		self.dragLayer.removeEventFrom(new Array("mouseout"), function(event) {
			if((event.x < cursorCoors.x - 50 || event.x > cursorCoors.x + 50) ||
				(event.y < cursorCoors.x - 50 || event.y > cursorCoors.y + 50))
			clearOutDrag();
		});
	
	}
	
}


/*
# ----------------------------------------------------------------------------- #
# Animation functions												#
# ----------------------------------------------------------------------------- #*/


DC.FrameSet.prototype.show = function() {
	
	var self = this;
	
	if(self.isAnimating || !self.isHidden) return NO;
	
	if(
		self.onlyVisible &&
		(DC.FrameSet.checkForAnyAnimation() ||
		DC.FrameSet.visibleFrameSets.length > 0)
	) {
		DC.FrameSet.minimizeAllDialogs();
		DC.FrameSet.functionToCallAfterClear = function() { self.show(); };
		return NO;
	}
	
	self.isAnimating = YES;
	self.frameLayerObject.setStyle("display", "block");
	
	tryout(function() {
		self.delegate.isAnimating = YES;	
	});
	
	// Create controller object
	
	var controller = {
		fade:	NO,
		slide: 	NO,
		scale: 	NO,
	}
	
	// Interpret transition types
	
	if(
		this.transitionIn & TransitionTypeSlideIn	||
		this.transitionIn & TransitionTypeSwoopIn
	)	controller.slide = YES;

	if(
		this.transitionIn & TransitionTypeFadeIn		||
		this.transitionIn & TransitionTypeFadeInPartial
	)	controller.fade = YES;
	
	if(
		this.transitionIn & TransitionTypeExpandIn
	)	controller.scale = YES;
	
	controller.layerDidFinishFloatAnimation = function(cLayer) {
		this.slide = NO;
		this.layerDidFinishAllAnimatons(cLayer);
	}
	
	controller.layerDidFinishFadeAnimation = function(cLayer) {
		this.fade = NO;
		this.layerDidFinishAllAnimatons(cLayer);
	}
	
	controller.layerDidFinishExpandAnimation = function(cLayer) {
		this.scale = NO;
		this.layerDidFinishAllAnimatons(cLayer);
	}
	
	controller.layerDidFinishAllAnimatons = function(cLayer) {
		if(!this.slide && !this.fade && !this.scale)  {
			
			self.initialOrigin = new CGPoint(self.frameLayerObject.getLeft(), self.frameLayerObject.getTop());
			
			self.isAnimating 	= NO;
			self.isAdjusting	= YES;
			
			var waitingForAdjustmentsInterval;
			
			function waitForAdjustments() {
				if(self.isAdjusting) return;
				self.isHidden = NO;
				DC.FrameSet.visibleFrameSets.push(self);
				tryout(function() { self.delegate.frameSetDidBecomeVisible(self); });
				tryout(function() { clearInterval(waitingForAdjustmentsInterval); });
			}
			
			if(self.autoResizes) {
				self.autoResize(YES);
				waitingForAdjustmentsInterval = setInterval(waitForAdjustments, 30);
			} else {
				self.isAdjusting = NO;
				waitForAdjustments();
			}
			
		}
	}
	
	self.frameLayerObject.setDelegate(controller);
	self.frameLayerObject.animateTransition(self.transitionIn);
	
}


DC.FrameSet.prototype.autoResize = function(setFinal) {
	var self = this;
	tryout(function() {
		var w = self.frameLayerObject.getWidth();
		var h =
			self.titleLayer.getHeight() +
			(self.titleLayer.getAttr("padding-top").replace("px", "").toInt() * 2) +
			self.contentLayer.getHeight() +
			(self.contentLayer.getAttr("padding-top").replace("px", "").toInt() * 2) + 10;
		self.adjustToSize(w, h);
		if(setFinal) self.finalDimensions = new CGDim(w, h);
	});
}


DC.FrameSet.prototype.adjustToSize = function(w, h) {
	
	self = this;
	self.frameLayerObject.expandTo(w, h);
	
	self.frameLayerObject.checkAndCreate();
	
	self.frameLayerObject.delegate.layerDidFinishExpandAnimation = function(cLayer) {
		self.isAdjusting = NO;
		tryout(function() { self.delegate.frameSetDidFinishAdjustingSize(self); });
	}
	
}


DC.FrameSet.prototype.hide = function() {
	
	var self = this;

	if(self.isAnimating || self.isHidden) return NO;
	
	self.isAnimating = YES;
	
	tryout(function() {
		self.delegate.isAnimating = YES;	
	});
	
	// Create controller object
	
	var controller = {
		fade:	NO,
		slide: 	NO,
		scale: 	NO,
	}
	
	// Interpret transition types
	
	if(
		this.transitionOut & TransitionTypeSlideOut	||
		this.transitionOut & TransitionTypeSwoopOut
	)	controller.slide = YES;

	if(
		this.transitionOut & TransitionTypeFadeOut		||
		this.transitionOut & TransitionTypeFadeOutPartial
	)	controller.fade = YES;
	
	if(
		this.transitionOut & TransitionTypeMinimize
	)	controller.scale = YES;
	
	controller.layerDidFinishFloatAnimation = function(cLayer) {
		this.slide = NO;
		this.layerDidFinishAllAnimatons(cLayer);
	}
	
	controller.layerDidFinishFadeAnimation = function(cLayer) {
		this.fade = NO;
		this.layerDidFinishAllAnimatons(cLayer);
	}
	
	controller.layerDidFinishExpandAnimation = function(cLayer) {
		this.scale = NO;
		this.layerDidFinishAllAnimatons(cLayer);
	}
	
	controller.layerDidFinishAllAnimatons = function(cLayer) {
		if(!this.slide && !this.fade && !this.scale)  {
			self.isAnimating 	= NO;
			self.isHidden 		= YES;
			DC.FrameSet.visibleFrameSets.remove(DC.FrameSet.visibleFrameSets.indexOf(self));
			DC.FrameSet.frameSetContainer.dropChild(self.frameLayerObject);
			if(!DC.FrameSet.checkForAnyAnimation()) {
				tryout(function() {
					DC.FrameSet.functionToCallAfterClear();
				});
			}
			if(self.purgeOnHide) {
				DC.FrameSet.functionToCallAfterClear = null;
			}
			tryout(function() {
				self.delegate.frameSetDidBecomeInvisible(self);
			});
		}
	}
	
	self.frameLayerObject.setDelegate(controller);
	self.frameLayerObject.animateTransition(self.transitionOut);
	
}


DC.FrameSet.prototype.maximize = function(newY) {

	self = this;
	
	if(self.isMaximized) {
		self.restore();
		return;
	}
	
	var controller = {
		finishedFloat: NO,
		finishedExpand: NO,
		layerDidFinishFloatAnimation: function(cLayer) {
			controller.finishedFloat = YES;
			controller.layerDidFinishAllAnimations();
		},
		layerDidFinishAllAnimations: function(cLayer) {
			if(!controller.finishedFloat || !controller.finishedExpand) return;
			self.isMaximized = YES;
			self.maximButton.setClass("restoButton");
			self.autoResize();
		},
	}
	
	self.frameLayerObject.setDelegate(controller);
	
	var frameSetController = {
		frameSetDidFinishAdjustingSize: function(cLayer) {
			controller.finishedExpand = YES;
			controller.layerDidFinishAllAnimations();
		},
	}
	
	with(self) {
		
		setDelegate(frameSetController);
		
		maxOrigin = new CGPoint((window_width() / 2) - (maxSize.width / 2), 40);
		
		frameLayerObject.floatTo(maxOrigin);
		adjustToSize(maxSize);
		
		tryout(function() {
			maximFunc();
		});
		
	}
	
}


DC.FrameSet.prototype.restore = function() {
	
	self = this;
	
	if(!self.isMaximized) {
		self.maximize();
		return;
	}
	
	var controller = {
		finishedFloat: NO,
		finishedExpand: NO,
		layerDidFinishFloatAnimation: function(cLayer) {
			controller.finishedFloat = YES;
			controller.layerDidFinishAllAnimations();
		},
		layerDidFinishAllAnimations: function(cLayer) {
			if(!controller.finishedFloat || !controller.finishedExpand) return;
			self.isMaximized = NO;
			self.maximButton.setClass("maximButton");
			self.autoResize();
		},
	}
	
	self.frameLayerObject.setDelegate(controller);
	
	var frameSetController = {
		frameSetDidFinishAdjustingSize: function(cLayer) {
			controller.finishedExpand = YES;
			controller.layerDidFinishAllAnimations();
		},
	}
	
	with(self) {
		
		setDelegate(frameSetController);
		
		frameLayerObject.floatTo(initialOrigin);
		adjustToSize(finalDimensions);
		
		tryout(function() {
			minimFunc();
		});
		
	}
	
}


DC.FrameSet.prototype.minimize = function() {
	
}
