function build_events(filters, views, offset) {	var user_id = $('#user_id').val();	var timezone = $('#whenTimezone').val();	$('#events').html("<br />loading <img src='/images/loader.gif' width='128' height='15' />");	$.post("/scripts/events/build", { user_id: user_id, filter: filters, view: views, timezone: timezone, offset:offset }, function(data) {		$('#events').html(data);	});}function submit_event() {	$.post("/scripts/event/add", $("#eventForm").serialize(), function(data) {		//build_events();		//popbox('Success', 'Your event was successfully added to your flowh.');		//$('.openClose').toggle();		//$('#user_infoz').slideToggle();		//$('#eventFormDiv').slideToggle();		location.reload(true);	});}function submit_event_simple() {	$.post("/scripts/event/add", $("#eventForm_simple").serialize(), function(data) {		location.reload(true);	});}function approve_event(user_id, event_id) {	$.post("/scripts/event/approve", { user_id: user_id, event_id: event_id }, function(data) {		location.reload(true);	});}function approve_friends(creator_id, user_id) {	$.post("/scripts/user/friends/approve", { creator_id: creator_id, user_id: user_id }, function(data) {		location.reload(true);	});}function add_friend(creator_id, user_id) {	$.post("/scripts/user/friends/add", { creator_id: creator_id, user_id: user_id }, function(data) {		location.reload(true);	});}function un_friend(creator_id, user_id) {	$.post("/scripts/user/friends/delete", { creator_id: creator_id, user_id: user_id }, function(data) {		location.reload(true);	});}function add_follow(creator_id, user_id) {	$.post("/scripts/user/follows/add", { creator_id: creator_id, user_id: user_id }, function(data) {		location.reload(true);	});}function un_follow(creator_id, user_id) {	$.post("/scripts/user/follows/delete", { creator_id: creator_id, user_id: user_id }, function(data) {		location.reload(true);	});}function update_tf(text) {	$('#frompicker').val(text);	$('#simp_when').val(text+' 09:00:00').unbind('focus').css("color","#333");	if($('#simp_duration').is(':hidden')) {		$('#simp_when').next().next().show()	}	$('#topicker').val(text);	$("#openClose_o").hide();	$("#openClose_c").show();	$("#eventFormDiv").slideDown();}function getCategory(parent) {	var timezone = $('#whenTimezone').val();	$.post("/scripts/build_category.php", { parent_id: parent, timezone: timezone }, function(data) {		if($("#cat"+parent).next().attr('class')=='categories') {			$("#cat"+parent).next().remove();		}		else {			$("#cat"+parent).after(data);		}	});}function popbox(title, text, footer) {	footer = typeof(footer) != 'undefined' ? footer : '';	var popbox_cls = $("<div></div>").attr("id","popbox_cancel").attr("class","round btn").html("close").click(function() {		var parent = $(this).parent().parent();		$(parent).fadeOut(500, function() {			$(this).remove();		});	});	var popbox = $("<div></div>").attr("id","popbox").attr("class","popbox round").html('<div class="popbox_title round_top">'+title+'</div><div class="popbox_content">'+text+'</div><div class="popbox_footer round_bottom">'+footer+' </div>').hide();	$('body').append(popbox);	if(footer == '') {		$('#popbox .popbox_footer').append(popbox_cls);	}	$(popbox).fadeIn(1000);	$( document ).bind("mousedown",function() {		$("#popbox").remove();	});	$("#popbox").bind("mousedown",function(event) {		event.stopPropagation();	});}function logout() {	$.post("/scripts/user/logout", function(data) {		location.href="/";	});}function comment(event_id) {	var comment_text = $('#comment_text').val();	var viewer_id = $('#viewer_id').val();	var timezone = $('#viewer_timezone').val();	$.post("/scripts/event/comment/add", { text:comment_text, event_id:event_id, timezone:timezone, commenter_id:viewer_id }, function(data) {		//location.reload(true);		$('#comments').html(data);	});}function fbs_click_custom(url) {	if(url) {		u=url;	}	else {		u=location.href;	}	t=document.title;	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');	return false;}function init_events() {	$(".day_m h2").click(function() {		$(this).next().slideToggle();	});	$(".day").mouseover(function() {		$(".day_count",this).css("color","#999");	}).mouseout(function() {		$(".day_count",this).css("color","#CCC");	});	$(".event").mouseover(function() {		if($(".event_actions .flwh_actions > img", this).size()==0) {			$(".event_actions .flwh_actions", this).hide();		}		$(".event_actions", this).show();	}).mouseout(function() {		$(".event_actions", this).hide();	});	$(".event_trash").click(function() {		var user_id = $("#user_id").val();		var event_id = $(this).next().val();		var instance=false;		var instance_btn='';		if($(this).next().attr('rel')) {			instance = $(this).next().attr('rel');			instance_btn = '<div id="popbox_ok_inst" class="round btn">Instance</div>';		}		var event_div = $(this).parent().parent().parent();		popbox("Delete Event", "Are you sure you want to delete this event?<br />This can't be undone.", 'Delete: '+instance_btn+'<div id="popbox_ok" class="round btn">Event</div><div id="popbox_cancel" class="round btn">Cancel</div>');		$("#popbox_cancel").click(function() {			var parent = $(this).parent().parent();			$(parent).fadeOut(500, function() {				$(this).remove();			});		});		$("#popbox_ok").click(function() {			var parent = $(this).parent().parent();			$(parent).fadeOut(500, function() {				$(this).remove();			});			$.post("/scripts/event/delete", { user_id: user_id, event_id: event_id }, function(data) {				if(data==1) {					$(event_div).fadeOut();				}				else {					popbox("Oops", "There was a problem trying to delete this event.");				}			});		});		$("#popbox_ok_inst").click(function() {			var parent = $(this).parent().parent();			$(parent).fadeOut(500, function() {				$(this).remove();			});			$.post("/scripts/event/delete", { user_id: user_id, event_id: event_id, instance: instance }, function(data) {				if(data==1) {					$(event_div).fadeOut();				}				else {					popbox("Oops", "There was a problem trying to delete this instance.");				}			});		});	});	$(".follow_event_trash").click(function() {		var event_div = $(this).parent().parent();		var user_id = $("#user_id").val();		var event_id = $(this).next().val();		popbox("Delete Event", "Are you sure you want to stop following this event?", '<div id="popbox_ok" class="round btn">Delete</div> <div id="popbox_cancel" class="round btn">Cancel</div>');		$("#popbox_cancel").click(function() {			var parent = $(this).parent().parent();			$(parent).fadeOut(500, function() {				$(this).remove();			});		});		$("#popbox_ok").click(function() {			var parent = $(this).parent().parent();			$(parent).fadeOut(500, function() {				$(this).remove();			});			$.post("/scripts/event/delete", { user_id: user_id, event_id: event_id, follow: 1 }, function(data) {				if(data==1) {					$(event_div).fadeOut();				}				else {					popbox("Oops", "There was a problem trying to unfollow this event.");				}			});		});	});	$(".event_edit").click(function() {		var user_id = $("#user_id").val();		var event_id = $(this).prev().val();		$(this).remove();		$.post("/scripts/event/edit", { user_id: user_id, event_id: event_id }, function(data) {			if(data) {$("#openClose_o").hide();				$("#openClose_c").show();				$("#eventFormDiv").html(data);				$("#eventFormDiv").slideDown();			}			else {				popbox("Oops", "There was a problem trying to load this event to edit.");			}		});	});	$(".event_add").click(function() {		var user_id = $("#user_id").val();		var event_id = $(this).next().val();		$(this).remove();		$.post("/scripts/event/duplicate", { user_id: user_id, event_id: event_id }, function(data) {			if(data==1) {				popbox("Success", "Event has been successfully added to your flowh.");			}			else {				popbox("Oops", "There was a problem trying to add this event to your flowh, please try again or refresh your page.");			}		});	});	$(".event_follow").click(function() {		var user_id = $("#viewer_id").val();		var event_id = $(this).prev().val();		$(this).remove();		$.post("/scripts/event/follow", { user_id: user_id, event_id: event_id }, function(data) {			if(data==1) {				popbox("Success", "This event has been added to your flowh.");			}			else {				popbox("Oops", "There was a problem trying to follow this event, please try again or refresh your page.");			}		});	});	$(".event_watch").click(function() {		var user_id = $("#viewer_id").val();		var event_id = $(this).next().val();		$(this).remove();		$.post("/scripts/event/watch", { user_id: user_id, event_id: event_id }, function(data) {			if(data==1) {				popbox("Success", "This event has been added to your watch list.");			}			else {				popbox("Oops", "There was a problem trying to add this event to your watch list, please try again or refresh your page.");			}		});	});		$('.event:has(.event_link)').mouseenter(function() {		$(this).append($('#event_hcard').css('left','-322px'));		if(hcard_id!=$('.event_id',this).val()) {			hcard_id=$('.event_id',this).val();			$('#hcard_info').html('<img src="/images/loader.gif" width="128" height="15" style="margin:10px auto;" />');			$('#event_hcard .no_loc').remove();			$('#map_canvas').show();			$('#event_hcard').show();			$.post("/scripts/event_hcard.php",{event_id:hcard_id}, function(data) {				if(data) {					$('#hcard_info').html(data);				}			}, 'html');		}		else {			$('#event_hcard').show();		}	}).mouseleave(function() {		$('#event_hcard').hide();	});}function fetch() {	$.post("/scripts/activity/fetch", {}, function(data) {		if(data.messages) {			if($("#messages_count").length > 0) {				$("#messages_count").text(data.messages);			}			else {				$("#messages_bar").append('<div id="messages_count">'+data.messages+'</div>');			}		}		if(data.alerts) {			if($("#alerts_count").length > 0) {				$("#alerts_count").text(data.alerts);			}			else {				$("#alerts_bar").append('<div id="alerts_count">'+data.alerts+'</div>');			}		}		if(data.chats) {			for(var i in data.chats) {				var login = data.chats[i].login;				if($("#chat_ico_"+login).length == 0) {					init_chat(login);				}				else {					$("#chat_msgs_"+login).append(data.chats[i].messages);				}			}		}	}, "json");}function init_chat(login) {	$("#users_chat_box").hide();	var user_login = login;	if($("#chat_ico_"+user_login).length == 0) {		if($(".chat_ico").length == 0) {			$("#chats_bar").show();			$("#chats_bar .counts").eq(0).text("1");		}		else {			$("#chats_bar .counts").eq(0).text(($("#chats_bar .counts").eq(0).text()*1)+1);		}		$.post("/scripts/chat_initiate.php", { user:user_login }, function(data) {			if(data) {				$("#chat_box").show();				$("#chat_box_candy_l").prepend("<div id=\'chat_ico_"+data.login+"\' class=\'chat_ico\'><img height=\'32\' width=\'32\' src=\'http://flowh.com/profile_images/"+data.picture_name+"_m"+data.picture_ext+"\' /></div>");				$("#chat_box_npt").before("<div id=\'chat_msgs_"+data.login+"\' class=\'chat_msgs\'><span style=\'position:absolute; top:0px;\' class=\'caption\'>Chat with: "+data.user_name+"</span></div>");				$("#chat_ico_"+data.login).click(function() {					$("#chat_msgs_"+data.login).insertBefore("#chat_box_npt");					$("#chat_to_var").attr("value", data.login);				});				$("#chat_to_var").attr("value", data.login);				$("#chat_msgs_"+data.login).append(data.messages).scrollTop(10000);			}		}, "json");	}	else {		$("#chat_box").show();	}}function send_chat() {	var to = $("#chat_to_var").val();	var msg = $("#chat_message").val();	$("#chat_message").attr("value","");	if(msg != "") {		$.post("/scripts/send_chat.php", { to : to, message : msg }, function(data) {			if(data) {				$("#chat_msgs_"+data.to).append(data.message).scrollTop(10000);				//$("#chat_message").attr("value","");				fetch();			}		}, "json");	}}var menu_showing=null;var eventFormDef;$(document).ready(function(){		// BEGIN EVENT LISTENERS		$("#search").focus(function() {		if($(this).val() == "search") {			$(this).val("");			$(this).css("color","#333");		}	}).blur(function() {		if($(this).val() == "") {			$(this).val("search");			$(this).css("color","#999");		}	});		$('#pm_link').click(function() {		popbox('Message','<span class="caption">Subject:</span><br /><input type="text" maxlength="32" style="width:100%" /><br /><span class="caption">Message:</span><br /><textarea rows="5" style="width:100%" maxlength="512"></textarea>', '<div id="popbox_ok" class="round btn">Send</div> <div id="popbox_cancel" class="round btn">Cancel</div>');		$("#popbox_cancel").click(function() {			var parent = $(this).parent().parent();			$(parent).fadeOut(500, function() {				$(this).remove();			});		});		$("#popbox_ok").click(function() {			var user_id = $("#user_id").val();			var viewer_id = $("#viewer_id").val();			var parent = $(this).parent().parent();			var message = $('.popbox_content textarea', parent).val();			var subject = $('.popbox_content input', parent).val();			$(parent).fadeOut(500, function() {				$(this).remove();			});			$.post("/scripts/message/add", { user_id:user_id, viewer_id:viewer_id, subject:subject, message:message }, function(data) {				if(data==1) {					popbox("Success", "Your message was successfully sent.");				}				else {					popbox("Oops", "There was a problem trying to leave a message, please try again.");				}			});		});		return false;	});		$("#eventFormDiv .text_box").focus(function() {		eventFormDef = $(this).val();		$(this).val("");		$(this).css("color","#333");	}).blur(function() {		if($(this).val() == "") {			$(this).val(eventFormDef);			$(this).css("color","#999");		}		else {			$(this).unbind('focus');		}	});		$('#chat_bar').click(function() {		var height = $(window).height();		height -=145;		$('#users_chat_box').css('max-height',height+'px').toggle();		height-=40;		$('#users_chat_users').css('max-height',height+'px');		$.post("/scripts/build_chat_users.php", {}, function(data) {			$('#users_chat_users').html(data);		});	});		$('#users_chat_box_header').click(function() {		$('#users_chat_box').toggle();	});		$('#chats_bar').click(function() {		$('#chat_box').toggle();	});		$('#chat_box_header').click(function() {		$('#chat_box').toggle();	});		$('#alerts_bar').click(function() {		var height = $(window).height();		height -=145;		$('#alerts_box').css('max-height',height+'px').toggle();		height-=32;		$('#notifications').css('max-height',height+'px');		$('#alerts_count').hide();		$.post("/scripts/activity/build", {}, function(data) {			$('#notifications').html(data);		});	});		$('#alerts_box_header').click(function() {		$('#alerts_box').toggle();	});	$(".event_add").click(function() {		var user_id = $("#user_id").val();		var event_id = $(this).next().val();		$.post("/scripts/event/duplicate", { user_id: user_id, event_id: event_id }, function(data) {			if(data==1) {				popbox("Success", "Event has been successfully added to your flowh.")			}			else {				popbox("Oops", "There was a problem trying to add this event to your flowh, please try again or refresh your page.");			}		});		return false;	});	$(".event_follow").click(function() {		var viewer_id = $("#viewer_id").val();		var event_id = $(this).prev().val();		$.post("/scripts/event/follow", { user_id: viewer_id, event_id: event_id }, function(data) {			if(data==1) {				popbox("Success", "You are now following this event.")			}			else {				popbox("Oops", "There was a problem trying to follow this event, please try again or refresh your page.");			}		});		return false;	});	$(".event_watch").click(function() {		var user_id = $("#viewer_id").val();		var event_id = $(this).next().val();		$.post("/scripts/event/watch", { user_id: user_id, event_id: event_id }, function(data) {			if(data==1) {				popbox("Success", "This event has been added to your watch list.");			}			else {				popbox("Oops", "There was a problem trying to add this event to your watch list, please try again or refresh your page.");			}		});	});	$(".flo_embed_button").click(function() {		var event_id = document.location.pathname.split("/")[2];		popbox("Embed", '<textarea rows="5" style="width:100%" onClick="this.select()"><div id="flowh_event"></div>\n'+'<script type="text/javascript" src="http://flowh.com/widgets/build_event_html.js"></script>\n'+'<script type="text/javascript" src="http://flowh.com/flowhs/event.php?id='+event_id+'"></script></textarea><br /><span class="caption">We recommend placing the &lt;div /&gt; anywhere on your page and place the scripts before &lt;/body&gt;.</span>');		return false;	});		$('#invite').click(function() {		popbox('Invite Friends', '<span class="caption">Separate multiple email addresses with a "," (comma)</span><textarea rows="5" style="width:100%" id="invt_message"></textarea>','<div id="popbox_ok" class="round btn">Send</div> <div id="popbox_cancel" class="round btn">Cancel</div>');		$("#popbox_cancel").click(function() {			var parent = $(this).parent().parent();			$(parent).fadeOut(500, function() {				$(this).remove();			});		});		$("#popbox_ok").click(function() {			var user_id = $("#viewer_id").val();			var parent = $(this).parent().parent();			var message = $('#invt_message').val();			$(parent).fadeOut(500, function() {				$(this).remove();			});			$.post("/scripts/user/invite", { user_id:user_id, message:message }, function(data) {				if(data==1) {					popbox("Success", "Your invites were successfully sent.");				}				else {					popbox("Oops", "There was a problem trying to send your invite, please try again.");				}			});		});		return false;	});		$(window).scroll(function() {		if($('#eventFormDiv').is(':hidden')) {			var scrollTop=$(window).scrollTop();			if(scrollTop>394) {				$('#eventDiv').stop().animate({ 'margin-top':scrollTop-374 },100);			}			else if(parseInt($('#eventDiv').css('margin-top')) >0) {				if(scrollTop>394) {					$('#eventDiv').stop().animate({ 'margin-top':scrollTop-374 },100);				}				else {					$('#eventDiv').stop().animate({ 'margin-top':0 },100);				}			}		}	});			// BEGIN DOCUMENT CLICK LISTENER			$( document ).bind("mousedown",function() {				$("#alerts_box").hide();				$("#users_chat_box").hide();				$("#chat_box").hide();			});			$("#alerts_box").bind("mousedown",function(event) {				event.stopPropagation();			});			$("#users_chat_box").bind("mousedown",function(event) {				event.stopPropagation();			});			$("#chat_box").bind("mousedown",function(event) {				event.stopPropagation();			});		// END DOCUMENT CLICK LISTENER		// END EVENT LISTENERS				// BEGIN PAGE INIT		$(document).click(function(e) {		if(menu_showing && e.target != menu_showing && e.target.className.indexOf("dropdown") == -1) {			$(menu_showing).hide();		}	});		$(".dropdown.button").click(function() {		if(menu_showing) {			$(menu_showing).hide();		}		menu_showing = $(this).next();		$(menu_showing).width($(this).width() + 20);		$(menu_showing).show();		$("ul", menu_showing).focus();	}).focus(function() {		if(menu_showing) {			$(menu_showing).hide();		}		menu_showing = $(this).next();		$(menu_showing).width($(this).width() + 20);		$(menu_showing).show();		$("ul", menu_showing).focus();	});		$(".dropdown.menu li").click(function() {		$(this).parent().parent().hide();		var $kids = $(this).parent().children();		var len = $kids.removeClass("selected").length;		$(this).addClass("selected");		$(this).parent().parent().prev().html($(this).html() + ' <img class="dropdown" src="/images/dd_btn_icon.png"/>');		$(this).parent().parent().next().val($(this).html());	}).keypress(function (e) {		if(e.which == 13) {			$(this).click();			$(this).parent().parent().parent().next().focus();		}		else if(e.which == 40) {			$(this).blur();			$(this).next().trigger("focus");		}		else if(e.which == 38) {			$(this).blur();			$(this).prev().trigger("focus");		}	});	// END PAGE INIT	});
