var Item=Class.create();
Item.prototype={
	thDiv:null,
	id:null,
	picPath:null,
	initialize:function(thDiv){
		this.thDiv=thDiv;	
		this.id=this.thDiv.id;
		this.picPath=this.thDiv.select(".item_list_box_pic a")[0].rel;
		this.thDiv.observe("mouseover", this.select.bindAsEventListener(this))
	},
	select:function(event){
		Item.actImage.src=this.picPath;
	}
}
document.observe('dom:loaded', function () { 
	if(Item.actImage=$$("#item_list_act_image img")[0]){
		$$(".item_list_box").each(function(element){new Item(element)});
	}
	
});


var ItemImage=Class.create();
ItemImage.prototype={
	a:null,
	id:null,
	img:null,
	preloader:null,
	picPath:null,
	initialize:function(a){
		this.a=a;	
		this.img=this.a.select("img")[0];	
		this.picPath=this.a.href;
		
		
		this.img.observe("mouseover", this.over.bindAsEventListener(this));
		this.img.observe("mousemove", this.move.bindAsEventListener(this));
		this.img.observe("mouseout", this.out.bindAsEventListener(this));
		this.img.observe("click", function(e){
			e.stop(); 
			return false;
		}.bindAsEventListener(this));
	},
	over:function(event){
		this.preloader=new Image();
		this.preloader.onload=function(){
			this.bigPic=$("item_page_zoom");
			this.bigPic.show();
			
			Element.setStyle(this.bigPic,
				{
					backgroundImage:"url("+this.picPath+")",
					backgroundPosition:"0px 0px"
				}
			)
			
		}.bind(this)
		this.preloader.src=this.picPath;
	},
	out:function(event){
		if(this.bigPic){
			Element.setStyle(this.bigPic,
				{
					backgroundImage:"none",
					backgroundPosition:"0px 0px"
				}
			)
		}
	},
	move:function(event){
		var x;
		var y;
		if(!event.offsetX){
			var x=event.pageX-this.img.x;
			var y=event.pageY-this.img.y;
		}
		else{
			x=event.offsetX;
			y=event.offsetY
		}
		x=isNaN(x)?0:x;
		y=isNaN(y)?0:y;
		if(this.bigPic){
			
			Element.setStyle(this.bigPic, {backgroundPosition:Math.floor(x/this.img.width*(this.preloader.width-200))*-1+"px "+(Math.floor(y/this.img.height*(this.preloader.height-200)))*-1+"px"})
		}
	}
}
document.observe('dom:loaded', function () { 
	$$("a[rel=item_image]").each(function(element){new ItemImage(element)});
	
});
