window.addEvent('domready', function() {
	if ($('home')) {
		var siteViewer = new ProdViewer('production', 'viewProd');
		
		// Вывод сообщения для ИЕ
		// if (Browser.Engine.trident) {
		// 	var fuckOffIE = new FuckedIE();
		// }


		// flowplayer setup

		var siteIntro = $('intro');
		siteIntro.addClass('widthAudio');
		siteIntro.getElement('div.container').grab(new Element('div', {
			'id': 'playerOutput',
			'html': 'Use player to listen to our music. <span>Hint:</span> You can pick a song from Discography.'
		}));
		siteIntro.getElement('div.container').grab(new Element('div', { 'id': 'player' }));
		var playerOutput = $('playerOutput');
		var tracksUrls = siteIntro.getElements('.colTrackList > ol > li > span > a');
		var mp3s = ['files/Grenouer_vs_Gipnoz_-_Re-Active.mp3'];
		tracksUrls.each(function(item){
			mp3s.include(item.get('href'));
			item.set('title', 'Play Track');
		});

		tracksUrls.addEvent('click', function(event){
			event.preventDefault();
			$f('player').play(mp3s.indexOf(this.get('href')));
		});

		$f('player', '/design/flash/flowplayer.swf', {
		    plugins: {
		        controls: {
		            playlist: true,
		            fullscreen: false,
		            height: 25,
		            buttonOverColor: '#D26424',
		            timeColor: '#69B3FD',
		            durationColor: '#CCCCCC',
		            timeBgColor: '#242425'
		        }
		    },
		    clip: {
		        autoPlay: false,
		        autoPlayNext: true,
		        // optional: when playback starts close the first audio playback
		        onBeforeBegin: function() {
		            this.close();
		        },
		        onStart: function(song) {
			        playerOutput.set('html',
			        	'<span>Current track:</span>' +
			        	' <strong>' + song.metaData.TPE1 + '</strong>' +
			        	' <span>—</span> <strong>' + song.metaData.TIT2 + '</strong>' +
			        	' <span>from</span> <strong>' + song.metaData.TALB + '</strong>'
			        	);
			    }
		    },
		    playlist: mp3s.map(function(item){
		    	return item;
		    })// ,
		    // onMouseOver: function(){
		    // 	playerOutput.setStyle('visibility', 'visible');
		    // },
		    // onMouseOut: function(){
		    // 	playerOutput.setStyle('visibility', 'hidden');
		    // }
		    // ,
		    // onLoad: function(){
		    // 	console.log("Now playing song " + this.getClip().metaData.TIT2);
		    // 	playerOutput.set('text', 'Fuck');
		    // }
		});

	}
});

var ProdViewer = new Class({
	initialize: function(elNav, elView){
		this.elNav = $(elNav);
		this.elView = $(elView);
		this.navR = $('prodRestore');
		this.navA = this.elNav.getElements('ul a');
		this.elMove = new Fx.Tween(this.elView, { property: 'margin-left', duration: 'long', transition: 'quad:out' });
		this.attachEvents();
	},
	attachEvents: function(){
		this.navR.addEvent('click', function(event){
			event.stop();
			this.restore();
		}.bind(this));
		this.navA.each(function(link){
			link.addEvent('click', function(event){
				event.stop();
				if (link.hasClass('active')) { this.restore(); } else { this.move(link); }
			}.bind(this));
		}, this);
	},
	move: function(a){
		var x;
		switch (a.getProperty('href')) {
			case '#p2008': x = -1000; break;
			case '#p2007': x = -2000; break;
			case '#p2004': x = -3000; break;
			case '#p2001': x = -4000; break;
			case '#p1999': x = -5000; break;
			case '#p1996': x = -6000; break;
			default: x = 0;
		}
		this.navR.setStyle('display', 'block');
		this.navA.removeClass('active');
		a.addClass('active');
		this.elMove.cancel();
		this.elMove.start(x);
	},
	restore: function(){
		this.navR.setStyle('display', 'none');
		this.navA.removeClass('active');
		this.elMove.cancel();
		this.elMove.start(0);
	}
});

var FuckedIE = new Class({
	initialize: function(){
		this.iePanel = new Element ('div', {
			'id': 'iePanel',
			'style': 'float:left; width: 100%; background: #E3EEFB; color: #000; border-bottom: 5px solid #8E5A3C; font-size: 1.4em; text-align: right',
			'html': '<p style="width: 980px; margin: 1em auto; "><strong>There\'s a better way to browse the web!</strong> Grenouer recommends that you upgrade to the latest versions of <a href="http://www.google.com/chrome" title="Google Chrome Browser">Chrome</a>, <a href="http://www.firefox.com" title="Mozilla Firefox Browser">Firefox</a> or <a href="http://www.opera.com" title="Opera Browser">Opera</a>.</p>'
		});
		$$('body').grab(this.iePanel, 'top');
	}
});
