jQuery(function(){
jQuery(".gallery").lightBox({
	overlayBgColor: '#FFF',
	overlayOpacity: 0.6,
	imageLoading: 'data/lightbox-ico-loading.gif',
	imageBtnClose: 'data/lightbox-btn-close.gif',
	imageBtnPrev: 'data/lightbox-btn-prev.gif',
	imageBtnNext: 'data/lightbox-btn-next.gif',
	containerResizeSpeed: 350,
	txtImage: 'Image',
	txtOf: 'of'
   });
});


function SaveNote() {
	if (Registered() == 0) return;
 
	$.post("ajax.php", { title: $('#ntitle').val(), note: $('#nnote').val('')}, 
		function(data){});
	$('#ntitle').val('');
	$('#nnote').val('');
}

function clearValue(control) {
	if (control.value == 'Note title')
		control.value = "";
	if (control.innerText == 'Type your nore here')
		control.innerText = "";
}

function saveNote(title, desc, id) {
 if (Registered() == 0) return;
 
	if (id == '')  {
		$.post("ajax.php", {action: 'addnote', title: "" + title + "", note: "" + desc + ""}, function(data){
			if(data.length >0)
				$('#kenoteslist').html(data + $('#kenoteslist').html());
		});
		$('#ntitle').val('');
		$('#nnote').val('');
	}
	else  {
		$.post("ajax.php", {action: 'savenote', id: "" + id + "", title: "" + title + "", note: "" + desc + ""}, function(data){
			if(data.length >0)
				$('#notediv' + id).html(data);
		});
		
		closeModal();
	}
}

function saveComment(desc, noteid, commentid) {
	if (Registered() == 0) return;

	$.post("ajax.php", {action: 'savecomment', id: "" + noteid + "", cid: "" + commentid + "", note: "" + desc + ""}, function(data){
	if(data.length >0)
		$('#commentdiv' + noteid).html($('#commentdiv' + noteid).html() + data);
	});
		
	closeModal();
}

function deleteNote(id) {
 if (Registered() == 0) return;
 
 $.post("ajax.php", {action: 'deletenote', id: "" + id + ""}, function(data){
	$('#notediv' + id).hide();		
 });
}

function editNote(id) {
 if (Registered() == 0) return;
 
 showModal('Edit Note', 'ajax.php?action=editnote&id=' + id, 700, 400);
}

function addComment(id) {
 if (Registered() == 0) return;
 
 showModal('Add comment', 'ajax.php?action=addcomment&id=' + id, 700, 400);
}

function showModal(dlgtitle, windowscript, ms_winW, ms_winH) {
 var maskHeight = $(document).height();
 var maskWidth = $(window).width();
 
 $('#mask').css({'width':maskWidth,'height':maskHeight});
 
 $('#mask').fadeIn(1000);
 $('#mask').fadeTo("slow",0.8);
 
 var winH = $(window).height();
 var winW = $(window).width();
 
 $('#modalwindow').width(ms_winW); 
 $('#modalwindow').height(ms_winH); 
 
 $('#modalwindow').css('top', winH/2-$('#modalwindow').height()/2 - 50);
 $('#modalwindow').css('left', winW/2-$('#modalwindow').width()/2);

 $('#modalwindow').fadeIn(2000);
 $('#windowtitle').html(dlgtitle);
 
 $.get(windowscript, { }, function(data){
	if(data.length >0) {
		$('#windowcontent').html(data);
	}
 }); 
}

function closeModal() {
 $('#mask').hide();
 $('#modalwindow').hide();
}

function AddFriendDlg(id) {
 if (Registered() == 0) return;
 
 showModal('Select Folder', 'ajax.php?action=friendfolder&id='+ id, 400, 220);
}

function AddFriend(id, folder) {
 if (Registered() == 0) return;
 
 $.post("ajax.php", {action: 'addfriend', id: "" + id + "", folder: "" + folder + ""}, function(data){
	if ($('#addfriendbutton') != null)
		$('#addfriendbutton').hide();
	if ($('#addfriendbutton' + id) != null)
		$('#addfriendbutton' + id).hide();
	closeModal();
 });
}

function CreateConnection(id) {
 if (Registered() == 0) return;
 
 $.post("ajax.php", {action: 'connect', id: "" + id + ""}, function(data){
	$('#connectbutton').hide();
	closeModal();
 });
}

function AddFriendFolder(id) {
 if (Registered() == 0) return;
 $.post("ajax.php", {action: 'addfriendfolder', id: "" + id + "", title: "" + $('#newfolderinput').val() + ""}, function(data){
	$('#friendslist').html(data);
	$('#newfolderinput').val("");	
 });
}

function IngnoreFrindRequest(rt_key, id) {
	if (Registered() == 0) return;
	
	if ($('#addfriendbutton' + id) != null)
		$('#addfriendbutton' + id).hide();
	$.post("ajax.php", {action: 'ignorefriend', id: "" + rt_key + ""}, function(data){
	});
}

function Registered() {
	if (userstate == 0) {
		alert("Please login or register to finish the action. The action is not available for guests.");
		return 0;
	}
	else 
		return 1;
}

