﻿var addressBoxOpened = false;
var contentHeight =0;
var targetBlock;
var targetBlock2;
var speed = 0;
var intervalId ;
var timeOutID;
var currentAddressBox;

function slidingDown(targetName,targetHeight){
        targetBlock = get_element(targetName);    
        contentHeight = targetHeight; 
        if(targetBlock.style.visibility != "visible"){
        targetBlock.style.visibility = "visible";
        document.cookie = "openForm=opened";   
        intervalId = setInterval("doSlidingDown()",1);
  
   }
}
function slidingDownDown(targetName,targetHeight){
        targetBlock = get_element(targetName);    
        contentHeight = targetHeight; 
        if(targetBlock.style.visibility != "visible"){
        targetBlock.style.visibility = "visible";
        document.cookie = "openForm=opened";  
    targetBlock.style.height = contentHeight+"px";
   }
}

function keepItOpen(targetName,targetHeight){
    targetBlock = get_element(targetName);
     targetBlock.style.visibility = "visible";
     targetBlock.style.height = targetHeight +"px";
}

function slidingUp(targetName,originalHeight){
    targetBlock = get_element(targetName);    
    contentHeight = originalHeight;
   if(targetBlock.style.visibility == "visible"){
    intervalId = setInterval("doSlidingUp()",1);
    }   
}
function slidingUpUp(targetName,originalHeight){
    targetBlock = get_element(targetName);    
    contentHeight = originalHeight;
//   if(targetBlock.style.visibility == "visible"){
//    intervalId = setInterval("doSlidingUp()",1);
//    }   
}

function slidingDownContactDetail(targetName,targetHeight){
        if(addressBoxOpened == false){
            targetBlock = document.getElementById(targetName);    
            contentHeight = targetHeight; 
            if(targetBlock.style.visibility != "visible"){
                targetBlock.style.visibility = "visible";   
                intervalId = setInterval("doSlidingDown()",1);
               //alert(targetBlock.style.id);
               addressBoxOpened = true;
               currentAddressBox = targetName;
               
           }
      }else{
            if(currentAddressBox == targetName){}
            else toggle();
         }
}

function slidingUpContactDetail(targetName,originalHeight){
    targetBlock = get_element(targetName);    
    //contentHeight = originalHeight;
    targetBlock.style.visibility = "hidden";
    targetBlock.style.height = "0px";
   /*
   if(targetBlock.style.visibility == "visible"){
    intervalId = setInterval("doSlidingUp()",1);
    }
    */   
}

function toggle(){
    if(currentAddressBox == "phoneNumberBox"){
        slidingUpContactDetail(currentAddressBox);
        clearTimeout(timeOutID);
        timeOutID=slidingDown('emailAddressBox',65);
       
        currentAddressBox = "emailAddressBox" ;
    }
    else if(currentAddressBox == "emailAddressBox"){
        slidingUpContactDetail(currentAddressBox);
        clearTimeout(timeOutID);
        timeOutID=slidingDown('phoneNumberBox',40);
               
        currentAddressBox = "phoneNumberBox" ;
    }
    
}

function doSlidingUp(){
    contentHeight -= 15;    
    if(contentHeight <= 0){
        clearInterval(intervalId);
        targetBlock.style.visibility = "hidden";
        speed = 0;
        contentHeight = 0;
    }
    targetBlock.style.height = contentHeight+"px";
}
function doSlidingDown(){
    speed+=15;
    targetBlock.style.height = speed+"px";
    if(speed >= contentHeight){
        clearInterval(intervalId);
        speed = 0;
        contentHeight = 0;       
    }
}