/******************************************************/
/*	PEGSHOT.JS - Common Javascript Helper Functions
/*	Written by David Overcash - funnylookinhat@gmail.com
/*	Copyright Pegshot 2009
/*	
/*	
/******************************************************/

function follow_location(location_id) {
	$.post("/locationjson/follow_location/"+location_id+"/",function(data) {
		$('div#button_follow_location_'+location_id).html('FOLLOWING THIS PLACE');
	});
}

function follow_event(event_id) {
	$.post("/eventjson/follow_event/"+event_id+"/",function(data) {
		$('div#button_follow_event_'+event_id).html('FOLLOWING THIS EVENT');
	});
}

function follow_user(user_id) {
	$.post("/userjson/follow_user/"+user_id+"/",function(data) {
		$('div#button_follow_'+user_id).html('FOLLOWING');
	});
	return false;
}

function friend_user(user_id) {
	$.post("/userjson/friend_user/"+user_id+"/",function(data) {
		// Hide the follow box and update follow link
		$('div#follow_popup_box_'+user_id).hide();
		$('div#button_follow_'+user_id).html('<a href="javascript:void(0);" onclick="show_follow_box('+user_id+');">Confirming...</a>');
	});
	return false;
}

function unfollow_user(user_id) {
	$.post("/userjson/unfollow_user/"+user_id+"/",function(data) {
		// Hide the follow box and update follow link
		$('div#follow_popup_box_'+user_id).hide();
		$('div#button_follow_'+user_id).html('<a href="javascript:void(0);" onclick="show_follow_box('+user_id+');">FOLLOW</a>');
	});
	return false;
}

function unfriend_user(user_id) {
	$.post("/userjson/unfriend_user/"+user_id+"/",function(data) {
		// Hide the follow box and update follow link
		$('div#follow_popup_box_'+user_id).hide();
		$('div#button_follow_'+user_id).html('<a href="javascript:void(0);" onclick="show_follow_box('+user_id+');">FOLLOWING</a>');
	});
	return false;
}

function show_follow_box(user_id) {
	// First we have to hide any other follow box that might be shown...
	$('.follow_popup_box').hide();
	$('div#follow_popup_box_'+user_id).load('/userjson/follow_popup_box/'+user_id,function(data) {
		var y = window.pageYOffset;
		y = y + 150;
		// This is not IE compliant...
		document.getElementById('follow_popup_box_'+user_id).style.top = y+'px';
		$('div#follow_popup_box_'+user_id).fadeIn(250);
	});
	return false;
}

function show_follow_location_box(location_id) {
	$('.follow_popup_box').hide();
	$('div#follow_location_popup_box_'+location_id).load('/locationjson/follow_popup_box/'+location_id,function(data) {
		var y = window.pageYOffset;
		y = y + 150;
		// This is not IE compliant...
		document.getElementById('follow_location_popup_box_'+location_id).style.top = y+'px';
		$('div#follow_location_popup_box_'+location_id).fadeIn(250);
	});
	return false;
}

function hide_follow_location_box(location_id) {
	$('div#follow_location_popup_box_'+location_id).fadeOut(150);
	return false;
}

function show_follow_event_box(event_id) {
	$('.follow_popup_box').hide();
	$('div#follow_event_popup_box_'+event_id).load('/eventjson/follow_popup_box/'+event_id,function(data) {
		var y = window.pageYOffset;
		y = y + 150;
		// This is not IE compliant...
		document.getElementById('follow_event_popup_box_'+event_id).style.top = y+'px';
		$('div#follow_event_popup_box_'+event_id).fadeIn(250);
	});
	return false;
}

function hide_follow_event_box(event_id) {
	$('div#follow_event_popup_box_'+event_id).fadeOut(150);
	return false;
}

function hide_follow_box(user_id) {
	$('div#follow_popup_box_'+user_id).fadeOut(150);
	return false;
}

function feed_collapse_all() {
	$('a#collapse_feed').hide();
	$('a#expand_feed').show();
	$('.feed_item_mini').slideUp(150);
	$('.play_button_overlay').hide();
}

function feed_expand_all() {
	$('a#expand_feed').hide();
	$('a#collapse_feed').show();
	$('.feed_item_mini').slideDown(150, function(data) {
		$('.play_button_overlay').show();
	});
	
}

function remove_all_social_notifications() {
	// OMG!
	
	// Call the URL to remove all social notifications...
	$.post('/userjson/remove_all_social_notifications/', function(data) {
		// Hide all social DIVs
		$('.social_notification').slideUp(250);
	});
	return false;
}

function remove_all_media_notifications() {
	// OMG!
	
	// Call the URL to remove all media notifications...
	$.post('/userjson/remove_all_media_notifications/', function(data) {
		// Hide all social DIVs
		$('.media_notification').slideUp(250);
	});
	return false;
}

function remove_all_media_comment_notifications() {
	// OMG!
	
	// Call the URL to remove all media notifications...
	$.post('/userjson/remove_all_media_comment_notifications/', function(data) {
		// Hide all social DIVs
		$('.media_comment_notification').slideUp(250);
	});
	return false;
}

function remove_all_media_like_notifications() {
	// OMG!
	
	// Call the URL to remove all media notifications...
	$.post('/userjson/remove_all_media_like_notifications/', function(data) {
		// Hide all social DIVs
		$('.media_like_notification').slideUp(250);
	});
	return false;
}


function remove_social_notification(id) {
	// id: social_notification_id
	
	// Call the URL to remove the social notification.
	$.post('/userjson/remove_social_notification/'+id, function(data) {
		$('div#social_notification_'+id).slideUp(250);
	});
	return false;
}

function remove_media_notification(id) {
	// id: media_notification_id
	
	// Call the URL to remove the media notification.
	$.post('/userjson/remove_media_notification/'+id, function(data) {
		// Hide the DIV
		$('div#media_notification_'+id).slideUp(250);
	});
	return false;
}

function ignore_friend_request(id) {
	// id: connection_id
	
	// Call the URL to accept the friend request.
	$.post('/userjson/ignore_friend_request/'+id, function(data) {
		// Hide the DIV.
		$('div#friend_request_'+id).slideUp(250);
	});
	
	return false;
}

function accept_friend_request(id) {
	// id: connection_id
	
	// Call the URL to accept the friend request.
	$.post('/userjson/accept_friend_request/'+id, function(data) {
		// Hide the DIV.
		$('div#friend_request_'+id).slideUp(250);
	});
	
	return false;
}

function login_username_blur() {
	if($('input#login_username').val() == "") {
		$('input#login_username').val("Username");
	}
}

function login_username_focus() {
	if($('input#login_username').val() == "Username") {
		$('input#login_username').val("");
	}
}

function login_password_blur() {
	if($('input#login_password').val() == "") {
		$('span#login_password').html('<input name="password" id="login_password" type="text" class="login_text" value="Password" style="width: 140px;" onfocus="javascript:login_password_focus();" onblur="javascript:login_password_blur();">');
	}
}

function login_password_focus() {
	if($('input#login_password').val() == "Password") {
		$('span#login_password').html('<input name="password" id="login_password" type="password" class="login_text" value="" style="width: 140px;" onfocus="javascript:login_password_focus();" onblur="javascript:login_password_blur();">');
		$('input#login_password').focus();
	}
}