function OpenWindowCenter(url, width, height, title, status, resizable, scroll)
{
  if(!status)
    status = 'no';
    
  if(!scroll)
    scroll = 'no';

  if(!resizable)
    resizable = 'no';

  var top = ((screen.height / 2) - (height / 2));
  var left = ((screen.width / 2) - (width / 2));

  return window.open(url, title, 'location=no, titlebar=no, toolbar=no, menubar=no, directories=no, channelmode=no, width='+ width +', height='+ height +', resizable='+ resizable +', scrollbars='+ scroll +', status='+ status +', top='+ top +', left='+ left +'');
}

function setGalleryImg(id, url, current, amount)
{
  var glDiv = document.getElementById('detailsCarImg');
  var lnk = document.getElementById('detailsCarOverlayLink');

  lnk.href = '/gallery-overlay.aspx?source=details&id='+ id +'&amount='+ amount +'&current='+ current +'&url='+ url;
  
  if(glDiv)
  {
    var imgUrl = url + '404/'+ id;
    
    if(current != '0')
      imgUrl += '_' + current;
    
    imgUrl += '.jpg';
    
    glDiv.style.background = "transparent url("+ imgUrl +") no-repeat 0% 0%";
  }
}

function galleryOver(id)
{
  var gb = document.getElementById(id);
  
  if(gb)
    gb.className = 'galleryOverBoxOver';
}

function galleryOut(id)
{
  var gb = document.getElementById(id);
  
  if(gb)
    gb.className = 'galleryOverBox';
}

function filterList(filter)
{
  var rawUrl = document.location.href;
  var filterPosition = rawUrl.indexOf('?f=');
  
  if(filterPosition != -1)
  {
    rawUrl = document.location.href.substr(0, filterPosition);
  
    if(filter == '')
      document.location.href = rawUrl;
  }

  var fields = filter.split("|");
  var addToUrl = '?f=';
  
  for(i = 0; i < fields.length; i++)
  {
    if(document.getElementById(fields[i]).value != '' && document.getElementById(fields[i]).value != 0)
    {
      if(addToUrl != '?f=')
        addToUrl += '_';
      addToUrl += fields[i] + '-' + document.getElementById(fields[i]).value;
    }
  }
  
  if(addToUrl != '?f=')
    document.location.href = rawUrl + addToUrl;
  else
    document.location.href = rawUrl;
}

function fieldClick(obj, value)
{
  if(obj.value == value)
    obj.value = "";
  else
  {
    obj.focus();
    obj.select();
  }
}

function fieldBlur(obj, value)
{
  if(obj.value.trim() == "")
    obj.value = value;
}


$(function() {
  
$("#galleryImages img[title]").tooltip();
  
  $(".detailsCarGallerySlider").jCarouselLite({
      btnNext: ".detailsCarGalleryNext",
      btnPrev: ".detailsCarGalleryPrev",
      visible: 3,
      speed:400,
      scroll:3
  });
  
  // if the function argument is given to overlay,
  // it is assumed to be the onBeforeLoad event listener
  $("a[rel]").overlay({

    mask: 'lightgray',
    effect: 'apple',
    top: 10,
    
    onBeforeLoad: function() {

      // grab wrapper element inside content
      var wrap = this.getOverlay().find(".contentWrap");

      // load the page specified in the trigger
      wrap.load(this.getTrigger().attr("href"));
    }
  });

});



