// Active
var FlashButtons = function(url) {

	// Set banner reset
	if (Browser.Plugins.Flash.version<10 && $(document.body).getElement('div.video').getStyle('background-image')!='url(\'/images/document/header/banner.png\')')
		$(document.body).getElement('div.video').setStyle('background-image', 'url(\'/images/document/header/banner.png\')');
	if ($chk($(document.body).getElement('div.curtains').getElement('a')))
		$(document.body).getElement('div.curtains').getElement('a').destroy();
		
	// Start video
	if (url.toString().test('les-videos/#')) startVideo(url.split('#')[1], url);
	
	// Find each button with video as its target
	$each($(document.body).getElements('a[target=video]'), function(item) {
		item.addEvent('click', function(e) {
			e.stop();
			// Move window
		    new Fx.Scroll(window).start(0, 0);
			// Start video
			startVideo(this.get('href').split('#')[1], url);
		});
	});
}

var startVideo = function(video, url) {
	if (Browser.Plugins.Flash.version>=10) {
	    // Stop headerintro swf video
	    //$('header-intro').StopPlay();
		if (!url.test('#')) Swiff.remote($('header-intro'), 'remotePause');
	    
	    // Unfocus
		if($chk($(document.body).getElement('ul.videos').getElement('a.focus')))
		    $(document.body).getElement('ul.videos').getElement('a.focus').removeClass('focus');
		// Focus this button
		$(document.body).getElement('a[href*='+video+']').addClass('focus');
	    
	    // Create new video
	    if ($chk($('video-player'))) $(document.body).getElement('div.video').removeChild($('video-player'));
	    newVideo = new Swiff('/videos/video-player.swf', {
	    	id: 'video-player',
	    	width: 662,
	    	height: 372,
	    	params: {
	    		'codebase': 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
	    		'pluginspage': 'http://www.adobe.com/go/getflashplayer',
	    		'align': 'middle',
	    		'play': 'true',
	    		'loop': 'true',
	    		'scale': 'showall',
	    		'devicefont': 'false',
	    		'bgcolor': '#000000',
	    		'wmode': 'opaque',
	    		'menu': 'true',
	    		'allowFullScreen': 'false',
	    		'allowScriptAccess': 'sameDomain'
	    	},
	    	vars: {
	    		myVideo: video+'.mp4'
	    	}
	    });
	    newVideo.inject($(document.body).getElement('div.video'));
	// If no flash
	} else if (!$chk($(document.body).getElement('div.curtains').getElement('a'))) {
	    // Create anchor to get flash
	    new Element('a', {'href': 'http://get.adobe.com/flashplayer/', 'class':'noflash', 'target': '_blank', 'html': 'Obtenir Flash', 'styles': {
	    	'position': 'absolute',
	    	'width': 158,
	    	'height': 39,
	    	'top': 208,
	    	'left': $(document.body).getElement('div.container').getPosition().x.toInt()+401,
	    	'text-indent': '-9000px',
	    	'overflow': 'hidden'
	    }}).inject($(document.body).getElement('div.curtains'));
	    $(document.body).getElement('div.video').setStyle('background-image', 'url(\'/images/pages/les-videos/get-flash.png\')');
	}
}

var FlashEnd = function() {
	// Delete new video
	if ($chk($('video-player'))) {
		$(document.body).getElement('div.video').removeChild($('video-player'));
		// Play headerintro swf video
		Swiff.remote($('header-intro'), 'remotePlay');
		// Unfocus
		if($chk($(document.body).getElement('ul.videos').getElement('a.focus')))
			$(document.body).getElement('ul.videos').getElement('a.focus').removeClass('focus');
	}
}

var headerintro, newVideo;
window.addEvent('domready', function() {
	if (Browser.Plugins.Flash.version>=10) {
	
		// Header video
		headerintro = new Swiff('/videos/header-intro.swf', {
			id: 'header-intro',
			width: 662,
			height: 372,
			container: $(document.body).getElement('div.video'),
			params: {
				'codebase': 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
				'pluginspage': 'http://www.adobe.com/go/getflashplayer',
				'align': 'middle',
				'play': 'true',
				'loop': 'true',
				'scale': 'showall',
				'devicefont': 'false',
				'bgcolor': '#000000',
				'menu': 'true',
				'allowFullScreen': 'false',
				'allowScriptAccess': 'sameDomain'
			},
			callBacks: {
    		    onLoad: function() {
    		    	//alert('hey');
    		    	if (window.location.href.toString().test('les-videos/#')) {
    		    		//alert('hey');
    		    		this.remotePause();
    		    	}
    		    }
		    }
		});
	}
	
	FlashButtons.run(window.location.href);
});

var onLoad = function() {
	if (window.location.href.toString().test('les-videos/#')) {
		Swiff.remote($('header-intro'), 'remotePause');
	}
}

