$(document).ready(function(){
	var currentPlayer;
	
	$f(".player", "http://uman.square-enix-europe.com/contents/NL_200910/flow/flowplayer.commercial-3.1.3.swf",  {
	
		key: '@aaaf3b503bfa3d1a8db',
			
		plugins: {
			controls: {
				url: 'http://uman.square-enix-europe.com/contents/NL_200910/flow/flowplayer.controls-tube-3.1.3.swf',
				autoHide: 'always',
				hideDelay: 1000000000,
				borderRadius: '0px',
				progressColor: '#858585',
				backgroundGradient: 'none',
				bufferGradient: 'none',
				bufferColor: '#4a4a4a',
				sliderColor: '#165988',
				tooltipTextColor: '#D00000',
				volumeSliderColor: '#D00000',
				progressGradient: 'none',
				//timeColor: '#e8e8e8',
				time:false,
				buttonColor: '#f7f7f7',
				buttonOverColor: '#eb7d24',
				sliderGradient: 'none',
				backgroundColor: '#333333',
				timeBgColor: '#262626',
				volumeSliderGradient: 'none',
				volumeSliderColor: '#4a4a4a',
				durationColor: '#595959',
				tooltipColor: '#C9C9C9',
				height: 20,
				opacity: 0,
				zIndex:1000
			}
		},
		
		play:{
			url: "http://uman.square-enix-europe.com/contents/NL_200910/flow/player_vid.png",
			width: 96,
			height: 96
		},
		
		onBeforeFullscreen: function()  {
			this.hide().pause();
			this.getControls().enable({fullscreen:null});
			currentPlayer="#"+this.id();
			$("div.overlay").overlay().load();
			return false;
		},
		
		onKeyPress: function(key) {
			if (key == 27) {
				$("div.overlay").overlay().close();
			}
		},
		
		onMouseOver: function() {
			this.getControls().animate({"opacity":1});
		},
		onMouseOut: function() {
			this.getControls().animate({"opacity":0});
		},

		clip: {
			scaling: 'fit',
			bufferLength:6,
			
			onMetaData: function(clip) {
				if (console)
					console.dir(clip);
			},
			
			onStart: function() {
				$.getJSON(
					"http://weblet.square-enix-europe.com/video.php?callback=?",
					{
						"URL":$f().getClip().completeUrl,
						"DOC":window.location.href,
						"ACTION":"start"
					},function(data) {
						if (console)
							console.dir(data);
					});
			},
		
			onPause: function() {
				$.getJSON(
					"http://weblet.square-enix-europe.com/video.php?callback=?",
					{
						"URL":$f().getClip().completeUrl,
						"DOC":window.location.href,
						"ACTION":"pause"
					},function(data) {
						if (console)
							console.dir(data);
					});
			},
			
			onResume: function() {
				$.getJSON(
					"http://weblet.square-enix-europe.com/video.php?callback=?",
					{
						"URL":$f().getClip().completeUrl,
						"DOC":window.location.href,
						"ACTION":"resume"
					},function(data) {
						if (console)
							console.dir(data);
					});
			},
			
			onLastSecond: function() {
				$.getJSON(
					"http://weblet.square-enix-europe.com/video.php?callback=?",
					{
						"URL":$f().getClip().completeUrl,
						"DOC":window.location.href,
						"ACTION":"lastsecond"
					},function(data) {
						if (console)
							console.dir(data);
					});
			},
			
			onFinish: function() {
				$.getJSON(
					"http://weblet.square-enix-europe.com/video.php?callback=?",
					{
						"URL":$f().getClip().completeUrl,
						"DOC":window.location.href,
						"ACTION":"finish"
					},function(data) {
						if (console)
							console.dir(data);
					});
			},
			
			onStop: function() {
				$.getJSON(
					"http://weblet.square-enix-europe.com/video.php?callback=?",
					{
						"URL":$f().getClip().completeUrl,
						"DOC":window.location.href,
						"ACTION":"stop"
					},function(data) {
						if (console)
							console.dir(data);
					});
			}
		},
		
		canvas: {
			backgroundGradient: 'none'
		},
		screen: {
			width:"100%",
			height:"100%",
			zIndex:0
		}

	}); //*/
	
	// setup overlay 
	$("div.overlay").overlay({ 
	 
		expose: '#000000',
		top: ($(window).height()-550)/2,
		closeOnClick: false,
 
		onLoad: function() {
 
			var embed = $(currentPlayer+" :first"); 
			var el = this.getContent(); 
			var height = el.height();
			var sY=$(window).scrollTop();
			var cssData={ 
				width:800, 
				height:450, 
				left: parseInt(el.css("left")) + 50, 
				top: parseInt(el.css("top")) + 50 
			}

			embed.css(cssData);
			
			$f().resume();
			
			$(window).scroll(function() {
				$(window).scrollTop(sY);				
			});//*/
		}, 
	 
		onClose: function() { 
			$(currentPlayer+" :first").css({top: null, left: null, width: null, height: null}); 
			$f().getControls().enable({fullscreen:true});
			$(window).unbind("scroll");
		} 
	});
	
	var indexes={
		"KHD":0,
		"DFF":1,
		"OOW":2,
		"GAMESCOM":3,
		"FFXIV":4,
		"FME":5
	},
	
	loc=window.location.href.split("#");
	if (loc[1]) {
		$f(indexes[loc[1]]).load();
	}
	
});

