
$(document).ready(function(){

	Cufon.replace("div.h2_title, #news_pop div.title");

	$("#_id_mask").focus ( function () {		$(this).hide();
		$("input.pass").show().focus();	});

	$("#_id_site_pass").blur (function () {		if ($(this).val()=="") {			$(this).hide();
			$("input.mask").show();
		}	});


	$("#photo_front div.img, #invite div.img").dropShadow({left: 0, top: 0, blur: 2, opacity: 0.4});

	$(".photo").each(function(i){
  		$(this).find("div.img").dropShadow({left: 0, top: 0, blur: 2, opacity: 0.4});
	});

	$("div.form div.title").dropShadow({left: 0, top: -1, blur: 2, opacity: 0.4});

	$("#insets div.on").dropShadow({left: 0, top: -1, blur: 2, opacity: 0.4});

    $('#menu_line li:first').addClass("first");

	$("#menu_line li.li").hover(function(){
  		$(this).addClass("hover");
	},function(){
  		$(this).removeClass("hover");
	});

	$("#menu_line div.popup a").hover(function(){
  		$(this).parent("li").addClass("hover");
	},function(){
  		$(this).parent("li").removeClass("hover");
	});

	$("#main_left div.bans div.one").each(function(i){
		var height = $(this).height()+2;
		$(this).find('div').css({ height: height });
	});

	$("#bg_pipka a, #news_pop a.pipka, #calendar div.act a, div.form div.cancel a").focus(function(){
         $(this).blur();
    });
	$("#bg_pipka a").click( function() {
		$("#news_pop").show();
		return false;
	} );
	$("#news_pop a.pipka").click( function() {
		$("#news_pop").hide();
		return false;
	} );

	// календарь новостей
	flag_news = 2;
	if ($("#calendar").hasClass('big')) {
		left = -611;
		delta = 611;
		n_list = 13;
	} else {
		left = -329;
		delta = 329;
		n_list = 7;
	}
	n_one = Math.round($("#calendar div.one").length/3);
//	n_one = $("#calendar div.one").length-6;
	$('#calendar div.one:first').addClass("first");

	$("#calendar div.one").hover(function(){
  		$(this).addClass("hover");
  		elem = $(this).find("div.pop");
		    if ($(this).find("div.pop").length) {			if (!$(this).find("div.pop").find("div.top").length) {				//alert($(this).find("div.pop").attr("id"));			/*	$.getJSON("/pop.php?date="+$(this).find("div.pop").attr("id"), {}, function(json){
		            alert(json.text);
		            $(elem).html(json.text);
		        }); */
			  ident_req = new JsHttpRequest();

			  ident_req.caching = false;
			  ident_req.open('get', '/pop.php');
			  ident_req.onreadystatechange = function() {
			  if (false) {
			  } else {
			    if(ident_req==null)
			      return;
			    if (ident_req.readyState != 4)
			      return;
			       $(elem).html(ident_req.responseJS.text);
//			       alert(ident_req.responseJS.text);
			       //set_id_background((ident_req.responseJS.isset>0)?true:false, el, ident_req.tab);
			    }
			  }
			  d_d = $(this).find("div.pop").attr("id");
			  ident_req.send({date: d_d });


//				$(this).find("div.pop").load("/pop.php?date="+$(this).find("div.pop").attr("id"));			}
			var flag_one = $("#calendar div.one").index(this)+1;
			while (flag_one-n_list>0) {
				flag_one-=n_list;
			}
			var left = -111;
//			alert(n_one);
			if (flag_one==1) {
				left = 0;
				$(this).find("div.arrow").css({ left: "15px" });
			} else if (flag_one==2) {
				left = -47;
			} else if (flag_one==3) {
				left = -94;
			} else if (flag_one==n_one) {
				left = -215;
				$(this).find("div.arrow").css({ left: "-10px" });
			} else if (flag_one==n_one-1) {
				left = -168;
			} else if (flag_one==n_one-2) {
				left = -121;
			}
			$("#calendar").addClass("calendar_on");
			$("#calendar div.bg").addClass("bg_on");
			$(this).find("div.pop").css({ left: left }).show();
			$(this).find("div.arrow").show();
		}
	},function(){
  		$(this).removeClass("hover");
		if ($(this).find("div.pop").length) {
			$("#calendar").removeClass("calendar_on");
			$("#calendar div.bg").removeClass("bg_on");
			$(this).find("div.pop").hide();
			$(this).find("div.arrow").hide();
		}
	});


	$("#calendar").hover(function(){
		$("#news_pop").hide();
	});
	$("#news_pop").hover(function(){
	},function(){
  		$(this).hide();
	});

	$("#calendar div.bw a").click( function() {
		left+=delta;
		$("#calendar div.lenta").animate({ left: left }, "slow");
		flag_news--;
		if (flag_news==1) {
			$(this).hide();
		}
		$("#calendar div.fw a").show();
		return false;
	} );

	$("#calendar div.fw a").click( function() {
		left-=delta;
		$("#calendar div.lenta").animate({ left: left }, "slow");
		flag_news++;
		if (flag_news==3) {
			$(this).hide();
		}
		$("#calendar div.bw a").show();
		return false;
	} );

	$("table.table_default").each(function(i){
  		$(this).find("tr:even").addClass('bg');
	});

	$("div.form div.cancel a").click( function() {
		$("div.form input.input, div.form textarea").val("");
		return false;
	} );


});

