﻿(function ($) {
    /* Controller */
    $.fn.home_usercard = function () {
        if (!this.length) return;
        return this.each(function () {
            $('.toggler', this).toggler();
        });
    };

    /* Controller */
    $.fn.home_starters = function () {
        if (!this.length) return;
        return this.each(function () {
            var anchors = $('a', this);
            anchors.tooltip({
                offset: [-36, 0],
                relative: true,
                events: { def: 'click,mouseleave' },
                position: 'bottom left'
            });
        });
    };

    /* Controller */
    $.fn.match_list = function () {
        if (!this.length) return;

        function handle_click() {
            var item = $(this), uri = item.data('href');
            uri && (window.location = uri);
        };

        return this.each(function () {
            var list = $(this);
            list.delegate('.match-list-item', 'click', handle_click);
        });
    };

    $.fn.getMatches = function () {
        if (!this.length) return;

        $(this).psPopup({
            fadeTime: 400,
            showoverlay: true,
            ajaxrequest: false,
            popupid: '#refreshmatches'
        });
    };

})(jQuery);

(function($){
  $('#match-list').match_list();
  $('#home-usercard').home_usercard();
  $('#home-starters').home_starters();
  $('#getmatchpop').getMatches();

  /* QUICK FIX: Bind learn more link for free comm banner. */
  var link = $('#LearnMore a');
  if (link.length)
  {
	$.fn.pngFix = function(){};
	$('#jqmPopup').jqm({ modal: true, ajax: '@href', toTop: true });
  }


})(jQuery);

// Fix for show more matches
function updateLinks() {
    $('.match-list').match_list();
};
