function global_functions() {
  $(function() {
    // Posun hore
    $('.a-top, .topper').click(function() {
      $(document).scrollTo(0, 2000); 
      return false;
    });
    // Posun na akcie
    $('.action-scroll').click(function() {
      $(document).scrollTo( "#action-h3", 2000); 
      return false;
    });
    // Posun na sluzby
    $('.services-scroll').click(function() {
      $(document).scrollTo( "#services-h3", 2000); 
      return false;
    });
    // Posun na kontakt
    $('.contact-scroll').click(function() {
      $(document).scrollTo( "#contact-h3", 2000); 
      return false;
    });
    // Scroller na referenciach
    $('.ul_scroller').hoverscroll({
    	vertical: true,	// Display the list vertically or horizontally      	
    	width:    '100%',		// Width of the list container
    	height:   '370px',		// Height of the list container      	
    	arrows:   true,		// Display direction indicator arrows or not
    	arrowsOpacity: 0.95,	// Max possible opacity of the arrows      	
    	debug: false		// Debug output in the firebug console
    });
    // Autoclear
    $('.autoclear').autoclear();    
  });
};

function send_form() {
  $(function() {
    $('#contact_form').submit(function() {
      $("#contact_form").validate({
        rules: {
  				first_name: {	required: true },
  				second_name: { required: true },
  				subject: { required: true },
  				email: { required: true },
  				text: {	required: true },
  				secure: { required: true }
  			},
  			messages: {
  				first_name: {	required: " " },
  				second_name: { required: " " },
  				subject: { required: " " },
  				email: { required: " ", email:" " },
  				text: {	required: " " },
  				secure: { required: " " }
  			}
      });          
      return false;
    });  
    // Odosielanie formu
    $('#contact_form').submit(function() {
      if( $("#contact_form").valid() ) {
        $.ajax({
          url: "/js/ajax/email.ajax.php",
          type: "POST",
          dataType: "html",
          data: ({
                  meno : $("#first_name").val(),
                  priezvisko : $("#second_name").val(),                    
                  email : $("#email").val(),
                  predmet : $("#subject").val(),
                  text : $("#text").val(),
                  send : "send"
              }),
          success: function(msg) {
            contact_formF.hide(msg);
          }
        });
        return false;
      }
      return false;
    });
    return false;
  });
};

// plati pre newsletter, skryva a zobrazuje ten formular a vypisuje hlasky
var contact_formF = {
  show: function() {
    $("#contact_form").clearForm(); // zmazanie formu
    $("#first_name").val( "meno / first name" );
    $("#second_name").val( "priezvisko / second name" );
    $("#email").val( "email / email" );
    $("#subject").val( "predmet / subject" );
    $("#text").val( "text / text" ); 
    $("#secure").val( "overovací kód / verify code" );   
    $("#response").fadeOut("slow");
    $("#contact_form").fadeIn("slow");
  },
  hide: function(msg) {
    $("#contact_form").fadeOut("slow");
    $("#response").html(msg).fadeIn("slow").show();
    setTimeout( "contact_formF.show()" , 3000 );
  }
};

// Odoslat znamemu FORM
function send_friend_form( reference ) {
  $(function() {
    // skrývanie a zobrazovanie formu
    $('#friends_form').hide(); // defaultne skryty
    
    $("#open_friend_form").click(function() { // Po kliknuti sa bud zobrazi alebo skryje
      if ($("#friends_form").is(":hidden")) {
        $("#friends_form").slideDown("slow");
        $(this).html('Zatvoriť odoslať známemu / Close send to friend');
      } else {
        $("#friends_form").slideUp("slow");
        $(this).html('Odoslať známemu / Send to friend');
      }
      return false;
    });    
    
    $('#friends_form').submit(function() {
      $("#friends_form").validate({
        rules: {
  				friend_name: {	required: true },
  				friend_text: { required: true },
  				friend_emailFriend: { required: true },
  				friend_email: { required: true },
  				secure2: { required: true }
  			},
  			messages: {
  				friend_name: {	required: " " },
  				friend_text: { required: " " },
  				friend_emailFriend: { required: " ", email:" " },
  				friend_email: {	required: " ", email:" " },
  				secure2: { required: " " }
  			}
      });          
      return false;
    });  
    // Odosielanie formu
    $('#friends_form').submit(function() {
      if( $("#friends_form").valid() ) {
        $.ajax({
          url: "/js/ajax/email_friend.ajax.php",
          type: "POST",
          dataType: "html",
          data: ({
                  meno : $("#friend_name").val(),               
                  predmet : $("#friend_text").val(),
                  email : $("#friend_email").val(),                  
                  friend_email : $("#friend_emailFriend").val(),
                  odkaz: reference,
                  send : "send"
              }),
              success: function(msg) {
                friend_formF.hide(msg);
              }
        });
        return false;
      }
    });
  });
};
// plati pre zaslanie emailu kamaratovy, skryva a zobrazuje ten formular a vypisuje hlasky
var friend_formF = {
  show: function() {
    $("#friends_form").clearForm(); // zmazanie formu
    $("#friend_name").val( "meno / first name" );
    $("#friend_text").val( "predmet / subject" );
    $("#friend_emailFriend").val( "email / email" );
    $("#friend_email").val( "email kamaráta / email friend" );
    $("#secure2").val( "overovací kód / verify code" );   
    $("#response_friend").fadeOut("slow");
    $("#friends_form").hide();
    $("#open_friend_form").html('Odoslať známemu / Send friend');
  },
  hide: function(msg) {
    $("#friends_form").fadeOut("slow");
    $("#response_friend").html(msg).fadeIn("slow").show();
    setTimeout( "friend_formF.show()" , 3000 );
  }
}

function fancybox() {
  $(function() {
   // Vstupujem na referenciu a zobrazim overlay
   $("a.fancy").mouseenter(function() {
     var docHeight = '100px';  
     $(this).append("<div class='overlay'></div>");
  
     $(".overlay")
        .height(docHeight)
        .css({
           'opacity': 0.93,
           'position': 'absolute',
           'background-color': '#60A1AC',
           'top': '-5px',
           'left': '-5px',
           'width': '100%',
           'z-index': 500000
        })
        .html( $(this).next().html() );
    });
    
    // Ked z referencie odidem, tak mi zmaze overlay, aby to nesekalo
    $("a.fancy").mouseleave(function() {
      $(".overlay").each(function() {
        $(this).remove();
      }) 
    });    
  });
}

// Ajaxový filter na referencie
function referencies_filter() {
  $(function() {
    $(".filter").click(function(){
      $.ajax({
        url: "/js/ajax/filter.ajax.php",
        type: "POST",
        dataType: "json",
        data: ({
          category : $(this).html()
        }),
        success: function(msg) {
          if( msg.response == 1 ){
            $(".ul_scroller").html(msg.text); 
            //alert(msg.text);
          }
        }
      });
      return false;
    });
  });
}

// zmazanie formu
function clearForm() {
  $.fn.clearForm = function() {
    return this.each(function() {
      var type = this.type, tag = this.tagName.toLowerCase();        
      if (tag == 'form')
       return $(':input',this).clearForm();
      if (type == 'text' || type == 'password' || tag == 'textarea')
       this.value = '';
      else if (type == 'checkbox' || type == 'radio')
       this.checked = false;
      else if (tag == 'select')
       this.selectedIndex = -1;
      }
    );
  };    
}
