/**
* Div
* represents html div element
* @constructor
* @base Elem
* @namespace stubhub.ui.core
* @param {String} id The html id of div
* @return Div object
*/



stubhub.ui.core.Div = function(id){


	var iAnimateTimeout = 40;
	var iAnimateSteps = 5;
	

	function contractHelper(current, delta, obj){

		var s = obj.elem.style;

		var v = current - delta;

		if (v <= 0){

			s.height = stubhub.env.Client.bIE ? "1px" : "0px";
			s.display = "none";
			obj.isExpanded = false;
			obj.dispatchEvent("contract");

		}else{

			s.height = v + "px";

			setTimeout(function(){contractHelper(v, delta, obj);}, iAnimateTimeout);

		}

	}

	

	function expandHelper(current, delta, obj){

		var s = obj.elem.style;

		var v = current + delta;
		
		if (s.display == "none"){
			s.display = "block";
		}


		if (v >= obj.offsetHeight){

			s.height = obj.offsetHeight + "px";
			s.height = "auto";
			obj.isExpanded = true;
			obj.dispatchEvent("expand");			
		}else{

			s.height = v + "px";

			setTimeout(function(){expandHelper(v, delta, obj);}, iAnimateTimeout);

		}

	}

	

	function fadeHelper(current, end, delta, obj){

		var s = obj.elem.style;

		var v = current + delta;

		if (delta<0 && v<=0){	//fade out
			s.opacity = "0.0";
			s.filter = "alpha(opacity=\"0\")";
			s.display = "none";
			obj.dispatchEvent("fadeout");
		}else if (delta>0 && v>=end){  //fade in
			s.opacity = end/100;
			s.filter = "alpha(opacity=\"" + end + "\")";
			obj.dispatchEvent("fadein");
		}else{
			s.opacity = v/100;
			s.filter = "alpha(opacity=\"" + v + "\")";
			setTimeout(function(){fadeHelper(v, end, delta, obj);}, iAnimateTimeout);
		}
	}



	var o = stubhub.extend(new stubhub.ui.core.Elem(id));

	o.objType = "stubhub.ui.core.Div";

	o.isExpanded = true;

	

	o.expand = function(){
		var e = this.elem;
		if (e){

			var step = parseInt(this.offsetHeight/iAnimateSteps);

			expandHelper(0, step, this);

		}
	};
	o.contract = function(){;
		var e = this.elem;
		if (e){

			var step = parseInt(this.offsetHeight/iAnimateSteps);

			e.style.overflow = "hidden";

			contractHelper(this.offsetHeight, step, this);

		}
	};

	o.fade = function(iStart, iEnd){

		var step = parseInt((iEnd-iStart)/iAnimateSteps);
		fadeHelper(iStart, iEnd, step, this);

	}
	o.divShow = o.show;
	o.show = function(){
		var e = this.elem;
		if (e){
			o.divShow();
			e.style.display = "block";
		}
	}
	o.initOffsets = function(){
		//display=none will cause offsets to be zero.
		//If js changes display=block, then this.elem.offsetWidth/Height will
		//only get values if they were explicitly defined. 
		this.offsetWidth = this.elem.offsetWidth;
		this.offsetHeight = this.elem.offsetHeight;
	}

	

	if (o.elem){
		o.initOffsets();

	}

	

	return o;





};