var pPrevLink;
var pCatId;
var pEntryId;

function getbackimage( CatId, EntryId )
{  

   pCatId = CatId;
   
   $.post(
 		 'http://www.kazarla.ru/index.php/entry/GetPreviewPhoto/'+ pCatId + '/' + EntryId +'/prev',
  	{	
    		type: "test-request",
    		param1: "param1",
    		param2: 2
  	},
  	onAjaxSuccess
	);
     
   
}

function getforwimage( CatId, EntryId )
{
   pCatId = CatId;

   $.post(
 		 'http://www.kazarla.ru/index.php/entry/GetPreviewPhoto/'+ pCatId +'/' + EntryId + '/next',
  	{	
    	        type: "test-request",
    		param1: "param1",
    		param2: 2	
  	},
  	onAjaxSuccess
	);
}

function onAjaxSuccess(xml)
{
   EntryId = $(xml).find('entry').text();
   
   str1 = xml.indexOf("<introtext>");
   str1 = xml.indexOf("</introtext>");
   
   EntryId = xml.substr(xml.indexOf("<entry>") + 7 , xml.indexOf("</entry>") - xml.indexOf("<entry>") - 7 );
   PrevieImage = '<a href="http://www.kazarla.ru/index.php/media/photoview/'+EntryId+'">'+xml.substr(xml.indexOf("<introtext>") + 11 , xml.indexOf("</introtext>") - xml.indexOf("<introtext>") - 11 )+'</a>'
  
   $("#previewimage"+pCatId).html(PrevieImage);
   
   $('#switsher'+pCatId).html("<a href='#' class='arrow' onclick='getbackimage(" + pCatId + ", " + EntryId + "); return false;'>&larr;</a>&nbsp;<a href='#' class='switcher' onclick='getbackimage(" + pCatId + ", " + EntryId + "); return false;'>Предыдущая</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='#' class='switcher' onclick='getforwimage(" + pCatId + ", " + EntryId + "); return false;'>Следующая</a>&nbsp;<a href='#' class='arrow' onclick='getforwimage(" + pCatId + ", " + EntryId + "); return false;'>&rarr;</a>");
    
}

$(document).ready(function(){
 
    $("#back").click( function(){ getbackimage(); } );
    $("#backtext").click( function(){ getbackimage(); } );
    
    $("#forw").click( function(){ getforwimage(); } );
    $("#forwtext").click( function(){ getforwimage(); } );
   
});
