(function ($) {
  /**
   * Main menu behavior
   **/
  Drupal.behaviors.main_menu = {
    attach: function (context, settings) {
      $('#main-menu').find('> li').hoverIntent(function () {
        $('.main-submenu-wrapper', this).fadeIn();
      }, function () {
        $('.main-submenu-wrapper', this).hide();
      });
      $('#movies-wrapper, #events-wrapper').find('.view-movies-in-menu-fold a, .view-events-in-menu-fold a').hoverIntent(function () {
        $('.overlay', this).fadeIn();
      }, function () {
        $('.overlay', this).hide();
      });
    }
  };
  
  /**
   * IN the FAQ view
   * If you click the header of a FAQ item, it will expand.
   */
  Drupal.behaviors.faqExpand = {
    attach: function (context, settings) {
      $('.view-display-id-page .node-faq-item').each(function (index, val) {
        var header = $(val).children('h2');
        var content = $(val).children('.content');
        $(header).unbind('click');
        $(header).click(function () {
          $(content).slideToggle('fast');
          if ($(val).hasClass('faq-item-disabled')) {
            $(val).addClass('faq-item-enabled');
            $(val).removeClass('faq-item-disabled');
          } else if ($(val).hasClass('faq-item-enabled')) {
            $(val).addClass('faq-item-disabled');
            $(val).removeClass('faq-item-enabled');
          } else {
            $(val).addClass('faq-item-enabled');
          }
        });
      });
      
      // Automatically slide out correct faq if URL hash is given
      var anchor = window.location.toString().match(/#[\w|\W]*/);
      if (anchor) {
        anchor = anchor.toString().replace('#', '');
        var faqa = $('#faq-' + anchor);
        if (faqa) {
          faqa.trigger('click');
        }
      }
    }
  };
  
  Drupal.behaviors.loginExpand = {
    attach: function (context, settings) {
      $('.login_activator').attr('id', 'login');
      $('.login_activator').attr('href', '#login');
      $('.login_activator').unbind('click');
      $('.login_activator').click(function () {
        $(this).toggleClass('active');
        $('#registration_dropout').slideToggle('slow');
        return false;
      });
      if ($('#user-login-form').find('#edit-name').hasClass('error')) {
        $('#registration_dropout').slideToggle('slow');
      }
    }
  };
  
  Drupal.behaviors.autoSelectTheater = {
    attach: function (context, settings) {
      var cookiename = "kinepolis_default_theater";
      //Load the existing cookie.
      var myTheater = $.cookie(cookiename);
      if (Drupal.behaviors.utils.isNumber(myTheater)) {
        myTheater = myTheater + '';
        var select = $('#edit-theaters');
        if (Drupal.behaviors.kinepolis_movie != undefined) {
          select.val(myTheater);
          select.selectbox('detach');
          select.selectbox('attach');
          Drupal.behaviors.kinepolis_movie.select_ajax_call('#edit-theaters', '#edit-movies', 'kinepolis-movie/theater/movies');
          $('#cinema').val(myTheater);
        }
      }
      $('#kinepolis-movie-check-showtimes-form').bind('submit', function () {
        //bind the sudmit to update the cookie
        $('#kinepolis-movie-check-showtimes-form').find('#edit-theaters option:selected').each(function () {
          $.cookie(cookiename, $(this).val(), { expires: 999 });
        });
      });
      if (myTheater > 0) {
        $('.theater-detail .movie-version-title a').each(function () {
          this.href = this.href + '?theater=' + myTheater;
        });
      }
    }
  };
  
  Drupal.behaviors.autoSelectCountry = {
    attach: function (context, settings) {
      var cookiename = 'site';
      //Load the existing cookie.
      //var mySite = $.cookie(cookiename);
      //$('#COUNTRY').delay(1500).val(mySite.toUpperCase());
    }
  };
  
  Drupal.behaviors.openExternal = {
    attach : function (context, settings) {
      $('a[rel*=external], a[rel*=attachment]').click(function () {
        window.open(this.href);
        return false;
      }); 
    }
  };
  
  Drupal.behaviors.sidebanner = {
    attach: function (context, settings) {
      var offset = $('#main-wrapper').offset();
      $('#side-banner').css({top: (offset.top + 20) + 'px'});
    }
  };
  
  Drupal.behaviors.trailer_embedder = {
    attach: function (context, settings) {
      $('#show-embed-code').click(function () {
        $('#share-embed-code').find('textarea').slideToggle('fast');
        return false;
      });
    }
  };
  
  Drupal.behaviors.utils = {
    isNumber: function (n) {
      return !isNaN(parseFloat(n)) && isFinite(n);
    }
  };
  
}(jQuery));
;
/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);;
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
// https://gist.github.com/379601
(function ($) {
  Drupal.behaviors.plchldr = {
    attach: function (context, settings) {
      $('[placeholder]').focus(function() {
        var input = $(this);
        if (input.val() == input.attr('placeholder')) {
          input.val('');
          input.removeClass('placeholder');
        }
      }).blur(function() {
        var input = $(this);
        if (input.val() == '' || input.val() == input.attr('placeholder')) {
          input.addClass('placeholder');
          input.val(input.attr('placeholder'));
        }
      }).blur().parents('form').submit(function() {
        $(this).find('[placeholder]').each(function() {
          var input = $(this);
          if (input.val() == input.attr('placeholder')) {
            input.val('');
          }
        })
      });
    }
  };
}(jQuery));
;

