// JavaScript Document
$('div.block').hide();

$('.show_block a').toggle(function() {
	$(this).parent('h2').next('div.block').show();
	$(this).attr("title","Свернуть");
	$(this).addClass("active bg");
	return false;
}, function () {
	$(this).parent('h2').next('div.block').hide();
	$(this).attr("title","Развернуть");
	$(this).removeClass("active bg");
	return false;
});

$('a.action').toggle(function() {
	$(this).q_opens();
}, function () {
	$(this).q_close();
});

jQuery.fn.q_opens = function() {
	if(!this.hasClass("active")) {
	this.addClass('active').parent().addClass('open').show();
	}
	return this;
};

jQuery.fn.q_close = function() {
	this.removeClass('active').parent().removeClass('open').find('div').removeClass('open').hide();
	return this;
}

var myFile = document.location.toString();
if (myFile.match('#')) { // the URL contains an anchor
  // click the navigation item corresponding to the anchor
  var myAnchor = '#' + myFile.split('#')[1];
  $('a[href="' + myAnchor + '"]').click();
  $('a[href="' + myAnchor + '"]').parents('div.block').prev('h2').children('a').click();
}

