﻿$(function(){

var body_height = $(window).height();
var content_height = $(".container").height();
if (content_height < body_height ) {
    $(".container").css("minHeight", body_height+"px");
}


var cont_height = $(".container").height();
$(".favor_podl").height(cont_height);

$(window).resize(function(){
    var body_height = $(window).height();
    var content_height = $(".container").height();

    $(".container").css("minHeight", body_height+"px");
})

$(".search_input").click(function(){
    ish_val = $(this).val();
    if (ish_val== "Поиск") {
      $(this).val("");
    } else {   }
});
$(".search_input").blur(function() {
  var temp_val = $(this).val();
  if ( temp_val == "" ) {  $(this).val(""+ish_val);   }
});

Cufon.replace('.top_place_head, .reportage_head, .club_trip_head', { fontFamily: 'PF DinText Pro' });
Cufon.replace('.rc_item_head, .tags_list span, .comment_head_table .td1, .top_menu span, .hotz_table .td2');
Cufon.replace('.top_menu a', { hover: {  color: '#000000'    }});

Cufon.replace('.reportage_head a', { hover: {  color: '#000000'    }});

$('.opinion_ul .a_post').click(function() {
    var this_class = $(this).parent("li").attr("class");
    if (this_class=="act")   {}
    else {
        var arel=$(this).attr("rel");
        $(".opinion_ul li").removeClass("act");
        $(this).parent("li").addClass("act");
        $(".opinion").hide();
        $(".opinion"+arel).show();
    }
    return false;


});

$('div.sc_menu').each(function(){
        var div = $(this);
    	var ul = $('ul.sc_menu',this),
    		ulPadding = 0;
    	var divWidth = div.width();
    	div.css({overflow: 'hidden'});
    	var lastLi = ul.find('li:last-child');
    	div.mousemove(function(e){
    		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
    		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
    		div.scrollLeft(left);
    	});
});



$(".comment_otv textarea").click(function(){
    ish_val = $(this).val();
    if (ish_val== "Комментарий") {
      $(this).val("");
    } else {   }
});
$(".comment_otv textarea").blur(function() {
    var temp_val = $(this).val();
    if ( temp_val == "" ) {  $(this).val("Комментарий");   }
});




$('.reportage_item_photo_preview ul li a').click(function() {
    var this_class = $(this).parent("li").attr("class");
    if (this_class=="act")   {}
    else {
        var arel=$(this).attr("rel");
        $(".reportage_item_photo_preview li").removeClass("act");
        $(this).parent("li").addClass("act");
        $(".p_item_photho").hide();
        $(".p_item_photho_"+arel).show();
    }
    return false;


});



$(".comment_otv_link").click(function(){
    $(".comment_otv").hide();
    $(".comment_otv_link").show();
    $(this).hide();
    $(this).next("div").fadeIn();
    return false;
});

$(".lmess_link").mouseover(function(){
	$(".lmess_popup").show();
	$(this).addClass("lmess_link_act");
});

$(".lmess_popup").mouseover(function(){
	$(this).css("display","block");
	$(".lmess_link").addClass("lmess_link_act");
});



$(".lmess_popup").hover(
  function () {
  },
  function () {    $(this).hide(); 	$(".lmess_link").removeClass("lmess_link_act");
  }
);


$(".tuser_a").hover(
  function () {
    $(".tuser_vip").show();
  },
  function () {
  }
);
$(".tuser_vip").hover(
  function () {
  },
  function () {    $(this).hide();
  }
);

$(".tuser_b").hover(
  function () {
    $(".tuser_vip_b").show();
  },
  function () {
  }
);
$(".tuser_vip_b").hover(
  function () {
  },
  function () {    $(this).hide();
  }
);

$("a[href='button']").click(function(){
	var access=$("#access_"+$(this).attr("rel")).val();
	var selector=$(this);
	var norm_id=$(this).attr("rel");
	var id="#chel_"+$(this).attr("rel");
	var id_add="#add_man_"+$(this).attr("rel");
	var id_free="#free_"+$(this).attr("rel");
	var free_place=parseInt($(id_free).text());
	var all_man=parseInt($(id_add).val())+1;
	if(access=="yes")
	{
		if($(this).hasClass("ya_poedu"))
		{
			if(free_place<all_man)
			{
				var id_man="#member_"+$(this).attr("rel");
				$(id_man).html("<li>Извините, стольких мест нет</li>");
				$(id_man).slideDown("slow",function(){
					setTimeout(function(){$(id_man).slideUp("slow");},3000);		
				});
			}
			else
			{
				var data="travel=yes&id="+$(this).attr("rel")+"&col="+$(id_add).val();
				$.ajax({
					type: "POST",
					url: "/travels/poedu.php",
					data: data,
					success: function(msg){
						$(id).text(parseInt($(id).html())+1+parseInt($(id_add).val()));
						$(id_free).text(parseInt($(id_free).html())-1-parseInt($(id_add).val()));
						$(selector).removeClass();
						$(selector).addClass("ya_edu");
						$("#set_count_div_"+norm_id).css("visibility","hidden");
						$("#set_count_div_text_"+norm_id).css("visibility","hidden");
					}
				});
			}
			
		}
		else
		{
			var data="travel=no&id="+$(this).attr("rel");
			$.ajax({
				type: "POST",
				url: "/travels/poedu.php",
				data: data,
				success: function(msg){
					var refresh=parseInt(msg);
					$(id).text(parseInt($(id).html())-refresh);
					$(id_free).text(parseInt($(id_free).html())+refresh);					
					$(selector).removeClass();
					$(selector).addClass("ya_poedu");
					$("#set_count_div_"+norm_id).css("visibility","visible");
					$("#set_count_div_text_"+norm_id).css("visibility","visible");
				}
			});	
		}
	}
	else
	{
		if(access=="no")
		{
			var id_man="#member_"+$(this).attr("rel");
			$(id_man).html("<li>Извините, Вы должны быть зарегистрированны</li>");
			$(id_man).slideDown("slow",function(){
				setTimeout(function(){$(id_man).slideUp("slow");},3000);		
			});
		}
		else
		{
			var id_man="#member_"+$(this).attr("rel");
			$(id_man).html("<li>Извините, доступно только для членов клуба</li>");
			$(id_man).slideDown("slow",function(){
				setTimeout(function(){$(id_man).slideUp("slow");},3000);		
			});
		}
	}
	return false;
});


$(".view_user").click(function(){
	var id=$(this).attr("rel");
	var id_man="#member_"+id;
	if($(id_man).css("display")=="none")
	{
		var data="id="+id;
		$.ajax({
			type: "POST",
			url: "/travels/mans.php",
			data: data,
			success: function(msg){
				$(id_man).html(msg);
				$(id_man).css("display","block");
			}
		});
	}
	else
	{
		$(id_man).css("display","none");
	}
	return false;
});

$("a[rel='map_google']").click(function(){
	var location=$(this).attr("href");
	jsGoogleSearch_google_map_id.searchByAddress(location); 
	$("#wrap").animate(
		{opacity:0.2},
		400
	);
	$("#google_map").css("visibility","visible");
	return false;
	
});
$("#close_map").click(function(){
	$("#wrap").animate(
		{opacity:1},
		400
	);
	$("#google_map").css("visibility","hidden");
});
$("#new_message").click(function(){
	$(".mess_popup").css("display","block");
	return false;
});

$("#new_message_group").click(function(){
	$(".mess_popup").css("display","block");
	$("#group_input").attr('value', 'Y');
	return false;
});


$("#close_message_popup").click(function(){
	$(".mess_popup").css("display","none");
	return false;
});

$("#wrap").click(function(){
	$("#google_map").css("visibility","hidden");
	$(this).animate(
		{opacity:1},
		400
	);
});

$("#to_group_button").click(function(){
	if($("#group_input").val()=="N")
	{
		$("#group_input").val("Y");
		$("#user_input").val("");
		$(this).css("border","3px solid #FFCB08");
	}
	else
	{
		$("#group_input").val("N");
		$("#user_input").val($("#user_backup").val());
		$(this).css("border","3px solid #7F7F7F");
	}
});

$(".favor_podl").click(function(){    $(".favor_podl, .auth_block").fadeOut();} );
$(".group_mess a").each(function(){
        $(this).click(function() {
            location.href=$(this).attr('href');
			return false;
        });
    });
	
$(".group_mess2").click(function(){

	
		location.href=$(this).attr('rel');
		return false;
});	
	
$(".group_mess").click(function(){
	//alert($(this).attr('rel'));
	
		jsAjaxUtil.InsertDataToNode('/include/messages.php?readed='+$(this).attr('rel2'), 'template-messages', false); 
		jsAjaxUtil.InsertDataToNode('/include/messages_count.php?readed='+$(this).attr('rel2'), 'template-messages-count', false); 
		$("#user_input").attr('value', $(this).attr('rel'));
		$("#user_backup").attr('value', $(this).attr('rel'));
		$("#group_input").attr('value', 'N');
		$(".mess_popup").css("display","block");
		return false;
});

});




