﻿var ZoomImage = new Class({
    
    initialize: function(imageID, divContainerID, effectDirection, effectSize)
    {        
        var classRef = this;                
        this.image = $(imageID);
        this.divContainer = $(divContainerID);
        this.divContainerClassName = this.divContainer.className;
        this.effectDirection = parseInt(effectDirection,10);
        this.effectSize = parseInt(effectSize,10);
        this.sourseWidth = this.image.width;
        this.sourseHeight = this.image.height;
                        
        this.image.addEvent('mouseover', function(e){

            e = new Event(e);
            classRef.divContainer.className = classRef.divContainerClassName.replace("z_index_1", "z_index_5");
            var fx = new Fx.Morph(classRef.image, {duration:100, wait:false});
            var h, w, mLeft, mTop, mRight, mDown;
           
            h = 49 * (100 + classRef.effectSize)/100;
            w = 65 * (100 + classRef.effectSize)/100;
            
            switch(classRef.effectDirection)
            {
                //RightDown
                case 0:
                mLeft = 0;
			    mTop = 0;
			    mRight = 0;
			    mDown = 0;
                break;
                
                //Down
                case 1:
                mLeft = (classRef.sourseWidth - w)/2;
			    mTop = 0;
			    mRight = 0;
			    mDown = 0;
                break;
                
                //LeftDown
                case 2:
                mLeft = classRef.sourseWidth - w;
			    mTop = 0;
			    mRight = 0;
			    mDown = 0;
                break;
                
                //Right
                case 3:
                mLeft = 0;
			    mTop = (classRef.sourseHeight - h)/2;
			    mRight = 0;
			    mDown = 0;
                break;
                
                //Center
                case 4:                                
                mLeft = (classRef.sourseWidth - w)/2;
			    mTop = (classRef.sourseHeight - h)/2;
			    mRight = 0;
			    mDown = 0;
                break;
                
                //Left
                case 5:
                mLeft = classRef.sourseWidth - w;
			    mTop = (classRef.sourseHeight - h)/2;;
			    mRight = 0;
			    mDown = 0;
                break;
                
                //RightUp
                case 6:
                mLeft = 0;
			    mTop = classRef.sourseHeight - h;
			    mRight = 0;
			    mDown = 0;                
                break;
                                
                //Up
                case 7:                                
                mLeft = (classRef.sourseWidth - w)/2;
			    mTop = classRef.sourseHeight - h;
			    mRight = 0;
			    mDown = 0;
                break;
                
                //LeftUp
                case 8:                                
                mLeft = classRef.sourseWidth - w;
			    mTop = classRef.sourseHeight - h;
			    mRight = 0;
			    mDown = 0;
                break;
            }            
            fx.start({
                height: h,
                width: w,
                marginLeft: mLeft,
			    marginTop: mTop,
			    marginRight: mRight,
			    marginDown: mDown
            });
            
	        e.stop();
        });
        
        this.image.addEvent('mouseout', function(e){
	        
	        e = new Event(e);
	        
	        classRef.divContainer.className = classRef.divContainer.className.replace("z_index_5", "z_index_1");
            
            var fx = new Fx.Morph(classRef.image, {duration:100, wait:false});
            
            fx.start({
                height: classRef.sourseHeight,
                width: classRef.sourseWidth,
                marginLeft: 0,
			    marginTop: 0,
			    marginRight: 0,
			    marginDown: 0
            });            
	        e.stop();	        
        });
    }
});