/*
######################################################################################################################################
01.01 Зумер - увеличивает картинки и осуществляет навишацию между ними.

Примеры: 
	1. Увеличивает картинки
	$(function(){
		new zoomer({
			items:$('.zoomzoom'),
			func:function(o){return '<table cellspacing=0 cellpadding=0 border=0 width=100% height=100%><tr><td align=center valign=center><img src="'+$(o).attr('rel')+'"></td></tr></table>'
			},
			on_zoom:function(){transparent_events(); }
		})	
	});

######################################################################################################################################
*/


function zoomer(p){ //Может что то показать большим!
	this.items=p.items; //jQuery набор элементов для увеличения
	this.get_html_func=p.func; //Внешняя функция получения содержания зума
	this.on_zoom=p.on_zoom; //Внешняя функция вызываемая после увеличения
	this.on_zoom_out=p.on_zoom_out; //Внешняя функция вызываемая после уменьшения
	this.on_refresh=p.on_refresh; //Внешняя функция вызываемая при переходе на следующий элемент
	this.speed=p.speed?p.speed:300;
	this.cw=$(window).width();
	this.ch=$(window).height();	
	this.padding=p.padding?{top:p.padding.top,left:p.padding.left}:{top:50,left:100};

	this.items.bind('click',this,function(e){e.data.zoomIn(e,this); return false;});
 
	this.zoomIn=function(e,obj){
		$('body').append('<div class=dialog_shadow></div>');
		$('.dialog_shadow').css({zIndex:100000,background:'#000000',position:'absolute',opacity:0,display:'none',top:$(document).scrollTop(),width:$(window).width(), height:$(window).height()});
		$('.dialog_shadow').bind('click',this,function(d){d.data.zoomOut(d.data);});
				
		$('.dialog_shadow').css({display:''}).animate({opacity:0.5}, "slow"); 
		
		$('.zoomconeiner').remove();
		this.cst=$(document).scrollTop();
		$('body').append('<div class=zoomconeiner style="position:absolute"></div>');
		this.zc=$('.zoomconeiner');
		$('body').css({zIndex:100001});

		this.target=obj;		
		this.zc_w=this.cw-this.padding.left*2;
		this.zc_h=this.ch-this.padding.top*2;
		
		this.html=this.get_html_func(this.target);
		this.html=this.html?this.html:'Нет контента';		
		
		$(window).bind('scroll',this,function(d) {
			$('.dialog_shadow').css({top:$(document).scrollTop()});
			$('.zoomconeiner').css({top:Math.floor((d.data.ch-d.data.zc_h)/2)+$(document).scrollTop()});
		});		
		
		this.zc.css({top:Math.floor((this.ch)/2)+this.cst});
		this.zc.animate({width:this.zc_w,left:Math.floor((this.cw-this.zc_w)/2)},this.speed).animate({top:Math.floor((this.ch-this.zc_h)/2)+this.cst,height:this.zc_h},this.speed,this.afterZoom(this));
	}
	
	this.afterZoom=function(o){	
		o.zc.append($('<div class="hand zoomerclose" style="z-index:200"></div><div style="z-index:200" class="hand zoomerclose_clicker"></div>'));
		
		o.zc.append('<div class="zoomconeinerinner" style="height:100%">'+o.html+'</div>');
		o.zc.find('.zoomerclose_clicker').bind('click',this,function(e){e.data.zoomOut(e.data);});
		if (o.items.size()>1){
			o.zc.append($('<div class="hand larr button_transp"><div></div></div><div class="hand rarr button_transp"><div></div></div>'));
			o.zc.find('.larr').bind('click',this,function(e){e.data.zoomPrev();return false;});
			o.zc.find('.rarr').bind('click',this,function(e){e.data.zoomNext();return false;});
		//	o.zc.bind('click',this,function(e){e.data.zoomNext()});
		}else{
			o.zc.bind('click',this,function(e){e.data.zoomOut(e.data)});
		}
		if (o.on_zoom) o.on_zoom();
		if (o.on_refresh) o.on_refresh();
	}
	
	this.zoomOut=function(o){	
		this.cst=$(document).scrollTop();
		o.zc.find('object').hide();
		o.zc.find('.zoomerclose').fadeOut();
		o.zc.animate({top:Math.floor((o.ch)/2)+this.cst,height:10},o.speed).animate({width:0,left:Math.floor((o.cw)/2)},o.speed,function(){$(this).html('')}).fadeOut(300,function(){$(this).remove();});
		if (o.on_zoom_out) o.on_zoom_out();
		$('.dialog_shadow').animate({opacity:0}, "slow",function(){$(this).remove()}); 		
	}	
	
	this.zoomPrev=function(){	
		var t=this.target;
		var is=[]; 	//Массив элементов
		var cis=-1; //Текущий элемент
		this.items.each(function(n){
			is[n]=this;
			if (t==this) cis=n;
		});
		if (cis==-1) return;
		cis=(cis-1<0)?is.length-1:cis-1;
		this.target=is[cis];
		this.html=this.get_html_func(this.target); 
		this.html=this.html?this.html:'Нет контента';
		var o=this;
		this.zc.find('.zoomconeinerinner').fadeOut('fast',function(){$(this).html(o.html); $(this).fadeIn('fast',function(){if (o.on_refresh) o.on_refresh();}); });
	}
	
	this.zoomNext=function(){	
		var t=this.target;
		var is=[]; 	//Массив элементов
		var cis=-1; //Текущий элемент
		this.items.each(function(n){
			is[n]=this;
			if (t==this) cis=n;
		});
		if (cis==-1) return;
		cis=(cis+1>=is.length)?0:cis+1;
		this.target=is[cis];
		this.html=this.get_html_func(this.target); 
		this.html=this.html?this.html:'Нет контента';
		var o=this;
		this.zc.find('.zoomconeinerinner').fadeOut('fast',function(){$(this).html(o.html); $(this).fadeIn('fast',function(){if (o.on_refresh) o.on_refresh();}); });
	}
	
	
}
