/*==============================================================================
 JavaScript Document // EDVENS MEDIA s.r.o. // revize 0.7

# 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
05. jQuery - function: Fade In/Out Header Images (http://malsup.com/jquery/cycle/)
==============================================================================*/

/* Initialize jQuery Library
==============================================================================*/
jQuery.noConflict();
jQuery(document).bind('jQuery', function(event, data) {

  // ---------------------------------------------------------------------------
  // Variable name 'data' is RESERVED ARRAY !!! for interact with internal 
  // JavaScripts within XHTML templates
  // for (i in data) { alert ('debug: ' + i + ' = ' + data[i]); }
  // ---------------------------------------------------------------------------

  /* jQuery - function: FancyBox (http://fancy.klade.lv/howto)
  ============================================================================*/
  jQuery('.fancy a').fancybox({
    'zoomSpeedIn':	1000,
    'zoomSpeedOut':	1000,
    'overlayShow':	true
  });
  jQuery(".object a").fancybox({
    'frameWidth' : 480,
    'frameHeight' : 290,
    'hideOnContentClick': false
  });
  jQuery("a.iframe").fancybox({
    'frameWidth' : 352,
    'frameHeight' : 288,
    'hideOnContentClick': false
  });
  jQuery('a.fancy').fancybox({
    'zoomSpeedIn':	1000,
    'zoomSpeedOut':	1000,
    'overlayShow':	true
  });

  /* 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*=#object])').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#odeslat').click(function() {
    var jmeno   = jQuery("#form input#vase-jmeno").val();
    var telefon = jQuery("#form input#telefon").val();
    var email   = jQuery("#form input#e-mail").val();
    var lX      = '';
    if (jQuery("#form input#2-luzkovy").is(':checked')) lX = lX + ' 2-lůžkový,';
    if (jQuery("#form input#3-luzkovy").is(':checked')) lX = lX + ' 3-lůžkový,';
    if (jQuery("#form input#4-luzkovy").is(':checked')) lX = lX + ' 4-lůžkový,';
    if (jQuery("#form input#5-luzkovy").is(':checked')) lX = lX + ' 5-lůžkový,';
    /*if (jQuery("#form input#snidane").is(':checked')) snidane = 'Ano';
    else*/ snidane = 'Ne';
    var pu      = jQuery("#form input#pocet-ubytovanych").val();
    var dpr     = jQuery("#form input#den-prijezdu").val();
    var doj     = jQuery("#form input#den-odjezdu").val();
    var vzkaz  = jQuery("#form textarea#vas-vzkaz").val();

    if ((jmeno=="")||(telefon=="")||(email=="")||(pu=="")||(dpr=="")||(doj=="")) { alert('Je potřeba vyplnit všechna políčka.'); }
    else
    {
      jQuery.ajax({
        type: "POST",
        url: "./",
        //data: "jmeno=" + encodeURIComponent(jmeno) + "&telefon=" + encodeURIComponent(telefon) + "&email=" + encodeURIComponent(email) + "&l2=" + l2 + "&l3=" + l3 + "&l4=" + l4 + "&pu=" + encodeURIComponent(pu) + "&dpr=" + encodeURIComponent(dpr) + "&doj=" + encodeURIComponent(doj) + "&vzkaz=" + encodeURIComponent(vzkaz) + "&phpmailer=",
        data: "jmeno=" + encodeURIComponent(jmeno) + "&telefon=" + encodeURIComponent(telefon) + "&email=" + encodeURIComponent(email) + "&lX=" + lX + "&snidane=" + snidane + "&pu=" + encodeURIComponent(pu) + "&dpr=" + encodeURIComponent(dpr) + "&doj=" + encodeURIComponent(doj) + "&vzkaz=" + encodeURIComponent(vzkaz) + "&phpmailer=",
        success: function(msg){
          if (msg.substr(0,1)=="1")
          { // uspesne odeslano, proto vymazeme kolonky
            jQuery("input#vase-jmeno").val("");
            jQuery("input#telefon").val("");
            jQuery("input#e-mail").val("");
            jQuery("input#2-luzkovy").attr('checked', false);
            jQuery("input#3-luzkovy").attr('checked', false);
            jQuery("input#4-luzkovy").attr('checked', false);
            jQuery("input#5-luzkovy").attr('checked', false);
            //jQuery("input#snidane").attr('checked', false);
            jQuery("input#pocet-ubytovanych").val("");
            jQuery("input#den-prijezdu").val("");
            jQuery("input#den-odjezdu").val("");
            jQuery("textarea#vas-vzkaz").val("");
          }
          jQuery("#form-status").text( msg.substr(1) );
        }
      });
    }
    return false;
  });

  /* jQuery - function: Fade In/Out Header Images (http://malsup.com/jquery/cycle/)
  ============================================================================*/
  jQuery.fn.cycle.defaults.speed   = 900;
  jQuery.fn.cycle.defaults.timeout = 6000;
  jQuery('.slideshow').cycle();
  /*
  jQuery('.scroll-size').cycle({
    next: '.scroll-next',
    prev: '.scroll-prev'
  });
  */


});
