/********************************
Evolio - All right reserved
FPB - 2009.09.22
********************************/

var openingFlashBox = null;
var closingFlashBox = null;
var galleryTotalHeight = 570;
var galleryOpenHeight = 0;
var openingSpeed = 5;
var flashParams = "?language=" + language + "&whichGallery=" + whichGallery + "&whichGalleryModel=" + whichGalleryModel;
//var so = new SWFObject("", "galleryFlash", "980", "0", "8", "#CCC", "transparent");

function openFlashGallery(){
  if(galleryOpenHeight != galleryTotalHeight){
    clearTimeout(openingFlashBox);
    clearTimeout(closingFlashBox);
    document.getElementById('popBox').style.display = 'block';
    if(typeof(galleryInSite) != 'undefined'){
      document.getElementById('popGallery').style.display = 'block';
    }
    so = new SWFObject("/dealersite/brand/flash/gallery.swf"+flashParams, "galleryFlash", "980", "570", "8", "#CCC", "transparent");
    document.getElementById('popGallery').style.height = 1;
    openingFlashBox = setInterval('openit()', 50);
  }
}

function closeFlashGallery(){
  clearTimeout(openingFlashBox);
  clearTimeout(closingFlashBox);
  closingFlashBox = setInterval('closeit()', 50);
}

function openit(){
  if(parseInt((galleryTotalHeight - galleryOpenHeight)/openingSpeed) > 1){
    galleryOpenHeight = galleryOpenHeight + parseInt((galleryTotalHeight - galleryOpenHeight)/openingSpeed);
    document.getElementById('popGallery').style.height = galleryOpenHeight + 'px';
  }else if(parseInt((galleryTotalHeight - galleryOpenHeight)/openingSpeed) <= 1 && galleryOpenHeight != galleryTotalHeight){
    galleryOpenHeight = galleryOpenHeight + 1;
    document.getElementById('popGallery').style.height = galleryOpenHeight + 'px';
  }else{
    document.getElementById('popGallery').style.height = galleryTotalHeight + 'px';
    galleryOpenHeight = galleryTotalHeight;
    clearTimeout(openingFlashBox);
  }
  console.debug(galleryOpenHeight);
}

function closeit(){
  if (galleryOpenHeight > 2){
    galleryOpenHeight = galleryOpenHeight - parseInt(galleryOpenHeight/2);
    document.getElementById('popGallery').style.height = galleryOpenHeight + 'px';
  }else{
    so = new SWFObject("", "galleryFlash", "980", "0", "8", "#CCC", "transparent");
    document.getElementById('popGallery').style.height = '0px';
    if(typeof(galleryInSite) != 'undefined'){
      document.getElementById('popGallery').style.display = 'none';
    }else{
      document.getElementById('popBox').style.display = 'none';
    }
    clearTimeout(closingFlashBox);
  }
}
