/* thanks, jquery easing plugin */

jQuery.extend( jQuery.easing,
{
  easeInOutExpo: function (x, t, b, c, d) {
    if (t==0) return b;
    if (t==d) return b+c;
    if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
    return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
  }

});



$(document).ready(function() {

  /* hide search */

  $(".search input[type=text]").focus(function(){ this.value = ""; });


  /* sub-menu-dropdown*/
  
  

  if ( $.browser.msie && $.browser.version < 9 ) {


  } else {

    $(".dropdown").each(function(){
      $(this).append("<div class='arrow'></div>");
    });

  }

  $(".sub-navi li").mouseover(function(){

   $(".dropdown", this).stop().fadeTo(200,1); 
  
  }).mouseout(function(){
  
   $(".dropdown", this).stop().fadeOut(200); 

  });
  
  
  /* slide */
  
  /*

  function changeSlide(){
    
    var newSlide = $(".slide:first").html();
  
    $(".slideshow_container").animate({ left: "-=940px" }, 1800, "easeInOutExpo", function(){
      $(".slideshow_container").append("<div class='slide'>" + newSlide +"</div>");
      $(".slide:first").remove();
      $(".slideshow_container").css("left", "0px");
    });
     
    return false;
  }
  
  setInterval(changeSlide, 8000);

  */
  
    $(".slideshow_container").empty();

  var slide_no = Math.ceil(3*Math.random())

  i=0;
  while(i<=2){
    if(slide_no == 3){ slide_no = 1 } else { slide_no++; }
    $(".slideshow_container").append('<div class="slide slide'+slide_no+'"><a href=""><img src="/templates/consti/images/slide'+slide_no+'.png" alt=""/></a></div>');
    i++;
  }

  function changeSlide(){
    
    var newSlide = $(".slide:first").html();
  
    $(".slideshow_container").animate({ left: "-=940px" }, 1800, "easeInOutExpo", function(){
      $(".slideshow_container").append("<div class='slide'>" + newSlide +"</div>");
      $(".slide:first").remove();
      $(".slideshow_container").css("left", "0px");
    });
     
    return false;
  }
  
  setInterval(changeSlide, 8000);
  
  
  
  $('div.thumbs a').fancybox();  

  /* map pins */
  
/*
  $(".map-pin").hover(function(){
    $(".place", this).toggle(100);
  });

  $(".toggle-contact").click(function(){
    $(this).next(".contact").slideToggle(200);
    return false;
  }); */
  
/*  $(".company").hover(function(){
    var target = $(this).attr("id");
    $("#" + target + "-pin").toggleClass("active");
    $("#" + target + "-pin .place").toggle(100);
    $(".pin", this).toggleClass("active");
  });
  
  $(".map-pin").hover(function(){
    var target = $(this).attr("id");
    target = target.split("-")[0];
    $("#" + target + " .pin").toggleClass("active");
    $(this).toggleClass("active");
    $(".place", this).toggle(100);
  });
  
  $(".toggle-contact").click(function(){
    $(this).next(".contact").slideToggle(200);
    return false;
  }); */ 

  $('#pagerNeeded').pager('dl');

$("#kartta a").mouseenter(function(){
  $("span", this).stop().fadeTo(200,1);
}).mouseleave(function(){
  if(!$(this).hasClass("active")){
    $("span", this).stop().fadeTo(200,0, function(){ $(this).fadeOut(0); });
  }
}).click(function(){
  $("#kartta a").removeClass("active");
  var active = $(this).attr("class");
  $(".places li a").removeClass("active");
  $(".places ."+active).addClass("active");
  $(this).addClass("active");
  $("#kartta a").each(function(){
    if(!$(this).hasClass("active")){ $("span", this).fadeOut(200); }
  });
  var target = $(this).attr("href");
  $("#yhteys .hide").hide(); 
  $("#yhteys .first").hide();
  $(target).show();
  return false;
});

$(".places li a, p.place a").click(function(){
  var active = $(this).attr("class");
  $("#kartta ."+active).trigger("click");
  $("#kartta a.active span").stop().fadeTo(200,1);
  $("#kartta .pointer").each(function(){
    if(!$(this).hasClass("active")){ $("span", this).fadeOut(200); }
  });
  return false;
});

$(".placereset").click(function(){
  $('#yhteys').children().hide().end().children('.first').show();
  
  $("#kartta a").removeClass("active");
  $(".places li a").removeClass("active");
  
  $("#kartta a").each(function(){
    if(!$(this).hasClass("active")){ $("span", this).fadeOut(200); }
  });
  
  return false;
});

/* references */
var height = 0;
  $(".references_page").each(function() {
  height = ($(this).height() > height) ? $(this).height() : height;
});

$(".references_page, .references_spacer, .references_spacer_yrityksille").css('height',height+'px');
$(".references_main, .references").css('height',(height+20)+'px');

$(".scrollable_main").scrollable({
  circular: "true",
  items: ".references_page",
  next: ".references_next",
  prev: ".references_prev"
}).navigator({
  navi: ".references_navi"
});

$(".scrollable").scrollable({
  circular: "true",
  items: ".references_page",
  next: ".references_next",
  prev: ".references_prev"
}).navigator({
  navi: ".references_navi"
});


});

function relocate(url) {
  if(url != 'null') {
    window.location.href = url;
  }
}
