compare_last_top = 0;
compare_last_height = 0;

function photo_main_thumbnails() {
  photo_main_slideshow_stop();
  toggleVisibilitySwap('photo-mode', 'mode-thumbnails', 'mode-bigphoto');

  var o = document.getElementById("car-photo-thumbnails-btn");
  if(o != null && o.style.display != "none") { o.style.display = "none"; }
  o = document.getElementById("car-photo-number-str");
  if(o != null && o.style.display != "none") { o.style.display = "none"; }
  
  return false;
}

function initialize_compare_scroll_arrows() {
  // Get Scroll Arrow Container
  var sa_container = document.getElementById("content");
  if(sa_container != null) {
    var xy = YAHOO.util.Dom.getXY(sa_container);
    var sa_left = document.getElementById("compare-scroll-left");
    var sa_right = document.getElementById("compare-scroll-right");
    if(sa_left != null) { 
      sa_left.style.left = (xy[0] - 12) + "px";
      sa_left.style.zIndex = "999";
      sa_left.style.display = "";
    }
    if(sa_right != null) {
      sa_right.style.left = (xy[0] + 578) + "px";
      sa_right.style.zIndex = "999";
      sa_right.style.display = "";
    }
  }
  
  _set_compare_scroll_ypos();
}

function _set_compare_scroll_ypos() {
  var sa_left = document.getElementById("compare-scroll-left");
  var sa_right = document.getElementById("compare-scroll-right");
  var fcontainer = document.getElementById("flow-container");
  var fcxy = fcontainer != null ? YAHOO.util.Dom.getXY(fcontainer) : 0;
  var y = YAHOO.util.Dom.getViewportHeight();
  var topY = YAHOO.util.Dom.getDocumentScrollTop();
  var footer = document.getElementById("compare-footer");
  var fty = footer != null ? YAHOO.util.Dom.getY(footer) : 0;
  
  var fcy = fcxy != 0 ? fcxy[1] : 0;
  var fcx = fcxy != 0 ? fcxy[0] : 0;
  
  if(y == compare_last_height && topY == compare_last_top) {
    setTimeout('_set_compare_scroll_ypos()', 200);
    return;
  }
  
  compare_last_top = topY;
  compare_last_height = y;
  
  // V2
  var the_top = topY < fcy ? fcy : topY;
  var the_bottom = fty > topY+y ? topY+y : fty;
  var midY = (the_top + the_bottom) / 2;
  
  var t = midY - (148/2);
  if(t < the_top) t = the_top;
  if(t > the_bottom - 148) {
    t = the_bottom - 148;
  }
  
  if(t < the_top || t > the_bottom-148) {
    // not enough room to fit... just hide it cause it'll be ugly otherwise!
    YAHOO.util.Dom.setStyle(sa_left, "visibility", "hidden");
    YAHOO.util.Dom.setStyle(sa_right, "visibility", "hidden");
  }
  else {
    YAHOO.util.Dom.setStyle(sa_left, "visibility", "visible");
    YAHOO.util.Dom.setStyle(sa_right, "visibility", "visible");
  }
  
  
  var m1 = new YAHOO.util.Motion(sa_left.id, { points: { to: [fcx + (-8 - 10), t] }}, 0.2, YAHOO.util.Easing.easeNone); // -8
  var m2 = new YAHOO.util.Motion(sa_right.id, { points: { to: [fcx + (572 - 10), t] }}, 0.2, YAHOO.util.Easing.easeNone); // +574
  m1.animate();
  m2.animate();
  
  /*
  // V1
  var lxy = YAHOO.util.Dom.getXY(sa_left);
  var rxy = YAHOO.util.Dom.getXY(sa_right);
  
  if(topY < fcy) { y = (y + fcy) / 2; }
  else { y = y / 2; }
  
  if(sa_left != null && sa_right != null) {
    var t = topY + y;
    
    if(footer != null) {
      var fxy = YAHOO.util.Dom.getXY(footer);
      if(t > (fxy[1] - 32)) t = fxy[1] - 32;
    }
    
    var lxy = YAHOO.util.Dom.getXY(sa_left);
    var rxy = YAHOO.util.Dom.getXY(sa_right);
    
    var m1 = new YAHOO.util.Motion(sa_left.id, { points: { to: [lxy[0], t] }}, 0.2, YAHOO.util.Easing.easeNone);
    var m2 = new YAHOO.util.Motion(sa_right.id, { points: { to: [rxy[0], t] }}, 0.2, YAHOO.util.Easing.easeNone);
    m1.animate();
    m2.animate();
    
    //sa_left.style.top = t + "px";
    //sa_right.style.top = t + "px";
  }
  */
  
  setTimeout('_set_compare_scroll_ypos()', 300);
}

function compare_scroll_left(px) {
  var fc = document.getElementById('flow-container');
  if(fc != null) {
    fc.blur();
    fc.scrollLeft -= (px != null) ? px : 133;
  }
  return false;
}

function compare_scroll_right(px) {
  var fc = document.getElementById('flow-container');
  if(fc != null) {
    fc.blur();
    fc.scrollLeft += (px != null) ? px : 133;
  }
  return false;
}

function builder_stdequip_open() {
  fadeCenterBox("std-equip");
}

function carcontainer_builder_submit(f) {
  f.submit();
}
