/**
 * @Author: RAGBIT GmbH
 * @Developer: Anatolij Rau
 * @Date: 2009-09-02
 * @Version: 2.0 RC 1
 **/

var animation = true;
var ani_speed = 40;
var ani_steps = 4;


function easyBoxSwitch(element) {
	if (typeof element == 'object') {
		if (element.style.overflow != 'hidden') element.style.overflow = 'hidden';
		var title = document.getElementById(element.id+'_title');
		//alert(element.innerHTML);
		var to_height = title.offsetHeight+title.style.marginTop+title.style.marginBottom+title.style.paddingTop+title.style.paddingBottom;
		//alert(title.style.marginBottom);
		var from_height = element.offsetHeight+element.style.paddingTop+element.style.paddingBottom+element.style.marginBottom+element.style.marginTop;
		if (to_height == from_height) {
			var box_body = document.getElementById(element.id+'_body');
			//alert(from_height*1+box_body.offsetHeight*1);
			to_height = from_height*1+box_body.offsetHeight*1+box_body.style.marginTop*1+box_body.style.marginBottom*1+box_body.style.paddingTop*1+box_body.style.paddingBottom*1;
			if (animation) easyBoxAniPlus(element, to_height, from_height );
			else easyBoxHeight(element, to_height, from_height);
			
		} else {
			if (animation)
				easyBoxAnyMin(element, to_height, from_height );
			else
				easyBoxHeight(element, to_height, from_height);
		}
	}
  
}

function easyBoxAniPlus( element, to_height, from_height ) {
	var size_array = Array();
	var timeout = ani_speed;
	var to = Math.round((to_height-from_height)/3*1);
	var current;
	
	for (var i = 0; i<ani_steps; i++) {
		if (i!=0) {
			if (i == ani_steps-1) to = to_height-from_height*1;
			else to = Math.round(((to_height-from_height-to)/4*1)+to);
		}
		current = to*1+from_height*1;
		size_array.push(current);
		//alert('step:'+i+':'+to);
	}
	size_array.push('auto');
	//alert(size_array);
	easyBoxAnimate(element, size_array, 0);
}


function easyBoxAnyMin(element, to_height, from_height ) {
	var size_array = Array();
	var timeout = ani_speed;
	var to = Math.round((from_height-to_height)/3*2);
	for (var i = 0; i<ani_steps; i++) {
		
		if (i!=0) {
			if (i == ani_steps-1) to = 0;
			else to = Math.round(to/7*6);
		}
		size_array.push(to*1+to_height*1);
	}
	easyBoxAnimate(element, size_array, 0);
}

function easyBoxAnimate(element, size_array, i) {
	if (size_array[i]) {
		easyBoxHeight(element, size_array[i]);
		window.setTimeout(function(){easyBoxAnimate(element, size_array, i+1);}, ani_speed); 
	}
}

function easyBoxHeight(element, to_height) {
		if (to_height == 'auto') element.style.height = to_height;
		else element.style.height = to_height+'px';
		//alert(size_array[i]);
}

