(function($) {
	$.fn.slideDay = function(options) {
		var options = $.extend({
		}, options);

		return this.each(function() {
			var obj = $(this);
      
      if( ! $.cookie('slideday') ) {
        
        var doc = $(document),
						docW = doc.width(),
            docH = doc.height(),
            winH = $(window).height();
            
        $(window).resize(function() {
					docW = doc.width();
					docH = doc.height();
          winH = $(window).height();
				});
        
        $(window).scroll(function() {
          
					var isReadyToShow = ( (docW > 1200) && (doc.scrollTop() + winH/2 > docH/2 ) ) ? true : false;
					
					if((!obj.hasClass('slide_day_visible') && isReadyToShow) || (obj.hasClass('slide_day_visible') && !isReadyToShow)) {
            
            obj.toggleClass('slide_day_visible');
            
            obj.css('right', isReadyToShow ? -312 : -12).animate({right: isReadyToShow ? -12 : -312}, 300);
            
					}
          
				});
        
        obj.find('.close').click(function(e) {
					e.preventDefault();
          
					obj.toggleClass('slide_day_visible');
					$(window).unbind('scroll');
          
          $.cookie('slideday', 1, { expires: 3600000 }); // 1 hour
          
          obj.css('right', -12).animate({right: -312}, 300, function() {
            obj.css('right', '');
          });
          
				});
        
        obj.find('.slide_acts a').click(function(e) {
					e.preventDefault();
					var act = $(this),
            holder = obj.find('.plist');

					if (act.hasClass('slide_paging_disabled')) {
						return false;
					}

					holder.animate({top: (act.addClass('slide_paging_disabled').hasClass('next') ? '-' : '+') + '=270'}, function() {
						act.removeClass('slide_paging_disabled');
						$('.slide_acts .next')[Math.abs(parseInt(holder.css('top')) || 0) >= 540 ? 'addClass' : 'removeClass' ]('unvis');
						$('.slide_acts .prev')[Math.abs(parseInt(holder.css('top'))) == 0 ? 'addClass' : 'removeClass']('unvis');
					});
          
          return false;
				});
        
      }
		});
	};
})(jQuery);
