var enter_button_allowed;
var animation_slow_motion = 1;

$(document).ready(function() {
  
  $(window).keydown(function(event) {
    if (event.shiftKey) {
      animation_slow_motion = animation_slow_motion * 4;
    }
    if (event.ctrlKey) {
      animation_slow_motion = animation_slow_motion * 1.2;
    }
  });
  $(window).keyup(function(event) {
    animation_slow_motion = 1
  });
  
  var random_image_number = (Math.floor(Math.random() * 7) + 1);
  
  $("#intro").attr("class", "intro_image_" + random_image_number);
  $("#done_intro").attr("class", "intro_image_" + random_image_number);
  
  $("#enter_button").click(function(event) {
    event.preventDefault();
    enter_button_allowed = false;
    $(this).animate({ opacity: 'hide' }, 150);
    // $("#intro").animate({ top: 227, bottom: 314, left: 142, right: 142 }, 550 * animation_slow_motion);
    //$("#intro").animate({ width: 950, height: 260, top: "50%", marginTop: -190 }, 550 * animation_slow_motion);
    $("#intro").animate({ width: 950, height: 260, top: "50%", marginTop: -170, left: '50%', marginLeft: -475 }, 550 * animation_slow_motion);
    
    $("#shadow_top").delay(500).animate({ opacity: 'show' }, 1000 * animation_slow_motion);
    $("#shadow_bottom").delay(500).animate({ opacity: 'show' }, 1000 * animation_slow_motion);
    
    $("#product_type_selection").delay(300).animate({ opacity: 'show' }, 800 * animation_slow_motion);
  });
  
  $("#container_inner").mouseenter(function(){
    if(enter_button_allowed != false){
      $("#enter_button").animate({ opacity: 'show' }, 250);
    }
  });
  
  $("#container_inner").mousemove(function(){
    if(enter_button_allowed != false){
      $("#enter_button").animate({ opacity: 'show' }, 250);
    }
  });
  
  $("#container_inner").mouseleave(function(){
    $("#enter_button").animate({ opacity: 'hide' }, 250);
  });
  
  
  
  
  var info_current_content_index   = 0
  var info_scrollable_things_count = $('.info_scroller .info_scroller_inner').size();

  $("#next_info").click(function(){
    info_current_content_index++;
    $(".info_scroller").animate({ left: (info_current_content_index%info_scrollable_things_count) * (-690) }, 250 * animation_slow_motion);
  });
  
  $("#previous_info").click(function(){
    info_current_content_index--;
    if(info_current_content_index < 0) {
      info_current_content_index = ($(".info_scroller .info_scroller_inner").size() - 1);
    }
    $(".info_scroller").animate({ left: (info_current_content_index%info_scrollable_things_count) * (-690) }, 250 * animation_slow_motion);
  });
  
  
  var current_content_index   = 0
  var scrollable_things_count = $('.scrollable .inner').size();

  $("#next").click(function(){
    current_content_index++;
    $(".scroller").animate({ left: (current_content_index%scrollable_things_count) * (-890) }, 250 * animation_slow_motion);
  });
  
  $("#previous").click(function(){
    current_content_index--;
    if(current_content_index < 0) {
      current_content_index = ($(".scroller .inner").size() - 1);
    }
    $(".scroller").animate({ left: (current_content_index%scrollable_things_count) * (-890) }, 250 * animation_slow_motion);
  });
  
  
  $("#hide_information").click(function(){
    $("#hide_information").animate({ opacity: 'hide' }, 250 * animation_slow_motion);
    $(".info_wrapper").delay(250 * animation_slow_motion).animate({ opacity: 'hide' }, 500 * animation_slow_motion);
    $("#previous_info").delay(250).animate({ opacity: 'hide' }, 250 * animation_slow_motion);
    $("#next_info").delay(250).animate({ opacity: 'hide' }, 250 * animation_slow_motion);
    
  });
  
  $("#show_information").click(function(){
    $(".info_wrapper").animate({ opacity: 'show' }, 250 * animation_slow_motion);
    $("#hide_information").animate({ opacity: 'show' }, 250 * animation_slow_motion);
    $("#previous_info").delay(250).animate({ opacity: 'show' }, 250 * animation_slow_motion);
    $("#next_info").delay(250).animate({ opacity: 'show' }, 250 * animation_slow_motion);
  });
  
  
  $("a#show_information").delay(250).animate({ width: 60, height: 45 }, 250 * animation_slow_motion);
  
  
  
  
  
  $("#tubenseife_14").click(function(){
    $(".tube_14_photo").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
    $("#back_to_overview").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
  });
  
  $("#tubenseife_15").click(function(){
    $(".tube_15_photo").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
    $("#back_to_overview").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
  });
  
  $("#tubenseife_17").click(function(){
    $(".tube_17_photo").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
    $("#back_to_overview").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
  });
  
  $("#tubenseife_18").click(function(){
    $(".tube_18_photo").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
    $("#back_to_overview").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
  });
  
  
  $(".tube_14_photo").toggle(
    function(){
      $(".tube_14_photo").animate({ right: 280 }, 450 * animation_slow_motion);
      $(".tube_14_details").animate({ opacity: 'show', width: 280 }, 450 * animation_slow_motion);
    },
    function(){
      $(".tube_14_photo").animate({ right: 0 }, 450 * animation_slow_motion);
      $(".tube_14_details").animate({ opacity: 'hide', width: 0 }, 450 * animation_slow_motion);
    }
  );
  
  $(".tube_15_photo").toggle(
    function(){
      $(".tube_15_photo").animate({ right: 280 }, 450 * animation_slow_motion);
      $(".tube_15_details").animate({ opacity: 'show', width: 280 }, 450 * animation_slow_motion);
    },
    function(){
      $(".tube_15_photo").animate({ right: 0 }, 450 * animation_slow_motion);
      $(".tube_15_details").animate({ opacity: 'hide', width: 280 }, 450 * animation_slow_motion);
    }
  );
  
  $(".tube_17_photo").toggle(
    function(){
      $(".tube_17_photo").animate({ right: 280 }, 450 * animation_slow_motion);
      $(".tube_17_details").animate({ opacity: 'show', width: 280 }, 450 * animation_slow_motion);
    },
    function(){
      $(".tube_17_photo").animate({ right: 0 }, 450 * animation_slow_motion);
      $(".tube_17_details").animate({ opacity: 'hide', width: 280 }, 450 * animation_slow_motion);
    }
  );
  
  $(".tube_18_photo").toggle(
    function(){
      $(".tube_18_photo").animate({ right: 280 }, 450 * animation_slow_motion);
      $(".tube_18_details").animate({ opacity: 'show', width: 280 }, 450 * animation_slow_motion);
    },
    function(){
      $(".tube_18_photo").animate({ right: 0 }, 450 * animation_slow_motion);
      $(".tube_18_details").animate({ opacity: 'hide', width: 280 }, 450 * animation_slow_motion);
    }
  );
  
  
  
  
  
  $("#massagekerze_24").click(function(){
    $(".kerze_24_photo").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
    $("#back_to_overview").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
  });

  $("#massagekerze_25").click(function(){
    $(".kerze_25_photo").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
    $("#back_to_overview").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
  });

  $("#massagekerze_27").click(function(){
    $(".kerze_27_photo").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
    $("#back_to_overview").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
  });

  $("#massagekerze_28").click(function(){
    $(".kerze_28_photo").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
    $("#back_to_overview").delay(300).animate({ opacity: 'show' }, 450 * animation_slow_motion);
  });


  $(".kerze_24_photo").toggle(
    function(){
      $(".kerze_24_photo").animate({ right: 280 }, 450 * animation_slow_motion);
      $(".kerze_24_details").animate({ opacity: 'show', width: 280 }, 450 * animation_slow_motion);
    },
    function(){
      $(".kerze_24_photo").animate({ right: 0 }, 450 * animation_slow_motion);
      $(".kerze_24_details").animate({ opacity: 'hide', width: 0 }, 450 * animation_slow_motion);
    }
  );

  $(".kerze_25_photo").toggle(
    function(){
      $(".kerze_25_photo").animate({ right: 280 }, 450 * animation_slow_motion);
      $(".kerze_25_details").animate({ opacity: 'show', width: 280 }, 450 * animation_slow_motion);
    },
    function(){
      $(".kerze_15_photo").animate({ right: 0 }, 450 * animation_slow_motion);
      $(".kerze_15_details").animate({ opacity: 'hide', width: 280 }, 450 * animation_slow_motion);
    }
  );

  $(".kerze_27_photo").toggle(
    function(){
      $(".kerze_27_photo").animate({ right: 280 }, 450 * animation_slow_motion);
      $(".kerze_27_details").animate({ opacity: 'show', width: 280 }, 450 * animation_slow_motion);
    },
    function(){
      $(".kerze_27_photo").animate({ right: 0 }, 450 * animation_slow_motion);
      $(".kerze_27_details").animate({ opacity: 'hide', width: 280 }, 450 * animation_slow_motion);
    }
  );

  $(".kerze_28_photo").toggle(
    function(){
      $(".kerze_28_photo").animate({ right: 280 }, 450 * animation_slow_motion);
      $(".kerze_28_details").animate({ opacity: 'show', width: 280 }, 450 * animation_slow_motion);
    },
    function(){
      $(".kerze_28_photo").animate({ right: 0 }, 450 * animation_slow_motion);
      $(".kerze_28_details").animate({ opacity: 'hide', width: 280 }, 450 * animation_slow_motion);
    }
  );
  
  $(".product_photo").mousemove(function(e){
    var x = e.pageX - this.offsetLeft;
    var y = e.pageY - this.offsetTop;
    var view_port_width  = $(".product_photo").width();
    var view_port_inner_width  = $(".product_photo_inner", this).width();
    
    var product_photo_inner = 100;
    product_photo_inner_factor = ((product_photo_inner - view_port_width)/view_port_width)*-1;
    $(".product_photo_inner").css("background-position", ((x*product_photo_inner_factor))-250 + "px bottom");
    
    var product_photo = 1800;
    product_photo_factor = ((product_photo - view_port_width)/view_port_width)*-1;
    $(".product_photo").css("background-position", 0-250+((x*product_photo_factor)) + "px center");
    
    var hose = view_port_inner_width-120;
    hose_factor = ((hose - view_port_inner_width)/view_port_inner_width)*-1;
    $(".hose").css("background-position", x*hose_factor + "px bottom");
    
    var lamp = view_port_inner_width-120;
    lamp_factor = ((lamp - view_port_inner_width)/view_port_inner_width)*-1;
    $(".lamp").css("background-position", ((x*lamp_factor)) + "px bottom");
  });
  
  
  
  
  $(".toggle_description_and_ingredients").toggle(
    function(){
      $(".description").animate({ opacity: 'hide' }, 250 * animation_slow_motion);
      $(".ingredients_label").animate({ opacity: 'hide' }, 250 * animation_slow_motion);
      $(".description_label").delay(250 * animation_slow_motion).animate({ opacity: 'show' }, 250 * animation_slow_motion);
      $(".ingredients").delay(250 * animation_slow_motion).animate({ opacity: 'show' }, 250 * animation_slow_motion);
    },
    function(){
      $(".ingredients").animate({ opacity: 'hide' }, 250 * animation_slow_motion);
      $(".description_label").animate({ opacity: 'hide' }, 250 * animation_slow_motion);
      $(".ingredients_label").delay(250 * animation_slow_motion).animate({ opacity: 'show' }, 250 * animation_slow_motion);
      $(".description").delay(250 * animation_slow_motion).animate({ opacity: 'show' }, 250 * animation_slow_motion);
    }
  );
  
  
});

Cufon.replace('#breadcrumb a');
Cufon.replace('#foot_links a');
Cufon.replace('h2');
Cufon.replace('h3');
Cufon.replace('p');
Cufon.replace('.errors');
Cufon.replace('span.label');
Cufon.replace('.tubenseife_element', { hover: true }, { fontFamily: 'FilosofiaGrand' });
Cufon.replace('.massagekerze_element', { hover: true }, { fontFamily: 'FilosofiaGrand' });
