function cufon() { // cufon replacing
 Cufon.replace('.menu a, .hp-text',{hover: true, fontFamily: 'Museo500'});
 Cufon.replace('.btn-1, h1, #refs a.a-ref strong, .btn-3, .btn-5, #menu-1 li a',{hover: true, fontFamily: 'Museo700'});
 Cufon.replace('#awards h2, #people h2, h2.main-h2, .ref h3',{fontFamily: 'Museo700'});
 Cufon.replace('#offer-content h1, #offer-content big',{fontFamily: 'Museo500'});
 if (!$.browser.msie) { Cufon.replace('#rotate big',{fontFamily: 'Museo500'}); }
}

function menu() { // menu click
 $(".menu li a").click(function() {
  $(".menu li a").removeClass();
  $(this).addClass("act");
 });
}

function fancy() { // fancybox
 if ($("a[rel^='fancybox']").length != 0) $("a[rel^='fancybox']").fancybox({
  overlayColor: "#000",
  overlayOpacity: 0.8,
  titlePosition: 'inside'
 });
}

function menu2() { // menu-2 active
 $("#menu-2 li.act a").append('<span></span>');
}

function rotator() { // hp rotator init
 $('ul#rotate li').css({opacity: 0.0});
 $('ul#rotate li:first').addClass('show').css({opacity: 1.0});
 setInterval('rotate()',5000);
}

function rotate() { // hp rotator
 var current = ($('ul#rotate li.show')?  $('ul#rotate li.show') : $('ul#rotate li:first'));
 var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('ul#rotate li:first') :current.next()) : $('ul#rotate li:first'));
 next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 500);
 current.animate({opacity: 0.0}, 500).removeClass('show');
}

function animat() { // anchor scrolling init
 $(".menu.anim a, a.logo-footer, a.btn-2, a.btn-3, a.btn-1").anchorAnimate(); // odebrano a.btn-5 
}

jQuery.fn.anchorAnimate = function(settings) { // anchor scrolling
 settings = jQuery.extend({ speed: 500 }, settings);
 return this.each(function(){
  var caller = this
  $(caller).click(function (event) {
   event.preventDefault()
   var locationHref = window.location.href
   var elementClick = $(caller).attr("href")
   var destination = $(elementClick).offset().top;
   $("html,body").animate({ scrollTop: destination}, settings.speed, function() {
    window.location.hash = elementClick
   });
   return false;
  })
 })
}

function openRef(i) { // open portfolio window
 $("#ref-"+i).css({display: "block"});
}

function closeRef() { // close portfolio window
 $(".ref span").hover(
  function () {
   $(this).addClass('hover');
  }, function () {
   $(this).removeClass('hover');
  }
 );
 $(".ref span").click(function() {
  $(".ref").css({display: "none"});
 });
}

function inputFocus() {
 $('.inp').focus(function() { if (this.value==this.defaultValue) this.value=""; });
 $('.inp').blur(function()  { if (this.value=="") this.value=this.defaultValue; });
 $('textarea').focus(function() { if (this.value==this.defaultValue) this.value=""; });
 $('textarea').blur(function()  { if (this.value=="") this.value=this.defaultValue; });
}

function buttonHover() { // button hover
 $(".btn-4").hover(
  function () {
   $(this).addClass('hover');
  }, function () {
   $(this).removeClass('hover');
  }
 );
}

$(document).ready(function() {
 cufon();
 fancy();
 menu();
 menu2();
 rotator();
 animat();
 closeRef();
 inputFocus();
 buttonHover();
});

$(document).keyup(function(e) {
 if (e.keyCode == 27) {
  $(".ref").css({display: "none"});
 }
});

