// Animenu
// Custom version for Rubber Productions Ltd
// Copyright Artlogic www.artlogic.net

aniMenuOps = Object.extend({

	// Parameters you can set
	
	elementId: 	'header',
	tagName: 	'a',
	
	cssControl: 	'opacity',
	defaultState: 	'1',
	hoverState: 	'0.5',
	activeState: 	'1',
	animateSpeed: 	'0.6'
	
}, window.aniMenuOps || {});

var aniMenu = Class.create();

aniMenu.prototype = {
	initialize: function() {
		if (location.href.indexOf("/work") > 0 && isNew == 1) {
			document.getElementById('artistList').style.display = 'none';
			new Effect.Morph('artistList', {style: 'opacity: 0;',duration:0});
			$('n_rubbersoul').addClassName('active');
		} else if (location.href.indexOf("/work") > 0 && isNew == 0) {
			if ($('n_rubbersoul')) {
				document.getElementById('artistList2').style.display = 'none';
				new Effect.Morph('artistList2', {style: 'opacity: 0;',duration:0});
			}
			$('n_work').addClassName('active');
		} else {
			document.getElementById('artistList').style.display = 'none';
			new Effect.Morph('artistList', {style: 'opacity: 0;',duration:0});
			if ($('n_rubbersoul')) {
				document.getElementById('artistList2').style.display = 'none';
				new Effect.Morph('artistList2', {style: 'opacity: 0;',duration:0});
			}
		}
		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].id == 'n_work' && location.href.indexOf("/work") > 0 && isNew == 0) {
				els[i].onclick = this.reset;
				els[i].onmouseover = this.reset;
				els[i].onmouseout = this.reset;
			} else if (els[i].id == 'n_work') {
				els[i].onclick = this.revealList;
			}
			if (els[i].id == 'n_rubbersoul' && location.href.indexOf("/work") > 0 && isNew == 1) {
				els[i].onclick = this.reset;
				els[i].onmouseover = this.reset;
				els[i].onmouseout = this.reset;
			} else if (els[i].id == 'n_rubbersoul') {
				els[i].onclick = this.revealList2;
			}
		}
	},
	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 }});
	},
	revealList: function() {
		new Effect.Morph(this, {style: aniMenuOps.cssControl + ':' + aniMenuOps.defaultState + ';',duration:aniMenuOps.animateSpeed, queue: { position: 'end', scope: this.id }});
		this.onclick = '';
		this.href = '#';
		this.onmouseover = '';
		this.onmouseout = '';
		new Effect.SlideDown('artistList', {duration:0.5, queue: { position: 'end', scope: 'new' }});
		new Effect.Morph('artistList', {style: 'opacity:1;', duration:1, queue: { position: 'end', scope: 'new' }});
		return false;
	},
	revealList2: function() {
		new Effect.Morph(this, {style: aniMenuOps.cssControl + ':' + aniMenuOps.defaultState + ';',duration:aniMenuOps.animateSpeed, queue: { position: 'end', scope: this.id }});
		this.onclick = '';
		this.href = '#';
		this.onmouseover = '';
		this.onmouseout = '';
		new Effect.SlideDown('artistList2', {duration:0.5, queue: { position: 'end', scope: 'new' }});
		new Effect.Morph('artistList2', {style: 'opacity:1;', duration:1, queue: { position: 'end', scope: 'new' }});
		return false;
	},
	reset: function() {
		return false;
	}
};

document.observe('dom:loaded', function () { new aniMenu(); });