/*==============================================================================
 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: Scroll Header Images
06. jQuery - function: Fade In/Out Header Images
07. jQuery - function: Clear input fields after they has been focused
08. jQuery - function: Mofify Members Area form
09. jQuery - function: Calendar
10. jQuery - function: Reserve
11. jQuery - function: Anketa
12. jQuery - function: Pratele
==============================================================================*/

/* 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.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;
  });

  /* jQuery - function: Scroll Header Images (http://flesler.blogspot.com/2008/02/jqueryserialscroll.html)
  ============================================================================*
  if (!data['calendar-month']) { // FiX for co-operation with Calendar
  jQuery('#scroll-header').serialScroll({
    target: '.scroll-area',
    items:  '.scroll-item', // Selector to the items ( relative to the matched elements, '#sections' in this case )
    prev:   '.scroll-prev', // Selector to the 'prev' button (absolute!, meaning it's relative to the document)
    next:   '.scroll-next', // Selector to the 'next' button (absolute too)
    axis:   'xy', // The default is 'y' scroll on both ways
    start:  data['iScroll'],

    duration: 350,  // Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
    force:    true  // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
  }); // jQuery('.scroll-area').trigger('goto', ['1']); // scroll to scroll-item with index 1
  }

  /* jQuery - function: Fade In/Out Header Images (http://malsup.com/jquery/cycle/)
  ============================================================================*
  if (!data['calendar-month']) { // FiX for co-operation with Calendar
    jQuery.fn.cycle.defaults.speed   = 900;
    jQuery.fn.cycle.defaults.timeout = 6000;
    jQuery('.scroll-size').cycle({
      next: '.scroll-next',
      prev: '.scroll-prev'
    });
  }
  */

  /* jQuery - function: Clear input fields after they has been focused
  ============================================================================*/
  jQuery('#name').focus(function () { jQuery(this).attr({value:''}); });
  jQuery('#pass').focus(function () { jQuery(this).attr({value:''}); });

  /* jQuery - function: Mofify Members Area form
  ============================================================================*/
  jQuery('form#members-area').attr({action: site + "members-area"});
  jQuery('form#members-area').attr({method: "post"});

  /* jQuery - function: Calendar
  ============================================================================*/
  if (data['calendar-month'] && data['calendar-year']) {
    jQuery.ajax({
      type: "GET",
      url: site + "kernel/plug_calendar.php",
      data: "month=" + data['calendar-month'] + "&year=" + data['calendar-year'],
      success: function(msg){
        jQuery("#calendar").html( msg );
      }
    });
  }
  jQuery('#calendar_goto_button').click(function() {
    var str = "";
    jQuery("select#calendar_year option:selected").each(function () {
      str += jQuery(this).val() + "-";
    });
    jQuery("select#calendar_month option:selected").each(function () {
      str += jQuery(this).val();
    });
    document.location.href = site + 'calendar/' + str + '/overview';
    return false;
  });

  /* jQuery - function: Reserve
  ============================================================================*/
  jQuery('form#reserve').attr({action: site + "index.php?page=hotel/rezervace"});
  jQuery('form#reserve').attr({method: "post"});
  jQuery('#third-column input').click(function() {
    var ad   = jQuery("form#reserve select#date-arrival-day").val();
    var am   = jQuery("form#reserve select#date-arrival-month").val();
    var ay   = jQuery("form#reserve select#date-arrival-year").val();
    var dd   = jQuery("form#reserve select#date-departure-day").val();
    var dm   = jQuery("form#reserve select#date-departure-month").val();
    var dy   = jQuery("form#reserve select#date-departure-year").val();
    var na   = jQuery("form#reserve select#number-adults").val();
    var nk   = jQuery("form#reserve select#number-kids").val();
    var nr   = jQuery("form#reserve select#number-rooms").val();
    var tr   = jQuery("form#reserve select#type-of-room").val();
    var jmeno   = jQuery("form#reserve input#reserve-name").val();
    var email   = jQuery("form#reserve input#reserve-e-mail").val();
    var telefon = jQuery("form#reserve input#reserve-tel").val();
    var poznamka = jQuery("form#reserve textarea#poznamka").val();

    if ((jmeno=="")||(email=="")||(telefon=="")) { alert('Je potřeba vyplnit všechna políčka.'); }
    else
    {
      jQuery.ajax({
        type: "POST",
        url: site + "index.php?page=hotel/rezervace",
        data: "ad=" + ad + "&am=" + am + "&ay=" + ay + "&dd=" + dd + "&dm=" + dm + "&dy=" + dy + "&na=" + na + "&nk=" + nk + "&nr=" + nr + "&tr=" + tr + "&jmeno=" + jmeno + "&email=" + email + "&telefon=" + telefon + "&poznamka=" + poznamka + "&reserve=",
        success: function(msg){
          if (msg.substr(0,1)=="1") jQuery("#content").html("Děkujeme za Váš zájem o služby našeho hotelu.<br />Váš požadavek rezervace byl přijat.<br />Obratem Vám bude zaslán email o stavu Vaší rezervace.");
          else jQuery("#content").text( msg.substr(1) );
        }
      });
    }
    return false;
  });


  /* jQuery - function: Anketa
  ============================================================================*/
  if (data['vote']) {
    jQuery.ajax({
      type: "GET",
      url: site + 'kernel/plug_anketa.php',
      data: 'vote=' + data['vote'],
      success: function(msg){
        jQuery(".anketa").html( msg );
      }
    });
  }

  /* jQuery - function: Pratele
  ============================================================================*/
  jQuery('form#pratele').attr({action: site + "index.php?page=kontakt"});
  jQuery('form#pratele').attr({method: "post"});
  jQuery('input#send').click(function() {
    var jmeno   = jQuery("form#pratele input#pratele-name").val();
    var email   = jQuery("form#pratele input#pratele-e-mail").val();
    var stat = jQuery("form#pratele input#pratele-stat").val();

    if ((jmeno=="")||(email=="")||(stat=="")) { alert('Je potřeba vyplnit všechna políčka.'); }
    else
    {
      jQuery.ajax({
        type: "POST",
        url: site + "index.php?page=kontakt",
        data: "jmeno=" + jmeno + "&email=" + email + "&stat=" + stat + "&pratele=",
        success: function(msg){
          if (msg.substr(0,1)=="1") {
            jQuery("#stav").html("Děkujeme za Váš zájem.");
            jQuery("form#pratele input#pratele-name").val("");
            jQuery("form#pratele input#pratele-e-mail").val("");
            jQuery("form#pratele input#pratele-stat").val("");
          }
          else jQuery("#stav").text( msg.substr(1) );
        }
      });
    }
    return false;
  });
});