var noslide, player, currentime, contactformulier, pwformulier, val, valide;
var terugkoppeling=0; 
window.addEvent('load', function() {
	
	if(noslide!=1){
	data = {
			'3048661432_f14a94674e_b.jpg':{caption: 'Meditation Live' }, 
			'2296380793_03294eef18_b.jpg':{caption: 'Meditation Live' }, 
			'3009381945_69419a5bd3_o.jpg':{caption: 'Meditation Live' }, 
			'universum.jpg':{caption: 'Meditation Live' }, 
			'looking_down_on_earth.jpg':{caption: 'Meditation Live' }, 
			'm31_gendler_Nmosaic1.jpg':{caption: 'Meditation Live' }, 
			'00000162.jpg':{caption: 'Meditation Live' }, 	    
		    'jongen.jpg':{caption: 'Meditation Live' }, 
		    'meditation-hall_f2.jpg':{caption: 'Meditation Live' }
			    };
	var myShow = new Slideshow($('slideshow'), data, {duration: 1750, captions: false, controller: false, height: 200, hu: '/images/slideshow/', width: 950});
	}else{
	$('slideshow').setStyle("display", "none");	
	}
	
	behaviour()
	});

window.addEvent('domready', function() {
	toonmelding('klaar', 10);
	schalen();
});


window.addEvent('resize', function() {
	schalen();
});


function behaviour(){
	
$('sluiten').setStyle("opacity", "0.3");
	
	$('sluiten').addEvent('mouseover', function(event){
	$('sluiten').setStyle("opacity", "0.6");
	});
	
	$('sluiten').addEvent('mouseout', function(event){
	$('sluiten').setStyle("opacity", "0.3");
	});
	
	$('sluiten').addEvent('click', function(event){
	closePopup();
	});
	
	
}


function JWplayer(furl){
	pageTracker._trackEvent('Videos', 'JWplayer', furl);

	$('playerdiv').innerHTML='';
	var winDims 	= window.getCoordinates();
	$('bgdiv').setStyles({display:'block', width:winDims.width+"px", height:document.documentElement.scrollHeight+"px"});

	$('floatwindow').setStyles({width:'640px', display:'block'});
	

	(function(){
	//var winDims 	= window.getCoordinates();
	var floatDims 	= $('floatwindow').getCoordinates();

	fl				= (winDims.width/2)-(floatDims.width/2);;
	ft				= (winDims.height/2)-(floatDims.height/2);;
	$('floatwindow').setStyles({left:fl+'px', top:ft+'px'});
	$('sluiten').removeEvents('click');
	$('sluiten').addEvent('click', closefaq);
	;}).delay(100);
	
	var so = new SWFObject('/flvplayer/player.swf','deflvplayer','640','500','9','#ffffff');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addVariable('image','/images/verbinden.jpg');
	so.addParam('wmode','opaque');		  
	so.addVariable('backcolor','#000000');
	so.addVariable('frontcolor','#c0c0c0');
	so.addVariable('file', furl);
	so.addVariable("id", 'flvplayer');
	so.addVariable('autostart','true');
	so.write('floatcontent');
	}


function WMVplayer(furl, pd){
	pageTracker._trackEvent('Videos', 'WMVplayer', furl);
	//alert(furl);
	if(pd!='1'){
	$('playerdiv').innerHTML='';
	}
	var winDims 	= window.getCoordinates();
	$('bgdiv').setStyles({display:'block', width:winDims.width+"px", height:document.documentElement.clientHeight+"px"});

	$('floatwindow').setStyles({display:'block', width:'600px', height:'470px'});
	

	(function(){
	//var winDims 	= window.getCoordinates();
	var floatDims 	= $('floatwindow').getCoordinates();
	//alert(floatDims.h);
	fl				= (winDims.width/2)-(floatDims.width/2);
	ft				= (winDims.height/2)-(floatDims.height/2);
	$('floatwindow').setStyles({height: 500+'px', left:fl+'px', top:ft+'px'});
	$('sluiten').removeEvents('click');
	$('sluiten').addEvent('click', closefaq);
	;}).delay(100);
	
	
	cnt = $('floatcontent');
	src = "/wmvplayer/wmvplayer.xaml";
	//deurl = base64_decode(person.url);
	var cfg = {
			height:470,
			width: 600,
			backgroundcolor:'000000',
			id:'wmvplayer',
			file:furl,
			image:'http://www.meditation-live.eu/images/verbinden.jpg',
			start: '0',
			backcolor:'000000',
			frontcolor:'c0c0c0',
			lightcolor:'340b99',
			screencolor:'000000',
			logo:'http://www.meditation-live.eu/images/streamlogo.png',
			bufferlength:'15',
			overstretch:'false',
			autostart:'true',
			windowless:'true'
			};
	
	
	//cfg = {id: 'wmvplayer', windowless:'true',name:'wmvplayer', backcolor: '#000000', frontcolor: '#c0c0c0', volume:100, height:"470", width:"600", file:furl, image:'/images/verbinden.jpg', repeat: 'true', autostart:'true'};
	player = new jeroenwijering.Player(cnt,src,cfg);

	$('sluiten').removeEvents('click');
	$('sluiten').addEvent('click', closefaq);
	}


function FAQplayer(furl){
	pageTracker._trackEvent('Videos', 'FAQplayer', furl);
	$('playerdiv').innerHTML='';
	var winDims 	= window.getCoordinates();
	$('bgdiv').setStyles({display:'block', width:winDims.width+"px"});

	$('floatwindow').setStyles({display:'block', width: '950px'});
	

	(function(){
	//var winDims 	= window.getCoordinates();
	var floatDims 	= $('floatwindow').getCoordinates();

	fl				= (winDims.width/2)-(floatDims.width/2);
	ft				= (winDims.height/2)-(floatDims.height/2);
	$('floatwindow').setStyles({ left:fl+'px', top:ft+'px'});
	$('sluiten').removeEvents('click');
	$('sluiten').addEvent('click', closefaq);
	;}).delay(100);
	
	var so = new SWFObject('/flvplayer/player.swf','deflvplayer','950','555','9','#ffffff');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addVariable('image','/images/verbinden.jpg');
	so.addParam('wmode','opaque');		  
	so.addVariable('backcolor','#000000');
	so.addVariable('frontcolor','#c0c0c0');
	so.addVariable('file', furl);
	so.addVariable("id", 'faqplayer');
	so.addVariable('autostart','true');
	so.write('floatcontent');
	}





function liveMeditatie(container, fullscreen){
	 if($('centerplayer')){
	 $('centerplayer').addEvent('click', function(){
		centerwmvplayer();
		});
	 }
	 if(fullscreen==1){
		 var winDims= window.getCoordinates();
		 pheight	= winDims.height-50;
		 phwidth	= parseInt(pheight*1.276);
		 $('floatwindow').setStyles({width: phwidth, display:'block'});
	 }else{
		 pheight	= 450;
		 phwidth 	= 600;
	 }
	 
		//console.log(pheight); 
	 
	 	tijd=(currentime>0) ? parseInt(currentime) : 0;
	//var jsonRequest = new Request.JSON({url: "/index.php", onSuccess: function(person){
	//}}).post({module:'mediteren', ajaxrequest:'1', f:'getstr'});	
		//pageTracker._trackEvent('Videos', 'FLVplayer', 'livestream');
	// alert(tijd);	
	 	$clear(player);
		cnt = $(container);
		src = "/wmvplayer/wmvplayer.xaml";
		//deurl = "http://www.meditation-live.eu/media/candle.wmv";//base64_decode(person.url);
		var cfg = {
		height:pheight,
		width: phwidth,
		backgroundcolor:'000000',
		id:'ply',
		file:'http://www.meditation-live.eu/media/candle.wmv',
		image:'http://www.meditation-live.eu/images/verbinden.jpg',
		start:tijd,
		backcolor:'000000',
		frontcolor:'c0c0c0',
		lightcolor:'340b99',
		screencolor:'000000',
		logo:'http://www.meditation-live.eu/images/streamlogo.png',
		bufferlength:'5',
		overstretch:'false',
		autostart:'true'
		};
		
		//(function(){ 
		//player.sendEvent('play', 'true');
		//alert(cnt+" - "+src+" - "+cfg);
		//console.log(tijd);
		player = new jeroenwijering.Player(cnt,src,cfg);
		
		(function(){ 
			addListeners() 
		}).delay(200);

	
		
		
		terugkoppeling=melding.periodical(5000); 
	
	/*
		terugkoppeling=melding.periodical(5000, 'aass'); 
		new Request.HTML({url:'/index.php', update: 'terugkoppeling'}).post({module:'mediteren', ajaxrequest:'1', f:'updateMelding'});
		(function(){ schalen();}).delay(1000);
	 */
		
	}


var melding = function(){ 
	if($('antwoordveld')==undefined || $('antwoordveld').value==''){
	new Request.HTML({url:'/mediteren/updateMelding', update: 'terugkoppeling'}).post({module:'mediteren', ajaxrequest:'1', f:'updateMelding'});
	}
	}

function addListeners() {
	if(player.view) {
		player.addListener('TIME',timeUpdate);
	} else {
		setTimeout(addListeners,100);
	}
};


function timeUpdate(time) { 
	currentime=time;
};



function schalen(){
	if(!Browser.Engine.trident){
	$('wrapper').setStyle('height', document.documentElement.scrollHeight-2);
	}	
}


function UserOpties(){
	
	new Asset.javascript('/js/SimpleTabs.js', {id: 'SimpleTabs'});
	
	var tabIndex=(Cookie.read('selectedTab')!=null)? Cookie.read('selectedTab') : '0' ; 
	(function(){ 
	new SimpleTabs($('tabbladen'), {show: tabIndex, selector: 'li a'});
	$('tabbladen').setStyle('display', 'block');
	}).delay(600);
	
//(function(){$('tabbladen').setStyle('display', 'block'); }).delay(800);
	/**/
}



function centerwmvplayer(){
	$('playerdiv').innerHTML='';
	

	
	//createPlayer("floatcontent", uurl, "true");
	liveMeditatie("floatcontent", 1);
	
	
	(function(){
	var winDims 	= window.getCoordinates();
	var floatDims 	= $('floatwindow').getCoordinates();

	fl				= parseFloat((winDims.width/2)-(floatDims.width/2));
	ft				= (winDims.height/2)-(floatDims.height/2);;
	//alert(fl+" - "+winDims.width+" - "+floatDims.width);
	$('floatwindow').setStyles({left:fl+'px', top:ft+'px'});
	$('bgdiv').setStyles({display: 'block', height: document.documentElement.scrollHeight});
	
	$('sluiten').removeEvents('click');
	$('sluiten').addEvent('click', closePopup);
	}).delay(100);
	
	//console.log(+" - "+$('bgdiv').getStyle('height'));
	}

function closefaq(){
	$('floatwindow').setStyles({display:'none'});	
	$('bgdiv').setStyle('display', 'none');
	$('floatcontent').innerHTML='';
	}


function closePopup(){
	$('floatwindow').setStyles({display:'none', height:'0', width:'0'});	
	$('bgdiv').setStyles({display: 'none', height:'0', width:'0'});
	$('floatcontent').innerHTML='';

	liveMeditatie("playerdiv", 0);
}

function leegmelding(){
	$('loader').removeClass('ajax-loading').set('text','');
	$('load').style.display='none';
	
}


function toonmelding(txt, tijd){
	$('loader').addClass('ajax-loading').set('text',txt);
	$('load').style.display='block';
	leegmelding.delay(tijd);
}

function email(naam, email){
	document.location.href="mailto:"+naam+"<"+email+">";
}

function wachtwoord(uitloggen){
	toonmelding(uitloggen, 1000);
	(function(){
	new Request.HTML({url:'/mediteren/uitloggen/', update: 'response'}).post({ajaxrequest:1});	
	}).delay(5500);
}

function alternatieve_spelers(){
$clear(terugkoppeling);
$('terugkoppeling').removeClass('ajax-loading');
new Request.HTML({url:'/mediteren/alternatieve_spelers', update: 'terugkoppeling'}).post({ajaxrequest:1});	
}
