var MainState = function()
{	
	// properties
	this.isExpanded = false;
	// this.isWithRightLink = true;
	// this.isWithLeftLink = true;
	
	
	this.exitUrl = null;
	
	this.item = null;
	this.prevItem = null;
	
	this.subItem = null;
	this.prevSubItem = null;
	
	this.subItems = new Array();
	
	
	
	// track all updateable elements
	this.updateables = $('.updateable, .updateable_children ul li a');
	
	
	// methods
		
	//
	this.setExpanded = function(value) {
		this.isExpanded = value;
		return this;
	}
	
	//
	this.getExpanded = function() {
		return this.isExpanded;
	}
	
	//
	this.toggleExpanded = function() {
		if (false == this.isExpanded) {
			this.isExpanded = true;
		} else {
			this.isExpanded = false;
		}
		return this;
	}
	
	
	
	
	//
	this.setItem = function(value) {
		this.prevItem = this.item;
		this.item = value;
		return this;
	}
	
	//
	this.getItem = function() {
		return this.item;
	}

	//
	this.getPrevItem = function() {
		return this.prevItem;
	}
	
	//
	this.unsetItem = function() {
		
		this.item = null;
		this.prevItem = null;
		
		this.subItem = null;
		this.prevSubItem = null;
		
		this.subItems = new Array();
		
		return this;
	}
	
	
	
	//
	this.getSubItemCurIdx = function() {
		return $.inArray(this.subItem, this.subItems);
	}
	
	
	//
	this.setSubItem = function(value) {
		this.prevSubItem = this.subItem;
		this.subItem = value;
		return this;
	}
	
	//
	this.getSubItem = function() {
		return this.subItem;
	}

	//
	this.getPrevSubItem = function() {
		return this.prevSubItem;
	}
	
	//
	this.setNextSubItem = function() {
		var idx = this.getSubItemCurIdx() + 1;
		this.setSubItem(this.subItems[idx]);
		return this;
	}

	//
	this.setPrevSubItem = function() {
		var idx = this.getSubItemCurIdx() - 1;
		this.setSubItem(this.subItems[idx]);
		return this;
	}	
	
	
	
	//
	this.setExitUrl = function(value) {
		this.exitUrl = value;
		return this;
	}

	//
	this.getExitUrl = function(value) {
		return this.exitUrl;
	}
	
	
	
	//
	this.getWithRightLink = function() {
		return (this.getSubItemCurIdx() < ($(this.subItems).size() - 1));
	}
	
	//
	this.getWithLeftLink = function() {
		return (this.getSubItemCurIdx() > 0);
	}
	
	
	//
	this.setSubItems = function(value) {
		this.subItems = value;
		this.setSubItem(this.subItems[0]);
		return this;
	}
	
	
	//
	this.update = function() {
		this.updateables.trigger('update');
	}
	
	
	
	/* /
	this.update = function() {
		alert('foo');
	}
	/* */
	
	// alert('foo');
	
}



var LinkTransition = function()
{
	// pseudo constants
	this.CONTRACTED = 0;
	this.EXPANDING = 1;
	this.FADING_IN = 2;
	this.EXPANDED = 3;
	this.FADING_OUT = 4;
	this.CONTRACTING = 5;
	
	// properties
	this.currentState = this.CONTRACTED;
	
	this.getCurrentState = function() {
		return this.currentState;
	}
	
	//
	this.isContracted = function() {
		return (this.currentState == this.CONTRACTED);
	}
	
	//
	this.setContracted = function() {
		this.currentState = this.CONTRACTED;
		return this;
	}

	//
	this.isExpanding = function() {
		return (this.currentState == this.EXPANDING);
	}
	
	//
	this.setExpanding = function() {
		this.currentState = this.EXPANDING;
		return this;
	}

	//
	this.isFadingIn = function() {
		return (this.currentState == this.FADING_IN);
	}

	//
	this.setFadingIn = function() {
		this.currentState = this.FADING_IN;
		return this;
	}

	//
	this.isExpanded = function() {
		return (this.currentState == this.EXPANDED);
	}

	//
	this.setExpanded = function() {
		this.currentState = this.EXPANDED;
		return this;
	}

	//
	this.isFadingOut = function() {
		return (this.currentState == this.FADING_OUT);
	}

	//
	this.setFadingOut = function() {
		this.currentState = this.FADING_OUT;
		return this;
	}

	//
	this.isContracting = function() {
		return (this.currentState == this.CONTRACTING);
	}
	
	//
	this.setContracting = function() {
		this.currentState = this.CONTRACTING;
		return this;
	}
	
	
	//
	this.isStopped = function() {
		return ((this.currentState == this.EXPANDED) || (this.currentState == this.CONTRACTED));
	}
	
	//
	this.setNextLinkState = function() {
		if (this.isContracted()) {
			this.currentState = this.EXPANDING;
		} else {
			this.currentState = this.FADING_IN;
		}
		return this;
	}
	
	
}


