var bMouseOver = false;
var timerID = 0;

var timerFlip;
var timerFlipping;
var timerUnFlip;
var timerUnFlippping;
timerFlip         = setTimeout("return false;", 10);
timerFlipping     = setTimeout("return false;", 10);
timerUnFlip       = setTimeout("return false;", 10);
timerUnFlippping  = setTimeout("return false;", 10);

var bFlipping = false;
var bUnFlipping = false;
var bFlipped = false;
var bUnFlipped = true;

var nStep = 20;
var bContinue = true;

function showFlipStats ()
{
  clearInterval ( timerFlip );
  clearInterval ( timerFlipping );
  clearInterval ( timerUnFlip );
  clearInterval ( timerUnFlippping );
  bContinue=false;
  bFlipped = true;
  bUnlipped = false;
  //alert ('flipped: ' + bFlipped);
  //alert ('flipping: ' + bFlipping);
  //alert ('unflipped: ' + bFlipped);
  //alert ('unflipping: ' + bFlipping);
  alert ('flipped: ' + bFlipped + '\nflipping: ' + bFlipping + '\nunflipped: ' + bFlipped + '\nunflipping: ' + bFlipping);
  
}

function xximageFlip(imgId){
  if (!bFlipping && !bFlipped) {
    bFlipping = true;
    timerID = setInterval("imageFlipResize('" + imgId + "', " + nStep + ")", 100);
  }
}

function xximageUnFlip(imgId){
  if (!bFlipping && bFlipped) {
    bFlipping = true;
    timerID = setInterval("imageUnFlipResize('" + imgId + "', " + nStep + ")", 1);
  }
}

function imageFlip(imgId){

  if ((!bUnFlipping) && (!bFlipping) && (!bFlipped)){
    bFlipping = true;
    timerFlipping = setInterval("imageFlipResize('" + imgId + "', " + nStep + ")", 20);
  }else{
    bFlipping = false;
    bUnFlipping = false;
    bFlipped = false;
    clearInterval ( timerUnFlip );
    clearInterval ( timerUnFlipping );
    timerFlip = setTimeout("imageFlip('" + imgId + "')",  50);
    //}
  }

}

function xximageUnFlip(imgId){
  if ((!bUnFlipping) && (!bFlipping) && (!bUnFlipped)){
    bUnFlipping = true;
    timerUnFlipping = setInterval("imageUnFlipResize('" + imgId + "', " + nStep + ")", 10);
  }else{
    bFlipping = false;
    bUnFlipping = false;
    bUnFlipped = false;
    clearInterval ( timerFlip );
    clearInterval ( timerFlipping );
    timerUnFlip = setTimeout("imageUnFlip('" + imgId + "')", 50);
  }
}
function imageUnFlip(imgId){
  bUnFlipping = true;
  clearInterval ( timerFlip );
    clearInterval ( timerFlipping );
  timerUnFlipping = setInterval("imageUnFlipResize('" + imgId + "', " + nStep + ")", 20);
}

function imageFlipResize(imgId, iStep){
  var objImg = document.getElementById(imgId);
  var iHeight = objImg.offsetHeight;
  if (bFlipping) {
  if (iHeight > iStep) {
    iHeight = iHeight - iStep;
    objImg.style.height = iHeight + 'px';
    objImg.style.top = (((90 - iHeight)/2) -90) + 'px';
    objImg.style.borderTop ='1px solid \#6f8b9c';
    objImg.style.borderBottom ='1px solid \#6f8b9c';
    
  }else{
    clearInterval ( timerFlip );
    clearInterval ( timerFlipping );
    bFlipped = true;
    bFlipping = false;
    bUnFlipping = false;
    bUnFlipped = false;
    objImg.style.height = '0px';
    objImg.style.display = 'none';
  }
  }
}

function imageUnFlipResize(imgId, iStep){
  //var iWidth  = objImg.offsetWidth;
  var objImg = document.getElementById(imgId);
  var iHeight = objImg.offsetHeight;
  
  if (bUnFlipping) {
  if (iHeight < (90 - iStep)) {
    iHeight = iHeight + iStep;
    objImg.style.display = 'block';
    objImg.style.height = iHeight + 'px';
    objImg.style.top = (((90 - iHeight)/2) - 90) + 'px';
    objImg.style.borderTop ='1px solid \#6f8b9c';
    objImg.style.borderBottom ='1px solid \#6f8b9c';
    
  }else{
    clearInterval ( timerUnFlip );
    clearInterval ( timerUnFlipping );
    bUnFlipped = true;
    bUnFlipping = false;
    bFlipped = false;
    bFlipping = false;
    objImg.style.height = '90px';
    objImg.style.border ='none';
    objImg.style.top = '-90px';
    
  } 
  }
}