$.fn.extend({
	mmenu: function(){
		var $this = $(this),
			t;

		var hideAll = function(){
			$this.find(".dd").hide();
			$this.find("li.item").removeClass("selected");
		}

		$this.find("li.item").hover(function(){
			clearTimeout(t);
			hideAll();

			$(this).addClass("selected")
			$(this).find(".dd").show()
			$(this).find("span").hide(0).show(0)
			
		}, function(){
			t = setTimeout(function(){hideAll()}, 500);

//			$(this).removeClass("selected")
//			$(this).find(".dd").hide()
		})
	},

	calendar: function(){

		var $this = $(this),
			$img = $(document.createElement('img')).css({position: "absolute", display: "none"}).attr({src: "images/01 str.jpg"})

			$("body").append($img);

		$this.hover(
				function(e){$img.css({left: e.clientX+5, top: e.clientY+21}).show();},
				function(){$img.hide();}
			);
		$this.mousemove(function(e){ $img.css({	left: e.clientX+5, top: e.clientY+21 })})
	},

	eventCalendar: function(){
		var $this = $(this)

		$.datepicker.setDefaults( $.datepicker.regional[ "ru" ] );
		$this.datepicker({
			showOtherMonths: true,
			selectOtherMonths: true,
			beforeShowDay: function(date){
				return [1, '', $.datepicker.formatDate("yy-mm-dd", date)];
			}
		});

		$this.find('td a').live("mouseover",function(event){
			var $a = $(this), $td=$a.closest("td");
			if ($a.attr("rel")=='')
			{
				$a.attr("rel", "ajax.php?block=calendar&action=index&d="+$td.attr("title")+"&tag_id="+$("#select_tag").val());
				$a.cluetip({
					sticky: true, showTitle: false, topOffset:0, leftOffset:0, positionBy: "auto",
					closeText: '<img src="default/css/i/close.png" alt="" />',
					onShow: function() {if($("#cluetip-inner").find(".cont").length==0) $("#cluetip").hide(0);}
				});
				$a.trigger(event)
			}
		});
	},
	
	subscribe: function(){
		var $this = $(this),		
			$inp = $this.find("input"),
			val = $inp.val();
		
		$inp.focus(function(){if ($(this).val()==val) $(this).val("");});		
		$inp.blur(function(){if ($(this).val()=="") $(this).val(val);});
		
		$this.find("a").click(function(){
			$.post("ajax.php?block=subscribe&action=submit",{email:$inp.val()}, function(){
				alert("Спасибо за регистрацию");
				$inp.val(val);
			})
		});
	}
});

$(document).ready(function(){
	var i = Math.round(2*Math.random())+1
	$("body").css("background", "transparent url(default/css/i/bg/"+i+".jpg) top left")
})
