/*
 * Lazy Load - jQuery plugin for lazy loading images
 *
 * Copyright (c) 2007-2011 Mika Tuupola
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Project home:
 *   http://www.appelsiini.net/projects/lazyload
 *
 * Version:  1.6.0-dev
 *
 */
(function(a){a.fn.lazyload=function(b){var c={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:window,skip_invisible:!0};b&&(null!==b.failurelimit&&(b.failure_limit=b.failurelimit,delete b.failurelimit),a.extend(c,b));var d=this;return 0==c.event.indexOf("scroll")&&a(c.container).bind(c.event,function(b){var e=0;d.each(function(){if(c.skip_invisible&&!a(this).is(":visible"))return;if(!a.abovethetop(this,c)&&!a.leftofbegin(this,c))if(!a.belowthefold(this,c)&&!a.rightoffold(this,c))a(this).trigger("appear");else if(++e>c.failure_limit)return!1});var f=a.grep(d,function(a){return!a.loaded});d=a(f)}),this.each(function(){var b=this;b.loaded=!1,a(b).one("appear",function(){this.loaded||a("<img />").bind("load",function(){a(b).hide().attr("src",a(b).data("original"))[c.effect](c.effectspeed),b.loaded=!0}).attr("src",a(b).data("original"))}),0!=c.event.indexOf("scroll")&&a(b).bind(c.event,function(c){b.loaded||a(b).trigger("appear")})}),a(c.container).trigger(c.event),this},a.belowthefold=function(b,c){if(c.container===undefined||c.container===window)var d=a(window).height()+a(window).scrollTop();else var d=a(c.container).offset().top+a(c.container).height();return d<=a(b).offset().top-c.threshold},a.rightoffold=function(b,c){if(c.container===undefined||c.container===window)var d=a(window).width()+a(window).scrollLeft();else var d=a(c.container).offset().left+a(c.container).width();return d<=a(b).offset().left-c.threshold},a.abovethetop=function(b,c){if(c.container===undefined||c.container===window)var d=a(window).scrollTop();else var d=a(c.container).offset().top;return d>=a(b).offset().top+c.threshold+a(b).height()},a.leftofbegin=function(b,c){if(c.container===undefined||c.container===window)var d=a(window).scrollLeft();else var d=a(c.container).offset().left;return d>=a(b).offset().left+c.threshold+a(b).width()},a.extend(a.expr[":"],{"below-the-fold":function(b){return a.belowthefold(b,{threshold:0,container:window})},"above-the-fold":function(b){return!a.belowthefold(b,{threshold:0,container:window})},"right-of-fold":function(b){return a.rightoffold(b,{threshold:0,container:window})},"left-of-fold":function(b){return!a.rightoffold(b,{threshold:0,container:window})}})})(jQuery);
(function ($) {

  Drupal.grandhotel = Drupal.grandhotel || {};

  Drupal.behaviors.grandhotel = {
    attach: function(context) {
      Drupal.grandhotel.slideshow();
      Drupal.grandhotel.spotlights();
      Drupal.grandhotel.popups();
      
      $("img.lazyload").lazyload({
        event : "scroll",
        effect : "fadeIn",
        effectspeed: "fast",
        failurelimit : 10,
        skip_invisible: false
      });
      $("body").trigger("scroll");
    }
  }

  /**
   * Init slideshow.
   */
  Drupal.grandhotel.slideshow = function() {
    var $slideshow = $(".field-name-field-hip-slideshow, .field-name-field-gh-slideshow");
    if ($slideshow.length) {
      if ($slideshow.find(".field-item").length == 1) {
        $slideshow.find(".field-item").show();
      }
      else {
        $slideshow.after('<div class="slideshow-navigation"></div>').cycle({
          pager: ".slideshow-navigation",
          activePagerClass: 'active',
          slideExpr: ".field-item",
          pause: true,
          pauseOnPagerHover: true
        });
      }
    }
  }

  /**
   * Do some javascript magic on spotlights.
   */
  Drupal.grandhotel.spotlights = function() {
    $(".spotlight-large .views-row, .spotlight-small .views-row").each(function(){
      // Enlarge click area on spotlights.
      if ($(this).find("a[href]:eq(0)").length) {
        $(this).css("cursor", "pointer").click(function(){
          window.location = $(this).find("a[href]:eq(0)").attr("href");
        });
      }

      // Remove heading on small spotlights that have no body text.
      if ($(this).parent().parent().parent().hasClass("spotlight-small")) {
        if ($(this).find("p").length == 0) {
          $(this).find("h3").hide();
        }
      }
    });
  }

  /**
   * Request a quote fancybox.
   */
  Drupal.grandhotel.popups = function() {
    // Change action on forms.
    $("body.page-ghc-dialog form.webform-client-form").each(function(){
      var $self = $(this);
      var nid = $self.attr("id").replace("webform-client-form-", "");
      $self.attr("action", "/ghc/dialog/" + nid);
    });
    
    $("a.request-quote").bind("click", function() {
      var nid = 0;
      if (Drupal.settings.pathPrefix == "") {
        nid = 33;
      }
      else {
        nid = 289;
      }
      $.fancybox({
        type: "iframe",
        href: Drupal.settings.basePath + Drupal.settings.pathPrefix + "ghc/dialog/" + nid,
        width: 640,
        height: 450
      });

      return false;
    });

    $("a.book-table").bind("click", function(){
      $.fancybox({
        type: "iframe",
        href: Drupal.settings.basePath + Drupal.settings.pathPrefix + "ghc/livebooking/SE-RES-GRANDGROUPCHANNEL:16558",
        width: 400,
        height: 450
      });

      return false;
    });

    $("a.book-table-cardier").bind("click", function(){
      $.fancybox({
        type: "iframe",
        href: Drupal.settings.basePath + Drupal.settings.pathPrefix + "ghc/livebooking/SE-RES-CADIERBAREN_108994:16209",
        width: 400,
        height: 450
      });

      return false;
    });

    $("a.book-table-verandan").bind("click", function(){
      $.fancybox({
        type: "iframe",
        href: Drupal.settings.basePath + Drupal.settings.pathPrefix + "ghc/livebooking/SE-RES-GRANDSVERANDA_100080:11217",
        width: 400,
        height: 450
      });

      return false;
    });

    $("a.book-table-dahlgren").bind("click", function(){
      $.fancybox({
        type: "iframe",
        href: Drupal.settings.basePath + Drupal.settings.pathPrefix + "ghc/livebooking/SE-RES-MATHIASDAHLGRENMATBAREN_108914:16210",
        width: 400,
        height: 450
      });

      return false;
    });
  
    $("a.book-table-dahlgrenmatsalen").bind("click", function(){
      $.fancybox({
        type: "iframe",
        href: Drupal.settings.basePath + Drupal.settings.pathPrefix + "ghc/livebooking/SE-RES-MATHIASDAHLGREN_104687:16212",
        width: 400,
        height: 450
      });

      return false;
    });

//    $("a.book-spa").bind("click", function(){
//      $.fancybox({
//        type: "iframe",
//        href: "http://booking.raisondetrespa.se/",
//        width: 510,
//        height: 450
//      });
//
//      return false;
//    });
  }

})(jQuery);
;

