iUserRating = 0;
bEditMode = false;

function createNewAlbum(sAlbumTitle) {
	$.getJSON("/api/js/album/add.php", { t: sAlbumTitle }, function(aData){
			createNewAlbumRsp(aData);
		});
}

function createNewAlbumRsp(aData) {
	if (!aData['errors']) {
		$('#jscontent').append("<div id=\"gAlbum"+aData['id']+"\" class=\"albm clearfix drop-album\" albumid=\""+aData['id']+"\"><div class=\"rslts-ph\"><a href=\"/gallery/album/view/id/"+aData['id']+"/\" class=\"ph pl\"><img class=\"albumPic\" src=\"/images/phAlbum-85.png\"  border=\"0\" /></a></div><ul class=\"albm-info\"><li><h5><a href=\"/gallery/album/view/id/"+aData['id']+"\">"+aData['t']+"</a></h5></li><li class=\"txt999\">Photos: 0 </li><li>Videos: 0</li><li class=\"txt999\">Created just now</li><li><a href=\"/gallery/album/view/id/"+aData['id']+"/\">View</a> | <a href=\"/gallery/album/view/id/"+aData['id']+"/?edit=true\">Edit</a> | <a href=\"#\" onclick=\"deleteAlbum("+aData['id']+"); return false;\">Delete</a></li></ul></div>");
		$('#NewAlbum').slideUp(function() { $('.error', $('#NewAlbum')).hide(); });
	} else {
		$('.error', $('#NewAlbum')).html(aData['errors']);
		$('#NewAlbum').slideDown();
	}
}

function getAlbum(iAlbumId) {
	$.getJSON("/api/js/album/getalbum.php", { id: iAlbumId }, function(aData){
			getAlbumRsp(aData);
		});
}

function getAlbumRsp(aData) {
	if (!aData['errors']) {
		if (!aData['album']['r']) {
			$('#albumTitle').html(aData['album']['t']);
			$('#albumDesc').html(aData['album']['d']);
			$('#albumDate').html(aData['album']['p']);
			if (aData['album']['tg']) {
				sTags = '';
				for (iTagId in aData['album']['tg']) {
					sTags += '<a href="/gallery/search/tag/'+aData['album']['tg'][iTagId]['t']+'">'+aData['album']['tg'][iTagId]['t']+'</a>, ';
				}
				$('#albumTags').html(sTags.substr(0, sTags.length - 2));
				$('.albumTags').show();
			}

			$('#access'+aData['album']['ac']).attr('checked', 'checked');
			$('#access'+aData['album']['ac']).click();
			$('#albumSection').slideDown();

			if (bEditMode) {
				$('#editDetailsLink').click();
			}
		} else {
			if (!bIsLogedIn) {
				$('#albumResricted').slideDown();
			} else if (aData['album']['r'] == 1) {
				$('#albumResrictedFriends').slideDown();
			} else {
				$('#albumResrictedPrivate').html(ownerAlias+" has made this a &quot;private&quot; album with restricted access.<br /><input type=\"Button\" onclick=\"startRequester(iRequestAccessTypeAlbum, "+aData['album']['id']+", "+ownerUserId+");\" value=\"Request Access\" class=\"frmBtn\"/>");
				$('#albumResrictedPrivate').slideDown();
			}
			$('#jscontent2').slideUp();
			$('#jscontent3').slideUp();
		}
	}
}

function getPhoto(iPhotoId) {
	$.getJSON("/api/js/photo/getphoto.php", { id: iPhotoId }, function(aData){
			getPhotoRsp(aData);
		});
}

var iAlbumId = 0;
var iPhotoId = 0;
var iVideoId = 0;

function getPhotoRsp(aData) {
	if (!aData['errors']) {
		if (aData['photo']['ar']) {
			iAlbumId = aData['photo']['aid'];
			$('#albumId').html(aData['photo']['aid']);
			$('#photoTitle').html(sErrorRestricted);
			if (aData['photo']['pp'] != 0) {
				$('#photoPrev').html('<a href="/gallery/photo/view/id/'+aData['photo']['pp']+'">&laquo; '+sTextPrevious+'</a>');
			} else {
				$('#photoPrev').hide();
			}
			if (aData['photo']['np'] != 0) {
				$('#photoNext').html('<a href="/gallery/photo/view/id/'+aData['photo']['np']+'">'+sTextNext+' &raquo;</a>');
			} else {
				$('#photoNext').hide();
			}
			iPhotoId = aData['photo']['id'];
			if (aData['photo']['r'] == 1) {
				$('.photoContent').slideUp(function() { $('#albumResricted').slideDown(); } );
			} else {
				if (bIsLogedIn) {
					$('.photoContent').slideUp(function() { $('#albumResrictedPrivate').slideDown(); } );
				} else {
					$('.photoContent').slideUp(function() { $('#albumResricted').slideDown(); } );
				}
			}
		} else if (!aData['photo']['r']) {
			if (aData['photo']['aid'] > 0) {
				sParent = 'Album';
			} else {
				sParent = 'Gallery Photos'
			}
			getComments(aData['photo']['id'], 'photo', 1);
			$('#photoImage').attr('src', '/images/photos/'+aData['photo']['f']);
			if (aData['photo']['t'] == '') {
				$('#photoImage').attr('alt', sTextUntitledPhoto);
				$('#photoTitle').html(sTextUntitledPhoto);
			} else {
				$('#photoImage').attr('alt', aData['photo']['t']);
				$('#photoTitle').html(aData['photo']['t']);
			}
			$('.photoAlias').each(function() {
					if ($(this).html() == '') {
						$(this).html(aData['photo']['a']);
					}
				});
			$('a.photoAlias').attr('href', $('a.photoAlias').attr('href')+aData['photo']['a']);
			if (aData['photo']['b'] != '') {
				$('.photoBody').show();
				$('dd.photoBody').html(aData['photo']['b']);
			}
			$('#photoDate').html(aData['photo']['p']);
			$('#photoComments').html(aData['photo']['pc']);
			$('#albumTitle').html(sParent);
			if (aData['photo']['at']) {
				$('#albumTitle').append(" &quot;"+aData['photo']['at']+"&quot;");
			}
			if (aData['photo']['pp'] != 0) {
				$('#photoPrev').html('<a href="/gallery/photo/view/id/'+aData['photo']['pp']+'">&laquo; '+sTextPrevious+'</a>');
			} else {
				$('#photoPrev').hide();
			}
			if (aData['photo']['np'] != 0) {
				$('#photoNext').html('<a href="/gallery/photo/view/id/'+aData['photo']['np']+'">'+sTextNext+' &raquo;</a>');
			} else {
				$('#photoNext').hide();
			}

			if (aData['photo']['tg']) {
				sTags = '';
				for (iTagId in aData['photo']['tg']) {
					sTags += '<a href="/gallery/search/tag/'+aData['photo']['tg'][iTagId]['t']+'">'+aData['photo']['tg'][iTagId]['t']+'</a>, ';
				}
				$('dd.photoTags').html(sTags.substr(0, sTags.length - 2));
				$('.photoTags').show();
			}

			// set the album hrefs
			if (aData['photo']['aid'] > 0) {
				$('.backTo').html('Back to '+sParent);
				$('.viewAlbum').attr('href', '/gallery/album/view/id/'+aData['photo']['aid']);
			} else {
				$('.backTo').html(aData['photo']['a']+'\'s '+sParent);
				$('.viewAlbum').attr('href', '/gallery/view/'+aData['photo']['a']+'/#gPhotos');
			}

			$('#access'+aData['photo']['ac']).attr('checked', 'checked');
			$('#access'+aData['photo']['ac']).click();

			if (!aData['o']) {
				if (bIsLogedIn) {
					$('#ownerLinks').append("<li><a href=\"/gallery/view/"+aData['photo']['a']+"\" class=\"icoCamera\">"+aData['photo']['a']+"'s Photos</a></li><li><a href=\"#\" onclick=\"startComposer(iMessageTypeNormal, "+aData['photo']['uid']+"); return false;\" title=\"send "+aData['photo']['a']+" a message\" class=\"icoMsg\">Send a Message</a></li><li class=\"sub\"><a href=\"#\" class=\"icoSayhi\" title=\"open say hi sub-menu\" onclick=\"$('#sayhi').slideToggle('fast'); return false;\">Say hi...</a><ul id=\"sayhi\" class=\"jhide submenu\"><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['photo']['uid']+", iQuickMessageTypeHi); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"say hi\" class=\"q-hi\">Say hi</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['photo']['uid']+", iQuickMessageTypeSmile); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a smile\" class=\"q-smile\">Smile</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['photo']['uid']+", iQuickMessageTypeWink); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a wink\" class=\"q-wink\">Wink</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['photo']['uid']+", iQuickMessageTypeKiss); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a kiss\" class=\"q-kiss\">Kiss</a></li></ul></li><li><a href=\"#\" onclick=\"startReporter(iQuickIssueTypePhoto, "+aData['photo']['id']+"); return false;\" class=\"icoQ\">Report Member</a></li>");
					$('#ratethis').show();
				} else {
					$('#ownerLinks').append("<li><a href=\"/gallery/view/"+aData['photo']['a']+"\" class=\"icoCamera\">"+aData['photo']['a']+"'s Photos</a></li><li><a href=\"#\" onclick=\"startComposer(iMessageTypeNormal, "+aData['photo']['uid']+"); return false;\" title=\"send "+aData['photo']['a']+" a message\" class=\"icoMsg\">Send a Message</a></li><li class=\"sub\"><a href=\"#\" class=\"icoSayhi\" title=\"open say hi sub-menu\" onclick=\"$('#sayhi').slideToggle('fast'); return false;\">Say hi...</a><ul id=\"sayhi\" class=\"jhide submenu\"><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['photo']['uid']+", iQuickMessageTypeHi); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"say hi\" class=\"q-hi\">Say hi</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['photo']['uid']+", iQuickMessageTypeSmile); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a smile\" class=\"q-smile\">Smile</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['photo']['uid']+", iQuickMessageTypeWink); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a wink\" class=\"q-wink\">Wink</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['photo']['uid']+", iQuickMessageTypeKiss); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a kiss\" class=\"q-kiss\">Kiss</a></li></ul></li>");
					$('#ratethis').show();
				}
			} else {
				$('#profileLink').show();
				if (aData['photo']['aid']) {
					$('#ownerLinks').append('<li><a href="#" onclick="togglePhotoMan(this); $(\'#editphoto'+aData['photo']['id']+'\').editable(this, \'/api/js/photo/update.php\');return false;" class="icoEdit">Edit Photo Details</a></li><li><a href="#" onclick="setAvatar('+aData['photo']['id']+'); return false;" class="icoProf">Make Profile Photo</a></li><li><a href="#" onclick="setAlbumCover('+aData['photo']['aid']+', '+aData['photo']['id']+'); return false;" class="icoProf">Make Album Cover</a></li><li><a href="/gallery/photo/upload/album/'+aData['photo']['aid']+'" class="icoAdd">Add Photo to Album</a></li><li><a href="/gallery/album/view/id/'+aData['photo']['aid']+'/?edit=true" class="icoCamera">Edit '+sParent+'</a></li>');
					$('#ratethis').hide();
				} else {
					$('#ownerLinks').append('<li><a href="#" onclick="togglePhotoMan(this); $(\'#editphoto'+aData['photo']['id']+'\').editable(this, \'/api/js/photo/update.php\'); return false;" class="icoEdit">Edit Photo Details</a></li><li><a href="#" onclick="setAvatar('+aData['photo']['id']+'); return false;" class="icoProf">Make Profile Photo</a></li><li><a href="#" onclick="setAlbumCover('+aData['photo']['aid']+', '+aData['photo']['id']+'); return false;" class="icoProf">Make Album Cover</a></li><li><a href="/gallery/photo/upload/" class="icoAdd">Add New Photos</a></li><li><a href="/gallery/album/view/id/'+aData['photo']['aid']+'/?edit=true" class="icoCamera">Edit '+sParent+'</a></li>');
					$('#ratethis').hide();
				}
			}
			if(aData['photo']['rt']!=0) {
				$('#jsRating').html(aData['photo']['rt']);
			}
			iUserRating = aData['photo']['ur'];
			setRating('rating', iUserRating);
			if (!bIsLogedIn) {
				$('#ratethis').hide();
				$('#comment_post').hide();
				$('#comment_preview').hide();
			}

			$('#photoSection').slideDown();
		} else {
			$('#photoTitle').html(sErrorRestricted);
			if (aData['photo']['pp'] != 0) {
				$('#photoPrev').html('<a href="/gallery/photo/view/id/'+aData['photo']['pp']+'">&laquo; '+sTextPrevious+'</a>');
			} else {
				$('#photoPrev').hide();
			}
			if (aData['photo']['np'] != 0) {
				$('#photoNext').html('<a href="/gallery/photo/view/id/'+aData['photo']['np']+'">'+sTextNext+' &raquo;</a>');
			} else {
				$('#photoNext').hide();
			}
			iPhotoId = aData['photo']['id'];
			if (aData['photo']['r'] == 1) {
				if (bIsLogedIn) {
					$('.photoContent').slideUp(function() { $('#photoResricted').slideDown(); } );
				} else {
					$('.photoContent').slideUp(function() { $('#photoNotMemberResricted').slideDown(); } );
				}
			} else {
				if (bIsLogedIn) {
					$('.photoContent').slideUp(function() { $('#photoResrictedPrivate').slideDown(); } );
				} else {
					$('.photoContent').slideUp(function() { $('#photoNotMemberResricted').slideDown(); } );
				}
			}
		}
	}
}

function getVideo(iVideoId) {
	$.getJSON("/api/js/video/getvideo.php", { id: iVideoId }, function(aData){
			getVideoRsp(aData);
		});
}

function getVideoRsp(aData) {
	if (!aData['errors']) {
		if (aData['video']['ar']) {
			iAlbumId = aData['video']['aid'];
			$('#videoTitle').html(sErrorRestricted);
			$('#albumId').html(aData['video']['aid']);
			if (aData['video']['pp'] != 0) {
				$('#videoPrev').html('<a href="/gallery/photo/view/id/'+aData['video']['pp']+'">&laquo; '+sTextPrevious+'</a>');
			} else {
				$('#videoPrev').hide();
			}
			if (aData['video']['np'] != 0) {
				$('#videoNext').html('<a href="/gallery/photo/view/id/'+aData['video']['np']+'">'+sTextNext+' &raquo;</a>');
			} else {
				$('#videoNext').hide();
			}
			iPhotoId = aData['video']['id'];
			if (aData['video']['r'] == 1) {
				$('.videoContent').slideUp(function() { $('#albumResricted').slideDown(); } );
			} else {
				if (bIsLogedIn) {
					$('.videoContent').slideUp(function() { $('#albumResrictedPrivate').slideDown(); } );
				} else {
					$('.videoContent').slideUp(function() { $('#albumResricted').slideDown(); } );
				}
			}
		} else if (!aData['video']['r']) {
			if (aData['video']['aid'] > 0) {
				sParent = 'Album';
			} else {
				sParent = 'Gallery Videos'
			}
			getComments(aData['video']['id'], 'video', 1);
			$('#videoImage').html(aData['video']['e']);
			if (aData['video']['t'] == '') {
				$('#videoImage').attr('alt', sTextUntitledPhoto);
				$('#videoTitle').html(sTextUntitledPhoto);
			} else {
				$('#videoImage').attr('alt', aData['video']['t']);
				$('#videoTitle').html(aData['video']['t']);
			}
			$('.videoAlias').each(function() {
					if ($(this).html() == '') {
						$(this).html(aData['video']['a']);
					}
				});
			$('a.videoAlias').attr('href', $('a.videoAlias').attr('href')+aData['video']['a']);
			if (aData['video']['b'] != '') {
				$('.videoBody').show();
				$('dd.videoBody').html(aData['video']['b']);
			}
			$('#videoDate').html(aData['video']['p']);
			$('#photoComments').html(aData['video']['vc']);
			$('#albumTitle').html(sParent);
			if (aData['video']['at']) {
				$('#albumTitle').append(" &quot;"+aData['video']['at']+"&quot;");
			}
			if (aData['video']['pp'] != 0) {
				$('#videoPrev').html('<a href="/gallery/video/view/id/'+aData['video']['pp']+'">&laquo; '+sTextPrevious+'</a>');
			} else {
				$('#videoPrev').hide();
			}
			if (aData['video']['np'] != 0) {
				$('#videoNext').html('<a href="/gallery/video/view/id/'+aData['video']['np']+'">'+sTextNext+' &raquo;</a>');
			} else {
				$('#videoNext').hide();
			}

			if (aData['video']['tg']) {
				sTags = '';
				for (iTagId in aData['video']['tg']) {
					sTags += '<a href="/gallery/search/tag/'+aData['video']['tg'][iTagId]['t']+'">'+aData['video']['tg'][iTagId]['t']+'</a>, ';
				}
				$('dd.videoTags').html(sTags.substr(0, sTags.length - 2));
				$('.videoTags').show();
			}

			// set the album hrefs
			if (aData['video']['aid'] > 0) {
				$('.backTo').html('Back to '+sParent);
				$('.viewAlbum').attr('href', '/gallery/album/view/id/'+aData['video']['aid']);
			} else {
				$('.backTo').html(aData['video']['a']+'\'s '+sParent);
				$('.viewAlbum').attr('href', '/gallery/view/'+aData['video']['a']+'/#gVideos');
			}

			$('#access'+aData['video']['ac']).attr('checked', 'checked');
			$('#access'+aData['video']['ac']).click();

			if (!aData['o']) {
				if (bIsLogedIn) {
					$('#ownerLinks').append("<li><a href=\"/gallery/view/"+aData['video']['a']+"\" class=\"icoCamera\">"+aData['video']['a']+"'s Videos</a></li><li></li><li><a href=\"#\" onclick=\"startComposer(iMessageTypeNormal, "+aData['video']['uid']+"); return false;\" title=\"send "+aData['video']['a']+" a message\" class=\"icoMsg\">Send a Message</a></li><li class=\"sub\"><a href=\"#\" class=\"icoSayhi\" title=\"open say hi sub-menu\" onclick=\"$('#sayhi').slideToggle('fast'); return false;\">Say hi...</a><ul id=\"sayhi\" class=\"jhide submenu\"><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['video']['uid']+", iQuickMessageTypeHi); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"say hi\" class=\"q-hi\">Say hi</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['video']['uid']+", iQuickMessageTypeSmile); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a smile\" class=\"q-smile\">Smile</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['video']['uid']+", iQuickMessageTypeWink); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a wink\" class=\"q-wink\">Wink</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['video']['uid']+", iQuickMessageTypeKiss); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a kiss\" class=\"q-kiss\">Kiss</a></li></ul></li><li><a href=\"#\" onclick=\"startReporter(iQuickIssueTypeVideo, "+aData['video']['id']+"); return false;\" class=\"Qico\">Report Member</a></li>");
					$('#ratethis').show();
				} else {
					$('#ownerLinks').append("<li><a href=\"/gallery/view/"+aData['video']['a']+"\" class=\"icoCamera\">"+aData['video']['a']+"'s Videos</a></li><li></li><li><a href=\"#\" onclick=\"startComposer(iMessageTypeNormal, "+aData['video']['uid']+"); return false;\" title=\"send "+aData['video']['a']+" a message\" class=\"icoMsg\">Send a Message</a></li><li class=\"sub\"><a href=\"#\" class=\"icoSayhi\" title=\"open say hi sub-menu\" onclick=\"$('#sayhi').slideToggle('fast'); return false;\">Say hi...</a><ul id=\"sayhi\" class=\"jhide submenu\"><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['video']['uid']+", iQuickMessageTypeHi); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"say hi\" class=\"q-hi\">Say hi</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['video']['uid']+", iQuickMessageTypeSmile); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a smile\" class=\"q-smile\">Smile</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['video']['uid']+", iQuickMessageTypeWink); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a wink\" class=\"q-wink\">Wink</a></li><li><a href=\"#\" onclick=\"sendMessage(iMessageTypeQuick, "+aData['video']['uid']+", iQuickMessageTypeKiss); $(this).parent().parent().fadeOut('slow'); return false;\" title=\"send a kiss\" class=\"q-kiss\">Kiss</a></li></ul></li>");
					$('#ratethis').hide();
				}
			} else {
				$('#profileLink').show();
				if (aData['video']['aid']) {
					$('#ownerLinks').append('<li><a href="#" onclick="$(\'#editvideo'+aData['video']['id']+'\').editable(this, \'/api/js/video/update.php\'); return false;" class="icoEdit">Edit Video details</a></li><li><a href="/gallery/video/upload/album/'+aData['video']['aid']+'" class="icoAdd">Add Video to Album</a></li><li><a href="/gallery/album/view/id/'+aData['video']['aid']+'/?edit=true" class="icoCamera">Edit '+sParent+'</a></li>');
					$('#ratethis').hide();
				} else {
					$('#ownerLinks').append('<li><a href="#" onclick="$(\'#editvideo'+aData['video']['id']+'\').editable(this, \'/api/js/video/update.php\'); return false;" class="icoEdit">Edit Video details</a></li><li><a href="/gallery/video/upload/" class="icoAdd">Add new Video</a></li><li><a href="/gallery/album/view/id/'+aData['video']['aid']+'/?edit=true" class="icoCamera">Edit '+sParent+'</a></li>');
					$('#ratethis').hide();
				}
			}
			if(aData['video']['rt']!=0) {
				$('#jsRating').html(aData['video']['rt']);
			}

			iUserRating = aData['video']['ur'];
			setRating('rating', iUserRating);
			if (!bIsLogedIn) {
				$('#ratethis').hide();
				$('#comment_post').hide();
				$('#comment_preview').hide();
			}

			$('#videoSection').slideDown();
		} else {
			iVideoId = aData['video']['aid'];
			$('#videoTitle').html(sErrorRestricted);
			if (aData['video']['pp'] != 0) {
				$('#videoPrev').html('<a href="/gallery/photo/view/id/'+aData['video']['pp']+'">&laquo; '+sTextPrevious+'</a>');
			} else {
				$('#videoPrev').hide();
			}
			if (aData['video']['np'] != 0) {
				$('#videoNext').html('<a href="/gallery/photo/view/id/'+aData['video']['np']+'">'+sTextNext+' &raquo;</a>');
			} else {
				$('#videoNext').hide();
			}
			iPhotoId = aData['video']['id'];
			if (aData['video']['r'] == 1) {
				$('.videoContent').slideUp(function() { $('#videoResricted').slideDown(); } );
			} else {
				if (bIsLogedIn) {
					$('.videoContent').slideUp(function() { $('#videoResrictedPrivate').slideDown(); } );
				} else {
					$('.videoContent').slideUp(function() { $('#videoResricted').slideDown(); } );
				}
			}
		}
	}
}

currentAlbumVideosFirst = false;

function getAlbums(iUserId, iPage, bVideosFirst) {
	if (bVideosFirst) {
		currentAlbumVideosFirst = bVideosFirst;
	} else {
		currentAlbumVideosFirst = false;
	}
	$.getJSON("/api/js/album/getalbums.php", { id: iUserId, p: iPage }, function(aData){
			getAlbumsRsp(aData);
		});
}

function getAlbumsRsp(aData) {
	if (!aData['errors']) {
		if (!bIsLogedIn) {
			$('#jscontent').html("<div class=\"pad\"><a href=\"/profile/view/"+ownerUrlAlias+"/\">View "+ownerAlias+"'s Profile</a></div>");
		} else if (aData['o']) {
			$('#jscontent').html("<div class=\"pad\"><a href=\"/profile/view/home/\">My Profile</a> | <a href=\"#\" onclick=\"$('#NewAlbum').slideToggle(); document.getElementById('NewAlbumTitle').focus(); return false;\">Add Album</a> | <a href=\"/gallery/photo/upload/\">Upload Photo</a></div>");
		} else {
			$('#jscontent').html("<div class=\"pad\"><a href=\"/profile/view/"+ownerUrlAlias+"/\">View "+ownerAlias+"'s Profile</a> | <a href=\"#\" onclick=\"startReporter(iQuickIssueTypeUser, "+ownerUserId+"); return false;\">Report This Member</a></div>");
		}
		totalCount = 0;
		for (oAlbum in aData['albums']) {
			totalCount++;
		}
		if (totalCount) {
			count = 0;
			if (totalCount>1) {
				float = 'albm-l';
			} else {
				float = '';
			}
			for (oAlbum in aData['albums']) {
				count++;
				oAlbum = aData['albums'][oAlbum];

				//is it the last album and is it an odd number
				if ((count == totalCount) && (count % 2 != 0)) {
					float = '';
					$('#jscontent').append('<div class="clear"></div>');
				}

				// WARNING: If you change the photo resolution bellow, make sure to chage it in the JS API file also!
				if (oAlbum['f']) {
					if (oAlbum['p']) {
						oAlbum['f'] = "/images/photos/"+oAlbum['f']+iThumbWidthA+"x"+iThumbHeightA;
					} else {
						oAlbum['f'] = "/api/images/processimage.php?o=1&w="+iThumbWidthA+"&h="+iThumbHeightA+"&f=/../images/photos/"+oAlbum['f'];
					}
				} else {
					oAlbum['f'] = "/images/phAlbum-85.png";
				}
				if (oAlbum['tg']) {
					sTags = '';
					for (iTagId in oAlbum['tg']) {
						sTags += '<a href="/gallery/search/tag/'+oAlbum['tg'][iTagId]['t']+'">'+oAlbum['tg'][iTagId]['t']+'</a>, ';
					}
					sTags = sTags.substr(0, sTags.length - 2);
					if (sTags != '') {
						sTags = '<li class="txt999">Tags: '+sTags+'</li>';
					}
				} else {
					sTags = '';
				}

				// Add the description from oAlbum['d'] in a tool tip when we decide on which one to use
				if (!oAlbum['r']) {
					if (aData['o']) {
						$('#jscontent').append("<div id=\"gAlbum"+oAlbum['id']+"\" class=\"albm "+float+" clearfix drop-album\" albumid=\""+oAlbum['id']+"\"><div class=\"rslts-ph\"><a href=\"/gallery/album/view/id/"+oAlbum['id']+"/"+((currentAlbumVideosFirst) ? 's/v' : '')+"\" class=\"ph pl\"><img class=\"albumPic\" src=\""+oAlbum['f']+"\"  border=\"0\" /></a></div><ul  class=\"albm-info\"><li><h5><a href=\"/gallery/album/view/id/"+oAlbum['id']+"\">"+oAlbum['t']+"</a></h5></li><li class=\"txt999\">Photos: "+oAlbum['pc']+"</li><li>"+((currentAlbumVideosFirst && (oAlbum['vc']!=0)) ? '<b class=\"brite\">' : '')+"Videos: "+oAlbum['vc']+""+((currentAlbumVideosFirst && (oAlbum['vc']!=0)) ? '</b>' : '')+"</li>"+sTags+"<li class=\"txt999\">Created "+oAlbum['pd']+"</li><li><a href=\"/gallery/album/view/id/"+oAlbum['id']+"\">View</a> | <a href=\"/gallery/album/view/id/"+oAlbum['id']+"/?edit=true\">Edit</a> | <a href=\"#\" onclick=\"deleteAlbum("+oAlbum['id']+"); return false;\">Delete</a></li></ul></div>");
					} else {
						$('#jscontent').append("<div id=\"gAlbum"+oAlbum['id']+"\" class=\"albm "+float+" clearfix\" albumid=\""+oAlbum['id']+"\"><div class=\"rslts-ph\"><a href=\"/gallery/album/view/id/"+oAlbum['id']+"/"+((currentAlbumVideosFirst) ? 's/v' : '')+"\" class=\"ph pl\"><img class=\"albumPic\" src=\""+oAlbum['f']+"\" border=\"0\" /></a></div><ul class=\"albm-info\"><li><h5><a href=\"/gallery/album/view/id/"+oAlbum['id']+"\">"+oAlbum['t']+"</a></h5></li><li class=\"txt999\">Photos: "+oAlbum['pc']+"</li><li>"+((currentAlbumVideosFirst && (oAlbum['vc']!=0)) ? '<b class=\"brite\">' : '')+"Videos: "+oAlbum['vc']+""+((currentAlbumVideosFirst && (oAlbum['vc']!=0)) ? '</b>' : '')+"</li>"+sTags+"<li class=\"txt999\">Created "+oAlbum['pd']+"</li><li><a href=\"/gallery/album/view/id/"+oAlbum['id']+"\">View</a></li></ul></div>");
					}
				} else {
					if (bIsLogedIn) {
						if (oAlbum['r'] == 1) {
							$('#jscontent').append("<div class=\"albm "+float+" clearfix\"><div class=\"rslts-ph\"><img src=\"/images/phRestricted-85.png\" border=\"0\" class=\"ph\" /></div><div class=\"clearfix\">Album is restricted to "+ownerAlias+"'s friends.</div></div>");
						} else {
							$('#jscontent').append("<div class=\"albm "+float+" clearfix\"><div class=\"rslts-ph\"><a href=\"#\" onclick=\"startRequester(iRequestAccessTypeAlbum, "+oAlbum['id']+", "+ownerUserId+"); return false;\" value=\"Request Access\"><img src=\"/images/phRestricted-85.png\" border=\"0\" class=\"ph\" /></a></div><div class=\"clearfix\">&quot;private&quot; album with restricted access.<div class=\"txt999\">Created "+oAlbum['d']+"</div><br /><button onclick=\"startRequester(iRequestAccessTypeAlbum, "+oAlbum['id']+", "+ownerUserId+");\" class=\"frmBtn\">Request Access</button></div></div>");
						}
					} else {
						if (oAlbum['r'] == 1) {
							$('#jscontent').append("<div class=\"albm "+float+" clearfix\"><div class=\"rslts-ph\"><a href=\"/join\"><img src=\"/images/phRestricted-85.png\" border=\"0\" class=\"ph\" /></a></div><div class=\"clearfix\">This album is restricted to "+ownerAlias+"'s Quechup friends.<br /><br /><button class=\"frmBtn\" onclick=\"window.location='/join/'\">Join Quechup</button></div></div>");
						} else {
							$('#jscontent').append("<div class=\"albm "+float+" clearfix\"><div class=\"rslts-ph\"><a href=\"/join\"><img src=\"/images/phRestricted-85.png\" border=\"0\" class=\"ph\" /></a></div><div class=\"clearfix\">&quot;private&quot; album entry with restricted access. You need to request access to view this.<br /><br /><button class=\"frmBtn\" onclick=\"window.location='/join/'\">Join Quechup</button></div></div>");
						}
					}
				}
				if (float == 'albm-l') {
					float = 'albm-r';
				} else {
					float = 'albm-l';
				}

			}
		} else {
			if (aData['o']) {
				$('#jscontent').append("<div class=\"albm clearfix\"><div class=\"rslts-ph\"><img src=\"/images/phNo-85.png\" border=\"0\" class=\"ph\" /></div><div class=\"clearfix\">You haven't created any albums yet. <a href=\"#\" onclick=\"$('#NewAlbum').slideToggle(); document.getElementById('NewAlbumTitle').focus(); return false;\">Add an Album</a></div></div> <div class=\"pad\"><button type=\"button\" class=\"frmBtn\" onclick=\"window.location='/gallery/photo/upload';\">Upload a photo now</button></div>");
			} else {
				$('#jscontent').append("<div class=\"albm clearfix\"><div class=\"rslts-ph\"><img src=\"/images/phNo-85.png\" border=\"0\" class=\"ph\" /></div><div class=\"clearfix\">"+ownerAlias+" has not added any albums. </div></div>");
			}

			google_ad_client = "pub-9194847592297973";
			google_ad_width = 468;
			google_ad_height = 60;
			google_ad_format = "468x60_as_rimg";
			google_cpa_choice = "CAAQ0OqI_AEaCBvz3TlBKjahKIjLynM";
			google_ad_channel = "";
			//include('http://pagead2.googlesyndication.com/pagead/show_ads.js');
		}
	}
	$(".drop-album").droppable({
			accept: ".myphoto,.myvideo",
			tolerance: 'pointer',
			activeClass: 'dropActive',
			hoverClass: 'dropHover',
			drop: function(ev, ui) {
				if ($(ui.draggable).hasClass('photo')) {
					movePhoto($(ui.draggable).attr('photoid'), $(this).attr('albumid'));
				} else if ($(ui.draggable).hasClass('video')) {
					moveVideo($(ui.draggable).attr('videoid'), $(this).attr('albumid'));
				} else {
					alert('Oops, you can\'t drop that here!');
				}
			}
		});
}

var photoManStatus = false;
var tempManLinkText = '';

function togglePhotoMan(oSourceLink) {
// &#x21BB; - clockwise arrow
// &#x21BA; - anticlockwise arrow
// &#x263A; - smiley
	if (!photoManStatus) {
		photoManStatus = true;
		tempManLinkText = $(oSourceLink).html();
		$(oSourceLink).html(sTextDone);
		if($('#jscontent2').get(0)) {
			//gallery
			imgTarget = $('#jscontent2 .photo');
		} else {
			// main image view
			imgTarget =  $('#photoImage');
			$(oSourceLink).html(tempManLinkText);
		}
		$(imgTarget).each(function() {
			$(this).parent().get(0).style.position = 'relative';
			$(this).before('<div class="photoManDiv" style="width: '+($(this).width() + 12)+'px;"><a href="#" style="left: 0;" onclick="deletePhoto('+$(this).attr('photoid')+'); $(this).parent().remove(); return false;" title="delete photo" class="icoDel"><html:abbr title="delete photo">X</html:abbr></a></div>');
			$('.photoManDiv', $(this).parent()).append('<a href="#" style="right: 0;" onclick="setAvatar('+$(this).attr('photoid')+'); return false;" title="make this my profile photo" class=\"icoProfPh"><html:abbr title="make this my profile photo">&#x263A;</html:abbr></a>');
			$('.photoManDiv', $(this).parent()).append('<a href="#" style="left: 0; top: +'+($(this).height() - 7)+'px;" onclick="rotate($(\'.photo\', $(this).parent().parent()), \'right\'); return false;" title="rotate 90&deg; clockwise" class="icoClock"><html:abbr title="rotate 90&deg; clockwise">&#x21BB;</html:abbr></a><a href="#" style="top: +'+($(this).height() - 7)+'px; right: 0;" onclick="rotate($(\'.photo\', $(this).parent().parent()), \'left\'); return false;" title="rotate 90&deg; anti-clockwise" class="icoCounter"><html:abbr title="rotate 90&deg; anti-clockwise">&#x21BA;</html:abbr></a>');
		});
	} else {
		photoManStatus = false;
		$(oSourceLink).html(tempManLinkText);
		tempManLinkText = '';
		$('.photoManDiv').remove();
	}
}

var currentPhotoPage = 1;
var currentPhotoTarget = '';
var currentPhotosPerPage = 16;
var currentPhotosPerRow = 4;
var currentPhotosRequest = '';

function searchPhotos(oSearchValues, iPage, sTarget) {
	if (iPage) {
		oSearchValues.p = iPage;
	}
	currentPhotosPerPage = 6;
	currentPhotosPerRow = 3;
	currentPhotosRequest = 'search';
	oSearchValues.l = currentPhotosPerPage;
	if (sTarget) {
		currentPhotoTarget = sTarget;
	}
	currentPhotoPage = iPage;
	$.getJSON("/api/js/photo/search.php", oSearchValues, function(aData){
			getPhotosRsp(aData);
		});
}

function getPhotos(iUserId, iAlbumId, iPage) {
	currentPhotoPage = iPage;
	currentPhotosPerPage = 16;
	currentPhotosPerRow = 4;
	currentPhotosRequest = 'album';
	currentPhotoTarget = '#jscontent2';
	$.getJSON("/api/js/album/getphotos.php", { id: iAlbumId, user: iUserId, p: iPage }, function(aData){
			getPhotosRsp(aData);
		});
}

function getPhotosRsp(aData) {
	if (!aData['errors']) {
		if (!bIsLogedIn) {
			if (aData['id']!=0) {
				$(currentPhotoTarget).html("<div class=\"pad\"><a href=\"/gallery/view/"+ownerUrlAlias+"/\">View "+ownerAlias+"'s Photos</a> | <a href=\"/profile/view/"+ownerUrlAlias+"/\">View "+ownerAlias+"'s Profile</a></div>");
			} else {
				$(currentPhotoTarget).html("");
			}
		} else if (aData['o']) {

			if (aData['id']!=0) {
				$(currentPhotoTarget).html("<div class=\"pad\"><a href=\"/gallery/view/home/\">Back to My Photos</a> | <a href=\"/gallery/photo/upload/album/"+aData['id']+"\">Add Photo</a> | <a href=\"#\" onclick=\"togglePhotoMan(this); return false;\">Edit Photos</a></div>");
			} else {
				$(currentPhotoTarget).html("<div class=\"pad\"><a href=\"/gallery/photo/upload/\">Add Photo</a> | <a href=\"#\" onclick=\"togglePhotoMan(this); return false;\">Edit Photos</a></div>");
			}

		} else {
			try {
				if (aData['id']!=0) {
					$(currentPhotoTarget).html("<div class=\"pad\"><a href=\"/gallery/view/"+ownerUrlAlias+"/\">View "+ownerAlias+"'s Photos</a></div>");
				} else {
					$(currentPhotoTarget).html("");
				}
			} catch (e) {
				$(currentPhotoTarget).html('');
			}

		}
		$(currentPhotoTarget).append('<table class="gallery"></table>');
		totalCount = 0;
		for (oPhoto in aData['photos']) {
			totalCount++;
		}
		currentRow = '';
		if (totalCount) {
			count = 0;
			currentRow = $('<tr></tr>');
			for (oPhoto in aData['photos']) {
				if (count == currentPhotosPerRow) {
					count = 1;
				} else {
					count++;
				}
				oPhoto = aData['photos'][oPhoto];

				// WARNING: If you change the photo resolution bellow, make sure to chage it in the JS API file also!
				if (oPhoto['f']) {
					if (oPhoto['p']) {
						oPhoto['f'] = "/images/photos/"+oPhoto['f']+"120x120";
					} else {
						oPhoto['f'] = "/api/images/processimage.php?o=1&w=120&h=120&f=/../images/photos/"+oPhoto['f'];
					}
				} else {
					oPhoto['f'] = "/images/phNo-120.png";
				}
				// Add the description from oAlbum['d'] in a tool tip when we decide on which one to use
				if (!oPhoto['r']) {
					if (aData['o'] || bIsModerator) {
						currentRow.append("<td><a href=\"/gallery/photo/view/id/"+oPhoto['id']+"\"><img id=\"gPhoto"+oPhoto['id']+"\" class=\"ph-bdr pl drag photo myphoto\" src=\""+oPhoto['f']+"\" photoid=\""+oPhoto['id']+"\" /></a></td>");
					} else {
						currentRow.append("<td><a href=\"/gallery/photo/view/id/"+oPhoto['id']+"\"><img id=\"gPhoto"+oPhoto['id']+"\" class=\"ph-bdr pl drag photo\" src=\""+oPhoto['f']+"\" photoid=\""+oPhoto['id']+"\" /></a></td>");
					}
				} else {
					if (bIsLogedIn) {
						if (oPhoto['r'] == 1) {
							currentRow.append("<td><img class=\"ph-bdr pl\" src=\"/images/phRestricted-85.png\" /><div class=\"txt-ctr\">Restricted to "+ownerAlias+"'s friends</div></td>");
						} else {
							currentRow.append("<td><img class=\"ph-bdr pl\" src=\"/images/phRestricted-85.png\" /><div class=\"txt-ctr\">Restricted: &quot;private&quot; photo<br /><input type=\"Button\" onclick=\"startRequester(iRequestAccessTypePhoto, "+oPhoto['id']+", "+ownerUserId+");\" value=\"Request Access\" class=\"frmBtn\"/></div></td>");
						}
					} else {
						if (oPhoto['r'] == 1) {
							currentRow.append("<td><img class=\"ph-bdr pl\" src=\"/images/phRestricted-85.png\" /><div class=\"txt-ctr\">Restricted to "+ownerAlias+"'s friends</div></td>");
						} else {
							currentRow.append("<td><img class=\"ph-bdr pl\" src=\"/images/phRestricted-85.png\" /><div class=\"txt-ctr\">&quot;private&quot; photo</div></td>");
						}
					}

				}
				if (count == currentPhotosPerRow) {
					$(currentPhotoTarget+' table').append(currentRow);
					currentRow = $('<tr></tr>');
				}
			}
		} else {
			$(currentPhotoTarget).append("<div class=\"rslts clearfix\">There are no photos to display</div>");
			if (aData['o']) {
				$(currentPhotoTarget).append("<div class=\"pad\"><button type=\"button\" class=\"frmBtn\" onclick=\"window.location='/gallery/photo/upload';\">Upload a photo now</button></div>");
			}
			google_ad_client = "pub-9194847592297973";
			google_ad_width = 468;
			google_ad_height = 60;
			google_ad_format = "468x60_as_rimg";
			google_cpa_choice = "CAAQ0OqI_AEaCBvz3TlBKjahKIjLynM";
			google_ad_channel = "";
			//include('http://pagead2.googlesyndication.com/pagead/show_ads.js');
		}
		if (currentRow) {
			$(currentPhotoTarget+' table').append(currentRow);
		}
		if (currentPhotosRequest == 'album') {
			$(currentPhotoTarget).append('<div class="pageBar clearfix">'+paging(currentPhotoPage, totalCount, currentPhotosPerPage, 'getPhotos('+aData['u']+', '+aData['id']+', %d)', currentPhotoTarget)+'</div>');
		} else {
			$(currentPhotoTarget).append('<div class="pageBar clearfix">'+paging(currentPhotoPage, totalCount, currentPhotosPerPage, 'searchPhotos({ uid: '+aData['uid']+', dt: '+aData['mds']+' }, %d, \''+currentPhotoTarget+'\')', currentPhotoTarget)+'</div>');
		}
	}
	$('.drag').draggable({
			cursor: "grabbing",
//			cursorAt: {right: 1, top: 1},
			helper: 'clone',
			revert: true,
			opacity: 0.7,
			zIndex: 99,
			start: function(e, ui) { $('#dropMask').fadeIn(); $(this).addClass('dragging'); },
			stop: function(e, ui) { $('#dropMask').hide(); $(this).removeClass('dragging'); }
		});
	$(currentPhotoTarget).show();
}

var videoManStatus = false;
var tempVideoManLinkText = '';

function toggleVideoMan(oSourceLink) {
	if (!videoManStatus) {
		videoManStatus = true;
		tempVideoManLinkText = $(oSourceLink).html();
		$(oSourceLink).html(sTextDone);
		$('.videoGalDiv').remove();
		$('#jscontent3 .video').each(function() {
				//$(this).parent().get(0).style.position = 'relative';
				$(this).before('<div class="videoManDiv" style="width: '+($(this).width() + 12)+'px;"><a href="#" style="left: 0;" onclick="deleteVideo('+$(this).attr('videoid')+'); $(this).parent().remove(); return false;" title="delete video" class="icoDel"><html:abbr title="delete video">X</html:abbr></a></div>');
		});
	} else {
		videoManStatus = false;
		$(oSourceLink).html(tempVideoManLinkText);
		tempVideoManLinkText = '';
		$('.videoManDiv').remove();
		$('#jscontent3 .video').each(function() {
				//$(this).parent().get(0).style.position = 'relative';
				$(this).before('<div class="videoGalDiv" style="width: '+($(this).width() + 12)+'px;"><div class="icoGalleryVid"></div></div>');
		});
	}
}

var currentVideoPage = 1;
var currentVideoTarget = '';
var currentVideosPerPage = 8;
var currentVideosPerRow = 4;
var currentVideosRequest = '';

function searchVideos(oSearchValues, iPage, sTarget) {
	if (iPage) {
		oSearchValues.p = iPage;
	}
	currentVideosPerPage = 6;
	currentVideosPerRow = 3;
	currentVideosRequest = 'search';
	oSearchValues.l = currentVideosPerPage;
	if (sTarget) {
		currentVideoTarget = sTarget;
	}
	currentVideoPage = iPage;
	$.getJSON("/api/js/video/search.php", oSearchValues, function(aData){
			getVideosRsp(aData);
		});
}

function getVideos(iUserId, iAlbumId, iPage) {
	currentVideoPage = iPage;
	currentVideosPerPage = 8;
	currentVideosPerRow = 4;
	currentVideosRequest = 'album';
	currentVideoTarget = '#jscontent3';
	$.getJSON("/api/js/album/getvideos.php", { id: iAlbumId, user: iUserId, p: iPage }, function(aData){
			getVideosRsp(aData);
		});
}

function getVideosRsp(aData) {
	if (!aData['errors']) {
		if (!bIsLogedIn) {
			if (aData['id']!=0) {
				$(currentVideoTarget).html("<div class=\"pad\"><a href=\"/gallery/video/view/all/"+ownerUrlAlias+"/\">View "+ownerAlias+"'s Videos</a> | <a href=\"/profile/view/"+ownerUrlAlias+"/\">View "+ownerAlias+"'s Profile</a></div>");
			} else {
				$(currentVideoTarget).html("");
			}
		} else if (aData['o']) {
			if (aData['id']!=0) {
				$(currentVideoTarget).html("<div class=\"pad\"><a href=\"/gallery/video/view/all/"+ownerUrlAlias+"/\">Back to My Videos</a> | <a href=\"/gallery/video/upload/\">Add Video</a> | <a href=\"#\" onclick=\"toggleVideoMan(this); return false;\">Edit Videos</a></div>");
			} else {
				$(currentVideoTarget).html("<div class=\"pad\"><a href=\"/gallery/video/upload/\">Add Video</a> | <a href=\"#\" onclick=\"toggleVideoMan(this); return false;\">Edit Videos</a></div>");
			}

		} else {
			try {
				if (aData['id']!=0) {
					$(currentVideoTarget).html("<div class=\"pad\"><a href=\"/gallery/video/view/all/"+ownerUrlAlias+"/\">View "+ownerAlias+"'s Videos</a></div>");
				} else {
					$(currentVideoTarget).html("");
				}
			} catch (e) {
				$(currentVideoTarget).html('');
			}

		}
		$(currentVideoTarget).append('<table class="gallery"></table>');
		totalCount = 0;
		for (oVideo in aData['videos']) {
			totalCount++;
		}
		totalYTCount = 0;
		for (oUTVideo in aData['yt']) {
			totalYTCount++;
		}
		currentRow = '';
		if (totalCount) {
			count = 0;
			currentRow = $('<tr></tr>');
			for (oVideo in aData['videos']) {
				if (count == currentVideosPerRow) {
					count = 1;
				} else {
					count++;
				}
				oVideo = aData['videos'][oVideo];
				if (!oVideo['f']) {
					oVideo['f'] = "/images/phNo-120.png";
				}
				// Add the description from oAlbum['d'] in a tool tip when we decide on which one to use
				if (!oVideo['r']) {
					if (aData['o']) {
						currentRow.append("<td><a href=\"/gallery/video/view/id/"+oVideo['id']+"\"><div class=\"videoGalDiv\" style=\"width: 132px;\"><div class=\"icoGalleryVid\"></div></div><img id=\"gVideo"+oVideo['id']+"\" width=\"120\" class=\"ph-bdr pl drag video myvideo\" src=\""+oVideo['f']+"\" videoid=\""+oVideo['id']+"\" /></a></td>");
					} else {
						currentRow.append("<td><a href=\"/gallery/video/view/id/"+oVideo['id']+"\"><div class=\"videoGalDiv\" style=\"width: 132px;\"><div class=\"icoGalleryVid\"></div></div><img id=\"gVideo"+oVideo['id']+"\" width=\"120\" class=\"ph-bdr pl drag video\" src=\""+oVideo['f']+"\" videoid=\""+oVideo['id']+"\" /></a></td>");
					}
				} else {
					if (bIsLogedIn) {
						if (oVideo['r'] == 1) {
							currentRow.append("<td><a href=\"/gallery/album/view/id/"+oVideo['id']+"\"><img class=\"ph-bdr pl pad-sm\" src=\"/images/phRestricted-120.png\" /></a></div><div class=\"rslts-info clearfix\">This album is restricted to "+ownerAlias+"'s friends network only.<br /></td>");
						} else {
							currentRow.append("<td><a href=\"/gallery/album/view/id/"+oVideo['id']+"\"><img class=\"ph-bdr pl pad-sm\" src=\"/images/phRestricted-120.png\" /></a></div><div class=\"rslts-info clearfix\">&quot;private&quot; album entry with restricted access.<div class=\"txt999\">Created "+oVideo['d']+"</div><br /><br /><input type=\"Button\" onclick=\"startRequester(iRequestAccessTypeVideo, "+oVideo['id']+", "+ownerUserId+");\" value=\"Request Access\" class=\"frmBtn\"/></td>");
						}
					} else {
						if (oVideo['r'] == 1) {
						} else {
						}
					}
				}
				if (count == currentVideosPerRow) {
					$(currentVideoTarget+' table').append(currentRow);
					currentRow = $('<tr></tr>');
				}
			}
		} else {
			$(currentVideoTarget).append("<div class=\"rslts clearfix\">There are no videos to display</div>");
			if (aData['o']) {
				$(currentVideoTarget).append("<div class=\"pad\"><button type=\"button\" class=\"frmBtn\" onclick=\"window.location='/gallery/video/upload';\">Upload a video now</button></div>");
			}
		}
		if (currentRow) {
			$(currentVideoTarget+' table').append(currentRow);
		}
		if (totalYTCount) {
			$('#youTubeContent').show();
			$('#youTubeContent').html('<table class="gallery"></table>');
			count = 0;
			currentRow = $('<tr></tr>');
			for (oVideo in aData['yt']) {
				if (count == currentVideosPerRow) {
					count = 1;
				} else {
					count++;
				}
				oVideo = aData['yt'][oVideo];

				currentRow.append("<td><a href=\"/gallery/video/view/yt/"+oVideo['id']+"\"><div class=\"videoGalDiv\" style=\"width: 132px;\"><div class=\"icoGalleryVid\"></div></div><img id=\"gVideo"+oVideo['id']+"\" width=\"120\" class=\"ph-bdr pl\" src=\""+oVideo['tn']+"\" videoid=\""+oVideo['id']+"\" /></a></td>");
				if (count == currentVideosPerRow) {
					$('#youTubeContent table').append(currentRow);
					currentRow = $('<tr></tr>');
				}
			}
			if (currentRow) {
				$('#youTubeContent table').append(currentRow);
			}
			$('#youTubeSection').show();
		} else {
			$('#youTubeContent').html("");
			if (aData['o']) {
				$('#youTubeContent').append("<div class=\"pad\"><b><a href=\"/gallery/video/youtube/\">Activate YouTube video service</a> and get your favorite videos in your profile.</b></div>");
			}
		}
		if (currentVideosRequest == 'album') {
			$(currentVideoTarget).append('<div class="pageBar clearfix">'+paging(currentVideoPage, totalCount, currentVideosPerPage, 'getVideos('+aData['u']+', '+aData['id']+', %d)', currentVideoTarget)+'</div>');
		} else {
			$(currentVideoTarget).append('<div class="pageBar clearfix">'+paging(currentVideoPage, totalCount, currentVideosPerPage, 'searchVideos({ uid: '+aData['uid']+', dt: '+aData['mds']+' }, %d, \''+currentVideoTarget+'\')', currentVideoTarget)+'</div>');
		}
	}
	$('.drag').draggable({
			cursor: "grabbing",
//			cursorAt: {right: 1, top: 1},
			helper: 'clone',
			revert: true,
			opacity: 0.7,
			zIndex: 99,
			start: function(e, ui) { $('#dropMask').fadeIn(); $(this).addClass('dragging'); },
			stop: function(e, ui) { $('#dropMask').hide(); $(this).removeClass('dragging'); }
		});
	$(currentVideoTarget).show();
}

function setAlbumCover(iAlbumId, iPhotoId) {
	$.getJSON("/api/js/album/setalbumcover.php", { aid: iAlbumId, id: iPhotoId }, function(aData){
		setAlbumCoverResp(aData);
	});
}

function setAlbumCoverResp(aData) {
	if (!aData['errors']) {
		oMasterNotifier.alert(sTextAlbumCoverSet, -1);
	} else {
		alert(sErrorSetAvatar);
	}
}

function setAvatar(iPhotoId) {
	$.getJSON("/api/js/photo/setavatar.php", { id: iPhotoId }, function(aData){
		setAvatarResp(aData);
	});
}

function deleteAlbum(iAlbumId) {
	if (confirm("WARNING: Removing this album will also remove ALL photos inside it.\n\nClick OK to remove this album and all it's photos.")) {
		$.getJSON("/api/js/album/delete.php", { id: iAlbumId }, function(aData){
			deleteAlbumResp(aData);
		});
	}
}

function deleteAlbumResp(aData) {
	if (!aData['errors']) {
		$('#gAlbum'+aData['id']).fadeOut(function() {
				$('img.albumPic', this).attr('src', '/images/phDeleted-85.png');
				$(this).fadeIn();
				$(this).removeClass('drop-album');
			});
	} else {
		alert(sErrorDeleteVideo);
	}
}

function setAvatarResp(aData) {
	if (!aData['errors']) {
		$('#profileThumb').attr('src', '/api/images/processimage.php?o=1&w='+iThumbWidthA+'&h='+iThumbHeightA+'&f=/../images/photos/'+aData['av']);
	} else {
		alert(sErrorSetAvatar);
	}
}

function movePhoto(iPhotoId, iAlbumId) {
	if (confirm('Are you sure you wish to move this photo?\n\nClick OK to move this photo.')) {
		$.getJSON("/api/js/photo/move.php", { pid: iPhotoId, aid: iAlbumId }, function(aData){
			movePhotoResp(aData);
		});
	}
}

function movePhotoResp(aData) {
	if (!aData['errors']) {
		$('#gPhoto'+aData['id']).fadeOut(function() {
				$(this).attr('src', '/images/phMoved-120.png');
				$(this).fadeIn();
				$(this).removeClass('drag').removeClass('photo').draggable("disable");
			});
	} else {
		alert(sErrorMovingPhoto);
	}
}

function deletePhoto(iPhotoId) {
	if (confirm('Once removed, you cannot reclaim this photo without uploading it again.\n\nClick OK to remove this photo.')) {
		$.getJSON("/api/js/photo/delete.php", { id: iPhotoId }, function(aData){
			deletePhotoResp(aData);
		});
	}
}

function deletePhotoResp(aData) {
	if (!aData['errors']) {
		$('#gPhoto'+aData['id']).fadeOut(function() {
				$(this).attr('src', '/images/phDeleted-120.png');
				$(this).fadeIn();
				$(this).removeClass('drag').removeClass('photo').draggable("disable");
			});
		$('#editphoto'+aData['id']).after('<h1 id="photoTitle" class="secTit plaintext" name="title">Photo Deleted - Where now?</h1><div class="float-l"><img id="photoImage" class="ph-bdr" src="/images/phDeleted-120.png" alt="Photo has been removed"/></div><div class="float-l pad"><h5>Where would you like to go:</h5><a href="#" onclick="history.go(-1); return false;">back</a><br /><a href="/gallery/view/home/">My Gallery</a><br /><a href="/gallery/view/home/">My Profile</a></div>');
		$('#photoImage').hide();
		$('#editphoto'+aData['id']).fadeOut(function() {
				$('#photoImage').fadeIn();
			});
	} else {
		alert(sErrorDeletePhoto);
	}
}

function moveVideo(iVideoId, iAlbumId) {
	if (confirm('Are you sure you wish to move this video?\n\nClick OK to move this video.')) {
		$.getJSON("/api/js/video/move.php", { pid: iVideoId, aid: iAlbumId }, function(aData){
			moveVideoResp(aData);
		});
	}
}

function moveVideoResp(aData) {
	if (!aData['errors']) {
		$('#gVideo'+aData['id']).fadeOut(function() {
				$(this).attr('src', '/images/phMoved-120.png');
				$(this).fadeIn();
				$(this).removeClass('drag').removeClass('video').draggable("disable");
			});
	} else {
		alert(sErrorMovingVideo);
	}
}

function deleteVideo(iVideoId) {
	if (confirm('Once removed, you canot reclaim this video without uploading it again.\n\nClick OK to remove this video.')) {
		$.getJSON("/api/js/video/delete.php", { id: iVideoId }, function(aData){
			deleteVideoResp(aData);
		});
	}
}

function deleteVideoResp(aData) {
	if (!aData['errors']) {
		$('#gVideo'+aData['id']).fadeOut(function() {
				$(this).attr('src', '/images/phDeleted-120.png');
				$(this).fadeIn();
				$(this).removeClass('drag').removeClass('video').draggable("disable");
			});
	} else {
		alert(sErrorDeleteVideo);
	}
}
