//on Dom Ready
$(function() {

  //h1 und h2 werden ausgeschaltet, da jetzt ein Bild als Title ist
  $("#index_header h1").hide();
  $("#index_header h2").hide();

  var height_small = '85px';
  var width_small = '160px';
  var height_big = '132px';
  var width_big = '250px';
  init_car_effect("exige", height_small, width_small, height_big, width_big, "-80");
  init_car_effect("evora", height_small, width_small, height_big, width_big, "-135");
  init_car_effect("elise", height_small, width_small, height_big, width_big, "-190");

  /* load Impressum in application_lib.js */
  init_index_imprint_dialog();

});


function init_car_effect(car_name, height_small, width_small, height_big, width_big, margin_left) {
  $("#" + car_name + "_content").fadeOut();

  $("ul.index_car_select li." + car_name).hover(function() {
    $("#index_car_select_hover_div").html($("#" + car_name + "_content").html());
  }, function() {
    $("#index_car_select_hover_div").html("");
  });

  $("#" + car_name).hover(function() {
    $("#index_car_select_hover_div").html($("#" + car_name + "_content").html());
  }, function() {
    $("#index_car_select_hover_div").html("");
  });


  $("ul.index_car_select li." + car_name).hover(function() {
    car_amimate_drive_in_front($(this), height_big, width_big, margin_left);
  }, function() {
    car_aminmate_drive_back($(this), height_small, width_small, margin_left);
  });

  //auch bei den Autolinks im default Text soll das Auto vorfahren
  $("#" + car_name).hover(function() {
    car_amimate_drive_in_front($("ul.index_car_select li." + car_name), height_big, width_big, margin_left);
  }, function() {
    car_aminmate_drive_back($("ul.index_car_select li." + car_name), height_small, width_small, margin_left);
  });
}

function car_amimate_drive_in_front(element, height_big, width_big, margin_left) {
  element.css({'z-index' : '10'});
  if (IE = "\v" == "v") {  // true only in IE
    element.find('img').css({
      "width":width_big,
      "height":height_big,
      "marginTop":'-60px',
      "marginLeft": margin_left + "px",
      "top":'50%',
      "left": '50%'
    });
  } else {
    element.find('img').stop().animate({
      marginTop: '-60px', /* The next 4 lines will vertically align this image */
      marginLeft: margin_left + "px",
      top: '50%',
      left: '50%',
      width: width_big, /* Set new width */
      height: height_big,  /*Set new height */
      padding: '0px'
    }, 400);
  }
}

function car_aminmate_drive_back(element, height_small, width_small, margin_left) {
  element.css({'z-index' : '0'});
  if (IE = "\v" == "v") {  // true only in IE
    element.find('img').css({
      "width":width_small,
      "height":height_small,
      "marginTop":'0px',
      "marginLeft":"0px",
      "top":'0',
      "left": '0'      
    });
  } else {
    element.find('img').stop().animate({
      marginTop: '0px', /* Set alignment back to default */
      marginLeft: '0px',
      top: '0',
      left: '0',
      width: width_small, /* Set width back to default */
      height: height_small,  /*Set height back to default */
      padding: '0px'
    }, 400);
  }
}


