
var WebSiteMain = new Class({

	pageName: null,
	animateIn: true,
	absRoot: '/',
	
	_domReady: false,

	initialize: function() {
		window.addEvent('domready', this.onDOMReady.bind(this));
		window.addEvent('load', this.onLoad.bind(this));
	},
	
	onDOMReady: function() { 
		this.pageName = $('allContainer').get('class').split('-')[1];
		this._domReady = true;

		if(this.pageName == 'main') {
			this.animateIn = Cookie.read('firstPageAnimate') != 'no';
			Cookie.dispose('firstPageAnimate', { path: '/' });
			
			var swfObj = new Swiff(this.absRoot + "c/main.swf", {
				width: 700,
				height: "100%",
				params: { 
					wMode:'opaque', 
					swLiveConnect:'false',
					scale: 'noscale',
					bgcolor: '#000000'
				},
				properties: {
					bgcolor: '#000000'
				}, 
				vars: {
					'animate': (this.animateIn ? 1 : 0)
				}
			});
			$('mainFlash').adopt(swfObj);
		
		} else {
			$('mainTitle').addEvent('click', this.onMainTitleClik.bindWithEvent(this));
			if(this.pageName == 'videos') this.initVideos();
		}
	},
	
	onLoad: function() { 
		if(!this._domReady) {
			this.onLoad.delay(30, this);
			return;
		}
		
		if(this.pageName == 'main') {
			//alert(Browser.Engine.trident);
			//alert(Browser.Engine.version);
			//alert(this.animateIn);
			if(this.animateIn) {
				$('mainTitle').set('tween', {duration: 1200 }).fade('hide');
				$('menu').getElements('li').each(function(el) {
					el.set('tween', { duration: 800 }).fade('hide');
				});
				$('copyright').set('tween', {duration: 1200 }).fade('hide');
				this.showMenu.delay(200, this);
			}
			$('left').removeClass('hidden');
		}
	},
	
	showMenu: function() {
		$('mainTitle').fade('in');
		$('menu').getElements('li').each(function(el, idx) {
			el.fade.delay(130 + idx * 130, el, 'in');
		});
		$('copyright').tween.delay(1200, $('copyright'), [ 'opacity', 0.99 ]);
		
	},
	
	
	initVideos: function() {
		var flashvars = {};
			flashvars.allowSmoothing = "true";
			flashvars.autoPlay = "false";
			flashvars.buffer = "18";
			flashvars.showTimecode = "true";
			flashvars.loop = "false";
			flashvars.controlColor = "0xCCCCCC";
			flashvars.controlBackColor = "0x000000";
			flashvars.scaleIfFullScreen = "false";
			flashvars.showScalingButton = "false";
			flashvars.defaultVolume = "100";
			flashvars.crop = "false";
			// this variable controls what should happen if the playing video is clicked:
			//		- "http://www.somedomain.com/": The specified domain is opened in the same window
			//		- "togglePlay": The Video plays / pauses
			//		- "" or "disabled": nothing happens
			flashvars.onClick = "togglePlay";
	
		var params = {};
			params.menu = "false";
			params.allowFullScreen = "true";
			params.allowScriptAccess = "always";
	
		var properties = {};
			properties.bgcolor = "#000000";
			
		$$('.videoContainer').each(function(el, idx) {
			flashvars.mediaURL = window.videoInfo[idx].video;
			flashvars.teaserURL = window.videoInfo[idx].image;
			properties.id = 'video' + idx;
			properties.name = 'video' + idx;
			
			var swfObj = new Swiff(this.absRoot + "c/assets/NonverBlaster.swf", {
				'width': window.videoInfo[idx].width,
				'height': window.videoInfo[idx].height,
				'params': params,
				'properties': properties, 
				'vars': flashvars
			});
			el.adopt(swfObj);
		}, this);
			
		
	},
	
	
	onMainTitleClik: function(event) {
		event.stop();
		Cookie.write('firstPageAnimate', 'no', { path: '/' });
		//console.debug(Cookie.read('firstPageAnimate'));
		window.location = this.absRoot;
	}
	
	
	
});

var webSiteMain = new WebSiteMain();