var TINY={};

function getAccordById(accordId){
	return document.getElementById(accordId)
}
function getAccordByTag(h3Element,theAccord3){
	return theAccord3.getElementsByTagName(h3Element)
}

TINY.accordion = function(){

	function slider(theAccord){
		this.theAccord = theAccord;
		this.accordTagH3 = [];
		this.accordTagH3_2 = [];
	}

	slider.prototype.init = function(accordId,h3Element,expandAll,firstExpand,k){
		var anAccordId = getAccordById(accordId);
		var i = x = 0;
		this.s = '', theAccord2 = [], theAccord = anAccordId.childNodes, l = theAccord.length;
		this.expandAll = expandAll || false;
		for(i;i<l;i++){
			if(theAccord[i].nodeType != 3){
				theAccord2[x] = theAccord[i];
				x++;
			}
		}
		this.l = x;
		for(i=0;i<this.l;i++){
			// i would correspond to each nested tag:
			//   parentAccord[0] would be "Parking", parentAccord[1] would be "Cat Tran" ...
			//   nested1Accordion[0] would be "Garage", nested1Accordion[1] would be "Metered" ...
			var theAccord3 = theAccord2[i];
			this.accordTagH3[i] = accordTagH3 = getAccordByTag(h3Element,theAccord3)[0];
			this.accordTagH3_2[i] = accordTagH3_2 = getAccordByTag('div',theAccord3)[0];

			accordTagH3.onclick = new Function(this.theAccord + '.pr(false,this)');
			if(firstExpand==i){
				accordTagH3_2.style.height = 'auto';
				accordTagH3_2.d = 1;
			}else{
				accordTagH3_2.style.height = 0;
				accordTagH3_2.d = -1;
			}
		}
	};

	slider.prototype.pr = function(hardFalse,d){
		for(var i=0;i<this.l;i++){
			var accordTagH3 = this.accordTagH3[i], accordTagH3_2 = this.accordTagH3_2[i], k = accordTagH3_2.style.height;
			k = k == 'auto' ? 1 : parseInt(k);
			clearInterval(accordTagH3_2.accordId);
			if((k!=1 && accordTagH3_2.d==-1) && (hardFalse==1 || accordTagH3==d)){
				// open an accordian
				accordTagH3_2.style.height = '';
				accordTagH3_2.expandAll = accordTagH3_2.offsetHeight;
				accordTagH3_2.style.height = k+'px';
				accordTagH3_2.d = 1;
				su(accordTagH3_2,1);
			}else if(k>0 && (hardFalse==-1 || this.expandAll || accordTagH3==d)){
				// close an accordian
				accordTagH3_2.d = -1;
				su(accordTagH3_2,-1);
			}
		}
	};

	function su(accordTagH3_2){
		accordTagH3_2.accordId = setInterval(function(){sl(accordTagH3_2)},10)
	};

	function sl(accordTagH3_2){
		var h = accordTagH3_2.offsetHeight, d = accordTagH3_2.d == 1 ? accordTagH3_2.expandAll-h : h;
		accordTagH3_2.style.height = h+(Math.ceil(d/5)*accordTagH3_2.d)+'px';
		//jjj get rid of dynamic opacity.
		//accordTagH3_2.style.opacity = h/accordTagH3_2.expandAll;
		//accordTagH3_2.style.filter = 'alpha(opacity = '+h*100/accordTagH3_2.expandAll+')';
		if((accordTagH3_2.d == 1 && h >= accordTagH3_2.expandAll) || (accordTagH3_2.d != 1 && h == 1)){
			if(accordTagH3_2.d == 1){
				accordTagH3_2.style.height = 'auto';
				//document.body.style.cursor = "default";
			}
			clearInterval(accordTagH3_2.accordId);
		}
	};

	return{slider:slider}
}();