$(document).ready(function(){
	//bubble
	$('a[rel=popup]').live("click", function(e){
			hrefhref = $(this).attr('href');
			idtoshow = hrefhref.substr(1,hrefhref.length);
			var offset = $(this).offset();
			$('.bubble').hide();
			$('#'+idtoshow).css("top",(offset.top + 24) + "px")
	    .css("left",(offset.left) + "px").show();
			return false;
		});
		//hiding bubble on blur
		$(document).click(function(e){
			tar = $(e.target);
			if(!(tar.parents('.bubble').length > 0) && !(tar.hasClass(".bubble")) && !(tar.attr('rel')=='popup')){$('.bubble').hide();}
		});
	
	
	// инфографика
	$('.b-infog-table tbody tr:nth-child(2n)').addClass("alt");
	
	$('.b-infog dt').click(function() {
		if($(this).hasClass('opened')){
			$(this).removeClass('opened').next().slideUp();
		}
		else{
			$(this).addClass('opened').next().slideDown();
		}
	});	
	
	$('.b-infog-table tbody tr').click(function() {
		if($(this).parent().parent().hasClass('b-infog-table-notclickable')) return;
		if($(this).hasClass('razvernuto')){
			$(this).next().remove();
			$(this).removeClass('razvernuto')
		}
		else{
			$(this).addClass('razvernuto');
			popup = $(this).children('th').children('.b-infog-plus-content').html();
			$(this).after('<tr class="b-infog-plus"><td colspan="7">'+popup+'</td></tr>');
		}
		
	});
	
	$(".b-infog-table-sortable").tablesorter();
	    
	$(".b-infog-table").bind("sortStart",function() { 
	  	$('.b-infog-table tr').removeClass('razvernuto');
		$('.b-infog-plus').remove();
		
	}).bind("sortEnd",function() { 
		$('.b-infog-table tbody tr:nth-child(2n)').addClass("alt");
		$('.b-infog-table tbody tr:nth-child(2n+1)').removeClass("alt");
	});
	
	
	
	
	$('.b-dosje .expand').click(function(){
		$('.expandme').slideToggle();
		$(this).toggleClass('expanded');
	})

	$(".b-nomera-obl").fancybox({ 'hideOnContentClick': true }); 
	//subscribe
	$('.f-subscribe .b-but').click(function(){
		$('.f-subscribe .before').hide();
		$('.f-subscribe .after').show();
		return false;
	})
	//fake buttons submitt
	$('.b-but').live("click", function(){
		$(this).closest('form').submit();
		return false;
	});
	$('.b-vote i').click(function(){
		$(this).parent().parent().addClass('showresults');
	});
	//hover on tophot
 	$('.b-tophot').hoverIntent(function() {
 		//$(this).children('.slide-info').children('.descr').slideDown();
		$('.b-tophot .descr').slideDown();
 	}, function() {
 		//$(this).children('.slide-info').children('.descr').slideUp();
		$('.b-tophot .descr').slideUp();
 	});

  //sliding tophot
	shmapi = $('.b-tophot').scrollable({  
				size: 1,
				speed:600,
				api:true,
				clickable:false
				});
	$('.hs-nav a').click(function() {
		block = $(this).attr('href');	
		gotopage = block.split('slide');
		shmapi.seekTo(gotopage[1]-1);
		$('.hs-nav a').removeClass('here');
		$('.hs-nav a[href='+block+']').addClass('here');
		return false;
	});
	
	//scrollable video	
	$('.multimedia').each(function(){
		$(this).scrollable({  
			size: 1,
			next:'#multimedia-next',
			prev:'#multimedia-prev',
			speed:600
		}).circular();
	});

	$('.blogslider').each(function(){
		$(this).scrollable({  
			size: 1,
			next:'#blog-next',
			prev:'#blog-prev',
			speed:600
		}).circular();
	});
	
	$('.switcher a').click(function() {
		$('.switcher a').removeClass('here');
		$(this).addClass('here');
		return false;
	});

			$('input[title!=""],textarea[title!=""]').hint();
			
			$('.multimedia').height($('.multimedia').children('.slides').height());
			$('.blogslider').height($('.blogslider').children('.slides').height());
	});




	/**
	* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
	* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
	* 
	* @param  f  onMouseOver function || An object with configuration options
	* @param  g  onMouseOut function  || Nothing (use configuration options object)
	* @author    Brian Cherne <brian@cherne.net>
	*/
	(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
		jQuery.fn.hint = function () {
		  return this.each(function (){
		    var t = jQuery(this);
		    var title = t.attr('title');
		    if (title) {
		      t.blur(function (){
		        if (t.val() == '') {
		          t.val(title);
		          t.addClass('blur');
		        }
		      });
		      t.focus(function (){
		        if (t.val() == title) {
		          t.val('');
		          t.removeClass('blur');
		        }
		      });
		      t.blur();
		    }
		  });
		}