/*function closeAllBlocks(){
    popup_consultant.hide();
    if(popup_registration)
	popup_registration.hide();
}*/

function popupblock(call_block_id, body_block_id, width, height){

	this.start_widht = 10;
	this.width = width;
	this.height = height;
	
	this.call_block = document.getElementById(call_block_id);
	this.call_block.global_obj = this;
	this.call_block.onclick = function(){this.global_obj.view()};
	
	this.body_block = document.getElementById(body_block_id);
	
	//находим кнопку зактытия
	var divs = this.body_block.getElementsByTagName('DIV');
	for(var i in divs){
	    if(divs[i].className == 'closeButton'){
		divs[i].global_obj = this;
		divs[i].onclick = function(){this.global_obj.hide()};
		break;
	    }
	}
	this.window_state = false;
}


popupblock.prototype.view = function(event){
	
	if(!this.window_state){
		//closeAllBlocks();
		this.body_block.style.display = 'block';
		this.body_block.style.width = this.start_widht+'px';
		this.viewAnimation(this.start_widht, 0);
	}
	
	return false;
}

popupblock.prototype.viewAnimation = function(x, y){
	if(y<=this.height){
		this.body_block.style.height = y+'px';
		y+=this.width/10;
		var obj = {global_obj : this };
		window.setTimeout(function () {obj.global_obj.viewAnimation(x, y)}, 1);
	}
	else if(x<=this.width){
		this.body_block.style.width = x+'px';
		x+=this.height/10;
		var obj = {global_obj : this };
		window.setTimeout(function () {obj.global_obj.viewAnimation(x, y)}, 1);
	}
	else 
		this.window_state = true;
}

popupblock.prototype.hide = function(){
	if(this.window_state){
	    this.hideAnimation(this.width, this.height);
	}
	return false;
}

popupblock.prototype.hideAnimation = function(x, y){
	if(x >= this.start_widht){
		this.body_block.style.width = x+'px';
		x-=this.height/10;
		var obj = {global_obj : this };
		window.setTimeout(function () {obj.global_obj.hideAnimation(x, y)}, 1);
	}
	else if(y >= 0){
		this.body_block.style.height = y+'px';
		y-=this.width/10;
		var obj = {global_obj : this };
		window.setTimeout(function () {obj.global_obj.hideAnimation(x, y)}, 1);
	}
	else {
		this.body_block.style.display = 'none';
		this.window_state = false;
	}
}

