function scrollWindow(){
  var distance = 560;
  var num_pics = ecarlist.vehicle.pictures.length;
  num_pics = num_pics / 10;
  num_pics = Math.ceil(num_pics);
  distance += num_pics * 45;
  window.scrollTo(0, distance);
}

function apply_photo_links_sewell(){
//vehicle.tmpl: applies onclick events to main photo & thumbnail images. Also creates media center links below main photo
  if( $('#carimg').attr('className') != 'coming_soon' ){ 
  //change href of main photo to media_center
    var main_photo = $('#vehicle_mainPhoto > #picShadow > a:first');
    var main_photo_link = "/web/" + ecarlist.dealer.id + "/media_center/" + ecarlist.vehicle.id + "/photos/" + $(main_photo).attr('id').substr($(main_photo).attr('id').indexOf('-'), 1) + "/?KeepThis=true&TB_iframe=true&height=625&width=800&style=noframe&version=2&modal=true";
    main_photo.attr('href', main_photo_link);
    tb_init('#vehicle_mainPhoto > #picShadow > a:first');
  //change href of thumbnails and add onMouseOver event
    var thumbnail_images = $('#vehicle_thumbs > a');
    thumbnail_images.each( function() {
			$(this).addClass('thickbox'); 
      $(this).attr('href', '/web/' + ecarlist.dealer.id + '/media_center/' + ecarlist.vehicle.id + '/photos/' + $(this).attr('id') + '/?KeepThis=true&TB_iframe=true&height=625&width=800&style=noframe&version=2&modal=true');
    });
    tb_init('#vehicle_thumbs > a.thickbox');
    thumbnail_images.mouseover( function() { 
      ecarlist.media_center.change_image($(this).attr('id'));
    });
  }
  // create media center links if photos, video, or evox 360
  if(ecarlist.vehicle.photos || ecarlist.vehicle.evox_exterior || ecarlist.vehicle.video){
    var media_center_links = document.createElement('ul');
    $(media_center_links).attr('id', 'media_center_links');
    // link for photos
    if(ecarlist.vehicle.photos){
      var photo_li = document.createElement('li');
      var photo_a = document.createElement('a');
      var photo_span = document.createElement('span');
      var photo_text = document.createTextNode('Photos');
      $(photo_span).append(photo_text);
      $(photo_a).append(photo_span)
        .attr('id', 'media_center_photo')
        .attr('href', '/web/' + ecarlist.dealer.id + '/media_center/' + ecarlist.vehicle.id + '/photos/' + ecarlist.vehicle.initial_picture + '/?KeepThis=true&TB_iframe=true&height=625&width=800&style=noframe&version=2&modal=true')
        .addClass('thickbox');
      $(photo_li).append(photo_a);
      $(media_center_links).append(photo_li);
    }
    // link for video
    if(ecarlist.vehicle.video || ecarlist.vehicle.sister_media_id  ||  ecarlist.vehicle.third_party_video_url){
      var video_li = document.createElement('li');
      var video_a = document.createElement('a');
      var video_span = document.createElement('span');
      var video_text = document.createTextNode('Video');
      $(video_span).append(video_text);
      $(video_a).append(video_span)
        .attr('id', 'media_center_video')
        .attr('href', '/web/' + ecarlist.dealer.id + '/media_center/' + ecarlist.vehicle.id + '/video/?KeepThis=true&TB_iframe=true&height=625&width=800&style=noframe&version=2&modal=true')
        .addClass('thickbox');
      $(video_li).append(video_a);
      $(media_center_links).append(video_li);
    }
    // link for evox 360
    if(ecarlist.vehicle.evox_exterior){
      var ext_li = document.createElement('li');
      var ext_a = document.createElement('a');
      var ext_span = document.createElement('span');
      var ext_text = document.createTextNode('360');
      $(ext_span).append(ext_text);
      $(ext_a).append(ext_span)
        .attr('id', 'media_center_360')
        .attr('href', '/web/' + ecarlist.dealer.id + '/media_center/' + ecarlist.vehicle.id + '/view_360/?KeepThis=true&TB_iframe=true&height=625&width=800&style=noframe&version=2&modal=true')
        .addClass('thickbox');
      $(ext_li).append(ext_a);
      $(media_center_links).append(ext_li);
    }
    // link for contact in customer tools
    var contact_li = document.createElement('li');
    var contact_a = document.createElement('a');
    var contact_span = document.createElement('span');
    var contact_text = document.createTextNode('Contact');
    $(contact_span).append(contact_text);
    $(contact_a).append(contact_span)
      .attr('id', 'media_center_contact')
      .attr('href', '#')
      .click(function(){ scrollWindow(); return false; });
    $(contact_li).append(contact_a);
    $(media_center_links).append(contact_li);
    // append media center links to vehicle image div
    $('#picShadow > a').after(media_center_links);
    tb_init('#media_center_links > li > a.thickbox');
  }
  $('#vehicle_v2_vitals_contact').click(function(){ scrollWindow(); return false; });
}

