$(document).ready(function() {
	$(".b-left").each(function() {$(this).children("p:last").addClass("last");});
	$("#tagslist li").each(function() {if ($(this).children("input:checkbox").attr("checked")==true) {$(this).addClass("checked")};});
	$("#tagslist").children("li").has("input").click(function(){if ($(this).children("input:checkbox").attr("checked")==true) {$(this).children("input:checkbox").removeAttr("checked"); $(this).removeClass("checked");} else {$(this).children("input:checkbox").attr("checked","checked"); $(this).addClass("checked");};});
	$(".select-all").click(function (){
		$("#tagslist li").has("input").each(function(){if ($(this).children("input:checkbox").attr("checked")==false) {$(this).children("input:checkbox").attr("checked","checked"); $(this).addClass("checked");};});
	});
	$("body").append("<div class='popup-back'></div>");
	var popup_back = $(".popup-back");
	$("a[rel]").click(function (){
		var popup = $($(this).attr("rel"));
		popup.show().addClass("open-popup");
		popup_back.show();
		popup.css("left", $("body").width()/2-popup.width()/2);
		popup.css("top", "200px");
	});
	$(".popup-close,").click(function(){$(this).parent().hide();popup_back.hide()});
	popup_back.click(function(){$(this).hide();$(".open-popup").hide();});
	$(".ui-toggle").each(function(){
		var $toggle = $(this),
			$toggle_ctrl = $toggle.find(".ui-toggle-ctrl");
		function toggler() {
			$toggle.toggleClass("ui-toggle-open");
			if ($toggle.is(".ui-toggle-open")) {
				$toggle_ctrl.text("свернуть");
			} else {
				$toggle_ctrl.text("развернуть")
			};
		};
		$toggle_ctrl.click(function(){toggler(); return false;});
		if ($toggle.is(".open")) {toggler()};
	});
	$(".b-proj img[title]").tooltip({
		offset: [24, 0]
	}).dynamic();
});
