Cufon.replace('.cufon');
Cufon.replace('.cena');

var title = "";

$(function() {
  if($('#rotate').length) {
    $('#rotate').nivoSlider({
	effect:'sliceDown',
	slices:15,
	animSpeed:500,
	pauseTime:9000,
	startSlide:0,
	directionNav:false,
	directionNavHide:false,
	controlNav:true,
	keyboardNav:true,
	pauseOnHover:true,
	beforeChange: function() { 
	   $('#desc').animate({ width: "0", paddingLeft: "0", paddingRight: "0" }, 200);
	},
	afterChange: function() {
	    $('#desc').animate({ width: 0 }, 2000, function() {
	       $('#desc').animate({ width: "648px", paddingLeft: "12px", paddingRight: "12px" }, 500);
	    });
	    var curSlide = $("#rotate .nivo-imageLink").eq($('#rotate').data('nivo:vars').currentSlide);
	    $('#desc').html("<strong>" + curSlide.find("img").attr("alt") + "</strong>").append('<br/>' + curSlide.attr("title")); 
	}
    });
  }
});
  
$(document).ready(function() {
  if($('#rotate').length) {
    $('#rotate').append($('#desc'));
    var curSlide = $("#rotate .nivo-imageLink").eq($('#rotate').data('nivo:vars').currentSlide);
    $('#desc').html("<strong>" + curSlide.find("img").attr("alt") + "</strong>").append('<br/>' + curSlide.attr("title"));
  
    if($.browser.msie) {
      $('#rotate .nivo-controlNav a:last').css({ "margin-right" : "3px" });
    }
    $('#rotate .nivo-controlNav a:first').css({ "margin-left" : "-10px" }).before("<span></span>");
    if($.browser.msie && $.browser.version<=8) {
      $('#rotate .nivo-controlNav a:first').css({ "position":"absolute", "margin-left" : "-28px" });
      $('#rotate .nivo-controlNav span').css({ "margin-right" : "18px" });
    }
    $('#rotate .nivo-imageLink, #rotate .nivo-caption').hover(function () {
      title = this.title;
      this.title = "";
      $('#desc').fadeOut(800);
    },function () {
      this.title = title;
      $('#desc').fadeIn(800);
    });
  } else {
    if(!$.browser.msie) {
      $('#refwrapper2 cite').css("opacity","0");
      $('#refwrapper2 cite').animate({ opacity: "1" }, 1000);
    }
  }
  
  var mailn = "info";
  var maild = "kvalitnikod.cz";
  $('label.email').next().attr("href", "mailto:" + mailn + "@" + maild).text(mailn + "@" + maild);
  
  $('#menu li:first a').hover(function () {
    $('#menu ul').css({ "backgroundPosition" : "0 -106px" });
  },function () {
    $('#menu ul').css({ "backgroundPosition" : "0 0" });
  });
  $('#menu li:last a').hover(function () {
    $('#menu').css({ "backgroundPosition" : "right -141px" });
  },function () {
    $('#menu').css({ "backgroundPosition" : "right -35px" });
  });
  
  $("#content .sluzby").mouseover(function() {
    $(this).css("border-color","#e6e6e6");
  }).mouseout(function(){
    $(this).attr("style","");
  });
  
});

function checkFields(arr) {
  // KONTROLUJE POLE FORMULARU (CROSSBROWSER)
  // object:notEmpty | :mail | :phone | :shouldMail
  var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
  var emailExp2 = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4},?.*$/;
  var phoneExp = /^[ 0-9\.\+\/\-]{8,}$/;
  var pass;
  var ok = 0;
  var arl = arr.length;
  for(ar=0; ar<arl; ar++) {
     pass = false;
     var pie = arr[ar].split(':');
     var elm = document.getElementById(pie[0]);
     if(elm!=null) {
        if(pie[1]=="notEmpty") {
          if(elm.value.length > 0) {
             pass = true;
             ok+=1;
          }
        }
        else if(pie[1]=="mail") {
          if(elm.value.match(emailExp)) {
             pass = true;
             ok+=1;
          }
        }
        else if(pie[1]=="mailField") {
          if(elm.value.match(emailExp2)) {
             pass = true;
             ok+=1;
          }
        }
        else if(pie[1]=="shouldMail") {
          if(elm.value.length==0 || elm.value.match(emailExp)) {
             pass = true;
             ok+=1;
          }
        }
        else if(pie[1]=="phone") {
          if(elm.value.match(phoneExp)) {
             pass = true;
             ok+=1;
          }
        }
        if(pass==true) {
           elm.setAttribute("style","");
        } else {
           elm.focus();
           elm.style.border = "1px solid #ff0000";
        }
     }
  }
  if(ok==arl) {
     return true;
  } else {
     return false;
  }
}
