var itemPossibleImagesHTML = '';
var refreshChangeImageOption = true;

/**
* jQuery.ScrollTo - Easy element scrolling using jQuery.
* Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
* Dual licensed under MIT and GPL.
* Date: 5/25/2009
* @author Ariel Flesler
* @version 1.4.2
*
* http://flesler.blogspot.com/2007/10/jqueryscrollto.html
*/
; (function(d) { var k = d.scrollTo = function(a, i, e) { d(window).scrollTo(a, i, e) }; k.defaults = { axis: 'xy', duration: parseFloat(d.fn.jquery) >= 1.3 ? 0 : 1 }; k.window = function(a) { return d(window)._scrollable() }; d.fn._scrollable = function() { return this.map(function() { var a = this, i = !a.nodeName || d.inArray(a.nodeName.toLowerCase(), ['iframe', '#document', 'html', 'body']) != -1; if (!i) return a; var e = (a.contentWindow || a).document || a.ownerDocument || a; return d.browser.safari || e.compatMode == 'BackCompat' ? e.body : e.documentElement }) }; d.fn.scrollTo = function(n, j, b) { if (typeof j == 'object') { b = j; j = 0 } if (typeof b == 'function') b = { onAfter: b }; if (n == 'max') n = 9e9; b = d.extend({}, k.defaults, b); j = j || b.speed || b.duration; b.queue = b.queue && b.axis.length > 1; if (b.queue) j /= 2; b.offset = p(b.offset); b.over = p(b.over); return this._scrollable().each(function() { var q = this, r = d(q), f = n, s, g = {}, u = r.is('html,body'); switch (typeof f) { case 'number': case 'string': if (/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)) { f = p(f); break } f = d(f, this); case 'object': if (f.is || f.style) s = (f = d(f)).offset() } d.each(b.axis.split(''), function(a, i) { var e = i == 'x' ? 'Left' : 'Top', h = e.toLowerCase(), c = 'scroll' + e, l = q[c], m = k.max(q, i); if (s) { g[c] = s[h] + (u ? 0 : l - r.offset()[h]); if (b.margin) { g[c] -= parseInt(f.css('margin' + e)) || 0; g[c] -= parseInt(f.css('border' + e + 'Width')) || 0 } g[c] += b.offset[h] || 0; if (b.over[h]) g[c] += f[i == 'x' ? 'width' : 'height']() * b.over[h] } else { var o = f[h]; g[c] = o.slice && o.slice(-1) == '%' ? parseFloat(o) / 100 * m : o } if (/^\d+$/.test(g[c])) g[c] = g[c] <= 0 ? 0 : Math.min(g[c], m); if (!a && b.queue) { if (l != g[c]) t(b.onAfterFirst); delete g[c] } }); t(b.onAfter); function t(a) { r.animate(g, j, b.easing, a && function() { a.call(this, n, b) }) } }).end() }; k.max = function(a, i) { var e = i == 'x' ? 'Width' : 'Height', h = 'scroll' + e; if (!d(a).is('html,body')) return a[h] - d(a)[e.toLowerCase()](); var c = 'client' + e, l = a.ownerDocument.documentElement, m = a.ownerDocument.body; return Math.max(l[h], m[h]) - Math.min(l[c], m[c]) }; function p(a) { return typeof a == 'object' ? a : { top: a, left: a} } })(jQuery);



$(function() {
    $("#user_search_form_field").focus(function() { if (this.value == this.defaultValue) this.value = ""; }).bind("blur", function() { if (this.value == "") this.value = this.defaultValue; });
});



function wishListItems()
{
	this.id = [];
	this.item = [];
	this.cost = [];
	this.description = [];
	this.whereToBuy = [];
	this.link = [];
	this.whoFor = [];
	this.xid = [];
	this.imageURL = [];
	this.promisedBy = [];
}


function isUrl(s) {
	//var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function isPrice(s) {
	var regexp = /^\d+\.\d{2}$/
	if(!regexp.test(s)){ s = s+'.00'; }
	return regexp.test(s);
}


function showDropDownWidget(id) {
	$("#"+id).expose({closeOnEsc: false, closeOnClick: false});
	$("#"+id).animate({top:"0px"},500);
}

function hideDropDownWidget(id) {
	$.mask.close();
	$("#"+id).animate({top:"-350px"},300);
}

function loginAlert() {
	$("#alert-message").html("Please login or create an account to access this feature");

	$("#divAlert").overlay({
			top: 100,
			mask: {
				color: '#000000',
				loadSpeed: 100,
				opacity: 0.33
			},
			closeOnClick: false,
			load: true
		}
	).load();
}


function login()
{
	$.ajax({
		type: "POST",
		url: "/login/",
		data: "username=" + $("#username").val() + "&password=" + $("#password").val(),
		success: function(msg){
			if(msg == "OK") {
				var username = $("#username").val()
				$("#username").val("");
				$("#password").val("");
				window.location.href = $(location).attr('href'); //"/m/" + username;
			}
			else { $("#invalidLogin").html(msg); }
		}
		/*
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				$("#username").val("");
				$("#password").val("");
				//alert($("#password").val());
				window.location.reload();
			}
			else{ $("#invalidLogin").html($(xml).find('response').text()); }
		}
		*/
	});
}

function logout()
{
	$.ajax({
		type: "POST",
		url: "/logout/",
		data: "",
		success: function(msg) {
			window.location.href = $(location).attr('href');
		}
	});
}


function promiseToBuy(id, xid) {
	//alert(id + " - " + xid);
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=promiseItem&id=" + id + "&promisedBy=" + xid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				$("#td_" + id).html('<div style="font-weight:bold; font-size:12pt; color:#999; text-align:center;">Promised By Me!<br /><a href="javascript:void(0);" onclick="removePromise(\'' + id + '\', \'' + xid + '\')" style="text-decoration:none; color:#900; font-size:8pt;">Remove Promise</a></div>');
			}
			else{ /*alert("oops");*/ }
		}
	});
}

function removePromise(id, xid) {
	//alert(id + " - " + xid);
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=removePromiseItem&id=" + id + "&promisedBy=" + xid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				$("#td_" + id).html('<a title="Promise" href="javascript:void(0);" onclick="promiseToBuy(\'' + id + '\', \'' + xid + '\')"><img alt="Promise To Buy" src="/img/promise.png" /></a>');
			}
			else{ /*alert("oops");*/ }
		}
	});
}

function toggleNoCost() {
	if($("#addItemNoCost").is(":checked")) {
		$("#addItemCost").attr("readonly", "readonly");
		$("#addItemCost").css("color", "#CCC");
	}
	else {
		$("#addItemCost").attr("readonly", "");
		$("#addItemCost").css("color", "#000");
	}
}

function validateAddItem() {
	var error = true;
	$("#addItemItem").css("border-color","");
	$("#addItemCost").css("border-color","");
	$("#addItemWebLink").css("border-color","");
	$("#itemsRequired").html("");

	var itemName = jQuery.trim($("#addItemItem").val());
	var itemCost = jQuery.trim($("#addItemCost").val()).replace(/[$]/g, "").replace(/[,]/g, "");
	var itemLink = jQuery.trim($("#addItemWebLink").val());
	var itemWhereToBuy = jQuery.trim($("#addItemWhereToBuy").val());
	var itemDescription = jQuery.trim($("#addItemDescription").val());
	var itemImageURL = '';
	if(isUrl($('#provideImageURLInput').val())){ itemImageURL = jQuery.trim($("#provideImageURLInput").val()); }
	else { itemImageURL = jQuery.trim($("#addItemImageURLID").val()); }

	if(itemName == "") {
		$("#addItemItem").css("border-color","#F00");
		error = false;
	}
	if($.trim(itemImageURL) == "") {
		$("#itemPossibleImages").css("border-color","#F00");
		$("#provideImageURLInput").css("border-color","#F00");
		error = false;
	}

	//if($("#addItemNoCost").is(":checked")) { itemCost = "0.00"; }
	if($.trim(itemCost) == ''){ itemCost = "0.00"; }
	if(!isPrice(itemCost)) {
		$("#addItemCost").css("border-color","#F00");
		error = false;
	}

	if(itemLink == "http://" || itemLink == "") { itemLink = ""; }
	else if(!isUrl(itemLink)) {
		$("#addItemWebLink").css("border-color","#F00");
		error = false;
	}

	//if(itemWhereToBuy == "") { errorAlert += "Invalid Website URL\n"; }
	//if(itemDescription == "") { errorAlert += "Invalid Website URL\n"; }

	return error;
}

function addItem() {
	$('#addItemLoader').hide();
	//$("#addItem").animate({top:0}, 500);

	$("#addItemHeader").html("Add a New Item to Your Wish List");
	$("#addItemImage").attr("src", "/img/add-item.png");
	document.getElementById("addItemButton").onclick = function (event){ addItemSubmit(); };

	$("#addItemItem").val("");
	$("#addItemCost").val("$");
	//$("#addItemNoCost").attr("checked", "");
	//$("#addItemCost").attr("readonly", "");
	$("#addItemCost").css("color", "#000");
	$("#addItemWebLink").val("http://");
	$("#addItemWhereToBuy").val("");
	$("#addItemDescription").val("");
	$("#addItemImageURLID").val("");

	$("#addItemItem").css("border-color","");
	$("#addItemCost").css("border-color","");
	$("#addItemWebLink").css("border-color","");
	$("#itemPossibleImages").css("border-color","");
	$("#provideImageURLInput").css("border-color","");
	$("#itemsRequired").html("");

	itemPossibleImagesHTML = '';
	$('#itemPossibleImagesInner2').html('');
	$('#itemPossibleImagesInner2').css('left','0px');

	cancelProvideImageURL();
	$('#otherImageOptions').show();
	changeImage(true);

	showDropDownWidget("addItem");
}

function addItemSubmit() {

var itemName = jQuery.trim($("#addItemItem").val());
var itemCost = jQuery.trim($("#addItemCost").val()).replace(/[$]/g, "").replace(/[,]/g, "");
if($("#addItemNoCost").is(":checked")) { itemCost = "0.00"; }
var itemLink = jQuery.trim($("#addItemWebLink").val());
if(itemLink == "http://") { itemLink = ""; }
var itemWhereToBuy = jQuery.trim($("#addItemWhereToBuy").val());
var itemDescription = jQuery.trim($("#addItemDescription").val());
var itemImageURL = '';
if($.trim($('#provideImageURLInput').val()) != '') { itemImageURL = jQuery.trim($("#provideImageURLInput").val()); }
else { itemImageURL = jQuery.trim($("#addItemImageURLID").val()); }

	if(validateAddItem()){
		$('#addItemLoader').show();
		$.ajax({
			type: "POST",
			url: "/inc/services.php",
			dataType: "xml",
			data: "actionType=addItem&item=" + itemName + "&cost=" + itemCost + "&description=" + itemDescription + "&whereToBuy=" + itemWhereToBuy + "&webLink=" + itemLink + "&whoFor=" + $("#whoFor").val() + "&itemImageURL=" + itemImageURL,
			success: function(xml){
				if($(xml).find('status').text() == "OK") {
					window.location.href = $(location).attr('href');
				}
				else {
					if($(xml).find('response').text() == "Invalid image URL") { alert('Error! The image URL provided is invalid.\nPlease provide a valid image URL that links directly to the image.'); }
					else { alert($(xml).find('response').text()); }
				}
				$('#addItemLoader').hide();
			}
		});
	}
	else {
		$("#itemsRequired").html("Oops, please make sure the item information is accurate!");
	}
}

function addExistingItemFromOtherList(whoFor, itemXid, username) {
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=copyItem&whoFor=" + whoFor + "&itemXid=" + itemXid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				window.location.href = '/' + username;//$(location).attr('href');
			}
			else{ /*alert("oops");*/ }
		}
	});
}

function editItem(xid) {
	//alert(w);
	$('#addItemLoader').hide();
	refreshChangeImageOption = true;

	$("#addItemHeader").html("Update This Item");
	$("#addItemImage").attr("src", "/img/edit-item.png");
	document.getElementById("addItemButton").onclick = function (event){ editItemSubmit(xid); };

	if(jQuery.inArray(xid, w.xid) > -1) {
		//alert(w.item[jQuery.inArray(xid, w.xid)]);

		$("#addItemItem").val(w.item[jQuery.inArray(xid, w.xid)]);
		$("#addItemCost").val("$" + w.cost[jQuery.inArray(xid, w.xid)]);
		$("#addItemWebLink").val(w.link[jQuery.inArray(xid, w.xid)]);
		$("#addItemWhereToBuy").val(w.whereToBuy[jQuery.inArray(xid, w.xid)]);
		$("#addItemDescription").val(w.description[jQuery.inArray(xid, w.xid)]);

		/*$("#addItemNoCost").attr("checked", "");
		if(w.cost[jQuery.inArray(xid, w.xid)] == "0.00") {
			$("#addItemNoCost").attr("checked", "checked");
			toggleNoCost();
		}*/

		$("#addItemItem").css("border-color","");
		$("#addItemCost").css("border-color","");
		$("#addItemWebLink").css("border-color","");
		$("#itemPossibleImages").css("border-color","");
		$("#provideImageURLInput").css("border-color","");
		$("#itemsRequired").html("");

		cancelProvideImageURL();
		itemPossibleImagesHTML = '';
		if(w.imageURL[jQuery.inArray(xid, w.xid)] == ''){
			$('#otherImageOptions').show();
			changeImage();
			//getImagesByKeyWord(w.item[jQuery.inArray(xid, w.xid)]);
			//showCheckWebsiteURLForImage();
		}
		else {
			$('#otherImageOptions').hide();
			var timestamp = new Date().getTime();
			chooseImageURL('/itemImages/' + w.imageURL[jQuery.inArray(xid, w.xid)] + '?t=' + timestamp);
		}

		showDropDownWidget("addItem");
	}
}

function editItemSubmit(xid) {

var itemName = jQuery.trim($("#addItemItem").val());
var itemCost = jQuery.trim($("#addItemCost").val()).replace(/[$]/g, "").replace(/[,]/g, "");
if($("#addItemNoCost").is(":checked")) { itemCost = "0.00"; }
var itemLink = jQuery.trim($("#addItemWebLink").val());
if(itemLink == "http://") { itemLink = ""; }
var itemWhereToBuy = jQuery.trim($("#addItemWhereToBuy").val());
var itemDescription = jQuery.trim($("#addItemDescription").val());
var itemImageURL = '';
if($.trim($('#provideImageURLInput').val()) != '') { itemImageURL = jQuery.trim($("#provideImageURLInput").val()); }
else { itemImageURL = jQuery.trim($("#addItemImageURLID").val()); }

	if(validateAddItem()){
		$('#addItemLoader').show();
		$.ajax({
			type: "POST",
			url: "/inc/services.php",
			dataType: "xml",
			data: "actionType=updateItem&itemXid=" + xid + "&item=" + itemName + "&cost=" + itemCost + "&description=" + itemDescription + "&whereToBuy=" + itemWhereToBuy + "&webLink=" + itemLink + "&itemImageURL=" + itemImageURL,
			success: function(xml){
				if($(xml).find('status').text() == "OK") {
					window.location.href = $(location).attr('href');
				}
				else{
					if($(xml).find('response').text() == "Invalid image URL") { alert('Error! The image URL provided is invalid.\nPlease provide a valid image URL that links directly to the image.'); }
					else { alert($(xml).find('response').text()); }
				}
				$('#addItemLoader').hide();
			}
		});
	}
	else {
		$("#itemsRequired").html("Oops, please make sure the item information is accurate!");
	}
}

function confirmRemoveItem(xid, name) {
	$("#confirm-name").html(name);
	document.getElementById("confirm-yes").onclick = function (event){ removeItem(xid); };

	$("#divRemoveItem").overlay({
			top: 100,
			mask: {
				color: '#000000',
				loadSpeed: 100,
				opacity: 0.33
			},
			closeOnClick: false,
			load: true
		}
	).load();
}

function removeItem(xid) {
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=deleteItem&removeXid=" + xid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				window.location.href = $(location).attr('href');
			}
			else{ alert("oops"); }
		}
	});
}

function gotIt(xid) {
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=gotItem&gotXid=" + xid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				window.location.href = $(location).attr('href');
			}
			else{ alert("oops"); }
		}
	});
}

function setPriority(priorityID, xid) {
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=setPriority&priorityID=" + priorityID + "&iXid=" + xid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				window.location.href = $(location).attr('href');
			}
			else{ alert("oops"); }
		}
	});
}

function getImagesByKeyWord(kw) {
	itemPossibleImagesHTML = '';
	$('#itemPossibleImagesInner2').css('left','0px');
	if($.trim(kw) != '') {
		$('#itemPossibleImagesInner2').html('<img alt="loading..." src="/img/loading.gif" style="margin:18px 185px;" />');
		$.ajax({
			type: "GET",
			url: "/inc/getImages.php",
			dataType: "json",
			data: "k=" + kw,
			success: function(json){
				//alert(json.image_count);
				if(json.image_count > 0) {
					for(var i=0; i<json.image_count; i++){
						itemPossibleImagesHTML += '<a href="javascript:void(0)" onclick="chooseImageURL(\'' + json.images[i] + '\')"><img alt="" src="' + json.images[i] + '" /></a>';
					}
					$('#itemPossibleImagesInner2').html(itemPossibleImagesHTML);

					$("#itemPossibleImages").thumbnailScroller({ 
						scrollerType:"hoverPrecise", 
						scrollerOrientation:"horizontal", 
						scrollSpeed:2, 
						scrollEasing:"easeOutCirc", 
						scrollEasingAmount:600, 
						acceleration:4, 
						scrollSpeed:800, 
						noScrollCenterSpace:10, 
						autoScrolling:0, 
						autoScrollingSpeed:2000, 
						autoScrollingEasing:"easeInOutQuad", 
						autoScrollingDelay:500 
					});
				}
				else{ $('#itemPossibleImagesInner2').html("No Available Images Found!"); }
			}
		});
	}
}

/*function getImagesByURL(url) {
	itemPossibleImagesHTML = '';
	$('#itemPossibleImagesInner2').css('left','0px');
	if($.trim(url) != '') {
		$('#itemPossibleImagesInner2').html('<img alt="loading..." src="/img/loading.gif" style="margin:18px 185px;" />');
		$.ajax({
			type: "GET",
			url: "/inc/getImages.php",
			dataType: "json",
			data: "u=" + url,
			success: function(json){
				//alert(json.image_count);
				if(json.image_count > 0) {
					for(var i=0; i<json.image_count; i++){
						itemPossibleImagesHTML += '<a href="javascript:void(0)" onclick="chooseImageURL(\'' + json.images[i] + '\')"><img alt="" src="' + json.images[i] + '" /></a>';
					}
					$('#itemPossibleImagesInner2').html(itemPossibleImagesHTML);

					$("#itemPossibleImages").thumbnailScroller({ 
						scrollerType:"hoverPrecise", 
						scrollerOrientation:"horizontal", 
						scrollSpeed:2, 
						scrollEasing:"easeOutCirc", 
						scrollEasingAmount:600, 
						acceleration:4, 
						scrollSpeed:800, 
						noScrollCenterSpace:10, 
						autoScrolling:0, 
						autoScrollingSpeed:2000, 
						autoScrollingEasing:"easeInOutQuad", 
						autoScrollingDelay:500 
					});
				}
				else{ $('#itemPossibleImagesInner2').html("No Available Images Found!"); }
			}
		});
	}
}
function showCheckWebsiteURLForImage() {
	if(isUrl($('#addItemWebLink').val()) != ''){ $('#checkWebsiteURLForImage').show(); }
	else{ $('#checkWebsiteURLForImage').hide(); }
}*/

function provideImageURL() {
	$('#addItemImageURLID').val('');
	$('#itemSelectedImage').attr('src', '');
	$('#itemSelectedImageWrapper').hide();
	$('#itemPossibleImages').hide();
	$('#otherImageOptions').hide();
	$('#provideImageURLWrapper').show();
	$('#provideImageURLInput').val('');
}
function cancelProvideImageURL() {
	$('#addItemImageURLID').val('');
	$('#itemSelectedImage').attr('src', '');
	$('#itemSelectedImageWrapper').hide();
	$('#itemPossibleImages').show();
	$('#otherImageOptions').show();
	$('#provideImageURLWrapper').hide();
	$('#provideImageURLInput').val('');
	if($.trim($('#addItemItem')) != ''){
		getImagesByKeyWord($('#addItemItem').val());
	}
}

function chooseImageURL(url) {
	$('#addItemImageURLID').val(url);
	$('#itemPossibleImages').hide();
	$('#itemSelectedImage').attr('src', url);
	$('#itemSelectedImageWrapper').show();
	$('#otherImageOptions').hide();
}
function changeImage(skipItemNameCheck) {
	if(skipItemNameCheck == null){ skipItemNameCheck = false; }
	if($('#addItemItem').val()  == '' && !skipItemNameCheck){ alert('Please Provide an Item Name'); }
	else {
		$('#addItemImageURLID').val('');
		$('#itemSelectedImage').attr('src', '');
		$('#itemSelectedImageWrapper').hide();
		$('#itemPossibleImages').show();
		$('#otherImageOptions').show();
		if(refreshChangeImageOption){
			getImagesByKeyWord($('#addItemItem').val());
		}
		refreshChangeImageOption = false;
	}
}


function followUser(followerXid, followingXid, divFollowID) {
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=followUser&followerXid=" + followerXid + "&followingXid=" + followingXid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				if(divFollowID != null){ $("#" + divFollowID).html('Following'); }
				else { $("#td_follow").html('<a href="javascript:void(0);" onclick="removeFollowUser(\'' + followerXid + '\', \'' + followingXid + '\') "style="text-decoration:none; color:#690"><img alt="Stop Follow" src="/img/stop-following.png" style="margin-bottom:-16px;" /> Stop Following</a>'); }
				getFollowing(followerXid);
				//window.location.href = $(location).attr('href');
			}
			else{ alert("oops"); }
		}
	});
}

function removeFollowUser(followerXid, followingXid) {
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=removeFollowUser&followerXid=" + followerXid + "&followingXid=" + followingXid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				$("#td_follow").html('<a href="javascript:void(0);" onclick="followUser(\'' + followerXid + '\', \'' + followingXid + '\')" style="text-decoration:none; color:#690"><img alt="Follow" src="/img/follow.png" style="margin-bottom:-16px;" /> Follow</a>');
				getFollowing(followerXid);
				//window.location.href = $(location).attr('href');
			}
			else{ alert("oops"); }
		}
	});
}

function getFollowing(followerXid) {
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=getFollowing&followerXid=" + followerXid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				$("#following").html("");
				$(xml).find('item').each(function(){
					$("#following").append($(this).find('username').text() + ' (' + $(this).find('fname').text() + ') - [ <a href="/' + $(this).find('username').text() + '">view wish list</a> ] [ <a title="Stop Following" href="javascript:void(0);" onclick="removeFollowUser(\'' + followerXid + '\', \'' + $(this).find('xid').text() + '\')"><span style="color:#F00">x</span></a> ]<br />');
				});
				//window.location.href = $(location).attr('href');
			}
			else{
				$("#following").html("");
				$("#following").append("You're not following anyone!");
			}
		}
	});
}


function getFollowers(followingXid) {
	$.ajax({
		type: "POST",
		url: "/inc/services.php",
		dataType: "xml",
		data: "actionType=getFollowers&followingXid=" + followingXid,
		success: function(xml){
			if($(xml).find('status').text() == "OK") {
				$("#followers").html("");
				$(xml).find('item').each(function(){
					$("#followers").append($(this).find('username').text() + ' (' + $(this).find('fname').text() + ') - [ <a href="/' + $(this).find('username').text() + '">view wish list</a> ]<br />');
				});
				//window.location.href = $(location).attr('href');
			}
			else{
				$("#followers").html("");
				$("#followers").append("You're not being followed by anyone!");
			}
		}
	});
}



/*==================== Facebook stuff ====================*/
/*
try{ FB.init({appId: '116689265067243', status: true, cookie: true, xfbml: true}); }
catch(err){}

function fbLogin() {
	FB.login(function(response) {
		if (response.session) {
			window.location.reload();
			//window.location.href = $(location).attr('href');
		} else { }
	});
}

function fbLogout() {
	fbsession = FB.getSession();
	//alert(fbsession.session_key);
	FB.logout(function(response) {
		// user is now logged out
		window.location.href = "http://www.facebook.com/logout.php?app_key=116689265067243&session_key=" + fbsession.session_key + "&next=" + $(location).attr('href') + "?logout=true";
	});
}
*/
/*=========================================================*/




