/* ########################### scroll efect ################################# */
function scroll_to(id){
    var href=id;
    $('html, body').animate({
    scrollTop: $('#'+href).offset().top
    }, 1000);
    return false;
}

function loadInFrame(URL) {
    var pageFrame = document.getElementById('TB_iframeContent');
    pageFrame.src = URL; 
    pageFrame.style.height = '600px';
    pageFrame.style.width = '895px';
}

$(function() {

/* ########################### home projects hover-efect ####################### */
  $(".proj-box").hover(function(){
        var id = $(this).attr("id");
        $("#"+id+" img.off").show();
        $("#"+id+" img.on").hide();
  },
  function(){
    var id = $(this).attr("id");
        $("#"+id+" img.on").show();
        $("#"+id+" img.off").hide();
  });

/* ########################### change modeles menu ####################### */
  $(".type-habitation-menu li").click(function(){
    $(".type-habitation-menu li").removeClass("active");
    $(this).addClass("active");
  });

/* ########################### change modeles details ####################### */
  $(".type-habitation-menu li a").hover(function(){
    var href=$(this).attr("href");
    id="#info_"+href.substring(1);
    id_list="#details_"+href.substring(1);
    $("div.details p.info").hide();
    $("div.details ul.details-list").hide();
    $(id).show();
    $(id_list).show();
  },
  function(){
    var href=$(".type-habitation-menu li.active a").attr("href");
    id="#info_"+href.substring(1);
    id_list="#details_"+href.substring(1);
    $("div.details p.info").hide();
    $("div.details ul.details-list").hide();
    $(id).show();
    $(id_list).show();
  });

/* ########################### scroll efect ################################# */
  $(".separator a.go-up").click(function(){
    $('html, body').animate({
    scrollTop: $("#header").offset().top
    }, 1000);
  });

/* ########################### home slider ################################# */
  $("#main-content a.next").click(function(){
    var boxes_in_sight = 4;
    var boxes = $("#project-slider> div.proj-box").length;
    var box_width = $("div.proj-box").css("width");
    box_width = box_width.substring(0,(box_width.length - 2));
    var position = $("#project-slider").css("left");
    if(position=='auto'){
        position = 0;
    }
    else{
        position = position.substring(0,(position.length - 2));
    }
    if(boxes > boxes_in_sight)
    {
      if(position < -(box_width * boxes) + (box_width * (boxes_in_sight+1)-1))
      {
          $("#project-slider").animate({
            left: 0+"px"
        }, 500 );
      }
      else
      {
          $("#project-slider").animate({
            left: ((position * 1) - (box_width * 1))+"px"
        }, 500 );
      }
    }
    return false;
  });

  $("#main-content a.prev").click(function(){
    var boxes_in_sight = 4;
    var boxes = $("#project-slider> div.proj-box").length;
    var box_width = $("div.proj-box").css("width");
    box_width = box_width.substring(0,(box_width.length - 2));
    var position = $("#project-slider").css("left");
    if(position=='auto'){
        position = 0;
    }
    else{
        position = position.substring(0,(position.length - 2));
    }
    if(boxes > boxes_in_sight)
    {
      if(position > -1)
      {
        $("#project-slider").animate({
            left: "-"+((box_width * boxes) - (box_width * 4))+"px"
        }, 500 );
      }
      else
      {
        $("#project-slider").animate({
            left: (position * 1 + box_width * 1)+"px"
        }, 500 );
      }
    }
    return false;
  });
  
  /* ########################### galerie slider change ################################# */
  $(".thickbox-project .galerie-photo #information a").click(function(){
    $(".thickbox-project .galerie-photo #information a").removeClass("active");
    $(this).addClass("active");
    $(".thickbox-project .galerie-photo .slider-wrapper #project-slider").hide();
    $(".thickbox-project .galerie-photo .slider-wrapper div."+$(this).attr("href").substring(1)).show();
    $(".galerie-photo a.next").attr("href",$(this).attr("href"));
    $(".galerie-photo a.prev").attr("href",$(this).attr("href"));
  });
  
  /* ########################### galerie slider ################################# */
  $(".galerie-photo a.next").click(function(){
    var slide = $(".galerie-photo a.next").attr("href").substring(1);
    var boxes_in_sight = 3;
    var boxes = $("#project-slider."+slide+"> div.proj-box").length;
    var box_width = $("div.proj-box").css("width");
    box_width = box_width.substring(0,(box_width.length - 2));
    box_width = (box_width * 1) + (23 * 1);
    var position = $("#project-slider."+slide).css("left");
    if(position=='auto'){
        position = 0;
    }
    else{
        position = position.substring(0,(position.length - 2));
    }
    if(boxes > boxes_in_sight)
    {
      if(position < -(box_width * boxes) + (box_width * (boxes_in_sight+1)-1))
      {
          $("#project-slider."+slide).animate({
            left: 0+"px"
        }, 500 );
      }
      else
      {
          $("#project-slider."+slide).animate({
            left: ((position * 1) - (box_width * 1))+"px"
        }, 500 );
      }
    }
    return false;
  });

  $(".galerie-photo a.prev").click(function(){
    var slide = $(".galerie-photo a.prev").attr("href").substring(1);
    var boxes_in_sight = 3;
    var boxes = $("#project-slider."+slide+"> div.proj-box").length;
    var box_width = $("div.proj-box").css("width");
    box_width = box_width.substring(0,(box_width.length - 2));
    box_width = (box_width * 1) + (23 * 1);
    var position = $("#project-slider."+slide).css("left");
    if(position=='auto'){
        position = 0;
    }
    else{
        position = position.substring(0,(position.length - 2));
    }
    if(boxes > boxes_in_sight)
    {
      if(position > -1)
      {
        $("#project-slider."+slide).animate({
            left: "-"+((box_width * boxes) - (box_width * 4))+"px"
        }, 500 );
      }
      else
      {
        $("#project-slider."+slide).animate({
            left: (position * 1 + box_width * 1)+"px"
        }, 500 );
      }
    }
    return false;
  });

  /* ########################### realisations slider ################################# */
  $(".realisation .pictures-slider a.a-next").click(function(){
    var boxes_in_sight = 3;
    var boxes = $("#pictures-slider> div").length;
    var box_width = $("#pictures-slider div").css("width");
    box_width = box_width.substring(0,(box_width.length - 2));
    box_width = (box_width * 1) + (5 * 1);
    var position = $("#pictures-slider").css("left");
    if(position=='auto'){
        position = 0;
    }
    else{
        position = position.substring(0,(position.length - 2));
    }
    if(boxes > boxes_in_sight)
    {
      if(position < -(box_width * boxes) + (box_width * (boxes_in_sight+1)-1))
      {
          $("#pictures-slider").animate({
            left: 0+"px"
        }, 500 );
      }
      else
      {
          $("#pictures-slider").animate({
            left: ((position * 1) - (box_width * 1))+"px"
        }, 500 );
      }
    }
    return false;
  });

  $(".realisation .pictures-slider a.a-prev").click(function(){
    var boxes_in_sight = 3;
    var boxes = $("#pictures-slider> div").length;
    var box_width = $("#pictures-slider div").css("width");
    box_width = box_width.substring(0,(box_width.length - 2));
    box_width = (box_width * 1) + (5 * 1);
    var position = $("#pictures-slider").css("left");
    if(position=='auto'){
        position = 0;
    }
    else{
        position = position.substring(0,(position.length - 2));
    }
    if(boxes > boxes_in_sight)
    {
      if(position > -1)
      {
        $("#pictures-slider").animate({
            left: "-"+((box_width * boxes) - (box_width * 3))+"px"
        }, 500 );
      }
      else
      {
        $("#pictures-slider").animate({
            left: (position * 1 + box_width * 1)+"px"
        }, 500 );
      }
    }
    return false;
  });  
});
