window.addEvent('domready', function(){
	
	
	movies = [
			  	{el:'movie1_lnk', hover:'/movie1_over.jpg', width:280, height:155, movie:'http://www.youtube.com/v/VO1Mn3pubb0&hl=nl&fs=1&autoplay=1&enablejsapi=1&playerapiid='},
				{el:'movie2_lnk', hover:'/movie2_over.jpg', width:280, height:155, movie:'http://www.youtube.com/v/qz7WA5bewGw&hl=nl&fs=1&autoplay=1&enablejsapi=1&playerapiid='}
	];

	movies.each(function(mv){
		if($chk($(mv.el))){							
			var ml = $(mv.el);
			ml.adopt(new Element('img', {src: mv.hover, width:mv.width, height:mv.height, alt: ml.getElement('img').get('alt')}).setStyles({'opacity': 0, 'z-index': 2}));
			ml.addEvent('mouseenter', function(){
				ml.getLast().fade('in');
			});
			ml.addEvent('mouseleave', function(){
				ml.getLast().fade('out');
			});	
			ml.addEvent('click', function(e){
				e.stop();						
				var movie = new Movie();
				movie.show(mv.movie);			
			});
		}
	});
	
	if($chk($('imgs_block'))){
		img_focus('imgs_block');
	}
	
	if($chk($('face_imgs'))){
		img_focus('face_imgs');		
	}
		
});

function img_focus(el){
	$(el).getElements('li').each(function(child) {
		var siblings = child.getParent().getElements('li').erase(child);
		child.addEvents({
			mouseenter: function() { siblings.tween('opacity',0.5); },
			mouseleave: function() { siblings.tween('opacity',1); }
		});
	});	
}

var Movie = new Class({

	Implements: [Events, Options],
	
	options:{},

	initialize: function(){
		this.overlay = new Element('div',{'id':'video_overlay'}).setStyle('opacity', 0).inject('site_wrapper', 'after');
		this.wrapper = new Element('div', {'id':'video_wrapper'}).inject(this.overlay);	
		this.container = new Element('div', {'id':'video_container'}).inject(this.wrapper);
		this.close_btn = new Element('div', {'id':'video_close', 'title':'Sluiten', 'events':{ 'click': function(){this.close_movie();}.bind(this)}}).inject(this.wrapper);
		this.obj = null;
		
		this.resize_overlay();
		window.addEvent('resize', function(){this.resize_overlay();}.bind(this));
		
	},
	
	show: function(video){
		var vid = "fgc_movie";
		this.overlay.fade('in').retrieve('tween').chain(function(){
			this.obj = new Swiff(video + vid, {
				id: vid,				
				width: 560,
				height: 340,
				params: {
					wmode: 'opaque',
					bgcolor: '#000000'
				}								
			});
			this.obj.inject('video_container');
		}.bind(this));	
	},
	
	close_movie: function(){		
		//$('fgc_movie').stopVideo();
		this.overlay.dispose();
		/*this.overlay.fade('out').retrieve('tween').chain(function(){						
			this.container.set('html', '');														  
		}.bind(this));*/
		
	},
	
	resize_overlay: function(){
		var scrollSize = $(window).getScrollSize().y;
		var scrollTop = $(window).getScroll().y;
		this.overlay.setStyles({ 'height':scrollSize+scrollTop,'top':-scrollTop });
	}
});

function build_action_url(action){
	var url = window.location.href.toURI();
	var data = url.getData();
	data["action"] = action;
	url.setData(data, true);
	return url.toString();
}
