var player = null; 

var fullscreencoords = {'top': 0,'left': 0,'height': "100%",'width': "100%"};
var smallscreencoords = {};
var isfullscreen = false;
var targetlocation = '';
var myVideoCounter;

function playerReady(obj) {
	// Nur für den Flupperplayer aktivieren
	if (obj['id']=="flupperplayer"){
		player = document.getElementById(obj['id']);
		player.addViewListener("fullscreen","change_stretching_mode");
		if (showCounter){
			// Nur wenn der Counter aktiviert ist
	
			player.addModelListener("TIME","playerMediaTime");
			
		}
	}
};
function change_stretching_mode(obj) {
	document.location = targetlocation;
}
function playerMediaTime(object){
	myVideoCounter.setTime(object.position,object.duration);
	if(object.position == object.duration){ //wenn video zu ende
		//setURLonTop();	//setze url auf das video drauf - function noch nicht ausprogrammiert.
	}
}



window.addEvent('domready', function(){
if (showCounter){
	// Nur wenn der  Counter aktiviert ist
	myVideoCounter = new VideoCounter($('sidebar'));
}
if ($('videoflupper')){
// Inhalte Einlesen
var images = Array();
var imagecount = 0;
$('videoflupper').getElements('li.videoflupperitem').each(function(item,index){
    var tempdata={
		src:item.getElement('img').getProperty('src'), 
		title:item.getElement('div.videofluppershowurl').getProperty('html')+'<h2>'+item.getElement('h2').getProperty('html')+'</h2>'+item.getElement('div.videoflupperitemshortdesc').getProperty('html'), 
		href:item.getElement('a.videolink').getProperty('rel'), 
		alt:item.getElement('a.videolink').getProperty('href')
	};
	imagecount++;
	images.push(tempdata);
	
});
var imagesArray = {"images":images};
if (startIndex > imagecount){
	startIndex = imagecount-1;

}





// Mooflow erweitern
var LukasFlow = new Class ({
	Extends: MooFlow,
	options: {
		onGlideClick: $empty
	},
	glideTo: function(index){
		this.index = index;
		this.aniFx.start(this.aniFx.get(), index*-this.foc);
		if(this.cap) this.cap.set('html', this.getCurrent().title);
		this.fireEvent('onGlideClick');
	},
	process: function(x){
		var z,W,H,zI=this.iL,foc=this.foc,f=this.factor,sz=this.sz,oW=this.oW,offY=this.offY,div,elh,elw;
		this.master.images.each(function(el){
			div = el.div.style;
			elw = el.width;
			elh = el.height;
			if(x>-foc*6 && x<foc*6){
				with (Math) {
					z = sqrt(10000 + x * x) + 100;
					H = round((elh / elw * f) / z * sz);
					W = round(elw * H / elh);
					if(H >= elw * 0.5) {W = round(f / z * sz);}
					div.left = round(((x / z * sz) + sz) - (f * 0.5) / z * sz) + 'px';
					div.top = round(oW * 0.4 - H) + offY/2 + 'px';
					// Lukas
					div.top = abs(round(x / 9.5))+'px';
					
				}	
				el.con.style.height = H*2 + 'px';		
				div.width = W + 'px';
				div.zIndex = x < 0 ? zI++ : zI--;
				div.display = 'block';
			} else {
				div.display = 'none';
			}
			x += foc;
		});
	}


});


var mf = new LukasFlow($('videfluppercontainer'), {
		startIndex: startIndex,
		bgColor: 'transparent',
		factor: 200,
		reflection: 0,
		useCaption: 1,
		offsetY: -50,
		useCaption: true,
		useMouseWheel: true,
		useKeyInput: true,
		useViewer: true,
		onGlideClick: function() {
			if (myVideoCounter) {myVideoCounter.setTime(0,0);}
			this.myVideoplayerContainer.empty();
			this.myPlaybutton.show();
		},
		onStart: function() {
			this.myPlaybutton = new Element('div',{
				id: 'myplaybutton',
				styles: {
					cursor: 'pointer',
					position: 'absolute',
					background: 'transparent url(/typo3conf/ext/lusan_videoflupper/res/video_arrow.png) no-repeat 50% 50%',
					'z-index': '2000'
				},
				events: {
					click: function(){this.fireEvent('clickView')}.bind(this)
				
				}
			}).inject(this.MooFlow);
			this.leftbutton = new Element('div',{
				id: 'leftutton',
				events: { click: function(){this.prev()}.bind(this)},
				styles: {
					position:'absolute',
					height: '300px',
					width: '60px',
					top: '0px',
					left: '0px',
					cursor: 'pointer'
				}
			}).inject(this.MooFlow.getParent());
			this.rightbutton = new Element('div',{
				id: 'rightutton',
				events: { click: function(){this.next()}.bind(this)},
				styles: {
					position:'absolute',
					height: '300px',
					width: '60px',
					top: '0px',
					right: '0px',
					cursor: 'pointer'
				}
			}).inject(this.MooFlow.getParent());
		},
		onEmptyinit: function(){
			this.master = imagesArray;
			this.clearMain();
			this.fireEvent('request', imagesArray);
			this.myVideoplayerContainer = new Element('div',{
						'id':'myVideoplayerContainer',
						'styles': {
							'top': 0,
							'left': 158,
							'height': 185,
							'width': 317,
							'position':'absolute',
							'z-index':1000
						}
					}).inject(this.MooFlow);
			


		},
		onClickView: function(clickedImage){
			// Wenn es ein Pagelink ist:
			if (this.master.images[this.index].href=="PAGELINK"){
				document.location = this.master.images[this.index].alt;
			}
			else {
			var myCoords = this.MooFlow.getElements('img')[this.index].getCoordinates(this.MooFlow);
			smallscreencoords={'top': myCoords.top,'left': myCoords.left,'height': myCoords.height,'width': myCoords.width};
			targetlocation = this.master.images[this.index].alt;
			this.myVideoPlayer = new Swiff(lusan_assetspath+'javascript/videoplayer/player.swf',{
						id:"flupperplayer",  
						width: "100%",
						height: "100%",	
						container: this.myVideoplayerContainer,
						properties: {
							name:"flupperplayer"
						},
						vars: {
							stretching: 'exactfit',
							file : this.master.images[this.index].href,
							autostart : true
						}
			});
			
			this.myPlaybutton.hide();
			}	
		}
});
}

//cb: height von div.tx-lusanvideoflupper-pi1 verringern
$$('.tx-lusanvideoflupper-pi1').setStyle('height','300px');

}); 




