﻿//*-----------------------------------------------------------------------------------------------*/
//
// SlideList.js v1.0
//
// Copyright (c) 2008 vabstudio
// Author: Mario blažević | http://vab-studio.hr/
// 
// Accordion is freely distributable under the terms of an MIT-style license.
//
/*-----------------------------------------------------------------------------------------------*/

var SlideList = Class.create({
	initialize: function(menu) {
		this.menu = $$('#'+menu+' div.vabmenu, #'+menu+' div.vabsubmenu');
		this.current =  $$('#'+menu+' div.current').first();

		$(menu).observe('mouseout', function() { this.range(); }.bindAsEventListener(this));
		this.menu.each(function(item) {
			$(item).observe('mouseover', function() { this.over(item); }.bindAsEventListener(this));
			//$(item).observe('mouseout', function() { this.out(item); }.bindAsEventListener(this));
			$(item).observe('click', function() { this.click(item); }.bindAsEventListener(this));
		}.bind(this));

		/*
		this.menu.up(0).insert(
			new Element('div', { 'class': 'background' }).setStyle({'display': 'none'}).insert(
				new Element('div', { 'class': 'left' })
			), {before}
		);
		*/
		this.background = $$('#'+menu+' div.background').first();
		if (this.current) {
			this.setCurrent(this.current);
		};
	},

	setCurrent: function(elem) {
		this.current = elem;
		this.background.setStyle({ left: (this.current.offsetLeft)+'px', width: (this.current.offsetWidth)+'px' }); 
	},

	click: function(item) {
		if (!this.current) this.setCurrent(item, true);
		this.current = item;
	},

	over: function(item) {
		if (!this.current) {
			this.background.show();
		}
		new Effect.Parallel([
			new Effect.Move(this.background, { sync: true, transition: Effect.Transitions.swingTo, x: (item.offsetLeft-10), y: 10, mode: 'absolute' }),
			new Effect.Morph(this.background, { sync: true, style: { width: (item.getWidth()+20)+'px' }})
		]);
	},

	out: function(item) {
		new Effect.Parallel([
			new Effect.Move(this.background, { sync: true, transition: Effect.Transitions.swingTo, x: (item.offsetLeft-10), y: 10, mode: 'absolute' }),
			new Effect.Morph(this.background, { sync: true, style: { width: (item.getWidth()+20)+'px' }})
		]);
	},
	range: function() {
		if (!this.current) {
			this.background.hide();
		} else {
			this.background.show();
			this.over(this.current);
		}
	}
});
