__IMAGES__={'keyIndex':[],'keySRC':[]};
function get_cycle(mover){
	var i		=__IMAGES__,
		o		=$("#dialog img"),
		src		= $(o).attr('src'),
		cur		=i.keySRC[src],
		next	=mover>0?( cur==i.keyIndex.length-1?0:cur+mover ):(cur==0?i.keyIndex.length-1:cur+mover),
		nextSRC	=i.keyIndex[next];
		$(o).attr('src',nextSRC);
		$('#dialog').dialog("option","title",next+1);
		return false;
}
function dialog_del(){$("#dialog").remove();}
$(".photos a").each(function(i){
	var hrefV = $(this).attr('href');
	__IMAGES__.keyIndex[i]=hrefV;
	__IMAGES__.keySRC[hrefV]=i;
	$(this).click(function(){
		$('<div id="dialog"><div class="l"><a href="javascript:;">prev</a></div><div class="r"><a href="javascript:;">next</a></div></div>').append($('<img/>').attr({src:hrefV}).click(function(){get_cycle(1);})).dialog({close:dialog_del,open:function(){},title:i+1,modal:true,width:(window.innerWidth||document.body.clientWidth)-300});
		$(".ui-dialog").css('top', (window.scrollY||document.documentElement.scrollTop||document.body.scrollTop)+15+'px').
		find('div.r a').click(function(){get_cycle( 1);}).end().
		find('div.l a').click(function(){get_cycle(-1);});
		return false;
	});
});
