function appearEffect(id)
{	
	new Effect.Appear(document.getElementById(id),{duration:.5, from:.4});
}

function appearGalleryEffect(id)
{
	var img = "img_" + $(id);	
	new Effect.Appear(img,{duration:.5, from:.4});
}

function openGallery(id)
{
	var target = "img_" + $(id);
	new Effect.Puff(target);	
	setTimeout('document.location.href=\"?p=galleryview&id=' + id + '\";', 500);	
}

function movePrevious(id, jarjestys, kategoria)
{
	var target = "img_" + $(id);	
	new Effect.Pulsate(target);
	ajaxMovePrevious(id, jarjestys, kategoria);
}


function moveNext(id, jarjestys, kategoria)
{
	var target = "img_" + $(id);	
	new Effect.Pulsate(target);
	ajaxMoveNext(id, jarjestys, kategoria);
}

function ajaxMoveNext(id, jarjestys, kategoria)
{
	new Ajax.Request("ajax_movenext.php", {
			   method: 'post',
			   postBody: "id="+id+"&jarjestys="+jarjestys+"&kategoria="+kategoria,
			   onComplete: showMoveNextResponse
		});
}

function ajaxMovePrevious(id, jarjestys, kategoria)
{
		new Ajax.Request("ajax_moveprevious.php", {
			   method: 'post',
			   postBody: "id="+id+"&jarjestys="+jarjestys+"&kategoria="+kategoria,
			   onComplete: showMovePreviousResponse
		});

}

function showMoveNextResponse(req)
{
	var res=/false/;
	if(!req.responseText.match(res))
   	{
   		setTimeout('document.location.href = document.location.href;', 750);
   	}
   	else
   	{
		document.location.href = document.location.href;
   	}
}

function showMovePreviousResponse(req)
{
	var res=/false/;
	
	if(!req.responseText.match(res))
   	{
   		setTimeout('document.location.href = document.location.href;', 750);
   	}
   	else
   	{
		document.location.href = document.location.href;
   	}
}

function deletePicture(folder, pic, num)
{
	new Effect.Pulsate(document.getElementById(pic));
	
	var msg = "Are you sure you wanna delete the picture: #" + num + "?";
		
	if(confirm(unescape(msg))) {
		new Ajax.Request("ajax_deletepicture.php", {
			   method: "post",
			   postBody: "f="+folder+"&action=deletepicture&pic="+pic,
			   onComplete: showDeletePictureResponse 			   
		});	
	}
	else {
		return false;
	}
}

function showDeletePictureResponse(req)
{
   var res=/false/;
       
   if(!req.responseText.match(res))
   {
   		Effect.SwitchOff($(req.responseText));
   }
   else
   {
		document.location.href = document.location.href;
   }
}

function deleteGallery(folder)
{
	Effect.Shake(document.getElementById("pics"));
	
	var msg = "Are you sure you wanna delete all picture(s) in this gallery?";
	
	if(confirm(unescape(msg))) {
		new Ajax.Request("ajax_deletepicture.php", {
			   method: "post",
			   postBody: "f="+folder+"&action=deletefolder",
			   onComplete: showDeleteFolderResponse 			   
		});	
	}
	else {
		return false;
	}		
}

function showDeleteFolderResponse(req)
{
   var res=/false/;
       
   if(!req.responseText.match(res))
   {
   		Effect.SwitchOff($('pics'));
   		setTimeout('document.location.href = document.location.href;', 1000);
   		
   }
   else
   {
		document.location.href = document.location.href;
   }
}

// ajax delete gallery, response is ok if succeeded
function deleteWholeGallery(id, galleria)
{
	var q = "Are you sure you wanna delete whole gallery with all pictures?";
	var target = "img_" + $(id);
	new Effect.Shake(target);
			
	if(confirm(q))
	{		
		new Ajax.Request("ajax_deletegallery.php", {
			   method: 'post',
			   postBody: "id="+id+"&galleria="+galleria,
			   onComplete: showDeleteWholeGallery
		});
	}
	else {
		return false;
	}
}

function showDeleteWholeGallery(req)
{    
   var res=/false/;
   
   if(!req.responseText.match(res))
   {   	
   		document.location.href = document.location.href;
   }
   else
   {   		
		document.location.href = document.location.href;
   }
}
