/*
================================================
DialogBox 

this is used to control the creation, opening, and closing 
of dialog boxes in the taster editor

================================================
*/


// pass in item_id to edit item
function DialogBox(element_id,promobox_nested,instance_name){


	try{
		
		this._props = new Array();
		this.opened = false;	
		this.autoOpen = true;
		this.instance_name = instance_name;
		
		this.element = document.getElementById(element_id);		
		this.nested = document.getElementById(promobox_nested);
			
		this.Center();
		
		//controls the opening and closing animation of the dialog box
	
	    
		this.interv = null; 	
		
		// array of heights for our dialog box
		this.dialog = new Array();
		
		this.rate_open = 5;
		this.rate_close = 5;
		
		if(document.all){
			this.nested.className = "dialogNestedIE";
		}
	
	
	} catch (e){
		
			alert(e.message);
	}

} 

DialogBox.prototype.setProperty = function(name,value){
	this._props[name] = value;
} 


DialogBox.prototype.Center = function(){

    try{
    
        this.element.style.left =  (base_x() - 800) / 2 + "px";
       
    } catch (e) {
    
        alert(e.message);
    }
}


DialogBox.prototype.Open = function(a,b) {


	try{
	    
	    
	    this.autoOpen = false;
	 
	
		this.opened = true;
		
		if(this.interv != null){
			clearInterval(this.interv);
		}
		
		while(a < b){					
			a = Math.ceil(a + ((b - a)  / this.rate_open));
			this.dialog.push({height:a,f:null});								
		}
		
		
		this.dialog.push({height:null,f:"clearInterval(this.interv);"});	
		
		//this.updateHeight();
		
		//alert(dialogBoxes[this.instance_id]..src);
		
		var ifunc = this.instance_name  + ".updateHeight();";
		this.interv = setInterval(ifunc,1);
		
		
		} catch (e){
			alert(e.message);
		}
}


DialogBox.prototype.Close = function(){
	
	try{
		this.opened = false;
		// if there is a current animation kill the interval
		if(this.interv != null){
			clearInterval(this.interv);
		}
			
		// clear out the animation array
		this.dialog.length = 0;
		
		// start height
		var a = 350;		
		
		// end height
		var b = 1;
		
		// fill array with animction path, that is a sequence of heights.
		while(a > b){	
							
			a = Math.floor(a - ((a - b)  / this.rate_close));
			this.dialog.push({height:a,f:null});
		}												
				
		// add function to call when dialog is completely open		
		this.dialog.push({height:null,f:"clearInterval(this.interv);"});		
		
		// start animation
		var ifunc = this.instance_name + ".updateHeight();";
		this.interv = setInterval(ifunc,1);
	
	} catch (e){
	
		alert("closeDialog: " + e.message);
		
	}

}


DialogBox.prototype.updateHeight = function(){
	
	try{
		
	
		var d; 
		
		if(d = this.dialog.shift()){
	
			if(d.f != null){
				eval(d.f);
			}
			if(d.height != null){
				this.element.style.height = d.height + "px";
				
				this.nested.style.top = (d.height - 382) + "px";
				
			}
		}
	} catch (e){
	
		alert("updateHeight: " + e.message);
	}

}






function base_x(){
		var x;
		if(document.all){
			x = document.body.clientWidth;
		} else {
			x = window.innerWidth;
		}	
		return x;
}


	// determine height of browser in px
function base_y(){
		var y;
		if(document.all){
			y = document.body.clientHeight;
		} else {
			y = window.innerHeight;
		}	
		return y;
}


