﻿// JScript File
var objAnimatedCollapse;

function AnimatedCollapse(){
    this.insideHolder = null;
    this.contentHolder = null;
    this.height = 0;
    this.width = 0;
    this.destHeight;
    this.destWidth;
    this.speed = 3;
    this.frame = 10;
    
    this.show = AnimatedCollapse.Show;
    this.close = AnimatedCollapse.Close;
    this.run = AnimatedCollapse.Run;
    this.onComplete;
}

AnimatedCollapse.Run = function() {
    var mv = this.contentHolder;
    this.insideHolder.style.display = "none";
    mv.style.display = "block";    
    if (mv) {
        this.height = parseInt(mv.style.height);
        //this.width = parseInt(mv.style.width);
    }
    
    if (parseInt(mv.style.height) > 0){ 
        this.destHeight = 0;
    }

    mv.style.backgroundColor = "#eeeeee";
    AnimatedCollapse.SetOpacity(mv, 0.7);
    AnimatedCollapse.Execute(this);    
}

AnimatedCollapse.Show = function() {
    var mv = this.contentHolder;
    mv.style.display = "block";
    if (mv) {
        this.height = parseInt(mv.style.height);
        //this.width = parseInt(mv.style.width);
    }
    
    if (mv.getAttribute("dh")){
        this.destHeight = mv.getAttribute("dh");
    }
    if (mv.getAttribute("dw")){
        this.destWidth = mv.getAttribute("dw");
    }
    
    mv.style.backgroundColor = "#eeeeee";
    AnimatedCollapse.SetOpacity(mv, 0.7);
    AnimatedCollapse.Execute(this);
}

AnimatedCollapse.Close = function() {
    
}

AnimatedCollapse.Execute = function(node) {
    var mv = node.contentHolder;
	mv.spanHeight = Math.round( (node.destHeight - node.height) / node.frame);
	mv.spanWidth = Math.round( (node.destWidth - node.width) / node.frame);
	mv.num = 0;
	mv.frame = node.frame;
	objAnimatedCollapse = node;
    AnimatedCollapse.Animate();	
}

AnimatedCollapse.Animate = function() {

	var mv = objAnimatedCollapse.contentHolder;
	if (mv.num < mv.frame) {
		//mv.style.width = parseInt(mv.style.width) + mv.spanWidth;
		mv.style.height = (parseInt(mv.style.height) + mv.spanHeight) + "px";
		mv.num ++;
	    
		setTimeout("AnimatedCollapse.Animate()", objAnimatedCollapse.speed);
	}
	else {
		if (objAnimatedCollapse.onComplete) {
			objAnimatedCollapse.onComplete();
		}
		
		if (parseInt(mv.style.height) == 0)
		{
		    mv.style.display = "none";
		}
		else
		{
		    objAnimatedCollapse.insideHolder.style.display = "block";
		    mv.style.display = "block";		    
//            objAnimatedCollapse.insideHolder.style.visibility = "visible";		    
		}
		AnimatedCollapse.SetOpacity(mv, 1);
	}
}

AnimatedCollapse.SetOpacity = function(container, val) {
	container.style.opacity = val;
	container.style.filter = "alpha(opacity=" + (val * 100) + ")";
}


