/**************************************************************

	Script	: VI View
	Version	: 1.0
	Authors	: WangJinCheng
	Home	: Http://13640661.qzone.qq.com
	E-Mail	: My.Dog@QQ.Com

**************************************************************/

var ImageMenu = new Class({
	
	getOptions: function(){
		return {
			onOpen: false,
			onClose: Class.empty,
			openWidth: 200,
			transition: Fx.Transitions.quadOut,
			duration: 400,
			open: null,
			border: 0
		};
	},

	initialize: function(elements, options){
		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('click', function(e)
				{		
					
					//  直接点击Vi,就跳至第三层
					if( $("Super").value == 13640661   )
					{
					
					
						this.reset( 2  );
						
						$("Super").value = 0;
					
					
					
					
					}
					else
					{
						
					
					
					
						if( $('NowLi').value > i  )
						{
							if( $('Flag').value == 1 )
							{
								this.reset( i +1  );
								$('NowLi').value =  i  +1;
							}else
							{
								this.reset( i  );
								$('NowLi').value =  i ;	
							}
							$('Flag').value = 0 ;
							
						}else if( $('NowLi').value == i  )
						{
							
							this.reset( i );
							
						}
						else if( $('NowLi').value < i  )
						{
	
						}
					
					
					
					
					}
					
				}.bind(this));
			
			}
			
			
			el.addEvent('mouseleave', function(e){
				{
					//new Event(e).stop();
					//this.reset(this.options.open);
				}
				
				
			}.bind(this));
			var obj = this;
			
			el.addEvent('click', function(e){
				
				
			})
			
		}.bind(this));
		
		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;
			//alert(width);
			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': $('ClosedWidth'+i).value  };
			//alert($('ClosedWidth'+i).value);
			 
			
			
			
			
		}.bind(this));
		
		if($type(num) == 'number'){
			 	
				
				//if( $("NowLi").value == 2)
				if( num == 2)
				{
					obj[num] = { 'width':  680 };
				}else
				{
					obj[num] = { 'width':  this.widths.openSelected };	
				}
				//alert(num);
		}
				
		this.fx.start(obj);
		
	}
	
});

ImageMenu.implement(new Options);
ImageMenu.implement(new Events);


/*************************************************************/