

$(document).ready(function(){
	$('.btnPostReadmore').live('click',function () {
        if ($(this).attr("data-expanded")=="true")
        {
            $(this).html('Read more');

            $(this).parent().parent().parent().find('.newsPostTextRest').slideUp();
            $(this).attr("data-expanded","false");
        } else {
            $(this).parent().parent().parent().find('.newsPostTextRest').slideDown();
            $(this).html('Close');
            $(this).attr("data-expanded","true");
        }
        return false;
    });

	$('ul#activityNav li').live({
        mouseenter:
            function(){
				if ($(this).hasClass('selected'))
					return;
				$(this).find('ul').stop(true,true).slideDown(500);
			},
		 mouseleave:
		    function(){
				if ($(this).hasClass('selected'))
					return;
				$(this).find('ul').stop(true,true).slideUp(500);
		    }
		});

	$('textarea#comment').live('click',function(){
		$(this).addClass('hideBar');
	});

	$('a.addComment').live('click',function(){
		var postId = $(this).attr('data-postid');
		$(this).toggleClass('addCommentOpen');
		if (!$(this).hasClass('addCommentOpen'))
		{
			//$(this).removeClass('addCommentOpen');
			$('#commentsForm'+postId).slideUp();
		}
		else
		{
			$('#commentsForm'+postId).hide().load($(this).attr('href'), function (){
				$(this).slideDown();
			});
		}
		return false;
	});

	$('#subscribeFormEmail').autofill({value:'email'});
	$('#searchFormSearch').autofill({value:'type your search'});

	$('#subscribeGo').live('click',function(){
        log($('#subscribeForm'))
		$('#subscribeForm').submit();
		return false;
	});

    $('#searchForm').live('submit',function(){
        log ($(this).parent('.content'))
        var _this = this;
        var data =
        {
            search:$('INPUT#search').val()
        };
        $.ajax({
            url:'/activity/search',
            data:data,
            type:'POST',
            success:function(data,textStatus,jqXHR)
            {
                $(_this).parents('.content').find('.main').html(data);
            }
        });
        return false;
    });

	$('#searchGo').live('click',function(){
        $('#searchForm').submit();


		return false;
	});

	$('#subscribeForm').live('submit',function(){
        log($(this).serialize());
		$.ajax({
			url:'/subscribe',
			data:$(this).serialize(),
			type:'POST',
			success:function(data,textStatus,jqXHR)
			{
				$('#subscribe').html(data);
			}
		});
		return false;
	});
});
