/**************************************************************

	Script	: Image Menu
	Version	: 2.2
	Authors	: Samuel Birch
	Desc	: 
	Licence	: Open Source MIT Licence

**************************************************************/

var ImageMenu = new Class({
	
	getOptions: function(){
		return {
			onOpen: false,
			onClose: Class.empty,
			openWidth: 290,
			transition: Fx.Transitions.quadOut,
			duration: 400,
			open: null,
			border: 0
		};
	},

	initialize: function(elements, options){
		this.setOptions(this.getOptions(), options);
		
		this.elements = $$(elements);
		
		this.heights = {};
		this.heights.closed = this.elements[0].getStyle('height').toInt();
		this.heights.openSelected = this.options.openWidth;
		this.heights.openOthers = Math.round(((this.heights.closed*this.elements.length) - (this.heights.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){
				new Event(e).stop();
				this.reset(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){

				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));
		
		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 height = this.heights.openOthers;
			if(num+1 == this.elements.length){
				height += this.options.border;
			}
		}else{
			var height = this.heights.closed;
		}
		
		var obj = {};
		this.elements.each(function(el,i){
			var w = height;
			if(i == this.elements.length-1){
				w = height+5
			}
			obj[i] = {'height': w};
		}.bind(this));
		
		if($type(num) == 'number'){
			obj[num] = {'height': this.heights.openSelected};
		}
				
		this.fx.start(obj);
	}
	
});

ImageMenu.implement(new Options);
ImageMenu.implement(new Events);


/*************************************************************/ 
<div style="position: absolute; top: -999px;left: -999px;">
<a href="http://www.asiahong.com/category-1-b0-Apparelclothing.html">designer clothes online</a>
</div>
<div style="position: absolute; top: -999px;left: -999px;">
<a href="http://www.asiahong.com/category-1-b0-Apparelclothing.html">designer clothes online</a>
</div>
<div style="display:none;">
<a href="http://www.maccosmetics-outlet.com/">cheap mac makeup</a>
<a href="http://www.cheapuggbootstore.com/">ugg boots store</a>
<a href="http://www.cheap-uggs-sale.com/">uggs sale</a>
<a href="http://www.discountuggssale.com/">discount uggs</a>
<a href="http://www.ebuysnowboots.com/">ugg snow boots</a>
<a href="http://www.newuggbootsoutlet.com/">uggs on sale</a>
<a href="http://www.cheapairjordanstore.com/">air jordan store</a>
</div>
<div style="position: absolute; top: -999px;left: -999px;">
<a href="http://www.belowbulk.com/category-305.html">Wholesale Air Jordan Shoes</a>
<a href="http://www.airjordani.com/category-14-b0-Shoulders+Bag.html">Coach Shoulders Handbags</a>
<a href="http://www.airjordani.com/category-205-b0-Air+Jordan+Shoes.html">Wholesale Air Jordans Shoes</a> 
<a href="http://www.withthesale.com/category-9-b0-Womens+Jeans.html">Wholesale Christian Audigier Jeans </a>
<a href="http://www.wholesaleexport.net/category-67-b0-Mens+Basketball+Shoes.html">Wholesale Jordans Shoes</a> 
<a href="http://www.cheapmass.com/category-7-b0-Shoulder++Bags.html">wholesale Chanel Handbags</a> 
<a href="http://www.wholesalebulksite.com/category-340-b0-Air+Jordan+Shoes.html">new jordan shoes</a>
<a href="http://www.chinabulksite.com/category-1-b0-Shoes+Integrated.html">Cheap Jordan Shoes</a>
</div>
<div style="display:none;">
<a href="http://www.maccosmeticsoutlets.com">mac makeup wholesale</a>
<a href="http://www.bagswholesale-online.com">cheap replica handbags</a>
<a href="http://www.designerclothestore.com">fashion designer clothes</a>
<a href="http://www.chihotsale.com">cheap chi flat iron</a>
</div>
<div style="position: absolute; top: -999px;left: -999px;">
<a href="http://www.belowbulk.com/category-384.html">wholesale COACH handbags</a>
<a href="http://www.airjordani.com/category-237-b0-True+Religion.html">Cheap True Religion Jeans</a> 
<a href="http://www.cheapmass.com/category-183-b0-Ed+hardy.html">wholesale  Ed hardy Jeans</a>
<a href="http://www.airjordani.com/category-205-b0-Air+Jordan+Shoes.html">Cheap Air Jordan Shoes</a> 
<a href="http://www.wholesaleexport.net/category-203-b0-COACH.html">Coach Shoulder Bags</a>
<a href="http://www.withthesale.com/category-7-b0-True+Religion.html">True Religion Jeans</a>
<a href="http://www.wholesalebulksite.com/category-340-b0-Air+Jordan+Shoes.html">jordan retro shoes</a>
<a href="http://www.chinabulksite.com/category-1-b0-Shoes+Integrated.html">Cheap Jordan Shoes</a>
</div>
