function changeImg(id, r){
	if(!window.menuImg[id]) return false;
	var m = window.menuImg[id];
	var pos = m.obj.positionedOffset();
	if(r > 0){//увеличиваем
		if(m.obj.getWidth()<m.max[0]){
			$(m.obj).setStyle({
				width: 	parseInt(m.obj.getWidth()+m.koef[0])+'px',
				height: parseInt(m.obj.getHeight()+m.koef[1])+'px',
				left: 	parseInt(pos[0]-(m.koef[0]/2))+'px',
				top: 	parseInt(pos[1]-(m.koef[1]/2))+'px'
			});
		}
		 else {
		 	$(m.obj).setStyle({width:m.max[0]+'px',height: m.max[1]+'px'});
		 	m.obj.src = m.max[2];

            clearInterval(m.interval);
			m.interval = 0;
		}
	}
	 else {//уменьшаем
		if(m.obj.getWidth()>m.min[0]){
			$(m.obj).setStyle({
				width: 	parseInt(m.obj.getWidth()-m.koef[0])+'px',
				height: parseInt(m.obj.getHeight()-m.koef[1])+'px',
				left: 	parseInt(pos[0]+(m.koef[0]/2))+'px',
				top: 	parseInt(pos[1]+(m.koef[1]/2))+'px'
			});
		}
		 else {
		 	$(m.obj).setStyle({left:m.x+'px',top:m.y+'px',width:m.min[0]+'px',height: m.min[1]+'px'});
		 	m.obj.src = m.min[2];
            clearInterval(m.interval);
			m.interval = 0;
		}
	}
}

var imgResize = function(obj,x,y){
   var _ = this, speed = 10;
   if(!window.menuImg) window.menuImg = [];
   this.id = window.menuImg.length;
   window.menuImg[this.id] = _;

   this.min = null; this.max = null; this.koef = null; this.interval = 0;this.step = 5;this.x=x; this.y=y;
   var b = new Image(); b.src = obj.readAttribute('full');
   if(b.readyState == 'complete'){
      _.max = [b.width,b.height,b.src];
   }
   else {
	   b.onload = function(){
   		_.max = [b.width,b.height,b.src];
	   }
   }
   var s = new Image(); s.src = obj.readAttribute('src');
   if(s.readyState == 'complete'){
   		_.min = [s.width,s.height,s.src];
   }
   else {
	   s.onload = function(){
   		_.min = [s.width,s.height,s.src];
	   }
   }
   this.obj = $(obj);
   _.obj.up().observe('mouseover',function(){if(_.min && _.max ){
		if(!_.koef) _.koef = [(_.max[0]-_.min[0])/_.step,(_.max[1]-_.min[1])/_.step];
		if(_.interval) clearInterval(_.interval);
		window.menuImg[_.id].interval = setInterval("changeImg("+_.id+",1)", speed);
   }});
   _.obj.up().observe('mouseout',function(){if(_.min && _.max ){
		if(!_.koef) _.koef = [(_.max[0]-_.min[0])/_.step,(_.max[1]-_.min[1])/_.step];
		if(_.interval) clearInterval(_.interval);
		window.menuImg[_.id].interval = setInterval("changeImg("+_.id+",-1)", speed);
   }});
}

document.observe("dom:loaded", function() {
  var imgs = $$('img');if(!imgs){return false;}
  imgs.each(function(s){if(s.hasAttribute('full')){
       var pos = s.positionedOffset();
	   s.insert({after: new Element('img',{src:'/i/blank.gif'}).setStyle({width:s.width+'px', height: s.height+'px'})});
	   s.setStyle({position:'absolute', left:pos[0], top:pos[1]});
	   new imgResize(s,pos[0],pos[1]);
  }});
  //set click layer for goto index [gecko]
  if(Prototype.Browser.IE == false){
  	var s=0;if($('panel')){s+= $('panel').getHeight();}
	$$('body')[0].insert({top:new Element('DIV').observe('click',function(){location.href='/';}).setStyle({position:'absolute',left:'30px',top:(10+s)+'px',width:'280px',height:'80px',cursor:'pointer',zIndex:10})});
  }
});

