/*==============================================================================
 JavaScript Document // EDVENS MEDIA s.r.o. // revize 0.6

# CONTENT OF JS
-------------------------
01. jQuery: Initialize library
02. jQuery - function: FancyBox
03. jQuery - function: Animated Scrolling for Same-Page Links
04. jQuery - function: Ajax Send Form Contact
==============================================================================*/

/* Initialize jQuery Library
==============================================================================*/
jQuery.noConflict();
jQuery(document).ready(function() {

  /* jQuery - function: FancyBox (http://fancy.klade.lv/howto)
  ============================================================================*/
  jQuery("a.lightbox").fancybox({
    'zoomSpeedIn':	1000,
    'zoomSpeedOut':	1000,
    'overlayShow':	true
  });
	jQuery("a.flash").fancybox({
    'zoomSpeedIn':	1000,
    'zoomSpeedOut':	1000,
    'frameWidth': 480,
    'frameHeight': 290,
		'hideOnContentClick': false
	});


  /* jQuery - function: Animated Scrolling for Same-Page Links
  ============================================================================*/
  function filter(string) {
    return string
      .replace(/^\//,'')
      .replace(/(index|default)\.[a-zA-Z]{3,4}$/,'')
      .replace(/\/$/,'')
  }
  jQuery('a[href*=#]:not([href*=#vid])').each(function() {
    if (filter(location.pathname) == filter(this.pathname)
    && location.hostname == this.hostname
  	&& this.hash.replace(/#/,'') ) {
      var $targetId = jQuery(this.hash), $targetAnchor = jQuery('[name=' + this.hash.slice(1) +']');
      var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
      if ($target) {
        var targetOffset = $target.offset().top;
        jQuery(this).click(function() {
          jQuery('html, body').animate({scrollTop: targetOffset}, 400);
  	      return false;
  	    });
      }
    }
  });

  /* jQuery - function: Ajax Send Form Contact
  ============================================================================*/
  jQuery('#form form').attr({action: "./"});
  jQuery('#form form').attr({method: "post"});
  jQuery('#form input.button').click(function()
  {
    var jmeno   = jQuery("#form input#name").val();
    var email   = jQuery("#form input#mail").val();
    var zprava  = jQuery("#form textarea#message").val();
    if ((jmeno=="")||(email=="")||(zprava=="")) { alert('Je potřeba vyplnit všechna políčka.'); }
    else
    {
      jQuery.ajax({
        type: "POST",
        url: "./",
        data: "jmeno=" + jmeno + "&email=" + email + "&zprava=" + zprava + "&phpmailer=",
        success: function(msg){
          if (msg.substr(0,1)=="1")
          { // uspesne odeslano, proto vymazeme kolonky
            jQuery("input#name").val("");
            jQuery("input#mail").val("");
            jQuery("textarea#message").val("");
          }
          jQuery("#mail-status").text( msg.substr(1) );
        }
      });
    }
    return false;
  });

});
