var fadeSpeed = 150;

(function( $ ){
    $.fn.pfCheckbox = function() {
        var $checkboxs = this;
        $checkboxs.each(function() {
            $(this).click(function(){
                if($(this).hasClass('disable'))return;
                $(this).toggleClass('active');
            });
        });
    };
    $.fn.pfPopup = function(method) {
        var methods = {
            init : function( options ) {
                var $this = $(this),
                data = $this.data('popup'),
                $content = options,
                $close = $content.find('.close');

                if ( !data ) {

                    $(this).data('popup', {
                       target : $this,
                       content : $content,
                       close : $close,
                       status : 'close'
                    });
                    
                    $(document).click(function(event){
                        var t = $(event.target);
                        var date = $("#ui-datepicker-div");
                        if((!t.hasClass('ui-icon') &&
                            !t.hasClass('ui-datepicker-prev') &&
                            !t.hasClass('ui-datepicker-next') &&
                            !t.parents().is(date) &&
                            !t.is($content) &&
                            !t.parents().is($content) &&
                            !t.is($this)) || t.is($close)
                          )
                        {
                            $this.pfPopup('hide');
                            return true;
                        }
                        if(t.is($this)){
                            $content.fadeIn(fadeSpeed);
                            return true;
                        }
                    });
                }
                //var $overlay = $('<div>').addClass('g-overlay').css('height', $(document).height());
                //$('body').prepend($overlay);

                return this;
            },
            hide : function( ) {
                var $this = $(this),
                data = $this.data('popup');
                $content = data.content;
                //$content.find('input').val('');
                $content.fadeOut(fadeSpeed);
            },
            show : function( ) {
                var $this = $(this),
                data = $this.data('popup');
                $content = data.content;
                $content.fadeIn(fadeSpeed);
            }
        };

        if ( methods[method] ) {
            return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method ' +  method + ' does not exist on jQuery.pfPopup' );
        }
    };
    
    $.fn.cookie = function (key, value, options) {
        if (arguments.length > 1 && String(value) !== "[object Object]") {
            options = jQuery.extend({}, options);
        
            if (value === null || value === undefined) {
                options.expires = -1;
            }
        
            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setDate(t.getDate() + days);
            }
            
            value = String(value);
            
            return (document.cookie = [
                encodeURIComponent(key), '=',
                options.raw ? value : encodeURIComponent(value),
                options.expires ? '; expires=' + options.expires.toUTCString() : '',
                options.path ? '; path=' + options.path : '',
                options.domain ? '; domain=' + options.domain : '',
                options.secure ? '; secure' : ''
            ].join(''));
        }
        options = value || {};
        var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
        return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
    };      

})( jQuery ); 

$(document).ready(function(){

 $('#scrollbar1').tinyscrollbar();
 $("#menu li.m-dropdown").hover(function(){
     $(".b-dropdown").css("visibility","visible");
     $(".b-dropdown h2 *").css("visibility","visible");
 },
 function(){
     $(".b-dropdown").css("visibility","hidden");
     $(".b-dropdown h2 *").css("visibility","hidden");
 });
    
  Cufon.replace('.MyriadPro', {hover: true});
  $('.j-datepicker').datepicker();
  if($('.j-aims').length){
    $('.j-aims').pfAims();
  }
  //$('.g-optionCheckbox').pfCheckbox();
  
  $('#switcher_list').click(function(){
	  $('.b-results_switcher_map').removeClass('active');	  
	  $('.b-results_switcher_list').addClass('active');
  });
  
  $('#switcher_map').click(function(){
      $('.b-results_switcher_list').removeClass('active');     
      $('.b-results_switcher_map').addClass('active');
  });
  
  $('#showbutton').click(function(){
      type_container = 'ajax_content'; 
      $('#FilterClubs').submit();
   });  
    
  /*$("#SECTION_CODE").selectbox({
		'className' : 'jquery-selectbox-filter'
	});*/
	
  //$("select.select-decor").selectbox();
  $('.j-compose').click(function(){
      var $messsage = $('.b-messenger');
      //console.log($messsage);
      var $popup = $messsage.find('.g-popup');
      //console.log($popup);
      $(this).pfPopup($popup);
  });
  
  $('.b-clubs-item').hover(function(){$(this).addClass('active');},
  function(){$(this).removeClass('active');});
  centerPopup($('.b-map-popup-first'));
  centerPopup($('.b-map-popup-second'));
  $('.g-shadow').click(function(){
  	$('.g-shadow').fadeOut(fadeSpeed);
  	$('.g-map-popup').fadeOut(fadeSpeed);
  	$('.b-map-popup-first').css('z-index','999');
  });  
  $('.g-map-popup').click(function(){
  	$(this).fadeOut(fadeSpeed);
  	$('.g-shadow').fadeOut(fadeSpeed);
  	});
  
});

