(function(a){a.event.special.textchange={setup:function(){a(this).data("lastValue",this.contentEditable==="true"?a(this).html():a(this).val());a(this).bind("keyup.textchange",a.event.special.textchange.handler);a(this).bind("cut.textchange paste.textchange input.textchange",a.event.special.textchange.delayedHandler)},teardown:function(){a(this).unbind(".textchange")},handler:function(){a.event.special.textchange.triggerIfChanged(a(this))},delayedHandler:function(){var b=a(this);setTimeout(function(){a.event.special.textchange.triggerIfChanged(b)}, 25)},triggerIfChanged:function(b){var c=b[0].contentEditable==="true"?b.html():b.val();if(c!==b.data("lastValue")){b.trigger("textchange",b.data("lastValue"));b.data("lastValue",c)}}};a.event.special.hastext={setup:function(){a(this).bind("textchange",a.event.special.hastext.handler)},teardown:function(){a(this).unbind("textchange",a.event.special.hastext.handler)},handler:function(b,c){c===""&&c!==a(this).val()&&a(this).trigger("hastext")}};a.event.special.notext={setup:function(){a(this).bind("textchange", a.event.special.notext.handler)},teardown:function(){a(this).unbind("textchange",a.event.special.notext.handler)},handler:function(b,c){a(this).val()===""&&a(this).val()!==c&&a(this).trigger("notext")}}})(jQuery);
jQuery.fn.center=function(absolute){return this.each(function(){var t=jQuery(this);t.css({position:absolute?'absolute':'fixed',left:'50%',top:'50%'}).css({marginLeft:'-'+(t.outerWidth()/2)+'px',marginTop:'-'+(t.outerHeight()/2)+'px'});if(absolute){t.css({marginTop:parseInt(t.css('marginTop'),10)+jQuery(window).scrollTop(),marginLeft:parseInt(t.css('marginLeft'),10)+jQuery(window).scrollLeft()})}})};
(function( $ ) {$( ".ui-autocomplete-input" ).live( "autocompleteopen", function() {var autocomplete = $( this ).data( "autocomplete" ),menu = autocomplete.menu;if ( !autocomplete.options.selectFirst ) {return;}menu.activate( $.Event({ type: "mouseenter" }), menu.element.children().first() );});}( jQuery ));
(function(jQuery) {var self = null;jQuery.fn.autogrow = function(o){return this.each(function() {new jQuery.autogrow(this, o);});};	jQuery.autogrow = function (e, o){this.options		 	= o || {}; this.dummy = null; this.interval = null; this.line_height = this.options.lineHeight || parseInt(jQuery(e).css('line-height')); this.min_height	= this.options.minHeight || parseInt(jQuery(e).css('min-height')); this.max_height = this.options.maxHeight || parseInt(jQuery(e).css('max-height')); this.textarea = jQuery(e); this.expand_tolerance = (!isNaN(this.options.expandTolerance) && this.options.expandTolerance > 0) ? this.options.expandTolerance : 1; if(isNaN(this.line_height)) this.line_height = 0; this.init(); }; jQuery.autogrow.fn = jQuery.autogrow.prototype = { autogrow: '1.2.3' }; jQuery.autogrow.fn.extend = jQuery.autogrow.extend = jQuery.extend; jQuery.autogrow.fn.extend({ init: function() { var self = this; this.textarea.css({overflow: 'hidden', display: 'block'}); this.textarea.bind('focus', function() { self.startExpand() } ).bind('blur', function() { self.stopExpand() }); this.checkExpand(); }, startExpand: function() {	 var self = this; this.interval = window.setInterval(function() {self.checkExpand()}, 400); }, stopExpand: function() { clearInterval(this.interval);}, checkExpand: function() { if (this.dummy == null) { this.dummy = jQuery('<div></div>'); this.dummy.css({ 'font-size' : this.textarea.css('font-size'), 'font-family': this.textarea.css('font-family'), 'width' : this.textarea.css('width'), 'padding' : this.textarea.css('padding'), 'line-height': this.line_height + 'px', 'overflow-x' : 'hidden', 'position' : 'absolute', 'top' : 0, 'left': -9999 }).appendTo('body'); } else { this.dummy.show(); } var html = this.textarea.val().replace(/(<|>)/g, ''); if (jQuery.browser.msie) { html = html.replace(/\n/g, '<BR/>new'); } else { html = html.replace(/\n/g, '<br/>new'); } if (this.dummy.html() != html) { this.dummy.html(html); if (this.max_height > 0 && (this.dummy.height() + (this.expand_tolerance*this.line_height) > this.max_height)) { this.textarea.css('overflow-y', 'auto'); if (this.textarea.height() < this.max_height) { this.textarea.animate({height: (this.max_height + (this.expand_tolerance*this.line_height)) + 'px'}, 100); } } else { this.textarea.css('overflow-y', 'hidden'); if (this.textarea.height() < this.dummy.height() + (this.expand_tolerance*this.line_height) || (this.dummy.height() < this.textarea.height())) { if (this.dummy.height() < this.min_height) { this.textarea.animate({height: (this.min_height + (this.expand_tolerance*this.line_height)) + 'px'}, 100); } else { this.textarea.animate({height: (this.dummy.height() + (this.expand_tolerance*this.line_height)) + 'px'}, 100); } } } } this.dummy.hide(); } }); })(jQuery);
function stripTags(d){return d.replace(/<\/?[^>]+>/gi, '');}
var page = 1;
var prev_page = [];
var newlink ="";
var postVal = "";
var postDataVal = [];
var interval;
var uploading_choice = 0;
var upload_initiated = 0;
var pollimg_progress = 0;
var pollnullimage = "/images/f/poll_ch_img.png";
function post_response(pid, comment){
    $.post("/view.php", { comsub: "0", req: "ajax" , pid:pid, comment:comment},
    function(data){
        if(data == 'success'){
            var userid=$("input#session_userid").val();
            $(".buzzcnt").each(function(){
                if($(this).attr("title") == userid){
                    $(this).html(parseInt($(this).html())+1)					
                }
            });
			
            window.location.reload();
        }
    });
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function close_popup(){	


	
    $(".cls_img").unbind('click').click(function(event){
        $("#pic_ctr").hide();
    });
	
    $(".alert_popup").unbind('click').click(function(){
        $(this).hide();
        var close_x = $(this).attr('id');
        $.post("/close_notifs.php", {close: close_x},function(data){});});	
    $('.brws_closebutton').unbind('click').click(
    function(){
        document.cnclform.submit();
        uploading = 0;
        upload =0;
        $("div").removeClass('pop_open');
        $("#img_id").val("");
        $('.poll_img').each(function(){$(this).attr("src", pollnullimage)});
        $("#vdo_id").val("");
        $("#link_id").val("");
        $("#user_image").val('');
        $('#browseimage').hide();
        $('#showimage').html("");
        $('#showvideo').html("");
        $('#attach_url_text').val("http://");
        $('#ph_loading').hide();
        $('#link_loading').hide();
        $('#ph_uploadview').hide();
        $('#link_uploadview').hide();
        $('#video_upload_view').hide();
        $('#poll_uploadview').hide();
        $("#title_label").hide();
        $("#upload_label").hide();
        $("#p_img_div").hide();
        $(".dynamic").remove();
        //$('.brws_closebutton').hide();
        $("#pollelimg").hide();
        $(':text, :password, :file', '#poll_form').val(''); 
        $(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
			
        var follow_check=$("input#is_follow").val();
        var follower_id=$("input#follower_id").val();
        var user_id=$("input#uid").val();
        var cid=$("input#circle").val();
        $("textarea#update").show();
        if($("textarea#update").val()==''){
			
            if(follow_check==0 && follower_id!=user_id){
                $("textarea#update").val('To post on a profile you need to follow each other...');
            }
            else if(cid!=0){
                $("textarea#update").val("Start Writing...");
            }
            else{
                $("textarea#update").val("Start Writing Something...");
            }
            $("textarea#update").removeClass('typing');
        }
        //$("input#poll_title").css('width','404px');
        //$("textarea#update").val("Write me a message!");
        $("input#poll_title").val("e.g:should I tell all my friends about azooca.com?");
		
        $("input#post_text").val("Start Writing Something...");
        $(".hidenfile").hide(); 
        $("#bottom_lnks").show();$("#sgst_panel").show();
        $('#image_icon1').show();
        $('#video_icon').show();
        $('#link_icon').show();$("#txt").show();
        //$('#poll_icon').show();
        $('#add_txt').show();
        $("#submit").html($("#submit").html());
        show_popups();close_popup();poll_actions();
    });
    $('.drop_closebutton').unbind('click').click(
    function(){
        document.cnclform.submit();
        uploading = 0;
        upload =0;
        $("div").removeClass('pop_open');
        $("#img_id").val("");
        $('.poll_img').each(function(){$(this).attr("src", pollnullimage)});
        $("#vdo_id").val("");
        $("#link_id").val("");
        $("#user_image").val('');
        $('#browseimage').hide();
        $('#showimage').html("");
        $('#showvideo').html("");
        $('#attach_url_text').val("http://");
        $('#ph_loading').hide();
        $('#link_loading').hide();
        $('#ph_uploadview').hide();
        $('#link_uploadview').hide();
        $("#post_desc_container").hide();
        $("#PrivacySuggestions").hide();
        $("#poll_category").hide();	
        $('#video_upload_view').hide();
        $('#poll_uploadview').hide();
        $("#title_label").hide();
        $("#upload_label").hide();
        $("#p_img_div").hide();
        $(".dynamic").remove();
        $(".suggest_panel").hide();
        $(".add_sugst").hide();$(".allow_chk").hide();
        //$('.brws_closebutton').hide();
        $("#pollelimg").hide();
        $(':text, :password, :file', '#poll_form').val(''); 
        $(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
			
        var follow_check=$("input#is_follow").val();
        var follower_id=$("input#follower_id").val();
        var user_id=$("input#uid").val();
        var cid=$("input#circle").val();
        $("textarea#update").show();
        if($("textarea#update").val()==''){
			
            if(follow_check==0 && follower_id!=user_id){
                $("textarea#update").val('To post on a profile you need to follow each other...');
            }
            else if(cid!=0){
                $("textarea#update").val("Start Writing...");
            }
            else{
                $("textarea#update").val("Start Writing Something...");
            }
            $("textarea#update").removeClass('typing');
        }
        //$("input#poll_title").css('width','404px');
        //$("textarea#update").val("Write me a message!");
        $("input#poll_title").val("e.g:should I tell all my friends about azooca.com?");
		
        $("input#post_text").val("Start Writing Something...");
        $(".hidenfile").hide(); 
        $("#bottom_lnks").hide();$("#sgst_panel").hide();
        $('#image_icon1').show();
        $('#video_icon').show();$("#txt").show();
        $('#link_icon').show();
        //$('#poll_icon').show();
        $('#add_txt').show();
        $("#submit").html($("#submit").html());
        $("#poll_string_count").hide();
        $('.drop_closebutton').hide();
		
        show_popups();close_popup();poll_actions();
    });
}
function reset_box(){
	
	
    $('body').click(function(){
							 
	 $('.list_options').hide();
	 $(".close_notif").removeClass('selected');
	$("#poll_title").bind('textchange',function(e){
            //$(e.target).autogrow(this);
            reste=200;
            var len = $(e.target).val().length;
            reste = 200 - len;
            $("#poll_string_count span").html(reste);
	});
	    
	if($("#cmm_new").val()==''){
            $(".post_btncomment").hide();
	}	
		
	if($('#bottom_lnks:visible').length >0){
            uploading = 0;
            upload =0;
            /********************************************/
		
            if(document.cnclform){document.cnclform.submit();}
            uploading = 0;
            upload =0;
            if($("#poll_title").val()==''){
                $("div").removeClass('pop_open');
                $("#img_id").val("");
                $('.poll_img').each(function(){$(this).attr("src", pollnullimage)});
                $("#vdo_id").val("");
                $("#link_id").val("");
                $("#user_image").val('');
                $('#browseimage').hide();
                $('#showimage').html("");
                $('#showvideo').html("");
                $('#attach_url_text').val("http://");
                $('#ph_loading').hide();
                $('#link_loading').hide();
                $('#ph_uploadview').hide();
                $('#link_uploadview').hide();
				
                //$("#post_desc_container").hide();
                //$("#poll_category").hide();	
                //$("#poll_string_count").hide();	
                $("#p_desc").hide();	
                $('#video_upload_view').hide();
                $('#poll_uploadview').hide();
                $("#title_label").hide();
                $("#upload_label").hide();
                $("#p_img_div").hide();
                $(".dynamic").remove();
                $(".suggest_panel").hide();
                $(".add_sugst").hide();$(".allow_chk").hide();
                //$('.brws_closebutton').hide();
                $("#pollelimg").hide();
                $(':text, :password, :file', '#poll_form').val(''); 
                $(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
				
                var follow_check=$("input#is_follow").val();
                var follower_id=$("input#follower_id").val();
                var user_id=$("input#uid").val();
			
                $("#poll_title").val("");
                $("input#post_text").val("Write on the Wall...");
                $("textarea#msg_text").val("Write a message...");
                $(".hidenfile").hide(); 
                //$("#bottom_lnks").hide();$("#sgst_panel").hide();
                $('#image_icon1').show();
                $('#video_icon').show();$("#txt").show();
                $('#link_icon').show();
                //$('#poll_icon').show();
                $('#add_txt').show();
                $("#submit").html($("#submit").html());
                //$('.drop_closebutton').hide();
                show_popups();close_popup();poll_actions();
            }
            /*
		if(($("#poll_title").val()=='' || $("textarea#update").val()=='Write on the Wall...' || $("textarea#update").val()=='Start Writing...' ||$("textarea#update").val()=='To post on a profile you need to follow each other...') && $(".pop_open").length==0 ){
			//$("#bottom_lnks").hide();
			$("#img_id").val("");
			$("#vdo_id").val("");
			$("#user_image").val('');
			$('#browseimage').hide();
			$('#showimage').html("");
			$('#showvideo').html("");
			$('#ph_loading').hide();
			$('#link_loading').hide();
			$('#ph_uploadview').hide();
			$('#link_uploadview').hide();
			$("#post_desc_container").hide();
			$('#video_upload_view').hide();
			$('#poll_uploadview').hide();
			$(".dynamic").remove();
			$(".suggest_panel").hide();
			$('#image_icon1').show();
			$('#video_icon').show();
			$('#link_icon').show();
			$("#txt").show();
			//$('#poll_icon').show();
			$('#add_txt').show();
			$("#poll_title").val("");
		
			$("input#post_text").val("Write on the Wall...");
			$("textarea#msg_text").val("Write a message...");
			$(".hidenfile").hide(); 
			//$("input#poll_title").css('width','404px');
			$("#bottom_lnks").hide();$("#sgst_panel").hide();
			$("#polldate").html('');
			var follow_check=$("input#is_follow").val();
			var follower_id=$("input#follower_id").val();
			var user_id=$("input#uid").val();
			var cid=$("input#circle").val();
			if(follow_check==0 && follower_id!=user_id){
				$("textarea#update").val('To post on a profile you need to follow each other...');
			}
			else if(cid!=0){
				$("textarea#update").val("Start Writing...");
			}
			else{
				$("textarea#update").val("Write on the Wall...");
			}
			$("textarea#update").removeClass('typing');
			$(".usr_grps").hide();
			poll_actions();
			}*/
        }
		
    });	
	
    $('#submit').click(function(event){event.stopPropagation();})
}
function voteYes(id,nb){
    if(readCookie(id) == null && $("#session_userid").val()!="")
    {
        $.post("/vote.php", {id:id,nb:nb,tp:'yes'},function(data){ var messagetype='message'; if(data.indexOf('error:')==0){messagetype= 'error'} //flash_message(data, messagetype);
        });
    }else if($("#session_userid").val()== ""){
        flash_message("You need to login to rate a Buzz", "error");
    }else{
        flash_message("You have already rated this Buzz", "error");	
    }
}

function voteNo(id,nb){
    if(readCookie(id) == null && $("#session_userid").val()!="")
    {
        $.post("/vote.php", {id:id,nb:nb,tp:'no'},function(data){ var messagetype='message'; if(data.indexOf('error:')==0){messagetype= 'error'} flash_message(data, messagetype);});
    }else if($("#session_userid").val()== ""){
        flash_message("You need to login to rate a Buzz", "error");
    }else{
        flash_message("You have already rated this Buzz", "error");
    }
}
function submitToggle() {
    if ($('#submit').css('display') == 'none') {
        $('#submit').slideDown();
    } else {
        $('#submit').slideUp();
    }
}

function plusToggle(id) {
    if ($('#plus'+id).css('display') == 'none') {
        $('#plus'+id).slideDown();
    } else {
        $('#plus'+id).slideUp();
    }
}
function loadContent(elementSelector, sourceURL) {
    $(""+elementSelector+"").load(""+sourceURL+"", function(){
	//$(".bubble_cont").each(function(){$(this).width($(this).parent().innerWidth()-56);});
	clicker();
    });
}
function removeSelected()
{		
    $(".postbit.selected,.memberbit.selected,.f_postbit.selected").each(function(){
        $(this).removeClass('selected');$(this).find(".this_arrow").removeClass('arr_visible');$(this).find(".this_arrow").removeClass('arr_show');
        $(this).css("background-color","");
		
        $(this).find(".bubble_bot").css("background-position","left bottom");
    });
}
function closePreview(){
    removeSelected();
    $("#fixme").animate({width:0, padding:0},"slow", function(){
        $('#loadme').hide().html('');
        $("#user_detail").fadeIn();
    }).hide();
		
}
function attachTailEvents(){
}
function submit_register(){
    if($('#register_username').val() == ""){flash_message("Please choose a username", 'message'); return false;}
    if($('#register_password1').val() == ""){flash_message("Please create a passsword", 'message'); return false;}
    if($('#register_password2').val() == ""){flash_message("Please confirm passsword", 'message'); return false;}
    if($('#register_email').val() == ""){flash_message("Please enter your email", 'message'); return false;}
    var username = $('#register_username').val();
    var password = $('#register_password1').val();
    var confirmpassword = $('#register_password2').val();
    var email = $('#register_email').val();
    $.post('/signup_check.php', {register:'register', username:username, password:password,confirmpassword:confirmpassword, email:email}, function(data){
        if(data == 'ok'){				
            window.location = "/updateprofile";
        }else{
            flash_message(data, 'error');
        }
    })
    return false;
}
function submit_login(){
    var username = $('#login_username').val();
    var password = $('#login_password').val();
    $.post('/login.php', {authenticate:'auth', lusername:username, lpassword:password}, function(data){
        if(data == 'loggedin'){
            /*flash_message("Successfully logged in", 'message');*/
            window.location = "/advice";
        }else{
            flash_message(data, 'error');
        }
    })
    return false;
}
function historyback(){
    var data = prev_page.pop();
    $('#loadme').html(data[1]);
    newlink = $("#back_link").html();
    $("#back_link").html(data[0]);
    clicker();
}

function getCategoryId(cid)
{

    var url=window.location.href;

    myregexp = /\h([^?]*)?/;
    myregexp.exec(url);
    var nurl=RegExp.$1;
	

    window.location.href="h"+nurl+"?cid="+cid;
	
	
}
function clicker(){
    $('#poll_explain').unbind('focus').focus(function(event){
        event.stopPropagation();
        if($(this).val() == "Want to explain your choice?"){
            $(this).val("");
            $(this).addClass('typing');
        }
    });
    $('#poll_explain').unbind('blur').blur(function(event){
        event.stopPropagation();
        if($(this).val() == ""){
            $(this).val("Want to explain your choice?");
            $(this).removeClass('typing');
        }
    });
    $(".post_com").bind('textchange',function(e){
        $(e.target).autogrow(this);
        var len = $(e.target).val().length;
        reste = 200 - len;
        $("#cm_count b").html(reste);
    });
    $("#poll_title").bind('textchange',function(e){
        //$(e.target).autogrow(this);
        var len = $(e.target).val().length;
        reste = 200 - len;
        $("#poll_string_count span").html(reste);
    });
    $(".ofr_Adv").bind('textchange',function(e){
        $(e.target).autogrow(this);
	
    });
    $("#cmm_new").bind('textchange',function(e){
        $(e.target).autogrow(this);
	
    });
	
    $(".bubble .respond").unbind('click').click(
    function(event){
        event.stopPropagation();
    });
    $(".bubble .share").unbind('click').click(
    function(event){
        event.stopPropagation();
    });
    $(".bubble .gift").unbind('click').click(
    function(event){
        event.stopPropagation();	
    });
    $(".bubble .like").unbind('click').click(
    function(event){
        event.stopPropagation();	
        var source = $(this).parent().parent().parent().parent().parent();
        var nb =0;
        var id = source.find('.postid').val();
        voteYes(id,nb)
    });
    $(".bubble .dislike").unbind('click').click(
    function(event){
        event.stopPropagation();
        var source = $(this).parent().parent().parent().parent().parent();
        var nb =0;
        var id = source.find('.postid').val();
        voteNo(id,nb)
    });
    $(".bubble .fav").unbind('click').click(
    function(event){
        event.stopPropagation();	
        var source = $(this).parent().parent().parent().parent().parent();
        var obj = source;
        var id = source.find('.postid').val();
        $.post("/add_to_fav.php", {req: "ajax" , id:id, action:'add'},
        function(data){
            var message = "This buzz is saved";
            var flash_type = 'message';
            if(data == 'added' || data == 'deleted'){
                if(data == 'deleted') {
                    message = "This buzz is removed from saved buzzes"
                    obj.find('.fav .icons').attr('class','icons ifav');
					
                    obj.find('.fav .favtxt').html('Save');
                    obj.find('.topfav').hide();
                    var userid=$("input#session_userid").val();
                    $(".favcnt").each(function(){
                        if($(this).attr("title") == userid){
                            $(this).html(parseInt($(this).html())-1)					
                        }
                    });
                }else{
                    obj.find('.fav .icons').attr('class','icons iunfav');
					
                    obj.find('.fav .favtxt').html('Remove');
                    obj.find('.topfav').show();
                    var userid=$("input#session_userid").val();
                    $(".favcnt").each(function(){
                        if($(this).attr("title") == userid){
                            $(this).html(parseInt($(this).html())+1)					
                        }
                    });
                }
                $("#dialog-modal").dialog('close');
                $('#resposnse_pid').val("");
                $('#resposnse_comment').val("");
				
            }else{
                message = 	"You need to login to favorite a Buzz";
                flash_type = 'error';
            }
            flash_message(message, flash_type);
        });
    });
    $(".bubble .remove").unbind('click').click(function(event){
        event.stopPropagation();
        var source = $(this).parent().parent().parent().parent().parent();
        var id = source.find('.postid').val();
		
        if(confirm("Are you sure want to delete this post?")){
            removePost(id);
        }
				
    });
    $(".add_group").unbind('click').click(
    function(event){
        event.stopPropagation();
        $(this).parent().find('.ad_loader').show();
        var uid=$(this).attr('title');
        uid=uid.replace("grp_","");
		
        var id =$(this).attr('id');
		
        if($("#groupList:visible").length >0){
            $("#groupList").remove();
            $('.ad_loader').hide();
        }
        else{
            $.post('/getUserGroups.php',{uid:uid},function(data){
                $('#'+id).parent('div').append(data).show();
                select_groups();
				 $(".create_grp").click(function(){
					$(".create_group").show().center();
					},
					function(){
						$(".create_group").hide();$("#gname").val('');
					});
                $('.ad_loader').hide();
            });
        }
	
		
    });
	
	
	
    select_groups();
    $(".bubble .c_remove").unbind('click').click(function(event){
        event.stopPropagation();
        var source = $(this).parent().parent().parent();
        var id = source.find('.comment_id').val();
        if(confirm("Are you sure want to delete this comment?")){
            removePost(id);
        }
				
    });
    $(".circle_bit, .circle_link").unbind('click').click(function(event){
        event.stopPropagation();
        var id =$(this).attr("title").replace("circle_","");
        location.href = "/circle/"+id;
    });
	
    $(".postbit").unbind('click').click(function(){
        if($('.update_bit').length ==0){
            var ref=$(this).find('a.story_link').attr('href');
            var pid=$(this).find('.postid').val();
            $.post("/update_viewed.php",{pid:pid},function(data){
            });
            window.location = ref;
        }
    });
	
	
    $(".f_postbit").unbind('click').click(function(){
		
        var ref=$(this).find('a.post_story').attr('href');
        window.location = ref;
			
    });

    $(".msgbit").unbind('click').click(function(){
        var msg_id=$(this).find('.msg_id').val();
        window.location="/inbox/"+msg_id;
    });
    $('.ajax_username').unbind('click').click(function(event){
        event.stopPropagation();
    });	
    $('.login_req').unbind('click').click(function(event){
        if($('#session_userid').val() == ""){
            event.preventDefault();
            event.stopPropagation()
            $(".password_popup").hide();															 
            $(".login_upload").hide();
            $(".user_login").show().center();
        }
    });
    attachTailgateEvents();
    attachTailEvents();
    tab_clicker();
    join_circles();
    post_circle_comments();poll_actions();
    $('.post_com').unbind('click').click(function(event){
        event.stopPropagation();});
    $('.post_com').unbind('focus').focus(function(event){
        event.stopPropagation();
        if($(this).val() == "Write a response..."){
            $(this).val("");
            $(this).addClass('typing');
        }
    });
    $('.post_com').unbind('blur').blur(function(event){
        event.stopPropagation();
        if($(this).val() == ""){
            $(this).val("Write a response...");
            $(this).removeClass('typing');
        }
    });
    $(".bubble .brws_button").unbind('click').click(function(event){
        event.stopPropagation();
        var com = $(this).parent().find('.post_com').val();
        var pid = $(this).parent().parent().find('input.postid').val();
        if(com != "" && com !="Write a response..."){
			
            post_response(pid,com);
            $(this).parent().find('.post_com').val("Write a response...");
            $(this).parent().find('.post_com').removeClass('typing');
			
        }
    });
    $(".comment_post .postcoment").unbind('click').click(function(event){
	
        var com = $(this).parent().find('.post_com').val();
        var pid = $(this).parent().find('input.postid').val();
        if(com != "" && com!="Write a response..."){
            $('#ad1_loader').show();
            post_response(pid,com);
            $(this).parent().find('.post_com').val("Write a response...");
            $(this).parent().find('.post_com').removeClass('typing');
            $('#ad1_loader').hide('very slow');
        }
    });
    close_popup();show_popups();

    $("#demo_input").unbind("click").click(function(event){
        event.stopPropagation();
        $(this).val('');
        $(this).hide();
        $("#new_advice").show();$("#new_advice").find(".comm_poll_div").show();
        $(".comm_poll_div").each(function(){$(this).find(".comm_poll").width($(this).innerWidth()-8);
            $(this).find(".comm_poll").autogrow();								
															
        });
		
        $("#pol_ch_new").attr('checked',true);	
        $("#cmm_new").val("Give Explanation...");
        $("#pol_ch_new").parent().parent().fadeTo(0,1);
        $("#poll_submit_new_div").fadeTo(0,1);
        $("#buzz_vote").fadeTo(0,0.3);
    });
	
    $("#cmm_new").unbind('click').click(function(event){
        event.stopPropagation();										 
        $(".post_btncomment").show();	
		
    });
    $(".s_agree").unbind('click').click(function(event){
        event.stopPropagation();
        $(".agreeList").hide();
        $(this).parent().parent().parent().find(".agreeList").toggle().center();	
		
    });
	
    $(".cls_btn").unbind('click').click(function(event){
        event.stopPropagation();
        $(".agreeList").hide();

    });
    $(".load_stat").unbind('click').click(function(event){
        event.stopPropagation();										   
    });
	
    $(".catg_cntr").unbind('click').click(function(event){
        event.stopPropagation();
        $("#categ_ul").toggle();
    });
	
    $("input.chkCat").change(function(){
        var cats='';
        var catarray=[];
        $(".chkCat:checked").each(function(){
            cat=$(this).val();
			
            catarray.push(cat);
        });
		
        for(var i=0;i<catarray.length;i++){
			
            if(cats==''){
                cats="  "+catarray[i];
            }
            else{
                cats+=",  "+catarray[i];
            }
        }
        cats=cats.replace(/\s+$/,"");
		
	
        $("#tpcs_like").html(cats);
		
		
        $.post("/advice",{cats:catarray,req:'ajax'},function(data){
            $("#timeline_home").html(data);
			
            $(".next_page").hide();
			
        });
    });
	
	
	
	
	
    $(".follow_member").unbind('click').click(function(event){
		
        event.preventDefault();
        event.stopPropagation();
		
        if($('#session_userid').val() == ""){
            $(".password_popup").hide();															 
            $(".login_upload").hide();
            $(".user_login").show().center();
            return;
        }
		
		
        var myuserid = $(this).attr('title');
		
        $.post("/ajax_userprofile.php", {req: "follow_add" , USERID:myuserid},
        function(data){	
		
            $('.follow_m'+myuserid).each(function(){
				
                $(this).addClass('unfollow_member').removeClass('follow_member');
                $(this).find('.f_act').html('FOLLOWING');
				
            });
			
            clicker();
        });
    });
	
    $(".follow_users").unbind('click').click(function(event){
		
        event.preventDefault();
        event.stopPropagation();
		
        if($('#session_userid').val() == ""){
            $(".password_popup").hide();															 
            $(".login_upload").hide();
            $(".user_login").show().center();
            return;
        }
		
		
        var myuserid = $(this).attr('title');
		
        $.post("/ajax_userprofile.php", {req: "follow_add" , USERID:myuserid},
        function(data){	
		
            $('.follow_u'+myuserid).each(function(){
				
                $(this).addClass('unfollow_users').removeClass('follow_users');
                $(this).find('.follow_u').hide();
                $(this).find('.link_divider').hide();
			
				
            });
		
            clicker();
        });
    });
	
    $(".unfollow_users").unbind('click').click(function(event){
		
        event.preventDefault();
        event.stopPropagation();
		
        if($('#session_userid').val() == ""){
            $(".password_popup").hide();															 
            $(".login_upload").hide();
            $(".user_login").show().center();
            return;
        }
		
		
        var myuserid = $(this).attr('title');
        var myusername = $(this).parent().find('.profile_name').val();
		
        $.post("/ajax_userprofile.php", {req: "follow_rem" , USERID:myuserid},
        function(data){	
		
            $('.follow_u'+myuserid).each(function(){
				
                $(this).addClass('follow_users').removeClass('unfollow_users');
                $(this).find('.follow_u').show();
                $(this).find('.link_divider').show();
				
            });
		
            clicker();
        });
    });
	
	
    $(".unfollow_member").unbind('click').click(function(event){
		
        event.preventDefault();
        event.stopPropagation();
		
        if($('#session_userid').val() == ""){
            $(".password_popup").hide();															 
            $(".login_upload").hide();
            $(".user_login").show().center();
            return;
        }
		
		
        var myuserid = $(this).attr('title');
		
        $.post("/ajax_userprofile.php", {req: "follow_rem" , USERID:myuserid},
        function(data){	
            $(".unfollow_member").unbind();
			
            $('.follow_m'+myuserid).each(function(){
				
                $(this).unbind('hover');
                $(this).removeClass('unfollow_member').addClass('follow_member');
                $(this).find('.f_act').html('FOLLOW');
				
            });
            clicker();
			
        });
    });
	
    $(".unfollow_member").unbind('hover').hover(function(){
        $(this).find('.f_act').html('UNFOLLOW');
    },
    function(){
        $(this).find('.f_act').html('FOLLOWING');
		
    }
);
	
	
    $('.youtubevideo_icon').click(
    function(event){
        event.preventDefault();
        event.stopPropagation();
        var parent_div=$(this).parent().parent().parent().parent();
        var ref=$(parent_div).find('.story_link').attr('href');
					
        window.location=ref;
			
    }
);
	
}
function resizedata()
{
	
    var mintotal_height = $(window).height() - $("#email_con_notif").outerHeight()- $("#haut").outerHeight()-$("#footer").outerHeight();
    if($('#content_right').outerHeight() < mintotal_height)$('#content_right').outerHeight(mintotal_height);
    var remHeight = $("#email_con_notif").outerHeight()+ $("#haut").outerHeight()+$("#footer").outerHeight();
    var preview = $('#loadme');
    var cPreview = $('#closeloadme');
    var fixme = $("#fixme");
    preview.height($(window).height()-remHeight);
    fixme.height($(window).height()-remHeight);
    var width = $("#droite").width();
    if(fixme.width()>0){
        fixme.width(width);
        $("#user_detail").hide();
        preview.width(width)			
        cPreview.width(width)	
    }
    cPreview.find(".closeloadme").unbind('click').click(closePreview);
    clicker();
}
function flash_message(message,type){
    if(message == "") return;
    if(type=='error'){
        message=message.replace("Error:","");
        $( "#flash_message .error_txt").html('');
        $( "#flash_message .error_container").show();
        $( "#flash_message .message_container").hide();	
        $( "#flash_message .error_txt").html(message);
        $( "#flash_message").center().show(400).delay(2000).fadeOut(600);
    }
}
function redirect(path){
    window.location=path;	
}

function attachScroll(){
}
$(document).ready(function() {
    resend_confirm();
    postautogrows();
    setTimeout("getnotificationcount()", 10000);	
    image_clicker();
    $("#tw_login").click(function(event){
        event.stopPropagation();
        event.preventDefault();
        var ref = $("#tw_login").attr('href');
        window.open (ref,"mywindow","menubar=1,resizable=1,width=780,height=350");
    });fb_twit_connect();
    get_prof_image();
    $('.dating').datepicker({ dateFormat: 'mm-dd-yy' });
		
    $('.dating').datepicker({
        inline: true
    });
    $(".ui-datepicker").click(function(event){
        event.stopPropagation();
    });
			 
    attachgroupedit();poll_actions();
    $('.c_tip').hover(function(){$(this).parent().find('.c_tip_pop').show();},function(){$(this).parent().find('.c_tip_pop').hide()})
		
    if($("#selectAllPeople").length >0 ){
        $("#selectAllPeople").click(function() {
            if($(this).is(':checked')) {
                $('.select_people').each(function(){$(this).attr('checked', true);});
            } else {
                $('.select_people').each(function(){$(this).attr('checked', false);});
            }
        })
    }
    reset_box()
		
    scroll(0,0);
    function extractLast( term ) {	
        var temp = term.split(/\s+/);
        var nowVal = [];
        for( var i=0; i <temp.length; i++)
        {
            if(temp[i].substring(0,1)=='@'){
                nowVal.push(temp[i].substring(1));
            }
        }
        var temp = postVal.split(/\s+/);
        postVal = term;
        var earlyVal = [];
        var j = 0;
        for(i=0; i <temp.length; i++)
        {
            if(temp[i].substring(0,1)=='@'){
				
                earlyVal.push(temp[i].substring(1));
            }
        }
        var temp2 = [];
        var retval = "";
        for(i=0; i <nowVal.length; i++)
        {
            temp2.push(nowVal[i]);
            if(nowVal[i]!=earlyVal[i]){
                retval = nowVal[i];
            }
        }
        return retval;
    }
	
    function split( val ) {
        return val.split( /@/ );
    }
    if($( "#update" ).length >0)
	$( "#update" ).autocomplete({
            selectFirst: true,
            minLength: 0,
            source: function( request, response ) {
                var searchterm = extractLast( request.term ).toLowerCase();
                var ret = [];
                if(searchterm==""){
                    response(ret);
                    return;
                }
                for(var i=0; i< all_follows.length ; i++){
                    if(all_follows[i][0].toLowerCase().indexOf(searchterm) == 0)
                    {
                        ret.push({name:all_follows[i][1], value:all_follows[i][0], image:all_follows[i][2]});
                    }
                }
            response(ret);
        },
        focus: function() {
            return false;
        },
        select: function( event, ui ) {
            var terms = split( this.value );
            terms.pop();
            terms.push(ui.item.value+" " );
            this.value = terms.join( "@" );
            return false;
        }
    }).data( "autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li></li>" )
        .data( "item.autocomplete", item )
        .append( '<a style="height:auto; display:block; font-size: 1.3em;" ><img src="/images/membersprofilepic/'+item.image+'" width="50" style="width: 22px; height:22px" align="left"/><strong style="margin-right: 3px;">'+item.value+'</strong><span style="font-size: 0.8em;" >'+item.name+'</span></a>' )
        .appendTo( ul );
    };
    ;
	
    var preview = $('#loadme');
    var cPreview = $('#closeloadme');
    var fixme = $("#fixme");
    $(window).scrollTop(0);
    attachScroll();
    attach_categories();
    sign_up();
    sign_in();
    frgt_pass();user_actions();delete_circle();expand_more();post_votes();
    //autosuggest();
    $(window).resize(function() {			
        resizedata();
    });
    resizedata();
	
    view_polls();
    remove_notifications();
    notific_links();
    feed_hide_show();
    interest_hide_show();
    $("#dialog-modal").dialog({
        width:447,
        modal:true,
        autoOpen:false
    });
    $("#login_form").dialog({
        width:665,
        height:235,
        modal:true,
        autoOpen:false,
        position: ['center', 50]
    });
	
    $("#search_text,#c_search_text,#p_search_text").unbind('focus').focus(function(){
		
        if($(this).val()=='Search All' || $(this).val()=='Search'){
            $(this).val('');
            $(this).next('input').css('background-position','100% 0');
        }
    });
    $("#search_text").unbind('blur').blur(function(){
		
        if($(this).val()==''){
            $(this).val('');
            $(this).next('input').css('background-position','100% 100%');
        }
    });
    $("#c_search_text,#p_search_text").unbind('blur').blur(function(){
		
        if($(this).val()==''){
            $(this).val('Search');
            $(this).next('input').css('background-position','100% 100%');
        }
    });
	
    $(".anonymous").unbind('click').click(function(){
												 
        $(".password_popup").hide();													 
        $(".user_login").hide();									 
        $(".login_upload").show().center();sign_up();
        return false;
    });
    $('#submit_resposnse').unbind('click').click(function(){
        var pid =$('#resposnse_pid').val();
        var comment = $('#resposnse_comment').val();
        var username = $('#dialog-modal').find('a.ajax_username').attr('title');
		
        if(comment == '' || comment == '@'+username){
            flash_message("Please type in a response.", 'error');
            return false;
        }
        post_response(pid, com);
    });
    $('#usertabs .tab a').click(function(event){
        event.preventDefault();
    });
    $('#usertabs .tab').unbind('click').click(function(event){
        var tab =$(this).attr('title');
        var userid = $('#memberprofile_userid').val();
        $('#userdetails').load('/usertabs.php',{USERID:userid,tab:tab}, function(){
            $('#usertabs .tab').each( function(){
                if($(this).attr('title') == tab)$(this).addClass('sel');
                else $(this).removeClass('sel');
            });
            clicker();
            page =1;
            attachScroll();
        })
    });
	
    show_popups();
	
    close_popup();
    $('.bubble .postdata a').click(function(event){
        event.stopPropagation();
    })

    $('#picture').click(
    function(){
	$('#picture1').hide();
        $('#brows_picture').show();
					
    });

    $('#delete_picture').click(
    function(){
	var user_id = $('#session_userid').val();
	$.post("/editaccount.php", {user_id: user_id,delete_image:'delete'},
	function(data){
            if(data=='deleted')
            {
                $("#change_image").css('background-image','');
                $("#change_image").find('img').attr('src','/images/noprofilepicture.gif');
                $("a#delete_picture").parent('div').prev('span').css('background-image','');
                $("a#delete_picture").parent('div').prev('span').find('img').attr('src','/images/noprofilepicture.gif');		
            }
        });	 
		 
    });
	
	
    $('.show_imp').click(function(){
        $('.import_address').show().center();
        var option=$('.import_address').find('#contacts_option').val();
        $("#email").val('Your Email');
        $("#pswd").hide();
        $("#pswd_fake").show();
        //$("#pswd").val('Password');
		
        if(option=='gmail'){
            $('.import_address').find('#image_div img').attr('src','/images/gmail.jpg');
        }
        else if(option=='hotmail'){
            $('.import_address').find('#image_div img').attr('src','/images/hotmail.jpg');
        }
        else if(option=='yahoo'){
            $('.import_address').find('#image_div img').attr('src','/images/yahoo.jpg');
        }
		
    });
    $(".email_txt").unbind('click').click(function(event){
        event.stopPropagation();
        if($(".email_txt").val()=="Your Email"){
            $(".email_txt").val('');
        }
    });
    $("#register_email").unbind('click').click(function(event){
        event.stopPropagation();
        if($(this).val()=="Enter your email"){
            $(this).val('');
        }
    });
    $("#register_username").unbind('click').click(function(event){
        event.stopPropagation();
        if($(this).val()=="Choose a username"){
            $(this).val('');
        }
    });
    $(".paswd").unbind('focus').focus(function(event){
        event.preventDefault();				 
        event.stopPropagation();
        if($(this).val()=="Password" || $(this).val()=="New Password" || $(this).val()=="Confirm"){
            $(this).val('');
            var oldpswd = $(this);
            var newpswd = oldpswd.clone();
            newpswd.attr("type",'password');
			
            newpswd.insertBefore(oldpswd);
            oldpswd.remove();
            newpswd.focus(); 
        }
    });
    $("#firstname").unbind('focus').focus(function(event){
        event.stopPropagation();
        if($("#firstname").val()=="Name"){
            $("#firstname").val('');
            $("#alert_div").show();
        }
    });
    $("#firstname").unbind('blur').blur(function(event){
        event.stopPropagation();
        if($("#firstname").val()==""){
            $("#firstname").val('Name');
            $("#alert_div").hide();
        }
    });
    $("#prof_email").unbind('click').click(function(event){
        event.stopPropagation();
        if($("#prof_email").val()=="Email"){
            $("#prof_email").val('');
        }
    });
    $("#prof_description").unbind('click').click(function(event){
        event.stopPropagation();
        if($("#prof_description").val()=="Bio"){
            $("#prof_description").val('');
        }
    });
    $("#web").unbind('click').click(function(event){
        event.stopPropagation();
        if($("#web").val()=="Web"){
            $("#web").val('');
        }
    });
    $("#to_emails").unbind('click').click(function(event){
        event.stopPropagation();
        if($("#to_emails").val()=="(eg. rimplestinsken@whatever.com)"){
            $("#to_emails").val('');
        }
    });
    $("#cpassword").unbind('focus').focus(function(event){
        event.stopPropagation();
        if($(this).val()=="Password" || $(this).val()=="New Password" || $(this).val()=="Confirm"){
            $(this).val('');
            $("#alert_div").show();
        }
    });
    $("#cpassword").unbind('blur').blur(function(event){
        event.stopPropagation();
        $("#alert_div").hide();
    });
    send_invites();
    $('.invite_friends').click(function(event){
        event.preventDefault();
        var em=$("#email_id").val();
        em=em.replace(/^\s+|\s+$/g,"");
        var pw=$("#email_pass").val();
        var str=em.split('@');
        if(str.length==2){
            var str1=str[1];
            var str2=str1.split('.',1);
            var mystr=str2[0];
        }
        if(em=='' || em=='Your Email'){
            $("div.loading_contacts").hide();
            $("div#error_div2").html("Please enter a username");
            $("div#error_div2").fadeIn("slow").fadeOut(6000);
            return false;
        }
        else if(!isValidEmailAddress(em)){
            $("div.loading_contacts").hide();
            $("div#error_div2").html("Please enter a valid email");
            $("div#error_div2").fadeIn("slow").fadeOut(6000);
            return false;
        }
        else if(pw=='' || pw=='Password'){
            $("div.loading_contacts").hide();
            $("div#error_div2").html("Please enter your password");
            $("div#error_div2").fadeIn("slow").fadeOut(6000);
            return false;
        }
        else if(mystr!='yahoo' && mystr!='gmail' && mystr!='aol' && mystr!='hotmail' && mystr!='live'){
            $("div.loading_contacts").hide();
            $("div#error_div2").html("Please use any of the given service providers");
            $("div#error_div2").fadeIn("slow").fadeOut(6000);
            return false;
        }
        else{
            $('.contacts_option').val(mystr);
            $(this).parent().next("div.loading_contacts").show();
            //document.import_form2.submit();
			
            $.post("/invites", {email:em,pswd:pw,contacts_option:mystr},function(data){
                if(data=='success'){
                    window.location='/contact_list.php';
                }
                else{
                    $("div#error_div2").html(data);
                    $("div#error_div2").fadeIn("slow").fadeOut(6000);
                    return false;
                }
            });
	
        }
    });
	
    load_contacts();
	
    $("#submit_import").unbind('click').click(function(event){
        event.preventDefault();$("div.loading_contacts").show();
        var em=$("#email").val();em=em.replace(/^\s+|\s+$/g,"");
        var pw=$("#realpswd").val();
        var dest=$("#dest").val();
        var opt=$("#contacts_option").val();
        if(em==''){
            $("div.loading_contacts").hide();
            $("div#error_div1").html("Please enter a username");
            $("div#error_div1").fadeIn("slow").fadeOut(3000);
            return false;
        }
        else if(!isValidEmailAddress(em)){
            $("div.loading_contacts").hide();
            $("div#error_div1").html("Please enter a valid email");
            $("div#error_div1").fadeIn("slow").fadeOut(3000);
            return false;
        }
        else if(pw=='' || pw=='Password'){
            $("div.loading_contacts").hide();
            $("div#error_div1").html("Please enter your password");
            $("div#error_div1").fadeIn("slow").fadeOut(3000);
            return false;
        }
        else{
            var parent = $(this).parent();
            parent.next("div.loading_contacts").show();
            var mystr = $('#contacts_option').val();
			
            $.post("/invites", {email:em,pswd:pw,contacts_option:mystr},function(data){
                if(data=='success'){
                    if(dest=='parent'){
                        parent.next("div.loading_contacts").hide();
                        $.post("/addressbook.php", {req:'ajax'},function(data){
                            $("div.find_f_mail").removeClass('selected_mail');				 
                            $("div#"+opt).addClass('selected_mail');
                            $("div.contact_list").html(data);
                            $("div.contact_list").show();load_contacts();send_invites();
                            $(".import_address").hide();
                        });
                        return false;
                    }
                    else{
                        window.location='/contact_list.php';
                    }
				
                }
                else{
                    $("div#error_div1").html(data);
                    parent.next("div.loading_contacts").hide();
                    $("div#error_div1").fadeIn("slow").fadeOut(6000);
                    return false;
                }
            });
        }
		
    });
    error_response();view_decision();
	
    $(".create_grp").click(function(){
        $(".create_group").show().center();
    },
    function(){
        $(".create_group").hide();$("#gname").val('');
    });
	
    $("#creategroup").unbind('click').click(function(event){
        var gname=$("#gname").val();
        if(gname==''){
            $("div.loading_contacts").hide();
            $("div#error_div1").html("Please enter a group name");
            $("div#error_div1").fadeIn("slow").fadeOut(3000);
            return false;
        }
        else{
            $.post("/creategroup.php", {req:'ajax', gname: gname },
            function(data){			
                if(data.indexOf('Error:')==0){messagetype= 'error'}else{messagetype= 'message'} 
                if(messagetype=='message'){
                    var data1=data.split("-");
                    data=data1[0];
                    var id=data1[1];
                    var cln = $('.user_grps_list .grp:first').clone(true);
                    cln.css('display','block');
                    cln.find("a").each(function(){$(this).attr("rel",gname)})
                    cln.find('a span').html(gname); 
					cln.find('a span.grp_cnt').html('(0)');
                    $(".user_grps_list .grp:last").after(cln).slideDown();
                    $(".create_group").hide();$("#gname").val('');
                    var cln=$(".usr_grps ul li:first").clone(true);
                    cln.find("input[type=checkbox]").attr('id','chk_'+id);
                    cln.find("input[type=checkbox]").val(id);
                    cln.find("input[type=checkbox]").attr('title',gname);
                    cln.find("input[type=checkbox]").attr('checked',false);
                    cln.find("label").html(gname);
                    $(".usr_grps ul li#crGrp").before(cln);
						
                }
                flash_message(data, messagetype);
            });
        }
		
    });	
    load_paging();
    $(".profimg").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        if($("#pic_ctr:visible").length > 0){
            $("#pic_ctr").hide();
        }
        else{
            $("#pic_ctr").show().center();
            var username=$(this).attr('title');		
            $.post("/get_Image.php",{username:username},function(data){
                $("#pic_ctr div#profpic_popup").html(data);
                $("#pic_ctr").show().center();					
            });
        }		
    });
    $("#detail_images img").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        if($("#pic_ctr:visible").length > 0){
            $("#pic_ctr").hide();
        }
        else{
            $("#pic_ctr").show().center();
            var imgid=$(this).attr('id');		
            $.post("/get_popimg.php",{imgid:imgid},function(data){
                $("#pic_ctr div#profpic_popup").html(data);
                $(".cls_img").unbind('click').click(function(event){
                    $("#pic_ctr").hide();
                    $("#pic_ctr div#profpic_popup").html("<img src=\"/images/ajaxloader.gif\" />");
                });
                $("#pic_ctr").show().center();
            });
        }
    });
});
function attachTailgateEvents(){
    $('.follow_rem').unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        if($('#session_userid').val() == ""){
            $(".password_popup").hide();															 
            $(".login_upload").hide();
            $(".user_login").show().center();
            return;
        }
        $(this).next('.ad_loader').show();
        var myuserid =$(this).parent().find('.user_follow_id').val();
        var username = $(this).parent().find('.user_follow_name').val();
		
		
        $.post("/ajax_userprofile.php", {req: "follow_rem" , USERID:myuserid},
        function(data){
            var thisobj = $('.follow_'+myuserid);
            $('.follow_'+myuserid).each(function(){$(this).addClass('follow_add').removeClass('follow_rem');$(this).find('.f_img').css('background-position',"top");});
            attachTailgateEvents();
            var userid=$("input#session_userid").val();
            $(".tgcnt").each(function(){
                if($(this).attr("title") == userid){
                    $(this).html(parseInt($(this).html())-1)					
                }
            });
            $(thisobj).next('.ad_loader').hide('very slow'); 
        });
    })
    $('.follow_add').unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        if($('#session_userid').val() == ""){
            $(".password_popup").hide();															 
            $(".login_upload").hide();
            $(".user_login").show().center();
            return;
        }
        $(this).next('.ad_loader').show();
        var myuserid = $(this).parent().find('.user_follow_id').val();
        var username = $(this).parent().find('.user_follow_name').val();
		
        $.post("/ajax_userprofile.php", {req: "follow_add" , USERID:myuserid},
        function(data){			
            $('.follow_'+myuserid).each(function(){$(this).addClass('follow_rem').removeClass('follow_add');$(this).find('.f_img').css('background-position',"bottom");});
            attachTailgateEvents();
            var userid=$("input#session_userid").val();
            $(".tgcnt").each(function(){
                if($(this).attr("title") == userid){
                    $(this).html(parseInt($(this).html())+1)					
                }
            });		
            $('.follow_'+myuserid).each(function(){
                $(this).next('.ad_loader').hide('very slow');
            });
            var cln=$("#azooca_follow").find('.follow_img:last').clone(true);
            cln.attr('id','follow_'+myuserid);
            cln.attr('title',username);
            cln.find('a').attr('href','/'+username);
            var bgi=$('.member_'+myuserid).find('.profimg').css('background-image');
            bgi=bgi.replace('url("','');
            bgi=bgi.replace('")','');
            cln.find('img').attr('src',bgi);
            $("#azooca_follow").find('.follow_img:first').before(cln);
        });
    })
}

function attach_categories(){
    $("a#post_category").unbind('hover').hover(function(){
        $("div.category_list").css('display','table');
    },function(){
        $("div.category_list").hide();
    });
    $("div.category_list").unbind('hover').hover(function(){
        $(this).show();
    },function(){
        $(this).hide();
    });
}
function user_actions(){
    $(".msg_popup").unbind("click").click(function(event){
        event.stopPropagation();
        $("#post_msg").slideToggle().center();
        //var id=$(this).attr('title');
    });
	
}
function removePost(id){
    $.post("/removePost.php", {id:id},function(data){ $('.buzz_'+id).fadeOut('slow'); //flash_message(data, 'message'); 
        var userid=$("input#session_userid").val();
        $(".buzzcnt").each(function(){
            if($(this).attr("title") == userid){
                $(this).html(parseInt($(this).html())-1)					
            }
        });
        if(data!=''){
			
            $('.post_comment').each(function(){
				
                if($(this).find(".comment_id").val()==id){
                    $(this).remove();
                }
            });
        }
        if($("#tpl_poll_view").val() == 1){
            window.history.go(-1);
        }
	
    });
	
}

function removeMsg(id){
    $.post("/removeMsg.php", {id:id},function(data){ $('.msg_'+id).fadeOut('slow'); //flash_message(data, 'message'); 
        var userid=$("input#session_userid").val();
    });
	
}

function sign_up(){
    if($('#session_userid').val() == ""){
        $(".signup_buzz").unbind('click').click(function(){
            $(".password_popup").hide();													 
            $(".user_login").hide();									 
            $(".login_upload").show().center();sign_up();
        });
        $('#submit_register').unbind('submit').submit(function(event){
            event.stopPropagation();
            event.preventDefault();submit_register();
        });
		
        $("input.cancel_btn").unbind('click').click(function(){
            $(".login_upload").hide();
            $(".password_popup").hide();													 
            $(".user_login").hide();
            $(".import_address").hide();
            $(".create_group").hide();
        });
    }
}

function sign_in(){
	
    $(".login_buzz").unbind('click').click(function(){
        $(".password_popup").hide();													 
        $(".login_upload").hide();
        $(".user_login").show().center();
        sign_in();frgt_pass();
		
    });
    $('#submit_login').unbind('submit').submit(function(event){
        event.stopPropagation();
        event.preventDefault();frgt_pass();
        submit_login();
    });
    $("input.cancel_btn").unbind('click').click(function(){
	$(".login_upload").hide();
        $(".password_popup").hide();													 
        $(".user_login").hide();
        $(".import_address").hide();
        $(".create_group").hide();
    });
}
function frgt_pass(){
    $("a.frgt_pass").unbind('click').click(function(){
        $(".user_login").hide();
        $(".login_upload").hide();
        $(".password_popup").show().center();
			
    });
    $("#resetpasswordForm").unbind('submit').submit(function(event){
        var lusername=$("input#lusername").val();
        event.stopPropagation();
        event.preventDefault();
        $.post("/password.php", {lusername:lusername,resetpassword:'resetpassword'},function(data){
            if(data == "A reset password link has been sent to your e-mail address."){
                $(".password_popup").hide();
            }
            flash_message(data, 'error');
        });
    });
    $("input.cancel_btn").unbind('click').click(function(){
        $(".login_upload").hide();
        $(".password_popup").hide();													 
        $(".user_login").hide();
        $(".import_address").hide();
        $(".create_group").hide();
    });
}
function tab_clicker(){
    $(".member_tab .respond").unbind('click').click(
    function(event){
        event.stopPropagation();
        $("#dialog-modal").dialog('close');
        var showbit = $("#post_text_data");
        var source = $(this).parent().parent().parent().parent();
        $("#dialog-modal").find('.str_cnt b').html('200');
        $(".ui-dialog-title").html('Response '+'@'+source.find('a.ajax_username').attr('title'));
        showbit.find('.postdata').html(source.find('.post_data_right').html());
        showbit.find('.profimg').css('background-image',"url("+ source.find('#u_detail img').attr('src')+")");
        showbit.find('.postuser').html(source.find('.postuser').html());
        $('#resposnse_comment').val('');
        $('#resposnse_pid').val(source.find('.postid').val());
		
        if(source.find('.postimg').html() != null){
            showbit.find('.postimg').html(source.find('.postimg').html());
            showbit.find('.postimg').show();
        }else{
            showbit.find('.postimg').hide();
        }
			
        $("#dialog-modal").dialog('open');
    });
    $(".member_tab .like").unbind('click').click(
    function(event){
        event.stopPropagation();	
        var source = $(this).parent().parent().parent();
        var nb =0;
        var id = source.find('.postid').val();
        voteYes(id,nb)
    });
    $(".member_tab .dislike").unbind('click').click(
    function(event){
        event.stopPropagation();
        var source = $(this).parent().parent().parent();
        var nb =0;
        var id = source.find('.postid').val();
        voteNo(id,nb)
    });
    $(".member_tab .fav").unbind('hover').hover(function(){
        if($(this).find('.iunfav').length > 0) $(this).find('.favtxt').html('unfavorite');
    },function(){
        $(this).find('.favtxt').html('favorite');
    });
    $(".member_tab .fav").unbind('click').click(
    function(event){
        event.stopPropagation();	
        var source = $(this).parent().parent().parent();
        var obj = source;
        var id = source.find('.postid').val();
        $.post("/add_to_fav.php", {req: "ajax" , id:id, action:'add'},
        function(data){
            var message = "This buzz issaved";
            var flash_type = 'message';
            if(data == 'added' || data == 'deleted'){
                if(data == 'deleted') {
                    message = "This buzz is removed from your favorites";
                    obj.find('.fav .icon').attr('class','icon ifav');
                    obj.find('.fav .favtxt').html('favorite');
                    obj.find('.topfav').hide();
                    var userid=$("input#session_userid").val();
                    $(".favcnt").each(function(){
                        if($(this).attr("title") == userid){
                            $(this).html(parseInt($(this).html())-1)					
                        }
                    });
                }else{
                    obj.find('.fav .icon').attr('class','icon iunfav');
                    obj.find('.fav .favtxt').html('favorite');
                    obj.find('.topfav').show();
                    var userid=$("input#session_userid").val();
                    $(".favcnt").each(function(){
                        if($(this).attr("title") == userid){
                            $(this).html(parseInt($(this).html())+1)					
                        }
                    });
                }
                $("#dialog-modal").dialog('close');
                $('#resposnse_pid').val("");
                $('#resposnse_comment').val("");
				
            }else{
                message = 	"You need to login to favorite a Buzz";
                flash_type = 'error';
            }
            flash_message(message, flash_type);
        });
    });
}


function join_circles(){
    $(".join_circle").unbind('click').click(function(event){
			
        event.preventDefault();
        event.stopPropagation();
        var circle_id =$(this).attr('title');
        circle_id=circle_id.replace('join_','');
        $.post("/join_circle.php", {req:'ajax', CID: circle_id },
        function(data){			
            //flash_message(data, 'message');
			
            $('.circle_'+circle_id).each(function(){$(this).addClass('joined_circle').removeClass('join_circle');
                $(this).removeClass('new_circle');
            });
            join_circles();
        });
	
    });
    $(".joined_circle").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        var circle_id =$(this).attr('title').replace('join_','');
        $.post("/unjoin_circle.php", {req:'ajax', CID: circle_id },
        function(data){			
            //flash_message(data, 'message');			
            $('.circle_'+circle_id).each(function(){$(this).addClass('join_circle').removeClass('joined_circle')});
            join_circles();
        });
    });
	
    $(".join_c").unbind('click').click(function(event){
			
        event.preventDefault();
        event.stopPropagation();
        var circle_id =$(this).attr('title');
        circle_id=circle_id.replace('join_','');
        var this_id=circle_id;
        $.post("/join_circle.php", {req:'ajax', CID: circle_id },
        function(data){			
			
            //$('li.circle_'+circle_id).each(function(){$(this).remove()}); 
            getJoinedCircles();
            var cids=0;
			
            $(".join_c").each(function(){
                if(cids==0){
                    cids=$(this).attr('title').replace("join_","");
                }
                else{
                    cids+=','+$(this).attr('title'). replace("join_","");
                }
            });
            $.post("/getRecCircles.php",{cids:cids},
            function(data){
                if(data!=''){
                    $('.rec_circles ul li.circle_'+this_id).replaceWith(data);
                }
                else{
                    $('.rec_circles ul li.circle_'+this_id).remove();
                }
            });
			
            join_circles();
        });
	
    });
    $(".leave_c").unbind('hover').hover(function(){$(this).html("Leave")},function(){$(this).html("Joined")});
    $(".cir_joined").unbind('hover').hover(function(){$(this).html("Leave")},function(){$(this).html("Joined")});
    $(".leave_c").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        var circle_id =$(this).attr('title').replace('join_','');
        $.post("/unjoin_circle.php", {req:'ajax', CID: circle_id },
        function(data){			
			
            $('li.circle_'+circle_id).each(function(){$(this).remove()});
            if($('div.my_circles ul li').length==0){
                $('div.my_circles').html('You have not yet joined any circle.');
            }
            getJoinedCircles();
            join_circles();
        });
    });
	
    $(".close_circle").unbind('click').click(function(){
        var cids=0;
        var this_id=$(this).attr('title');
        $(".close_circle").each(function(){
            if(cids==0){
                cids=$(this).attr('title');
            }
            else{
                cids+=','+$(this).attr('title');
            }
        });
        $.post("/getRecCircles.php",{cids:cids},
        function(data){
            $('.rec_circles ul li.circle_'+this_id).replaceWith(data);
        });
    });
	
    $(".cir_join").unbind('click').click(function(event){
			
        event.preventDefault();
        event.stopPropagation();
        var circle_id =$(this).attr('title');
        circle_id=circle_id.replace('join_','');
	
        $.post("/join_circle.php", {req:'ajax', CID: circle_id },
        function(data){			
			
            $('.circle_'+circle_id).each(function(){$(this).find('span.cir_join').addClass('cir_joined').removeClass('cir_join').html('Joined')});
            $('.circle_'+circle_id).each(function(){$(this).find('span.cir_joined').addClass('circle_ujn').removeClass('circle_jn')});
            $('.circle_'+circle_id).each(function(){$(this).find('a.join_c').addClass('leave_c').removeClass('join_c')});
            $('.circle_'+circle_id).each(function(){$(this).addClass('joined_circle').removeClass('join_circle')});
            join_circles();
        });
	
    });
    $(".cir_joined").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        var circle_id =$(this).attr('title').replace('join_','');
        var cname =$(this).attr('id');
        $.post("/unjoin_circle.php", {req:'ajax', CID: circle_id },
        function(data){			
					
            $('.circle_'+circle_id).each(function(){$(this).find('span.cir_joined').addClass('cir_join').removeClass('cir_joined').html('+ Join');
            });
            $('.circle_'+circle_id).each(function(){$(this).find('span.cir_join').addClass('circle_jn').removeClass('circle_ujn')});
            $('.circle_'+circle_id).each(function(){$(this).find('a.leave_c').addClass('join_c').removeClass('leave_c')});
            $('.circle_'+circle_id).each(function(){$(this).addClass('join_circle').removeClass('joined_circle')});
            join_circles();
        });
    });
													 
}

function delete_circle(){
    $(".delete_circle").unbind('click').click(function(event){
			
        event.preventDefault();
        event.stopPropagation();
		
	var circle_id =$(this).parent().parent().find('.circle_id').val();
        $( "#dialog-confirm" ).dialog({
            resizable: true,
            height:160,
            modal: true,
            buttons: {
                "Delete Circle": function() {
                    $( this ).dialog( "close" );
                    $.post("/addcircle.php", {remove:'remove',CID: circle_id ,req:'ajax'},
                    function(data){
                        $(".circle_"+circle_id).hide();
						
						
						
                    });
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });
}


function post_circle_comments(){
    /*$('.input_img').hover(
		function(){
			$(this).find('.tip').show();							
		},
		function(){
		$(this).find('.tip').hide();							
	});*/

    $('.image_icon').unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        var parent_div=$(".circle_wrap");
        var imageforms = parent_div.find("td#imageforms");
        imageforms.html(parent_div.find('#imageformtpl').html());
        imageforms.find(".user_image").show();
        imageforms.show();
        parent_div.find('#ph_uploadview').css('display','block');
        imageforms.find("#showvideo").html("");
        imageforms.find("#showimage").html("");
        uploading = 0;
    });
	
    $('.video_icon').click(
    function(event){
        event.preventDefault();
        event.stopPropagation();
        var parent_div=$(".circle_wrap");
        parent_div.find('#video_upload_view').css('display','block');
        parent_div.find("#showvideo").html("");
        parent_div.find("#showimage").html("");
        parent_div.find("#user_video").show();
        uploading = 0;
        parent_div.find("#showvideo").html("");
        check_url();
    }
);
	
	
    $('.c_brws_closebutton').click(
    function(){var parent_div=$(".circle_wrap");
        document.cnclform1.submit();
        uploading = 0;
        upload =0;
			
        parent_div.find('#video_upload_view').css('display','block');
        parent_div.find("#img_id").val("");
        parent_div.find("#vdo_id").val("");
        parent_div.find("#user_image").val('');
        parent_div.find('#browseimage').hide();
        parent_div.find('#showimage').html("");
        parent_div.find('#showvideo').html("");
        parent_div.find('#ph_loading').hide();
        parent_div.find('#link_loading').hide();
        parent_div.find('#ph_uploadview').hide();
        parent_div.find('#video_upload_view').hide();
    });
	
    $('.bubble .postdata a').click(function(event){
        event.stopPropagation();
    });
	

    /*$('#picture').click(
	function(){
	//event.preventDefault();
	$('#picture1').hide();
		$('#brows_picture').show();
					
	});

	$('#delete_picture').click(
	function(){
	var user_id = $('#session_userid').val();
	$.post("/editaccount.php", {user_id: user_id,delete_image:'delete'},
	function(data){
			if(data=='deleted')
			{
				$("#change_image").css('background-image','');
				$("#change_image").find('img').attr('src','/images/noprofilepicture.gif');
				$("a#delete_picture").parent('div').prev('span').css('background-image','');
				$("a#delete_picture").parent('div').prev('span').find('img').attr('src','/images/noprofilepicture.gif');		
			}
		});	 
		 
	});*/
}

function select_groups(){
	
	
	
    $(".usr_grps,.usr_grps ul ,.usr_grps ul li").unbind('click').click(function(event){
        event.stopImmediatePropagation();
    });
	$("#search_clear").unbind().click(function(){$("#search_user").val('Find people');});
    $(".check_group").unbind('click').click(function(event){
        //event.preventDefault();
        event.stopImmediatePropagation();
    });
    $(".saveToGrps_cancel").unbind().click(function(event){
        event.stopPropagation();
        $(".usr_grps").hide();
        select_groups();
    });
    $(".saveToGrps").unbind('click').click(function(event){
		
        event.stopPropagation();
		
        $(".check_group").each(function(){
            var gid=$(this).val();
            var gname=$(this).attr('title');
            var uid=$(".usr_grps").find('#gmemberid').val();
			
            var action;
			
            if($(" INPUT[id='chk_"+gid+"']").attr('checked')== true){
                action='add';
            }
            else{
                action='remove';
			
            }
			
            $.post("/addtogroups.php", {req:'ajax', GID: gid ,UID:uid ,action:action },function(data){
                $(".usr_grps").hide();
					
            });
			
        });
        select_groups();
    });
	
	$("#userlist_popup .user_rem_grp").click(function(){
                var group = $("#userlist_popup .p_pop_cntr_title").attr("rel");
				
				var gtitle = $("#userlist_popup .p_pop_cntr_title").attr('title');
				$("#userlist_popup .p_pop_cntr_title").html("Loading...");
				
                var user = $(this).attr("rel");
                var cnt=$("a#user_group_name_"+group).find('span.grp_cnt').html();
                cnt=cnt.replace("(","");cnt=cnt.replace(")","");
                cnt=parseInt(cnt);
                $.post("/creategroup.php", {req:'ajax', group:group, userid:user, action:'rem_grp'},
                function(data){
                    if(data == 'deleted')
                    {cnt--;
                        $("#userlist_popup .post_cntr").each(function(){
                            if($(this).find(".user_rem_grp").attr('rel')==user){
                                $(this).remove();
								$("#userlist_popup .p_pop_cntr_title").html(gtitle);
            					$("#userlist_popup .p_pop_cntr_title").attr("rel", group);
						
						
                                $("a#user_group_name_"+group).find('span.grp_cnt').html("("+cnt+")");
                            }
                        });
                    }
					select_groups()
                }
            );	
            });
	
	
		
	
}

function load_contacts(){
    $("#sel").unbind('click').click(function(){
        $(" INPUT[type='checkbox']").attr('checked', true);
        $obj =$("input.contacts_check");
        $obj.each(function(){
            var c_value=$(this).val();
            if($(this).attr('checked')){
                $("input#c_values").val($("input#c_values").val()+","+c_value);
            }
        });
		
    })
    $("#de_sel").unbind('click').click(function(){
        $(" INPUT[type='checkbox']").attr('checked', false);
        $("input#c_values").val('');
    });
}

function send_invites(){
    $("#send_invites").click(function(){
        var c_values=$("#c_values").val();
        $('.contacts_check:checked').each(function(){
            c_values=","+$(this).val();
        });
		
        $.post("/send_invites.php", {invite:'invite',c_values:c_values,req:'ajax'},
        function(data){
            $("div.invites_list").html(data);$("div.invites_list").show();
            $("div.success_message").html("Invitations are successfully sent");
            $("div.success_message").show();
            $(".contact_list").hide();
            return false;
        });	
    });
}
function get_check_value(obj)
{var c_value =obj.value;
    if(obj.checked){
			
        document.invite_form.c_values.value =document.invite_form.c_values.value+","+c_value;
    }
    else{
		
        document.invite_form.c_values.value=document.invite_form.c_values.value.replace(','+c_value,'')
    }
		
}
function expand_more(){
    $("#showmore_people").unbind('click').click(function(){
        $("#bottom_loader").show();
        $("#bottomLoader").css("background-position","184px bottom");									 
        $("#page").val(parseInt($("#page").val())+14);
        $.post("/findinterest", {offset:page,req:'ajax'},
        function(data){
            $('.interests').append(data);$("#bottom_loader").hide();	
        });	
    });
}
function error_response(error){
    $("div#error_div1").html(error);
    $("div#error_div1").fadeIn("slow").fadeOut("slow");
}

	
function isValidEmailAddress(emailAddress) {			
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}
		
function show_message(mid)
{
    $.post("/mailbox.php", {req:'ajax', mid:mid},
    function(data){
        var remHeight = $("#email_con_notif").outerHeight()+ $("#haut").outerHeight()+$("#footer").outerHeight();
        var preview = $('#loadme');
        var cPreview = $('#closeloadme');
        var fixme = $("#fixme");
        $("#loadme").html(data);
        var width = $("#droite").width();
        preview.height($(window).height()-remHeight);
        if(fixme.width() == 0){
            $("#user_detail").hide();
            var height = $(window).height()-remHeight;
            fixme.height(height);
            preview.width(width)
            cPreview.width(width);
            $('#loadme').show();
            $('#closeloadme').show();
            fixme.show().animate({width:width, height:height},"slow");			
        }
        clicker();
        replyinit();
    });	
}
function attachgroupedit(){
    $(".user_group_name").unbind().click(function(){

        $("#userlist_popup .p_pop_cntr_title").html("Loading...");
        $("#userlist_popup .p_pop_cntr_middle").html("");
        $("#userlist_popup").show().center();
        var gid =  $(this).attr("rel");
        var gtitle =  $(this).attr("title");
        $.post("/creategroup.php", {req:'ajax', gid:gid, action:'getlist'}, function(data){
            $("#userlist_popup .p_pop_cntr_middle").html(data);
            $("#userlist_popup .p_pop_cntr_title").html(gtitle);
            $("#userlist_popup .p_pop_cntr_title").attr("rel", gid);
			$("#userlist_popup .p_pop_cntr_title").attr("title", gtitle);
			
            var wheight = $(window).height() - 100;
            if(wheight < 200) wheight = 200;
            if($("#userlist_popup").height() >= wheight){
                $("#userlist_popup .p_pop_cntr_middle").height(wheight-100);
            }else{
                $("#userlist_popup .p_pop_cntr_middle").height("");
            }search_user();
            $("#userlist_popup .user_rem_grp").click(function(){
                var group = $("#userlist_popup .p_pop_cntr_title").attr("rel");
                var user = $(this).attr("rel");
                var cnt=$("a#user_group_name_"+group).find('span.grp_cnt').html();
                cnt=cnt.replace("(","");cnt=cnt.replace(")","");
                cnt=parseInt(cnt);
                $.post("/creategroup.php", {req:'ajax', group:group, userid:user, action:'rem_grp'},
                function(data){
                    if(data == 'deleted')
                    {cnt--;
                        $("#userlist_popup .post_cntr").each(function(){
                            if($(this).find(".user_rem_grp").attr('rel')==user){
                                $(this).remove();
                                $("a#user_group_name_"+group).find('span.grp_cnt').html("("+cnt+")");
                            }
                        });
                    }
                }
            );	
            });
            $("#userlist_popup").center();
			search_user();
        });
    });
    $("#userlist_popup_close").unbind().click(function(){
        $("#userlist_popup").hide();
		$("#search_user").val('Find people');
    });
    $(".user_grps_list .del").unbind().click(function(){
        if(confirm("Are you sure you want to delete this group?")){
            var group = $(this).attr("rel");
            var thisindex = $(this).parent().parent().parent().index();
            $.post("/creategroup.php", {req:'ajax', group:group, action:'delete'},
            function(data){
                if(data == 'deleted')
                {
                    $(".user_grps_list .grp").each(function(){
                        if($(this).find(".edit").attr('rel')==group){
                            $(this).remove();
                        }
                    });
                }
            }
        );
        }
    });
    $(".user_grps_list .edit").unbind().click(function(){
        $("#oldgname").val($(this).attr("rel"));
        $("#newgname").val($(this).attr("rel"));
        $(".edit_group").show().center();
    })
    $("#editgroup").unbind().click(function(){
        var newname=$("#newgname").val();
        var oldname=$("#oldgname").val();
        $.post("/creategroup.php", {req:'ajax', newgname: newname, oldgname:oldname, action:'update' },
        function(data){			
            $('.user_grps_list .grp').each(function(){
                if($(this).find('.edit').attr("rel")==oldname){
                    $(this).find('a span').html(newname);
                    $(this).find("a").each(function(){$(this).attr("rel",newname)})
                }
            });				
            $(".edit_group").hide();
        }
    );
    });
    $("#c_g_u").unbind().click(function(){
        $(".edit_group").hide();
    });
}

function post_votes(){
    $(".comm_poll").focus( function(){
        if($(this).val() == 'Give Explanation...')
            $(this).val(''); 
    });
    $(".pol_ch").click( function(){
        if( $("#pol_ch_new").is(':checked') ){
            $("#pol_ch_new").parent().parent().fadeTo(0,1);
            $(".own_advice_img").fadeTo(0,1);
            $("#poll_submit_new").show();
            $(".previous_advices_img").fadeTo(0,0.3);
            //$(".previous_advices_img").css({ opacity: 0.3 });
        }
        else{
		 
            $(".previous_advices_img").fadeTo(0,1);
            $(".own_advice_img").fadeTo(0,0.3);
            $("#poll_submit_new").hide();
		 
        }
        var temp = $(this).val();
        if(temp != "new")$('#newpoll_input').val('');
        $(".comm_poll_div").each(function(){if($(this).find("#cmm_"+temp).length ==0){$(this).hide();}});
        if($(".comm_poll_div:visible").length == 0){
            // $("#cmm_"+$(this).val()).height(30);
            $("#cmm_"+$(this).val()).parent().show();
            // $("#cmm_"+$(this).val()).val("Give Explanation...");
        }
	 
    });
    $("#newpoll_input").unbind('focus').focus(function(){
        $(".comm_poll_div").each(function(){if($(this).find("#cmm_new").length == 0)$(this).hide();});
        if($(".comm_poll_div:visible").length == 0){
            $(".own_advice_img").fadeTo(0,1);
            $("#poll_submit_new").show();
            $("#cmm_new").parent().show();
            $("#pol_ch_new").attr('checked',true);	
            //  $("#cmm_new").val("Give Explanation...");
			  
        }
        $("#pol_ch_new").parent().parent().fadeTo(0,1);
        $("#poll_submit_new_div").fadeTo(0,1);
        //$("#buzz_vote").fadeTo(0,0.3);
        $(".previous_advices_img").fadeTo(0,0.3);
    });
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
    $("#poll_submit_new").unbind('click').click(function(){
        var uid=$("#session_userid").val();										 
        var poll_id=$(this).parent().parent().parent().parent().parent().parent().find('.poll_id:first').val();
        var poll_explain=$("#cmm_new").val();
        var poll_ch='';
			
		
        poll_ch=$(".pol_ch:checked").val();
	
		
        if(poll_explain == 'Give Explanation...')poll_explain ="";
        var poll_choice= "";
        if(poll_ch =='' || poll_ch =='new'){
            poll_choice=$("#newpoll_input").val();
            poll_ch = "";
        }
        if(uid==''){
            $(".user_login").show().center();
            return false;
        }
        else if(poll_id==''){
            $(this).parent().parent().find('.ad_loader').show();
            flash_message("this poll doesn't exist",'error');
            $(this).parent().parent().find('.ad_loader').hide('very slow');
            return false;
        }
        else if($(".pol_ch:disabled").length >0){
            $(this).parent().parent().find('.ad_loader').show();
            flash_message('You have already voted','error');
            $(this).parent().parent().find('.ad_loader').hide('very slow');
            return false;
        }
        else if(poll_ch =='' && poll_choice ==''){
            $(this).parent().parent().find('.ad_loader').show();
            flash_message('You have to vote or create a new option','error');
            $(this).parent().parent().find('.ad_loader').hide('very slow');
            return false;
        }
        else{$(this).parent().parent().find('.ad_loader').show();
            var pid = $(this).parent().parent().parent().parent().parent().parent().find('.postid:first').val();
            $.post("/poll.php",{poll_id:poll_id,poll_ch:poll_ch,poll_explain:poll_explain,pid:pid,poll_option:poll_choice},function(data){																										
										
                window.location.reload();																								
			
                //flash_message(data,'message');
                /*$("#vote_"+pid).html('<strong style="font-size:1.1em;color:#ccc"><img src="/images/f/vote_disable.png" /></strong>');
				if($("#tpl_poll_view").val() == 1){
				}
				else{
					
					$.ajax({url : "/viewajax.php?pid="+pid, success:function(data){
						$(".buzz_"+pid).find(".load_stat").html(data);
			
						$(".buzz_"+pid).find(".load_stat").show();
						clicker();post_votes();
						postautogrows();					
						$("#loadme").find('.ad_loader').hide('very slow');
					}});
				}*/
            });
        }
    });
	
	
	
    $(".agree_it").unbind('click').click(function(){
												  
        var uid=$("#session_userid").val();										 
        var poll_id=$(".post_wrapper").find('.poll_id:first').val();
        var poll_ch=$(this).attr('title');

        if(uid==''){
            $(".user_login").show().center();
            return false;
        }
        else if(poll_id==''){
            flash_message("this poll doesn't exist",'error');
            return false;
        }
        else if(poll_ch ==''){
            flash_message('You have to agree with any of the option','error');
            return false;
        }
        else{
            var pid = $(".post_wrapper").find('.postid:first').val();
            $.post("/poll.php",{poll_id:poll_id,poll_ch:poll_ch,pid:pid},function(data){																										
					
                $("#agree_it"+poll_ch).parent().parent().parent().find('.agree_cntr_middle').append(data);;
					
                $("#agree_it"+poll_ch).hide();
                var ag_txt=$("#agree_it"+poll_ch).parent().find('.s_agree').html();
                var ag_val=parseInt(ag_txt.replace("-",''));
                if(isNaN(ag_val)){
                    ag_val =0;
                }
                var cnt=ag_val+1;
                ag_txt =" - "+cnt+" Agree";
                $("#agree_it"+poll_ch).parent().find('.s_agree').html(ag_txt);
					
				
            });
        }
    });
	
    $(".decide_it").unbind('click').click(function(){
												  
        var uid=$("#session_userid").val();										 
        var poll_id=$(".post_wrapper").find('.poll_id:first').val();
		
        var poll_ch=$(this).attr('title');

        if(uid==''){
            $(".user_login").show().center();
            return false;
        }
        else if(poll_id==''){
            flash_message("this poll doesn't exist",'error');
            return false;
        }
        else if(poll_ch ==''){
            flash_message('You have to agree with any of the option','error');
            return false;
        }
        else{
            var pid = $(".post_wrapper").find('.postid:first').val();
            $.post("/decide_poll.php",{poll_id:poll_id,poll_ch:poll_ch,pid:pid},function(data){	
																	 
                if(data.indexOf('Error:')!=0){decision=data;}
                $(".decide_it").hide();
                if($("#tpl_poll_view").val() == 1){
                    window.location.reload();
                }
                else{
                    $.ajax({url : "/viewajax.php?pid="+pid+"&decision="+decision, success:function(data){
                            $(".buzz_"+pid).find(".load_stat").html(data);
					
                            $(".buzz_"+pid).find(".load_stat").show();
                            clicker();post_votes();
                            postautogrows();	
                            //$("#loadme").find('.ad_loader').hide('very slow');
                        }});
                }
				
            });
        }
    });
    $("#buzz_decide").unbind('click').click(function(){
													 
		
        var uid=$("#session_userid").val();	
        var poll_id=$(this).parent().parent().parent().parent().parent().parent().find('.poll_id:first').val();
        var poll_ch=$(".pol_ch:checked").val()?$(".pol_ch:checked").val():'';
        //var poll_ch=$(this).attr('title');
		
        var decision;
        if(uid==''){
            $(".user_login").show().center();
            return false;
        }else if(poll_id==''){
            $(this).parent().parent().find('.ad_loader').show();
            flash_message("this poll doesn't exist",'error');
            $(this).parent().parent().find('.ad_loader').hide('very slow');
            return false;
        }
        else if($(".pol_ch:disabled").length >0){
            $(this).parent().parent().find('.ad_loader').show();
            flash_message('You have already voted','error');
            $(this).parent().parent().find('.ad_loader').hide('very slow');
            return false;
        }
        else if(poll_ch ==''){
            $(this).parent().parent().find('.ad_loader').show();
            flash_message('You have to check atleast one option','error');
            $(this).parent().parent().find('.ad_loader').hide('very slow');
            return false;
        }
        else{
			
            var pid = $(this).parent().parent().parent().parent().parent().parent().find('.postid:first').val();
			
            $.post("/decide_poll.php",{poll_id:poll_id,poll_ch:poll_ch,pid:pid},function(data){
																								 
																					 
                //if(data.indexOf('Error:')!=0){decision=data;}
						
                /*if($("#tpl_poll_view").val() == 1){
							window.location.reload();
						}
						else{
								$.ajax({url : "/viewajax.php?pid="+pid+"&decision="+decision, success:function(data){
							$(".buzz_"+pid).find(".load_stat").html(data);
					
								$(".buzz_"+pid).find(".load_stat").show();
								clicker();post_votes();
								postautogrows();	
							//$("#loadme").find('.ad_loader').hide('very slow');
						}});
						}
                 */
            });
			
        }
    });
	
	
    $(".buzz_comment").unbind('click').click(function(){
        var uid=$("#session_userid").val();										 
        var poll_id=$(this).parent().parent().parent().parent().parent().parent().find('.poll_id:first').val();
		
        var poll_explain=$("#cmm_new").val();
		
		
        if(uid==''){
            $(".user_login").show().center();
            return false;
        }
        else if(poll_id==''){
            flash_message("this poll doesn't exist",'error');
            return false;
        }
        else{
            var pid = $(this).parent().parent().parent().parent().parent().parent().find('.postid:first').val();
			
            $.post("/poll.php",{poll_id:poll_id,poll_explain:poll_explain,pid:pid},function(data){
			
                if($("#tpl_poll_view").val() == 1){
                    window.location.reload();
                }
                else{
                    $.ajax({url : "/viewajax.php?pid="+pid, success:function(data){
                            $(".buzz_"+pid).find(".load_stat").html(data);
			
                            $(".buzz_"+pid).find(".load_stat").show();
                            clicker();post_votes();
                            postautogrows();	
                        }});
                }
            });
			
        }
    });
	
    $(".new_advc").unbind('click').click(function(){
		
        $(".advc_cntr").show();
    });
	
}
function poll_img_uploaded(id , img, imgid)
{
    $("#poll_img_"+id).attr("src", img);
    $("#poll_img_"+id).parent().parent().parent().removeClass("uploadwait");
    pollimg_progress = 0;
    postchoiceimg();
}
function poll_actions(){
    $("#post_desc").autogrow();
    $(".add_desc").unbind('click').click(function(){
        $("#p_desc_lnk").hide();
        $("#p_desc_div").show();
    });
    $(".hide_desc").unbind('click').click(function(){
        $("#p_desc_div").hide();
        $("#p_desc_lnk").show();			
    });
    $(".add_img").unbind('click').click(function(){
        $("#p_img_lnk").hide();
        $("#p_img_div").show();
    });
    $(".hide_img").unbind('click').click(function(){
        $("#p_img_div").hide();
        $("#p_img_lnk").show();			
    });
    $('.user_ch_image').change(function(){
        $(this).parent().parent().parent().addClass("uploadwait"); 
        postchoiceimg();
    });
    $(".add_choices").unbind('click').click(function(){
        var cln=$(".poll_choice:last").clone(true);
        cln.find('#poll_title');
        var id=cln.find('.choice_id').val();
        id=parseInt(id)+1;
        cln.find('.poll_img').attr("id", "poll_img_"+id);
        cln.find('.poll_img').attr("src", pollnullimage);
        cln.find('.choice_id').val(id);
        cln.find('.poll_ch').val('');
        cln.find('.user_ch_image').change(function(){
            $(this).parent().parent().parent().addClass("uploadwait");	
            postchoiceimg();
        });
        cln.addClass("dynamic");
        $(".poll_choice:last").after(cln);			
    });
	
	
    $(".hiddenupload").unbind('click').click(function(){
        $(this).hide();											 
        $(this).next(".hidenfile").show(); 
    });
}

function postchoiceimg(){
    if(pollimg_progress == 1)
    {
        return;	
    }
    if($(".uploadwait").length > 0){
        uploading_choice = 1;
        pollimg_progress = 1;
        $(".uploadwait:first").find('form').submit();
    }
    else{
        uploading_choice = 0;
        pollimg_progress = 0;
        if(upload_initiated == 1) uploaddata(1); 
    }
}

function changedate(){
    $("#ui-datepicker-div").unbind('click').click(function(){
	$("#polldate").html($("#ndatepicker").val());
    });}


function view_decision(){
    $(".dec_view").unbind('click').click(function(){
        var pid=$(this).attr("title")?$(this).attr("title"):$(this).parent().find(".postid").val();
        var preview = $('#loadme');
        var cPreview = $('#closeloadme');
        var fixme = $("#fixme");
        var history =false;
		
        var decision=$(this).parent().find(".decision").val()?$(this).parent().find(".decision").val():$(this).find(".decision").val();
        if(pid != undefined){
					
            var ajax_usernamename = $(this).find(".ajax_username_name").attr('title');
            if($('#loadme').length == 0){window.location = "/"+ajax_usernamename;}
            var d=$(this).parent().find(".postid").val();
		
            $.ajax({url : "/viewajax.php?pid="+pid+"&decision="+decision, success:function(data){
		
                    $("#loadme").html(data);
                    $(".closeloadme").click(closePreview);;
                    clicker();post_votes();
                    postautogrows();
                }});
            removeSelected();
            var remHeight = $("#email_con_notif").outerHeight()+ $("#haut").outerHeight()+$("#footer").outerHeight();
            var width = $("#droite").width();
            preview.height($(window).height()-remHeight);
            if(fixme.width() == 0){
                $("#user_detail").hide();
                var height = $(window).height()-remHeight;
                fixme.height(height);
                preview.width(width)
                cPreview.width(width);
                $('#loadme').show();
                $('#closeloadme').show();
                fixme.show().animate({width:width, height:height},"slow");	
				
            }
        }
        preview.scrollTop(0);
		
    });
}

function get_prof_image(){
    $("#login_username").unbind('blur').blur(function(){
        $('#unameerr').hide();
        var username=$(this).val();
        if(username==''){
            $("#prof_pic").hide();
        }
        else{
            $.post('/get_prof_pic.php',{username:username},function(data){
                if(data != "doesnot exist"){
                    //$('.txtfld').width(178).css('background-position','0 -27px');
                    $('#unameerr').hide();
                    //$("#prof_pic").show();
                    $("#prof_pic").html(data);
					
                }else{
                    //$('#unameerr').show();
                    flash_message('No account matching that username/email address  was found', 'error');
                    //$("#prof_pic").hide();
                    //$('.txtfld').width(233).css('background-position','0 0');
                }
            });
        }
    });
}

function f(){
    $(".msg_closebutton").unbind('click').click(function(){
														 
        $("#post_msg").hide();
    });
	
    $(".alert_popup").unbind('click').click(function(){
        $(this).hide();
        var close_x = $(this).attr('id');
        $.post("/close_notifs.php", {close: close_x},function(data){});});	
    $('.brws_closebutton').unbind('click').click(
    function(){
        document.cnclform.submit();
        uploading = 0;
        upload =0;
        var poll_title=$("#poll_title").val();
        var post_desc=$("#post_desc").val();
        var poll_categ=$("#poll_categ").val();
			
        $("div").removeClass('pop_open');
        $("#img_id").val("");
        $('.poll_img').each(function(){$(this).attr("src", pollnullimage)});
        $("#vdo_id").val("");
        $("#link_id").val("");
        $("#user_image").val('');
        $('#browseimage').hide();
        $('#showimage').html("");
        $('#showvideo').html("");
        $('#attach_url_text').val("http://");
        $('#ph_loading').hide();
        $('#link_loading').hide();
        $('#ph_uploadview').hide();
        $('#link_uploadview').hide();
        $('#video_upload_view').hide();
        $('#poll_uploadview').hide();
        $("#title_label").hide();
        $("#upload_label").hide();
        $("#p_img_div").hide();
        $(".dynamic").remove();
        //$('.brws_closebutton').hide();
        $("#pollelimg").hide();
        $(':text, :password, :file', '#poll_form').val(''); 
        $(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
			
			
			
        var follow_check=$("input#is_follow").val();
        var follower_id=$("input#follower_id").val();
        var user_id=$("input#uid").val();
        var cid=$("input#circle").val();
        $("textarea#update").show();
		
        $(".hidenfile").hide(); 
        $("#bottom_lnks").show();$("#sgst_panel").show();
        $('#image_icon1').show();
        $('#video_icon').show();
        $('#link_icon').show();$("#txt").show();
        $('#add_txt').show();
        $("#submit").html($("#submit").html());
			
        $("#poll_title").val(poll_title);
        $("#post_desc").val(post_desc);
        $("#poll_categ").val(poll_categ);
        show_popups();close_popup();poll_actions();
    });
	
	
	
	
    $('.drop_closebutton').unbind('click').click(function(){
			
			
        document.cnclform.submit();
        uploading = 0;
        upload =0;
        $("div").removeClass('pop_open');
        $("#img_id").val("");
        $('.poll_img').each(function(){$(this).attr("src", pollnullimage)});
        $("#vdo_id").val("");
        $("#link_id").val("");
        $("#user_image").val('');
        $('#browseimage').hide();
        $('#showimage').html("");
        $('#showvideo').html("");
        $('#attach_url_text').val("http://");
        $('#ph_loading').hide();
        $('#link_loading').hide();
        $('#ph_uploadview').hide();
        $('#link_uploadview').hide();
        $("#post_desc_container").hide();
        $("#PrivacySuggestions").hide();
        $("#poll_category").hide();
        $("#poll_string_count").hide();
        $("#p_desc").hide();
        $('#video_upload_view').hide();
        $('#poll_uploadview').hide();
        $("#title_label").hide();
        $("#upload_label").hide();
        $("#p_img_div").hide();
        $(".dynamic").remove();
        $(".suggest_panel").hide();
        $(".add_sugst").hide();$(".allow_chk").hide();
        //$('.brws_closebutton').hide();
        $("#pollelimg").hide();
        $(':text, :password, :file', '#poll_form').val(''); 
        $(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
			
        var follow_check=$("input#is_follow").val();
        var follower_id=$("input#follower_id").val();
        var user_id=$("input#uid").val();
        var cid=$("input#circle").val();
        $("textarea#update").show();
			
        $("#poll_title").val("");
			
        $("input#post_text").val("Write on the Wall...");
        $("textarea#msg_text").val("Write a message...");
        $(".hidenfile").hide(); 
        $("#bottom_lnks").hide();$("#sgst_panel").hide();
        $('#image_icon1').show();
        $('#video_icon').show();$("#txt").show();
        $('#link_icon').show();
        //$('#poll_icon').show();
        $('#add_txt').show();
        $("#submit").html($("#submit").html());
        $('.drop_closebutton').hide();
        var reste=200;
        $("#poll_string_count span").html(reste);
        $("#poll_title").bind('textchange',function(e){
            //$(e.target).autogrow(this);
				
            var len = $(e.target).val().length;
            reste = 200 - len;
            $("#poll_string_count span").html(reste);
        });
        show_popups();close_popup();poll_actions();
    });
	

}

function view_polls(){
	
}

function show_popups(){
	
    $('.input_img').hover(
    function(){
        $(this).find('.tip').show();							
    },
    function(){
        $(this).find('.tip').hide();							
    });
    $('.ok').hover(
    function(){
        $(this).find('.tip').show();							
    },
    function(){
        $(this).find('.tip').hide();							
    });
	
    $('#image_icon1,#r_image_icon1').click(
    function(event){
        event.preventDefault();
        close_popup();
        var imageforms = $("#imageforms");
        imageforms.html($('#imageformtpl').html());
        imageforms.find(".user_image").show();
        imageforms.show();
        $('#ph_uploadview').css('display','block');
        $('#ph_uploadview').addClass('pop_open');
        $('#image_icon1').hide();
        $('#video_icon').hide();
        $('#link_icon').hide();
        $('#add_txt').hide();
        $("#txt").hide();
        $("#txt").hide();
        $('#youtube_url_txt').val("http://");
        $("#link_id").val("");
        $("#showvideo").html("");
        $("#showimage").html("");
        uploading = 0;
			
    }
);
	
    $('#video_icon').click(
    function(event){
        event.preventDefault();
        close_popup();
        $('#video_upload_view').css('display','block');
        $('#video_upload_view').addClass('pop_open');			
        $("#showvideo").html("");
        $("#showimage").html("");
        $("#user_video").show();
        $('#image_icon1').hide();
        $('#video_icon').hide();
        $('#link_icon').hide();
        $("#txt").hide();
        $('#add_txt').hide();
        //$("#bottom_lnks").hide();
        $('#youtube_url_txt').val("http://");
        $("#link_id").val("");
			
        uploading = 0;
        $("#showvideo").html("");
    }
);
    $('#link_icon').click(
    function(event){
        event.preventDefault();	
        close_popup();
        $('#link_uploadview').css('display','block');
        $('#link_uploadview').addClass('pop_open');						
        $('#attach_url_text').val("http://");
        $("#link_id").val("");
        $('#image_icon1').hide();
        $('#video_icon').hide();
        $('#link_icon').hide();
        $('#add_txt').hide();
        $("#txt").hide();
        //$("#bottom_lnks").hide();
        $('#youtube_url_txt').val("http://");
        $("#link_id").val("");	
			
        uploading = 0;
        $("#showvideo").html("");
    }
);
	
    $('#poll_icon').click(
    function(event){
        event.preventDefault();	
        close_popup();
        $('#poll_uploadview').css('display','table');
        $(':text, :password, :file', '#poll_form').val(''); 
        $(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
        $('#poll_uploadview').addClass('pop_open');									
        $('#image_icon1').hide();
        $('#video_icon').hide();
        $('#link_icon').hide();
        $('#add_txt').hide();
        $('#poll_icon').hide();
        //$("#p_img_div").hide();$("#p_img_lnk").show();
        if($("textarea#update").val()!='' && $("textarea#update").val()!='Write on the Wall...' && $("textarea#update").val()!='Start Writing...' && $("textarea#update").val()!='To post on a profile you need to follow each other...'){
            $("#poll_title").val($("textarea#update").val());
				
        }$("#update").hide();
        $("#update").val('');
        //$("#bottom_lnks").hide();
        $('#attach_url_text').val("http://");
        $("#link_id").val("");	
			
        uploading = 0;
        $("#showvideo").html("");
			
			
	
        poll_actions();
    });
    $(".add_sugst").unbind('click').click(function(){
        $(this).hide();	$(this).next('span.allow_chk').show();								 
        $(".suggest_panel").show();
    });
    $("#activity_title").unbind('hover').hover(function(){
        $("#activity_notification").show();
    },
    function(){
        $("#activity_notification").hide();
    });
	
    $(".poll_agreed").unbind('hover').hover(function(){
        $(this).parent().parent().find(".agreed_popup").show();										 
    },
    function(){
        $(this).parent().parent().find(".agreed_popup").hide();
    });
	
	
    $("#youtube_url_txt").unbind('click').click(function(){
		
		
        if($(this).val()=='http://'){
            $(this).val('');
        }
    });
	
}

function remove_notifications(){
	
	
    $(".unreadnote").unbind().click(function(){
        $(this).unbind();
		
        var ref='';
        if($(this).find('a.link_ref')){
            ref= $(this).find('a.link_ref').attr('href');
            window.location=ref;
        }
        else{
            window.location=$(this).find('a:first').attr('href');
        }
    });
    $(".close_notif").unbind('click').click(function(event){
        event.stopPropagation();
        if($(this).hasClass('selected'))
            $(this).removeClass('selected');
        else 
            $(this).addClass('selected');
        var id=$(this).attr('title');
        $(this).parent().find('.list_options').toggle();
    });
	
    $(".advice_ref").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        var pid=$(this).parent().parent().attr('title');
        $("#giveAdvice").show().center();
        $("#giveAdvice").html('<div class="agree_cntr_title" style="padding: 12px 10px;">loading... </div>');
        $.post("/poll_view.php",{pid:pid,req:'answer'},function(data){
            $("#giveAdvice").html(data);
            $("#giveAdvice").show().center();
            $("#submitAdvice").unbind().click(function(){	
                var uid=$("#session_userid").val();										 
                var poll_id=$(this).parent().find('.poll_id:first').val();
                var poll_explain="";
                var poll_ch='new';
                poll_explain ="";
                poll_choice=$(this).parent().find(".txtmyAdvice").val();
                if(uid==''){
                    $(".user_login").show().center();
                    return false;
                }
                else if(poll_id==''){
                    flash_message("this poll doesn't exist",'error');
                    return false;
                } else if($.trim(poll_choice)==''){
                    flash_message("Please enter an answer",'error');
                    return false;
                }
                else{
                    var pid = $(this).parent().find('.postid:first').val();
                    $.post("/poll.php",{poll_id:poll_id,poll_ch:poll_ch,poll_explain:poll_explain,pid:pid,poll_option:poll_choice},function(data){
                        window.location.reload();
                    });
                }
            });

            $(".advice_close").unbind().click(function(event){$("#giveAdvice").hide(); $("#giveAdvice").html("loading...");});
        });
		
    });
    $("#submitAdvice").unbind('click').click(function(){
        var uid=$("#session_userid").val();										 
        var poll_id=$(this).parent().find('.poll_id:first').val();
        var poll_choice=$("#myAdvice").val();
	
		
        if(uid==''){
            $(".user_login").show().center();
            return false;
        }
        else if(poll_id==''){
            $(this).parent().parent().find('.ad_loader').show();
            flash_message("this poll doesn't exist",'error');
            $(this).parent().parent().find('.ad_loader').hide('very slow');
            return false;
        }		
        else if(poll_choice ==''){
            $(this).parent().parent().find('.ad_loader').show();
            flash_message('You have to create a new option','error');
            $(this).parent().parent().find('.ad_loader').hide('very slow');
            return false;
        }
        else{$(this).parent().parent().find('.ad_loader').show();
            var pid = $(this).parent().find('.postid:first').val();
            $.post("/poll.php",{poll_id:poll_id,pid:pid,poll_option:poll_choice},function(data){																										
                if(data !='success'){
                    flash_message(data,'error');	
                }
                else{
                    flash_message(data,'error');	
                }
				
            });
        }
        $("#giveAdvice").hide();
    });
	
    $(".archive_note").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        var id=$(this).attr('title');
        $.post('/advice_notifications.php',{req:'archive',id:id},function(data){
            $(".list_options").hide();
            if(data !='success'){
                flash_message(data,'error');	
            }
            else{
                $("#not_bit_"+id).fadeTo(1,0.5);
                flash_message("This question is archived",'error');	
				
            }
        });remove_notifications();
		
    });
    $(".hide_note").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        var id=$(this).attr('title');
        $.post('/advice_notifications.php',{req:'hide',id:id},function(data){
            $(".list_options").hide();
            if(data !='success'){
                flash_message(data,'error');	
            }
            else{
                $("#not_bit_"+id).hide();
                $("#closeNote_"+id).hide();
                flash_message("This question is now hidden",'error');	
				
            }
        });remove_notifications();
		
    });
    $(".unsub_user").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        var id=$(this).attr('title');
        $.post('/advice_notifications.php',{req:'unsub',id:id},function(data){
            $(".list_options").hide();
            if(data !='success'){
                flash_message(data,'error');	
            }
            else{
                $("#not_bit_"+id).hide();
                $("#closeNote_"+id).hide();
                flash_message("This person is removed from your feeds",'error');	
            }
        });remove_notifications();
		
    });
    $(".report_note").unbind('click').click(function(event){
        event.preventDefault();
        event.stopPropagation();
        var id=$(this).attr('title');
        var ref=$("#not_bit_"+id).find('.advice_ref').attr('title');
        $.post('/advice_notifications.php',{req:'report',id:id,ref:ref},function(data){
            $(".list_options").hide();
            if(data !='success'){
                flash_message(data,'error');	
            }
            else{
                $("#not_bit_"+id).hide();
                $("#closeNote_"+id).hide();
                flash_message("This question is now hidden",'error');	
				
            }remove_notifications();
        });
		
    });
    $("#clear_not").unbind('click').click(function(){
        var id = [];
        var temp2 ="";
        $(".close_notif").each(function(){
            temp2=$(this).attr('title');
            id.push(temp2);
        });
		
        $.post("/remove_notifs.php",{"id[]":id},function(data){
            if(data.indexOf('Error:')=='0'){
                flash_message(data, 'error');
                return false;
            }
            else{
                $('.not_wrap').fadeOut();
            }
        });
													 
    });
	
    $(".rem_msg").unbind('click').click(function(){
        var id=$(this).attr('title');
        removeMsg(id);
    });
    $(".del_msg").unbind('click').click(function(){
        $(".chk_msg:checked").each(function(){
            var id=$(this).val();
            removeMsg(id);
        });
    });
    $(".resp_msg").unbind('click').click(function(){
        var id=$(".sender_id").val();										  
        var name=$(".sender_name").val();
        var parent_id=$(".parent_id").val();
        $("#post_msg").find("#follower_id").val(id);
        $("#post_msg").find("#msg_uname").val(name);
        $("#post_msg").find(".parent_id").val(parent_id);
        $("#post_msg").find('#bottom_lnks').show();
        $("#post_msg").slideToggle().center();
        remove_notifications();
    });
    load_paging();
}

function notific_links(){
}
function feed_hide_show(){
    $(".feed_hide").unbind('click').click(function(){
        var follower = $(this).val();
        var action = 'hide';
        if($(this).hasClass('is_hide')){
            action = 'show';
        }		
        $.post("/setting.php", {req: "ajax" , follower:follower, action:action},
        function(data){
            var ob = $('#follow_'+data+' .feed_hide');
            if(ob.hasClass('is_hide')){
                ob.html('hide');
                ob.removeClass('is_hide');
            }else{
                ob.html('show');
                ob.addClass('is_hide');
            }
        });
    });
}
function getnotificationcount(){
    $.post('/getnotificationcount.php',{req:'update'},function(data){
	if(data !=''){
			data = data.split("/");
			var questions = data[1];
			data = data[0];
            $('a.n_cnt').prepend(data);
            var s=parseInt(data);
            if(isNaN(s)){
                s=0;
            }
            if(isNaN(parseInt(s))){
                s=0;
            }
            if(s >0){
                txt = s +" Notifications";
                $("a.n_cnt").css('color','#ff0000');
            }
            else{
                $("a.n_cnt").css('color','#249bb9');
                txt = s +" Notification";
            }
            $("a.n_cnt").text(txt);
			
			
			$('a.q_cnt').prepend(questions);
            var s=parseInt(questions);
            if(isNaN(s)){
                s=0;
            }
            if(isNaN(parseInt(s))){
                s=0;
            }
            if(s >1){
                txt = s +" Questions!";
                $("a.q_cnt").css('color','#ff0000');
            }else if(s ==1){
                txt = s +" Question!";
                $("a.q_cnt").css('color','#ff0000');
            }
            else{
                $("a.q_cnt").css('color','#249bb9');
                txt = s +" Questions";
            }
            $("a.q_cnt").text(txt);
	}
	setTimeout("getnotificationcount()", 10000);
    });
}
function interest_hide_show(){
    $(".interest_hide").unbind('click').click(function(){
        var interest = $(this).val();
        var action = 'hide';
        if($(this).hasClass('is_hide')){
            action = 'show';
        }		
        $.post("/setting_interest.php", {req: "ajax" , interest:interest, action:action},
        function(data){
            var ob = $('#interest_'+data+' .interest_hide');
            if(ob.hasClass('is_hide')){
                ob.html('hide');
                ob.removeClass('is_hide');
            }else{
                ob.html('show');
                ob.addClass('is_hide');
            }
        });
    });
}
function fb_twit_connect(){
    $(".twit_conct").unbind('hover').hover(function(){
        $(".display_popup").hide();
        $('#twimg.notlinked').attr('src','/images/twtr.jpg');
        $("#t_popup").show();
    },
    function(){
        if(!$(this).hasClass('clicked')){
            $('#twimg.notlinked').attr('src','/images/twtr_grey.jpg');
            $("#t_popup").hide();
        }
    });
    $(".fb_conct").unbind('hover').hover(function(){
        $(".display_popup").hide();
        $('#fbimg.notlinked').attr('src','/images/fb.jpg');
        $("#f_popup").show();
    },
    function(){		
        if(!$(this).hasClass('clicked')){
            $('#fbimg.notlinked').attr('src','/images/fb_grey.jpg');
            $("#f_popup").hide();
        }
    });
    $(".fb_conct").unbind('click').click(function(){$(".display_popup").hide();
        if($(this).hasClass('clicked')){
            $(this).removeClass("clicked"); 
            $("#f_popup").hide();
            $('#fbimg.notlinked').attr('src','/images/fb_grey.jpg');
        }
        else{
            $(this).addClass("clicked");
            $("#f_popup").show();
            $('#fbimg.notlinked').attr('src','/images/fb.jpg');
        }	
    });
	
    $(".twit_conct").unbind('click').click(function(){
        $(".display_popup").hide();
        if($(this).hasClass('clicked')){
            $(this).removeClass("clicked"); 
            $("#t_popup").hide();
            $('#twimg.notlinked').attr('src','/images/twtr_grey.jpg');
        }
        else{
            $(this).addClass("clicked");
            $("#t_popup").show();
            $('#twimg.notlinked').attr('src','/images/twtr.jpg');
        }	
    });	
    $(".close_fb_tw_pop").unbind('click').click(function(){
        $("#f_popup, #t_popup").each(function(){$(this).hide()});
        $(".twit_conct, .fb_conct").each(function(){
            $(this).removeClass("clicked");
            $('#twimg.notlinked').attr('src','/images/twtr_grey.jpg');
            $('#fbimg.notlinked').attr('src','/images/fb_grey.jpg');
        });
    });
	
    $(".t_unlink").unbind('click').click(function(){
        $.post('/unlink.php',{unlink:'twitter'},function(data){
            $('.unlinktwit_conct').find('img').attr('src','/images/twtr_grey.jpg');
            $("#t_popup").hide();
            $('.unlinktwit_conct').addClass('twit_conct');
            $(".twit_conct").removeClass('unlinktwit_conct');
            window.location='/'+data;
        });
    });
    $(".f_unlink").unbind('click').click(function(){
        $.post('/unlink.php',{unlink:'fb'},function(data){
            $('.unlinkfb_conct').find('img').attr('src','/images/fb_grey.jpg');
            $("#f_popup").hide();
            $('.unlinkfb_conct').addClass('fb_conct');
            $(".fb_conct").removeClass('unlinkfb_conct');
            window.location='/'+data;
        });
    });
	
	
    $('#twit').unbind('click').click(function(event){
        var t=$(this).val();
        if(t ==0){
            event.stopPropagation();
            //event.preventDefault();
            var ref = $("#t_login").attr('title');
            window.open (ref,"mywindow","menubar=1,resizable=1,width=780,height=350");
        }
    });
    $('#fbk').unbind('click').click(function(event){
        var t=$(this).val();
        if(t ==0){
            FB.login(function(response) {if (response.session) {$.post('/fb_connect/auth_ajax.php',{unlink:'fb'})}else{ $("#fbk").removeAttr("checked");}}, {perms:'email,offline_access,user_birthday,user_location,publish_stream,read_friendlists'});
        }
    });
}
function fb_lg_succ(){}
function resend_confirm(){
    $('.resend-confirmation-email-link').click(function(){
        $.post('/resendconfirmation.php',{resend:'resend'},function(data){
            flash_message(data, "error");
        });
    });
}
function postautogrows(){
}
function load_paging(){
    /*$("a.paging_link").unbind('click').click(function(event){
		event.preventDefault();
	});
	
	$(".next_page").unbind('click').click(function(){
			$("#page_loader").show();
			var search_text =$('#search_text').val();
				page++;
				$(window).unbind('scroll');
				if($("#userpage_tab").length > 0){
					var userpage_tab = $("#userpage_tab").val();
					var userid = $('#memberprofile_userid').val();
					$.post(location.pathname,{req:'ajax', page:page,tab:userpage_tab, userid:userid}, function(data) {
						if(data){
							$("#page_loader").hide();
							$(".next_page").hide();
							$('#userdetails').append(data);
							$('#wrapper').append($(".next_page"));
							$("#bottomLoader").hide();
							
							if(!(/^\s*$/.test(stripTags(data).replace(/\n/g,"").replace(/\r/g,"")))){attachScroll()}
							resizedata();
							var next=page+1;
							var p=$("a.paging_link").attr('href');
							var new_href=p.replace('='+page,'='+next);
							$("a.paging_link").attr('href',new_href);
							$(".next_page").show();
						}
						else{
							$(this).hide();
						}
					});
				}else{
					$.post(location.pathname,{req:'ajax', page:page,search_text:search_text}, function(data) {
						if(data){
							$("#page_loader").hide();
							$(".next_page").hide();$(".del_msg").hide();
							$('#timeline_home').append(data);
							$('#wrapper').append($(".del_msg"));
							
							$('#wrapper').append($(".next_page"));
							$("#bottomLoader").hide();
							if(!(/^\s*$/.test(stripTags(data).replace(/\n/g,"").replace(/\r/g,"")))){attachScroll()}
							resizedata();
							var cnt=$("#total_cnt").val();$(".del_msg").show();
							if(cnt > page*15){
								var next=page+1;
								var p=$("a.paging_link").attr('href');
								var new_href=p.replace('='+page,'='+next);
								$("a.paging_link").attr('href',new_href);
								$(".next_page").show();
							}
							else{
								$(".next_page").hide();
							}
						}
						remove_notifications();
						
					});
				}
	});*/
}
// Expose jQuery to the global object


var arr=[];

function image_clicker(){
	
    $("#nextBtn").unbind('click').click(function(){
	
        //$("#loading_img").show().center;				
        var p1= $("li#thumbs_list");
        var pos1 = p1.position().left;
				
        var p2=$("ul.thumbnail_Images");
        var pos2 = p2.position().left;
		
        var w1= $("li#thumbs_list").width();
        var w2=$("ul.thumbnail_Images").width();
		
		
        if(arr ==''){
            arr=get_pos();
        }
		
        if(w2 >w1){
	
            var l,nl;
            var shifted=$("ul.thumbnail_Images").css('right');
            if(isNaN(parseInt(shifted))){
                shifted=0;
            }
            var t=w1+parseInt(shifted);
		
            for(var i=0; i<arr.length;i++){
				
				
                if(w2-t > w1){
                    if(arr[i]== t){
                        nl=arr[i+1];
                    }
                    else if(arr[i]< t && arr[i+1] > t){
                        nl=arr[i];
                    }
                }
                else{
                    nl=w2-w1;
                }
				
            }
			
			
            $("ul.thumbnail_Images").animate({"right": nl +"px"}, "slow");
		
        }
        //$("#loading_img").hide();
	
    });
    $("#prevBtn").unbind('click').click(function(){
	
        //$("#loading_img").show().center;		
        var p1= $("li#thumbs_list");
        var pos1 = p1.position().left;
				
        var p2=$("ul.thumbnail_Images");
        var pos2 = p2.position().left;
		
        var w1= $("li#thumbs_list").width();
        var w2=$("ul.thumbnail_Images").width();
        if(arr==''){
            arr=get_pos();
        }
        if(w2 >w1){
			
            var l,nl,d;
            var shifted=$("ul.thumbnail_Images").css('right');
			
            if(isNaN(parseInt(shifted))){
                shifted=0;
            }
            var t=parseInt(shifted);
			
            var q=parseInt(shifted) % parseInt(w1);
			
		
		
            if(t >= w2-w1){
					
                nl= parseInt(shifted)-q;
            }
            else{
                nl= parseInt(shifted)-w1;
            }
            var temp = nl;
            if(nl <=0){
                nl=0;
            }
            else
                for(var i=0; i<arr.length;i++){
				
				
                    if(arr[i] >= temp){
				
                        break;
                    }
                else{
                    nl=arr[i];
                }
				
            }
			
					
            $("ul.thumbnail_Images").animate({"right": nl +"px"}, "slow");	
        }
        $("#loading_img").hide();
    });	
}

function get_pos(){
    $("ul.thumbnail_Images:first li").each(function(){
        var obj=$(this);
        var pos1 = obj.position().left;
        arr.push(pos1);
    });
    return arr;
}

function selectPostRec(){
    $("#frnds").unbind('click').click(function(){
		
        if($("#PrivacySuggestions").is(':visible')){
           $("#PrivacySuggestions").hide();
        }else{
			$("#PrivacySuggestions").show().center();
            
        }
        selectPostRec();
		
    });
    $(".cls_sugst").unbind('click').click(function(event){
        event.stopPropagation();
        $("#PrivacySuggestions").hide(); 
		$(".frnds_add").html('Ask Friends ('+$(".frnd_select:checked").length+')');
		selectPostRec();
    });
    $(".list_frnds,.list_frnds li").unbind('click').click(function(event){
        event.stopImmediatePropagation();
        var gid=$(this).attr('title');
        if($(this).parent('li').find('ul.frnd_list').is(':visible')){
            $(this).css('background-image',"url(/images/an_arw.jpg)");
        }
        else{
            $(this).css('background-image',"url(/images/arow_down.png)");
		
        }
		
        $(this).parent('li').find('ul.frnd_list').slideToggle('slow');selectPostRec();
    });
    $(".group_select").unbind('click').click(function(event){
        event.stopImmediatePropagation();
        if($(this).attr('checked')){
            $(this).parent('li').find('ul li .frnd_select').attr('checked',true);
        }
        else{
            $(this).parent('li').find('ul li .frnd_select').attr('checked',false);
        }
        selectPostRec();
		
    });
    $(".frnd_select").unbind('click').click(function(event){
        event.stopImmediatePropagation();
		
        $(".frnd_select").each(function(){
            if($(this).attr('checked')){
                $(this).parent('li').find('ul li .group_select').attr('checked',true);
            }
            else{
                $(this).parent('li').parent().parent().find('.group_select').attr('checked',false);
                return; 
				
            }
        });

		
        selectPostRec();
		
    });
    $("#postSuggest,.myGroups,.myGroups ul,.myGroups ul li,.myGroups ul li .leftLbl,.list_frnds li .leftLbl").unbind('click').click(function(event){
        event.stopImmediatePropagation();selectPostRec();
    });
}
var prev_text='';
var cur_text='';
var t;
function search_user(){
	
	
	$("#search_user").unbind('focus').focus(function(){
		
		if($("#search_user").val()=='Find people'){
			$("#search_user").val('');
		}
		t=setTimeout(search_me, 100);
	});
	
	$("#search_user").unbind('blur').blur(function(){
		delete t;
		
	});

	
}
function search_me(){
	
	var GId= $("#userlist_popup .p_pop_cntr_title").attr("rel");
	cur_text=$("#search_user").val();
	if(cur_text=='' || cur_text=='Find people') cur_text = '';
	if(prev_text !=cur_text && cur_text!='Find people'){		
		var gtitle = $("#userlist_popup .p_pop_cntr_title").attr('title');
		$("#userlist_popup .p_pop_cntr_title").html("Loading...");
		var uid=$("#session_userid").val();
		$.post('/search_user.php',{search_user:cur_text,gid:GId,uid:uid},function(data){
			
			var temp=$.parseJSON(data);
			
			if(temp.search_txt == $.trim($('#search_user').val()) || (temp.search_txt=='' && $.trim($('#search_user').val())=='Find people')){
				$('.p_pop_cntr_middle').html(temp.data);
			}
			
			$("#userlist_popup .p_pop_cntr_title").html(gtitle);
			$("#userlist_popup .p_pop_cntr_title").attr("rel", GId);
			select_groups();
			
			 $(".add_to_group").unbind('click').click(function(event){
		
				event.stopPropagation();
				var gtitle = $("#userlist_popup .p_pop_cntr_title").attr('title');
		
				$("#userlist_popup .p_pop_cntr_title").html("Loading...");
				
					var gid=$("#this_gid").val();
					var uid=$(this).attr('title');
					action='add';
					
					  var cnt=$("a#user_group_name_"+gid).find('span.grp_cnt').html();
						cnt=cnt.replace("(","");cnt=cnt.replace(")","");
						cnt=parseInt(cnt);
				
					$.post("/addtogroups.php", {req:'ajax', GID: gid ,UID:uid ,action:action },function(data){
						$("#add_to_group"+uid).replaceWith('<a href="javascript:void(0);" rel="'+uid+'" class="user_rem_grp" style="color:#999">Remove</a>');
						
						$("#userlist_popup .p_pop_cntr_title").html(gtitle);
            			$("#userlist_popup .p_pop_cntr_title").attr("rel", gid);
						
						cnt++;
						//$("#user_group_name_"+gid).find('span.grp_cnt').html();
						 $("a#user_group_name_"+gid).find('span.grp_cnt').html("("+cnt+")");
						 select_groups();
							
					});
					
				
				select_groups();
			});
			
			
			
			
		});
	}
	prev_text=cur_text;
	setTimeout(search_me, 100);
	
}

