//flow
(function(c){c.tools=c.tools||{};c.tools.tooltip={version:"1.1.1",conf:{effect:"toggle",fadeOutSpeed:"fast",tip:null,predelay:0,delay:30,opacity:1,lazy:undefined,position:["top","center"],offset:[0,0],cancelDefault:true,relative:false,events:{def:"mouseover,mouseout",input:"focus,blur",widget:"focus mouseover,blur mouseout"},api:false},addEffect:function(d,f,e){b[d]=[f,e]}};var b={toggle:[function(d){var e=this.getConf();this.getTip().css({opacity:e.opacity}).show();d.call()},function(d){this.getTip().hide();d.call()}],fade:[function(d){this.getTip().fadeIn(this.getConf().fadeInSpeed,d)},function(d){this.getTip().fadeOut(this.getConf().fadeOutSpeed,d)}]};function a(e,f){var o=this,j=c(this);e.data("tooltip",o);var k=e.next();if(f.tip){k=c(f.tip);if(k.length>1){k=e.nextAll(f.tip).eq(0);if(!k.length){k=e.parent().nextAll(f.tip).eq(0)}}}function n(t){var s=f.relative?e.position().top:e.offset().top,r=f.relative?e.position().left:e.offset().left,u=f.position[0];s-=k.outerHeight()-f.offset[0];r+=e.outerWidth()+f.offset[1];var p=k.outerHeight()+e.outerHeight();if(u=="center"){s+=p/2}if(u=="bottom"){s+=p}u=f.position[1];var q=k.outerWidth()+e.outerWidth();if(u=="center"){r-=q/2}if(u=="left"){r-=q}return{top:s,left:r}}var h=e.is(":input"),d=h&&e.is(":checkbox, :radio, select, :button"),g=e.attr("type"),m=f.events[g]||f.events[h?(d?"widget":"input"):"def"];m=m.split(/,\s*/);e.bind(m[0],function(q){var p=k.data("trigger");if(p&&p[0]!=this){k.hide()}q.target=this;o.show(q);k.hover(o.show,function(){o.hide(q)})});e.bind(m[1],function(p){o.hide(p)});if(!c.browser.msie&&!h){e.mousemove(function(){if(!o.isShown()){e.triggerHandler("mouseover")}})}if(f.opacity<1){k.css("opacity",f.opacity)}var l=0,i=e.attr("title");if(i&&f.cancelDefault){e.removeAttr("title");e.data("title",i)}c.extend(o,{show:function(q){if(q){e=c(q.target)}clearTimeout(k.data("timer"));if(k.is(":animated")||k.is(":visible")){return o}function p(){k.data("trigger",e);var s=n(q);if(f.tip&&i){k.html(e.data("title"))}var r=c.Event("onBeforeShow");j.trigger(r,[s]);if(r.isDefaultPrevented()){return o}s=n(q);k.css({position:"absolute",top:s.top,left:s.left});b[f.effect][0].call(o,function(){j.trigger("onShow")})}if(f.predelay){clearTimeout(l);l=setTimeout(p,f.predelay)}else{p()}return o},hide:function(q){clearTimeout(k.data("timer"));clearTimeout(l);if(!k.is(":visible")){return}function p(){var r=c.Event("onBeforeHide");j.trigger(r);if(r.isDefaultPrevented()){return}b[f.effect][1].call(o,function(){j.trigger("onHide")})}if(f.delay&&q){k.data("timer",setTimeout(p,f.delay))}else{p()}return o},isShown:function(){return k.is(":visible, :animated")},getConf:function(){return f},getTip:function(){return k},getTrigger:function(){return e},bind:function(p,q){j.bind(p,q);return o},onHide:function(p){return this.bind("onHide",p)},onBeforeShow:function(p){return this.bind("onBeforeShow",p)},onShow:function(p){return this.bind("onShow",p)},onBeforeHide:function(p){return this.bind("onBeforeHide",p)},unbind:function(p){j.unbind(p);return o}});c.each(f,function(p,q){if(c.isFunction(q)){o.bind(p,q)}})}c.prototype.tooltip=function(d){var e=this.eq(typeof d=="number"?d:0).data("tooltip");if(e){return e}var f=c.extend(true,{},c.tools.tooltip.conf);if(c.isFunction(d)){d={onBeforeShow:d}}else{if(typeof d=="string"){d={tip:d}}}d=c.extend(true,f,d);if(typeof d.position=="string"){d.position=d.position.split(/,?\s/)}if(d.lazy!==false&&(d.lazy===true||this.length>20)){this.one("mouseover",function(g){e=new a(c(this),d);e.show(g)})}else{this.each(function(){e=new a(c(this),d)})}return d.api?e:this}})(jQuery);
(function(b){var a=b.tools.tooltip;a.effects=a.effects||{};a.effects.slide={version:"1.0.0"};b.extend(a.conf,{direction:"up",bounce:false,slideOffset:10,slideInSpeed:200,slideOutSpeed:200,slideFade:!b.browser.msie});var c={up:["-","top"],down:["+","top"],left:["-","left"],right:["+","left"]};b.tools.tooltip.addEffect("slide",function(d){var f=this.getConf(),g=this.getTip(),h=f.slideFade?{opacity:f.opacity}:{},e=c[f.direction]||c.up;h[e[1]]=e[0]+"="+f.slideOffset;if(f.slideFade){g.css({opacity:0})}g.show().animate(h,f.slideInSpeed,d)},function(e){var g=this.getConf(),i=g.slideOffset,h=g.slideFade?{opacity:0}:{},f=c[g.direction]||c.up;var d=""+f[0];if(g.bounce){d=d=="+"?"-":"+"}h[f[1]]=d+"="+i;this.getTip().animate(h,g.slideOutSpeed,function(){b(this).hide();e.call()})})})(jQuery);
(function(d){var c=d.tools.tooltip;c.plugins=c.plugins||{};c.plugins.dynamic={version:"1.0.1",conf:{api:false,classNames:"top right bottom left"}};function b(h){var e=d(window);var g=e.width()+e.scrollLeft();var f=e.height()+e.scrollTop();return[h.offset().top<=e.scrollTop(),g<=h.offset().left+h.width(),f<=h.offset().top+h.height(),e.scrollLeft()>=h.offset().left]}function a(f){var e=f.length;while(e--){if(f[e]){return false}}return true}d.fn.dynamic=function(g){var h=d.extend({},c.plugins.dynamic.conf),f;if(typeof g=="number"){g={speed:g}}g=d.extend(h,g);var e=g.classNames.split(/\s/),i;this.each(function(){if(d(this).tooltip().jquery){throw"Lazy feature not supported by dynamic plugin. set lazy: false for tooltip"}var j=d(this).tooltip().onBeforeShow(function(n,o){var m=this.getTip(),k=this.getConf();if(!i){i=[k.position[0],k.position[1],k.offset[0],k.offset[1],d.extend({},k)]}d.extend(k,i[4]);k.position=[i[0],i[1]];k.offset=[i[2],i[3]];m.css({visibility:"hidden",position:"absolute",top:o.top,left:o.left}).show();var l=b(m);if(!a(l)){if(l[2]){d.extend(k,k.top);k.position[0]="top";m.addClass(e[0])}if(l[3]){d.extend(k,k.right);k.position[1]="right";m.addClass(e[1])}if(l[0]){d.extend(k,k.bottom);k.position[0]="bottom";m.addClass(e[2])}if(l[1]){d.extend(k,k.left);k.position[1]="left";m.addClass(e[3])}if(l[0]||l[2]){k.offset[0]*=-1}if(l[1]||l[3]){k.offset[1]*=-1}}m.css({visibility:"visible"}).hide()});j.onShow(function(){var l=this.getConf(),k=this.getTip();l.position=[i[0],i[1]];l.offset=[i[2],i[3]]});j.onHide(function(){var k=this.getTip();k.removeClass(g.classNames);d.extend(g,i[4])});f=j});return g.api?f:this}})(jQuery);
(function(b){b.tools=b.tools||{};b.tools.expose={version:"1.0.5",conf:{maskId:null,loadSpeed:"slow",closeSpeed:"fast",closeOnClick:true,closeOnEsc:true,zIndex:9998,opacity:0.8,color:"#456",api:false}};function a(){if(b.browser.msie){var f=b(document).height(),e=b(window).height();return[window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,f-e<20?e:f]}return[b(window).width(),b(document).height()]}function c(h,g){var e=this,j=b(this),d=null,f=false,i=0;b.each(g,function(k,l){if(b.isFunction(l)){j.bind(k,l)}});b(window).resize(function(){e.fit()});b.extend(this,{getMask:function(){return d},getExposed:function(){return h},getConf:function(){return g},isLoaded:function(){return f},load:function(){if(f){return e}i=h.eq(0).css("zIndex");if(g.maskId){d=b("#"+g.maskId)}if(!d||!d.length){var l=a();d=b("<div/>").css({position:"absolute",top:0,left:0,width:l[0],height:l[1],display:"none",opacity:0,zIndex:g.zIndex});if(g.maskId){d.attr("id",g.maskId)}b("body").append(d);var k=d.css("backgroundColor");if(!k||k=="transparent"||k=="rgba(0, 0, 0, 0)"){d.css("backgroundColor",g.color)}if(g.closeOnEsc){b(document).bind("keydown.unexpose",function(o){if(o.keyCode==27){e.close()}})}if(g.closeOnClick){d.bind("click.unexpose",function(){e.close()})}}var n=b.Event("onBeforeLoad");j.trigger(n);if(n.isDefaultPrevented()){return e}b.each(h,function(){var o=b(this);if(!/relative|absolute|fixed/i.test(o.css("position"))){o.css("position","relative")}});h.css({zIndex:Math.max(g.zIndex+1,i=="auto"?0:i)});var m=d.height();if(!this.isLoaded()){d.css({opacity:0,display:"block"}).fadeTo(g.loadSpeed,g.opacity,function(){if(d.height()!=m){d.css("height",m)}j.trigger("onLoad")})}f=true;return e},close:function(){if(!f){return e}var k=b.Event("onBeforeClose");j.trigger(k);if(k.isDefaultPrevented()){return e}d.fadeOut(g.closeSpeed,function(){j.trigger("onClose");h.css({zIndex:b.browser.msie?i:null})});f=false;return e},fit:function(){if(d){var k=a();d.css({width:k[0],height:k[1]})}},bind:function(k,l){j.bind(k,l);return e},onBeforeLoad:function(k){return this.bind("onBeforeLoad",k)},onLoad:function(k){return this.bind("onLoad",k)},onBeforeClose:function(k){return this.bind("onBeforeClose",k)},onClose:function(k){return this.bind("onClose",k)},unbind:function(k){j.unbind(k);return e}})}b.fn.expose=function(d){var e=this.eq(typeof d=="number"?d:0).data("expose");if(e){return e}if(typeof d=="string"){d={color:d}}var f=b.extend({},b.tools.expose.conf);d=b.extend(f,d);this.each(function(){e=new c(b(this),d);b(this).data("expose",e)});return d.api?e:this}})(jQuery);
//forms
jQuery.fn.uniform=function(settings){settings=jQuery.extend({valid_class : 'valid',invalid_class : 'invalid',focused_class : 'focused',holder_class : 'ctrlHolder',field_selector : 'input,select,textarea'},settings);return this.each(function(){var form=jQuery(this);var focusControlHolder=function(element){var parent=element.parent();while(typeof(parent)=='object'){if(parent){if(parent[0]&&(parent[0].className.indexOf(settings.holder_class)>=0)){parent.addClass(settings.focused_class);return;}}parent=jQuery(parent.parent());}};form.find(settings.field_selector).focus(function(){form.find('.'+settings.focused_class).removeClass(settings.focused_class);focusControlHolder(jQuery(this));}).blur(function(){form.find('.'+settings.focused_class).removeClass(settings.focused_class);});});};$(document).ready(function(){jQuery('form.uniForm').uniform();});
//notify
jQuery(document).ready(function($){
	Gritter = {
		fade_speed: 2000, // how fast the notices fade out
	    timer_stay: 6000, // how long you want the message to hang on screen for
	    
	    // PRIVATE - no touchy the private parts
		_custom_timer: 0,
	    _item_count: 0,
		_tpl_close: '<div class="gritter-close"></div>',
		_tpl_item: '<div id="gritter-item-[[number]]" class="gritter-item-wrapper" style="display:none"><div class="gritter-top"></div><div class="gritter-item">[[image]]<div class="[[class_name]]"><span class="gritter-title">[[username]]</span><p>[[text]]</p></div><div style="clear:both"></div></div><div class="gritter-bottom"></div></div>',
	    _tpl_wrap: '<div id="gritter-notice-wrapper"></div>',
	    
	    // Add a notification to the screen
	    add: function(user, text, image, sticky, time_alive){
	        
	        // This is also called from init, we just added it here because
	        // some people might just call the "add" method
	        this.verifyWrapper();
	        
	        var tmp = this._tpl_item;
	        this._item_count++;
			
			// reset
			this._custom_timer = 0;
			
			// a custom fade time set
			if(time_alive){
				this._custom_timer = time_alive;
			}
			
			var image_str = (image != '') ? '<img src="' + image + '" class="gritter-image" />' : '';
			var class_name = (image != '') ? 'gritter-with-image' : 'gritter-without-image';
			
	        tmp = this.str_replace(
	            ['[[username]]', '[[text]]', '[[image]]', '[[number]]', '[[class_name]]'],
	            [user, text, image_str, this._item_count, class_name], tmp
	        );
	        
	        $('#gritter-notice-wrapper').append(tmp);
	        var item = $('#gritter-item-' + this._item_count);
	        var number = this._item_count;
	        item.fadeIn();
	        
			if(!sticky){
				this.setFadeTimer(item, number);
			}
			
			$(item).hover(function(){
				if(!sticky){ 
					Gritter.restoreItemIfFading(this, number);
				}
				Gritter.hoveringItem(this);
			},
			function(){
				if(!sticky){
					Gritter.setFadeTimer(this, number);
				}
				Gritter.unhoveringItem(this);
			});
			
			return number;
	    
	    },
		
		// If we don't have any more gritter notifications, get rid of the wrapper
	    countRemoveWrapper: function(){
	        
	        if($('.gritter-item-wrapper').length == 0){
	            $('#gritter-notice-wrapper').remove();
	        }
	    
	    },
		
		// Fade the item and slide it up nicely... once its completely faded, remove it
	    fade: function(e){
	
	        $(e).animate({
	            opacity:0
	        }, Gritter.fade_speed, function(){
	            $(e).animate({ height: 0 }, 300, function(){
	                $(e).remove();
	                Gritter.countRemoveWrapper();
	            })
	        })
	        
	    },
		
		 // Change the border styles and add the (X) close button when you hover
	    hoveringItem: function(e){
	    	
	    	$(e).addClass('hover');
	    	
			if($(e).find('img').length){
				$(e).find('img').before(this._tpl_close);
			}
			else {
				$(e).find('span').before(this._tpl_close);
			}
			$(e).find('.gritter-close').click(function(){
				Gritter.remove(this);
			});
	        
	    },
	    
	    // Remove a notification, this is called from the inline "onclick" event
	    remove: function(e){
	        
	        $(e).parents('.gritter-item-wrapper').fadeOut('medium', function(){ $(this).remove();  });
	        this.countRemoveWrapper();
	        
	    },
		
		// Remove a specific notification based on an id (int)
		removeSpecific: function(id, params){
			
			var e = $('#gritter-item-' + id);
			
			if(typeof(params) === 'object'){
				if(params.fade){
					var speed = this.fade_speed;
					if(params.speed){
						speed = params.speed;
					}
					e.fadeOut(speed);
				}
			}
			else {
				e.remove();
			}
			
			this.countRemoveWrapper();
			
		},
		
		 // If the item is fading out and we hover over it, restore it!
	    restoreItemIfFading: function(e, number){
			
			window.clearTimeout(Gritter['_int_id_' + number]);
	        $(e).stop().css({ opacity: 1 });
	        
	    },
	    
	    // Set the notification to fade out after a certain amount of time
	    setFadeTimer: function(item, number){
			
			var timer_str = (this._custom_timer) ? this._custom_timer : this.timer_stay;
	        Gritter['_int_id_' + number] = window.setTimeout(function(){ Gritter.fade(item); }, timer_str);
	
	    },
		
		// Bring everything to a halt!    
		stop: function(){
	
			$('#gritter-notice-wrapper').fadeOut(function(){
				$(this).remove();
			});
	
		},
		
		// A handy PHP function ported to js!
	    str_replace: function(search, replace, subject, count) {
	    
	        var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
	            f = [].concat(search),
	            r = [].concat(replace),
	            s = subject,
	            ra = r instanceof Array, sa = s instanceof Array;
	        s = [].concat(s);
	        if (count) {
	            this.window[count] = 0;
	            }
	 
	        for (i=0, sl=s.length; i < sl; i++) {
	            if (s[i] === '') {
	                continue;
	            }
	            for (j=0, fl=f.length; j < fl; j++) {
	                temp = s[i]+'';
	                repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
	                s[i] = (temp).split(f[j]).join(repl);
	                if (count && s[i] !== temp) {
	                    this.window[count] += (temp.length-s[i].length)/f[j].length;}
	            }
	        }
	        return sa ? s : s[0];
	        
	    },
	    
	    // Remove the border styles and (X) close button when you mouse out
	    unhoveringItem: function(e){
	        
	        $(e).removeClass('hover');
	        $(e).find('.gritter-close').remove();
	        
	    },
		
		// Make sure we have something to wrap our notices with
		verifyWrapper: function(){
	      
			if($('#gritter-notice-wrapper').length == 0){
				$('body').append(this._tpl_wrap);
			}
	 
		}
	    
	}
	
	/********************************************
	 * Now lets turn it into some jQuery Magic!
	 */
	
	// Set it up as an object
	$.gritter = {};
	
	// Add a gritter notification
	$.gritter.add = function(params){

		try {
			if(!params.title || !params.text){
				throw "Missing_Fields"; 
			}
		} catch(e) {
			if(e == "Missing_Fields"){
				alert('Gritter Error: You need to fill out the first 2 params: "title" and "text"');
			}
		}
		
		var id = Gritter.add(
			params.title,
			params.text,
			params.image || '',
			params.sticky || false,
			params.time || ''
		);
		
		return id;

	}
	
	// Remove a specific notification
	$.gritter.remove = function(id, params){
		Gritter.removeSpecific(id, params || '');
	}
	
	// Remove all gritter notifications
	$.gritter.removeAll = function(){
		Gritter.stop();
	}
	
});

		$(document).ready(function() {
			
		   $('#getLiveComments').click(function(){
		       $('#getLiveTopics').removeClass("liveactive");
			   $('#getLiveComments').addClass("liveactive");
		   	   $('ul.livecomments').html('<li style="text-align:center;"><img src="/assets/img/complete/loading.gif" id="loader"></li>');
			   $.post("/ajax/getlivecomments/", function(data){
					$('ul.livecomments').html(data);
			   });
		   });
		   
		   $('#getLiveTopics').click(function(){
		       $('#getLiveComments').removeClass("liveactive");
			   $('#getLiveTopics').addClass("liveactive");
		   	   $('ul.livecomments').html('<li style="text-align:center;"><img src="/assets/img/complete/loading.gif" id="loader"></li>');
			   $.post("/ajax/getlivetopics/", function(data){
					$('ul.livecomments').html(data);
			   });
		   });
		   
		   $('div.mail a').each(function(){
		      $(this).qtip({
		         content: {
		            text: 'Новых сообщений нет',
		            url: "/mail/tipinbox",
		            title: {
		               text: 'Ваши личные сообщения',
		               button: 'Закрыть',
		            }
		         },
		         position: {
		            corner: {
		               target: 'bottomMiddle', // Position the tooltip above the link
		               tooltip: 'topRight'
		            },
		            adjust: {
		               screen: true // Keep the tooltip on-screen at all times
		            }
		         },
		         show: { 
		        	delay: 3000,
		        	when: { event: 'mouseover' },
		            solo: true // Only show one tooltip at a time
		         },
		         hide: { fixed: true, delay: 3000 },
		         style: {
		            tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
		            background: '#E4EDEE',
		            color: 'black',
		            border: {
		               width: 10,
		               radius: 10,
		               color: '#989E9F'
		            },
		            title: {
		            	background: '#E4EDEE'
		            },
		            name: 'light', // Use the default light style
		            width: 400 // Set the tooltip width
		         }
		      })
		   });
		});

