// $Id$

(function ($) {

  /**
   * Load superfish menu when its class is set on one of the
   * parent items of the menu list.
   */
  Drupal.behaviors.loadSuperfish  = {
    attach: function() {
      $('.superfish ul.menu').superfish();
    }
  };

})(jQuery);
;
/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 *
 * Modifications by Robin Ambachtsheer for use in Madtheme:
 * - Replaced 'each' loops with 'once' so it can be used in a Drupal behavior
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.once(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).once(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).once(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.once(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).once(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);
;
(function ($) {

  /**
   * Add carousel behaviour to specified views
   * with class carousel-list
   */
  Drupal.behaviors.loadCarousel  = {
    attach: function() {
      var carousel = $('.carousel-list');
      var items = $('.views-row', carousel);
      var count = 1;
      var autoClick;
      if (items.length > 0) {
        navigation = $('<div class="quicktabs-tabs-wrapper quicktabs-wrapper-nostyle">')
          .html($('<ul class="quicktabs-style-nostyle">'))
          .appendTo(carousel.parent());
        navigation.parent().addClass('quicktabs-wrapper quicktabs-wrapper-carousel');
        navigation = $('ul', navigation);
        items.each(function() {
          var title = $('.carousel-title', $(this));
          var link = $('<a>')
            .attr('href', '#')
            .attr('id', 'row-'+ count)
            .html($('<span>')
              .addClass('inner')
              .text(title.text())
            );
          link.click(function() {
            items.hide();
            $('li', navigation).removeClass('active');
            $('#'+ $(this).attr('id'), carousel).show();
            $(this).parent().addClass('active');
            return false;
          });
          var tab = $('<li>').html(link).appendTo(navigation);
          if ($(this).hasClass('views-row-1')) {
            tab.addClass('active');
          }
          title.hide();
          $(this).attr('id', 'row-'+ count);
          count++;
        });
      }
      setClickInterval();
      carousel
        .parent()
        .hover(function() {
          clearInterval(autoClick);
        },
        function() {
          setClickInterval();
        });
      function setClickInterval() {
        clearInterval(autoClick);
        autoClick = setInterval(simulateClick, 4000);
      }
      function simulateClick() {
        var nextItem = $('.quicktabs-tabs-wrapper li.active', carousel.parent()).next();
        if (nextItem.size() == 0) {
          nextItem = $('.quicktabs-tabs-wrapper li a[id="row-1"]', carousel.parent()).parent();
        }
        $('a', nextItem).click();
      }
    }
  };

})(jQuery);
;
/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);;
(function ($) {

  /**
   * Add tv guide behaviour to programme view
   */

  Drupal.behaviors.loadSearch  = {
    attach: function() {

      /* define search block, set height */
      var search= $('.recipe-search-form');
      var search_advanced= $('#edit-advanced', search);
      var height = 215;
      var use_defaults = true;
      if (Drupal.settings.tfk_search == false) {
        use_defaults = false;
      }
      search.css('overflow','hidden');

      /* create link */
      search_advanced.before('<a href="#" id="search-advanced" class="search-link">Uitgebreid zoeken</a>');
      search_advanced.before('<a href="#" id="foldin" class="search-link">Klap in</a>');
      var showLink = $('.recipe-search-form #search-advanced');
      var hideLink = $('.recipe-search-form #foldin');

      // Toggle links actions.
      showLink.click(function(){
        showSearch(search, true);
      });

      hideLink.click(function(){
        hideSearch(search, true);
      });

      if (use_defaults) {
        $('#edit-use-defaults input').change(function(e) {
          if ($('#edit-use-defaults input').is(':checked') == true) {
            $.each(Drupal.settings.tfk_search, function(field_name, value) {
              $('.field-name-' + field_name + ' select').attr('disabled', 'true');
              $('.field-name-' + field_name + ' select').val(value);
            });
          }
          else {
            $.each(Drupal.settings.tfk_search, function(field_name, value) {
              $('.field-name-' + field_name + ' select').removeAttr('disabled');
              $('.field-name-' + field_name + ' select').val('');
            });
          }
        });
      }

      var hideAdvanced = true;
      // Don't hide advanced search if terms are set.
      if ($('body').hasClass('page-recepten-search')) {
        hideAdvanced = false;
      }
      $('select', search).each(function() {
        if (!isNaN($(this).val())) {
          hideAdvanced = false;
          return;
        }
      });
      if ($('#edit-use-defaults input').is(':checked') == true) {
        hideAdvanced = false;
        $('#edit-use-defaults input').trigger('change');
      }

      // Should we hide or show the advanced search.
      if (hideAdvanced) {
        hideSearch(search, false);
      }
      else {
        showSearch(search, false);
      }

      function showSearch(item, animate) {
        if (animate) {
          $(item).animate({height: height + 'px'}, 600, function() {});
        }
        else {
          search.height(height);
        }
        hideLink.show();
        showLink.hide();
      }

      function hideSearch(item, animate) {
        if (animate) {
          $(item).animate({height: '70px'}, 600, function() {});
        }
        else {
          search.height(70);
        }
        hideLink.hide();
        showLink.show();
      }
    }
  };

})(jQuery);
;
// $Id$

(function ($) {

  /**
   * Load superfish menu when its class is set on one of the
   * parent items of the menu list.
   */
  Drupal.behaviors.loadSuperfish  = {
    attach: function() {
      $('.superfish ul.menu').superfish({
        animation: {height:'toggle'},
        speed: 0
      });
    }
  };

})(jQuery);
;
(function ($) {

  /**
   * Add tv guide behaviour to programme view
   */
  Drupal.behaviors.loadTvguide  = {
    attach: function() {
      var timezone = "Europe/Amsterdam";
      var guide = $('.region-content .view-programme');

      if (guide.size() > 0) {
        var programmes = $('.views-row', guide);

        $.getJSON(
          "http://json-time.appspot.com/time.json?tz="+timezone+"&callback=?",
          function(data) {
            var minute = data.minute;
            var urlGet = getUrlParameters();
            showProgramme(data.hour +''+ (data.minute < 10 ? '0'+ data.minute : data.minute), urlGet.description);
          }
        );
      }

      function getUrlParameters() {
        var map = {};
        var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
          map[key] = value;
        });
        return map;
      }

      function showProgramme(curTime, id) {
        var i = 1;

        programmes.each(function() {
          // Get the current shows time.
          var currentProgrammeTime = $('.date-display-single', this).html().replace(':', '');

          // Get the time of the next show.
          var nextProgramme = $('.views-row-' + (i+1), guide);
          if ($(nextProgramme).hasClass('views-row')) {
            var nextProgrammeTime = $('.date-display-single', nextProgramme).html().replace(':', '');
          }
          else {
            var nextProgrammaTime = '2400';
          }


          console.log(Drupal.settings.tfk_import_xml.active);
          if (parseInt(currentProgrammeTime) < parseInt(curTime) && parseInt(nextProgrammeTime) > parseInt(curTime)) {
            // Show the current programme as active.
            if (Drupal.settings.tfk_import_xml.active == true) {
              showDescription(this);
              $(this).addClass('active');
            }
          }

          if ($(this).hasClass('desc-' + id)) {
            showDescription(this);
          }

          // On click we show a the new description and collapse the old one.
          $(this).click(function() {
            showDescription(this);
          });

          // Add one to the counter.
          i++;
        }).css("cursor","pointer");
      }

      function showDescription(view_row) {
        $('.view-programme .active-row').each(function() {
          $('.views-field-tfk-show-description', this).hide();
          $(this).removeClass('active-row');
        });

        $(view_row).addClass('active-row');
        $('.views-field-tfk-show-description', view_row).show();
      }
    }
  };

})(jQuery);
;

