﻿//  im-->
var ImageMenu = new Class({
	
	getOptions: function()
	{
		return {
			onOpen: false,
			onClose: Class.empty,
			openWidth: 500,
			transition: Fx.Transitions.quadOut,
			duration: 1000,
			open: null,
			border: 0
		};
	},
    
    
	initialize: function(elements, options)
	{
        this.abcdefg=null;
		this.setOptions(this.getOptions(), options);
		
		this.elements = $$(elements);
		
		this.widths = {};
		this.widths.closed = this.elements[0].getStyle('width').toInt();
		this.widths.openSelected = this.options.openWidth;
		this.widths.openOthers = Math.round(((this.widths.closed*this.elements.length) - (this.widths.openSelected+this.options.border)) / (this.elements.length-1))
		
		
		this.fx = new Fx.Elements(this.elements, {wait: false, duration: this.options.duration, transition: this.options.transition});
		
		this.elements.each(function(el,i){
			el.addEvent('mouseenter', function(e){
			    if(this.abcdefg!=null)
			        $clear(this.abcdefg);
				new Event(e).stop();
				this.reset(i);
			}.bind(this));
			
			el.addEvent('mouseleave', function(e){
			    if(this.abcdefg!=null)
			        $clear(this.abcdefg);
				new Event(e).stop();
				this.reset(this.options.open);
				this.abcdefg=periodicalImageMenu.periodical(3500,ooo);
			}.bind(this));
			
			
//			var obj = this;
//			el.addEvent('click', function(e){
//				if(obj.options.onOpen){
//					new Event(e).stop();
//					if(obj.options.open == i){
//					    取消图片的打开新页面功能
//						obj.options.open = null;
//						obj.options.onClose(this.href, i);
//					}else{
//						obj.options.open = i;
//						obj.options.onOpen(this.href, i);
//					}
//					
//					
//				}
//				
//			})
			
			
		}.bind(this));
		
		/****************************************/
//			el.addEvent('domready',function(e){
//			    new Event(e).stop();
//			    this.reset(2);
//		    }.bind(this));

        var ooo=this;
        var iii=6;
        function periodicalImageMenu(){
            if(iii==6){
	            this.reset(2);
	            iii=0;
	        }
	        else if(iii==5){
	            iii=0;
	            this.reset(this.options.open);
	        }
	        else{
	            this.reset(iii);
	            iii++;
	        }
	    }
        
	    var abcdefg_1=function(){
	        if($('bottom_div').getStyle('bottom').toInt()>=40){
	            $clear(abcdefg_2);
	            if(this.abcdefg!=null)
	                $clear(this.abcdefg);
	            this.abcdefg=periodicalImageMenu.periodical(3500,ooo);
	        }
	    };
	    var abcdefg_2=abcdefg_1.periodical(100,ooo);
	    
		/****************************************/
		
		if(this.options.open){
			if($type(this.options.open) == 'number'){
				this.reset(this.options.open);
			}else{
				this.elements.each(function(el,i){
					if(el.id == this.options.open){
						this.reset(i);
					}
				},this);
			}
		}
		
	},
	
	reset: function(num){
		if($type(num) == 'number'){
			var width = this.widths.openOthers;
			if(num+1 == this.elements.length){
				width += this.options.border;
			}
		}else{
			var width = this.widths.closed;
		}
		
		var obj = {};
		this.elements.each(function(el,i){
			var w = width;
			if(i == this.elements.length-1){
				w = width+5
			}
			obj[i] = {'width': w};
		}.bind(this));
		
		if($type(num) == 'number'){
			obj[num] = {'width': this.widths.openSelected};
		}
				
		this.fx.start(obj);
	}
		
});

ImageMenu.implement(new Options);
ImageMenu.implement(new Events);

//        var iii=6;
//        function periodicalImageMenu(){
//            if(iii==6){
//	            this.reset(2);
//	            iii=0;
//	        }
//	        else if(iii==5){
//	            iii=0;
//	            this.reset(this.options.open);
//	        }
//	        else{
//	            this.reset(iii);
//	            iii++;
//	        }
//	    }

        window.addEvent('domready', function(){var myMenu = new ImageMenu($$('#imageMenu a'),{openWidth:500, border:0, onOpen:function(e,i){window.open(e);}});});
/*************************************************************/

