//Opens and Closes Div with smooth tween motion

function OpenClose(container){
	//	Establish superclass and inherit methods, StageElement contains 
	//	helper methods for objects that work with the screen
	//this.inheritFrom = StageElement;
	//this.inheritFrom(container);

	this.duration = 250;
	this.property = 'height';
	this.collection = new Object();
	
	this.toggle = openClose_toggle;
	this.toggleLogic = openClose_toggleLogic;
	this.createObj = openClose_createObj;
	this.clear = openClose_clear;
}

function openClose_toggleLogic(thisSlide) {
	if(thisSlide.tog == "closed"){
		thisSlide.tog = "open";
		thisSlide.fxObj.start(1, thisSlide.sizeOpen);
		return;
	} else {
		thisSlide.fxObj.element.setStyle({
			overflow: 'hidden'
		});
		thisSlide.sizeOpen = thisSlide.fxObj.element.getHeight();
		if(thisSlide.fxObj.element.getStyle('display') == 'none'){
			thisSlide.fxObj.element.setStyle({
				height: '1',
				display: 'block'
			});
			thisSlide.tog = "open";
			thisSlide.fxObj.start(1, thisSlide.sizeOpen);
			return;
		} else {
			thisSlide.tog = "closed";
			thisSlide.fxObj.start(thisSlide.sizeOpen, 1);
		}
	}
}
function openClose_toggle (obj, obj2, sizeOpen, sizeClosed, property, duration) {
	thisSlide = this.createObj(obj, obj2, sizeOpen, sizeClosed, property, duration);
	if(obj2){
		thisSlide2 = this.createObj(obj2, obj, sizeOpen, sizeClosed, property, duration);
		if(thisSlide2.tog == "open"){
			thisSlide2.chain = 'yes';
			//alert(thisSlide.chain+', '+thisSlide2.chain);
			this.toggleLogic(thisSlide2); // slider
		}else{
			this.toggleLogic(thisSlide); // slider
		}
	}else{
		this.toggleLogic(thisSlide);	// slider
	}
}


function openClose_createObj(obj, obj2, sizeOpen, sizeClosed, property, duration) {
	var id=obj;
	if(typeof obj=="object"){id=obj.id;}
	var id2=obj2;
	if(typeof obj2=="object"){id2=obj2.id;}
	if(this.collection[id]) {
		return(this.collection[id]);
	} else {
    	//	Create sliding object
    	
    	if (!sizeClosed){sizeClosed = 1;}
		if (!property){property = this.property;}
		if (!duration){duration = this.duration;}
		if (!sizeOpen){sizeOpen = $(obj).getHeight();}
		if ((sizeOpen === 1)||($(obj).getStyle('display') == 'none')){
			tog = "closed";
			$(obj).setStyle({
				overflow: 'hidden',
				height: '1',
				display: 'block'
			});
		} else {
			tog = "open";
		}
		chain = "notSet";
		this.collection[id] = {fxObj:new Fx.Style(obj, property,{duration:duration, transition:Fx.Transitions.sineInOut,
			onComplete:function(){
				//alert(thisSlide.tog+", "+thisSlide2.tog+", "+thisSlide2.chain+", "+obj2);
				if(obj2){
					if(thisSlide2.chain=='yes'){
						thisSlide2.chain='no';
						this.toggleLogic(thisSlide); // slider
					}
				}
				if(this.element.getHeight() > 1) {
					this.element.setStyle({
					overflow: 'visible',
					height: ''
					});
				}
			}
			}),sizeOpen:sizeOpen, tog:tog, chain:chain}
		}
		return(this.collection[id]);
}
function openClose_clear(){
	this.collection = new Object();
}

var slider = new this.OpenClose(document);


