(function($) {

     $(function() {
	   zoom('div.item a', on_zoom(modal('#modal', 660, 500)));
     });

     function on_zoom(modal) {
	 return function() {
	     var $a = $(this),
		 big_href = $a.attr('href');

	     if (modal.data('dialog').isOpen) {
		 replace_image(modal.find('div.big-image img'), big_href);
	     }
	     else {
		 var item_list = $a.parents('div.items'),
		     items = item_list.clone(true).removeAttr('id'),
		     big = $('<img src="' + big_href + '" />').wrap('<div class="big-image"/>').parent(),
		     wrap = big.wrap('<div class="wrap"/>').parent().append(items);
		 slider(make_slider(items), 5, 104, item_list.find('a').index(this) + 1);
		 modal.html(wrap).dialog('open');
	     }
	 };
     }
})(jQuery);
