library.prototype.default_link = "/ajax";
$(document).ready(function(){
	var b = new browser;
	if(b.ie){
		try{
			$.fixPNG( $("#menu_triangle").get(0)  );
		}
		catch(err){}
	}
	$("div.menu_item, div.menu_item_submenu").hover(function(){
		var $$ = $(this);
		$$.find("> a").css({
			opacity : 1
		});
		var child = $$.find("> div.menu_item_child");
		var b = new browser;
		if(  child.find("> div").get().length > 0  ){
			var content = child.html();
			var margin =  "-20px";
			if(b.ie || b.ie7) margin =  "-33px";
			if(b.ie8) margin =  "-24px";
			child.css({
				"margin-left" : $$.width() -4,
				"margin-top" : margin
			}).show();
			child.find("> div > div > a,> div > div > span").css({
					opacity : .9
				});
			if(b.ie)
				$("img.submenu_img").each(function(){
					$.fixPNG(this);
				});
		}
	}, function(){
		var $$ = $(this);
		$$.find("> a").css({
			opacity : .9
		});
		var child = $$.find("> div.menu_item_child");
		child/*.stop()*//*.fadeOut("slow");*/.hide();
	});
	{//time
		var time_string = $("#time_string").html().match("([0-9]{2}):([0-9]{2})");
		var i = 0;
		if(time_string[1] && time_string[2]){
			function _time(){
				now = new Date();
				$("#time_string").html(
					"<div style='float:left;'>"+(now.getHours()< 10 ? "0" : "")+now.getHours()+"</div>"+
					"<div style='float:left;left:28px;'>"+(++i%2 ? ":" : "&nbsp;")+"</div>"+
					"<div style='float:left;left:34px;'>"+(now.getMinutes()< 10 ? "0" : "")+now.getMinutes()+"</div>"
				);
				setTimeout(function(){
					 _time();
				}, 1000);
			}
			_time();
		}
	}
	{//datepicker
		$("#date").tooltip({x:-1,y:20}, function(){
			var now = new Date();
			var calendar_obj = new $.calendar;
			return calendar_obj.calendar(  now.getMonth(), now.getFullYear()  ).html();
		});
	}
	{//schedule
		$("div.time_header")
			.hover(function(){  $(this).addClass("time_header_hover");  }, function(){  $(this).removeClass("time_header_hover");  })
			.click(function(){
				$.ajj({
					type : "plugin_command_html",
					"class" : "TXT",
					instance : 6,
					command_type : "get"
				}, function(r){
					function back(){
						$("#win1").win({
							shadow : true,
							title : {
									id : "div.win .win_title",
									text : "Расписания"
								},
							drag : {
									id : "div.win .win_header"
								},
							content : {
									id : "div.win div.win_content",
									text : r.html
								},
							width : "300px",
							position : {top : "100px", left : "50%"},
							margin : "0px 0px 0px -150px",
							"class" : "win orange_win",
							after : function(){
								$("#win1 input.ok").hide();
								$("div.win_content a").click(function(e){
									var b = new browser;
									var id = (b.ie || b.ie7) ? unescape($(this).attr("href").match(/\/([^\/]+)$/i)[1]) : $(this).attr("href");
									$.ajj({
										type : "plugin_command_html",
										"class" : "TXT",
										instance : 1,
										fastid : id,
										command_type : "fastget"
									}, function(r){
										$("#win1 input.ok").show();
										$("div.win div.win_content").html(r.html);
										var width = $("#win1 div.win_content *:first").width() +20;
										$("#win1").css({
											width : width,
											"margin-left" : -width/2
										});
										$("div.win_content").css({
											padding : "10px"
										});
									});
									e.preventDefault();
								});
							}
						}, function(){
							setTimeout(function(){  back();  }, 500);
						});
					}
					back();
				});
			});
	}
	{//pager
		NEWS_plugin_1_reload = function(r, page){
			$("#news_content").parent().html(r.html);
		}
		NEWS_plugin_2_reload = function(r, page){
			$("#content").html(r.html);
		}
		COMMENTS_plugin_reload = function(r, page){
			$("#__COMMENTS__").html(r.html)
		}
	}
	{//image
		param = [];
		$("a[href$=png], a[href$=jpg], a[href$=jpeg], a[href$=gif]")
			.click(function(e){
				e.preventDefault();
			})
			.colorbox();
		var b = new browser;
		if(!b.ie)
			$("a[href$=png], a[href$=jpg], a[href$=jpeg], a[href$=gif]")
				.hover(function(){ $(this).css({opacity:.85}); }, function(){ $(this).css({opacity:1}); })
	}
	{//login buttons
		$("#send_button").hover(function(){
			$(this).css({
				"background-position" : "0px -41px"
			});
		}, function(){
			$(this).css({
				"background-position" : "0px 0px"
			});
		}).click(function(){
			location.href = "/send";
		});
		$("#sitemap_button").hover(function(){
			$(this).css({
				"background-position" : "0px -41px"
			});
		}, function(){
			$(this).css({
				"background-position" : "0px 0px"
			});
		}).click(function(){
			location.href = "/sitemap";
		});
	}
});