// Animenu
// Custom version for Victoria Miro
// Copyright Artlogic www.artlogic.net

aniMenuOps = Object.extend({

	// Parameters you can set
	
	elementId: 	'header',
	tagName: 	'li',
	
	cssControl: 	'opacity',
	defaultState: 	'1',
	hoverState: 	'0.5',
	activeState: 	'1',
	animateSpeed: 	'0.6'
	
}, window.aniMenuOps || {});

var aniMenu = Class.create();

aniMenu.prototype = {
	initialize: function() {
		var els = document.getElementById(aniMenuOps.elementId).getElementsByTagName(aniMenuOps.tagName);
		var idCount = '1';
		for(var i=0; i<els.length; i++) {
			els[i].onmouseover = this.animChange;
			els[i].onmouseout = this.animRestore;
			if (els[i].id == '') {
				els[i].id = 'el' + idCount;
				idCount = parseInt(idCount) + parseInt('1');
			}
			if (els[i].className == 'active') {
				els[i].onmouseover = '';
				els[i].onmouseout = '';
				new Effect.Morph(els[i], {style: aniMenuOps.cssControl + ':' + aniMenuOps.activeState + ';',duration:0});
			}
			if (els[i].title == 'ajax') {
				els[i].onclick = this.ajaxClick;
				els[i].title = '';
			}
			
			if (els[i].title == 'dynamic') {
				els[i].onclick = this.dynamicClick;
				els[i].title = '';
			}
		}
	},
	animChange: function() {
		var queue = Effect.Queues.get(this.id);
		queue.each(function(effect) { effect.cancel(); });
		new Effect.Morph(this, {style: aniMenuOps.cssControl + ':' + aniMenuOps.hoverState + ';',duration:(aniMenuOps.animateSpeed / 3), queue: { position: 'end', scope: this.id }});
	},
	animRestore: function() {
		new Effect.Morph(this, {style: aniMenuOps.cssControl + ':' + aniMenuOps.defaultState + ';',duration:aniMenuOps.animateSpeed, queue: { position: 'end', scope: this.id }});
	},
	ajaxClick: function() {
		if (hashValue !='' && hashValue !=undefined) {
			hashValue = '';
			location.href = '#list0';
		}
		records.load();
		var queue = Effect.Queues.get(this.id);
		queue.each(function(effect) { effect.cancel(); });
		
		var navEls2 = document.getElementById("subNav").getElementsByTagName("li");
		for(var i=0; i<navEls2.length; i++) {
			if (navEls2[i] != document.getElementById(this.id)) {
				navEls2[i].onmouseover = aniMenu.prototype.animChange;
				navEls2[i].onmouseout = aniMenu.prototype.animRestore;
				//new Effect.Morph(navEls2[i], {style:'opacity:1;',duration:0.6});
				navEls2[i].className = '';
			} else {
				navEls2[i].onmouseover = '';
				navEls2[i].onmouseout = '';
				navEls2[i].className = 'active';
				new Effect.Morph(this, {style:'opacity:1;',duration:0.6, queue: { position: 'end', scope: this.id }});
			}
		}
	},
	dynamicClick: function() {
		var queue = Effect.Queues.get(this.id);
		queue.each(function(effect) { effect.cancel(); });
		
		var navEls2 = document.getElementById("subNav").getElementsByTagName("li");
		for(var i=0; i<navEls2.length; i++) {
			if (navEls2[i] != document.getElementById(this.id)) {
				navEls2[i].onmouseover = aniMenu.prototype.animChange;
				navEls2[i].onmouseout = aniMenu.prototype.animRestore;
				//new Effect.Morph(navEls2[i], {style:'opacity:1;',duration:0.6});
				navEls2[i].className = '';
			} else {
				navEls2[i].onmouseover = '';
				navEls2[i].onmouseout = '';
				navEls2[i].className = 'active';
				new Effect.Morph(this, {style:'opacity:1;',duration:0.6, queue: { position: 'end', scope: this.id }});
			}
		}
	}
};

document.observe('dom:loaded', function () { new aniMenu(); });
