var video_width = 446;
var video_height= 251;
var logo = {width:573,height:114};
var browserwidth;
var browserheight;
var myViewer;
window.addEvent('domready', function(){
	window.resizeTo(screen.availWidth,screen.availHeight);
	window.moveTo(0,0);
	
	//loadContent('/slideshowplayer.php','twocols');
	resizeVideo();	
	window.addEvent('resize', function(){ 
		resizeVideo();
	});
	
	$$('#morefilms .internal').each(function(item,index){
		
			item.addEvent('click',function(e){
				e.stop();
				//myViewer = null;
				
				loadContent(this.href,'twocols');
				resizeVideo();	
			});
		
	});
});

function resizeVideo(){
	browserwidth = $(document).getSize().x;
	browserheight = $(document).getSize().y;
  
  	var video_zone = browserwidth * 0.7;
	var logo_zone = browserwidth *0.22;
	
	//resize uniquement si l'écran est plus grand que 960;
	
	if(browserwidth>=960){
	
		if(video_zone/browserheight < video_width/video_height){
			if($('vimeo')!=null){
				$('vimeo').setStyles({
					'width':video_zone,
					'height':	Math.round(( video_zone * video_height )/video_width) ,
					'top':Math.round(browserheight/2 - (Math.round(( video_zone * video_height )/video_width)/2))
				});
			}else if($('slideshow')!=null){
				$('slideshow').setStyles({
					'width':video_zone,
					'height':	Math.round(( video_zone * video_height )/video_width) ,
					'top':Math.round(browserheight/2 - (Math.round(( video_zone * video_height )/video_width)/2))
				});
				$$('#box1 img').each(function(item,index){
					item.setStyles({
						'width':video_zone,
						'height':	Math.round(( video_zone * video_height )/video_width) 
					});
				})
			}
			$('logo').setStyles({
				'width':logo_zone,
				'height':Math.round(( logo_zone * logo.height )/logo.width)
				})
				
			$('navigation').setStyles({
				'height':Math.round(( video_zone * video_height )/video_width),
				'top':Math.round(browserheight/2 - (Math.round(( video_zone * video_height )/video_width)/2))
				})
				}
		
		if(browserheight/video_zone < video_height/video_width){
			if($('vimeo')!=null){
				$('vimeo').setStyles({
					'width':Math.round(( browserheight * video_width )/video_height),
					'height':browserheight
				});
			}else if($('slideshow')!=null){
				$('slideshow').setStyles({
					'width':Math.round(( browserheight * video_width )/video_height),
					'height':browserheight
				});
				$$('#box1 img').each(function(item,index){
					item.setStyles({
						'width':Math.round(( browserheight * video_width )/video_height),
						'height':browserheight
					});
				})
				
				}
			$('navigation').setStyles({
				'height':(browserheight-2)
				})
		} 
		
	}
	
	
}

function loadContent(address,div)
{
	var options = {
		url: address, 	
		method : 'get', 
		update: $(div),
		evalScripts: true,					
		onRequest: function() {	
			$(div).innerHTML='loading';
		},									
		onSuccess: function() {	
			resizeVideo();
		}
	};									
	var monObjetAjax= new Request.HTML(options);
	monObjetAjax.send();
}
