// VideoPlayer
var FlashPlayer = new Class({

	Implements: [Events, Options],
	
	options: {
		videoClass: '',
		videoId: '',
		fallbackId: '',
		injectionTarget: undefined,
		siteUrl: '',
		videoPath: '',
		sources: undefined,
      src_application_assets : 'a/v/f/a/ApplicationAssets.swf',
		poster: '',
		width: -1,
		height: -1,
		params: null,
		
		quality: 'SD',
		
		autoplay: false,

		enableControls: true,
		//controlsEnabled: false,
		
		enableInfoScreen: true,
		//InfoScreenEnbabled: false,
		
		playing: false,
		loading: false,
		duration: undefined,
		startTime: undefined
	},
	
	flashVersion: '8',

	initialize: function(options){
		this.setOptions(options);
		
		/* Bei DecadeOne.com ist videoPath eine Globale... */
		/*
		var videoPath = videoPath;
		if(videoPath) {
			this.options.videoPath = videoPath;
		}		
		*/
		if($chk(this.options.injectionTarget)) this.options.injectionTarget.addClass('flash_player');
		this._build();
	},
	
	toElement: function(){ 
		return this.element; 
	},
	
	getVideoElement: function() {
		return this.element;
	},
	
	setNewOptions: function(options) {
		//this.stop();
		this.setOptions(options);
		this._destroy();
		this._build();
		if(this.options.autoplay) this.play();
	},
	
	setSource: function() {
		
	},
	
	setInjectionTarget: function() {
		
	},
	
	_build: function() {
		var fullVideoPath = this.options.siteUrl + this.options.videoPath;
		//console.log(this.options.sources[0].src);
		//this.element = new Element('div', {'class' : 'videoPlayer'});		
		//this.element.inject(this.options.injectionTarget);
		
		//console.log(this.options.sources.f4v.src_sd);
		
		var flashvars = {
			//'url': this.options.sources[0].src.replace("http://h264.sevenoneintermedia.de/", "rtmp://galileolexfs.fplive.net/galileolex/")
			//'src_sd': this.options.sources.f4v.src_sd,
			//'src_hd': this.options.sources.f4v.src_hd,
			'src_poster': this.options.poster,
			'src_application_assets': this.options.siteUrl + this.options.src_application_assets,
			'width': this.options.width,
			'height': this.options.height,
			'siteUrl': this.options.siteUrl,
			'autoplay': "false",
			'enableControls': this.options.enableControls,
			'enableInfoScreen': this.options.enableInfoScreen
		};
		var sources = this.options.sources;
		for (var key in sources) {
			if(sources[key].plattform == 'flash') {
				flashvars['src_sd'] = sources[key].src_sd;
				flashvars['src_hd'] = sources[key].src_hd;
				//console.log(flashvars['src_sd'] + ' - ' + flashvars['src_hd']);
				break;
			}
		}
				
		if(this.options.quality == 'SD') {
			flashvars.hd_off = true;
		}
		else if(this.options.quality == 'HD') {
			flashvars.hd_off = false;
		}

		var params = this.options.params;
		
		var attributes = {
			id: this.options.videoId,
			'class': this.options.videoClass
		};
		
		var swf = fullVideoPath + 'f/VideoPlayer.swf';
		var ei = fullVideoPath + 'f/expressInstall.swf';
		
		swfobject.embedSWF(swf, this.options.fallbackId, this.options.width, this.options.height, this.flashVersion, ei, flashvars, params, attributes, function(){});
	},
	
	_destroy: function() {
		if(this.element !== undefined) this.element = undefined;
		if(this.flashVideo !== undefined) this.flashVideo = undefined;
	},
	
	initEvents: function(){
	},
	
	togglePlay: function(){
	},
	
	toggleFullscreen: function () {
	},
		
	play: function(){
	},
	
	pause: function(){
	},

	stop: function(){
		if(Browser.ie) {
			document.getElementById('u7').stop();
		}
		else {
			Swiff.remote($('u7'), 'stop');	
		}
	},
	
	goToTimestamp: function(timestamp){		
		if(Browser.ie) {
			document.getElementById('u7').seek(timestamp);
		}
		else {
			Swiff.remote($('u7'), 'seek', timestamp);
		}
	},
	
	goToPercent: function(percent) {
	},
	
	volumeUp: function(){
	},
	
	volumeDown: function(){
	},
	
	setVolume: function(value){
	},
	
	toggleMute: function(){
	},
	
	showControls: function(value){
	},
	
	enableControls: function(flag) {
	}
});
