// JavaScript Document


/*
hacer array en php con nombres de fondos
obtener aleatoriamente el número de elemento del array
y asignar esa imagen como body background mediante js
*/
var arrBG=['buzo.jpg','darsena.jpg','helicoptero.jpg','submarino.jpg','tracker.jpg','bg01.jpg'];
var bgimg = arrBG[Math.floor(Math.random()*arrBG.length)];


var videoCargado=false;
var idBotActivo='';
var divP;
var playerExist=false;
window.addEvent('domready', function(){	
	/*botOn('home');
	idBotActivo='home';*/
	ajustarPagina();	
	var varBody = $$('body')[0];
	varBody.setStyles({		
			backgroundImage: 'url(fondos/' + bgimg + ')'	
		});
});
window.addEvent('resize',function(){ajustarPagina();})
function ajustarPagina(){
	var fondoTop, fondoLeft
	var ancho=window.getWidth();
	var alto=window.getHeight();
	if (alto>586){
		fondoTop=Math.ceil((alto-586)/2)+30;
	}else{
		fondoTop=60;
	}
	if (ancho>800){
		fondoLeft=Math.ceil((ancho-800)/2);
	}else{
		fondoLeft=6;
	}
	
		
	$('fondo').setStyles({
		backgroundColor: '#000',
		opacity: 0.75,
		position: 'absolute',
		top: fondoTop,
		left: fondoLeft
	});
	
	var coords=$('fondo').getCoordinates();
	var contTop=coords.top;
	var contLeft=coords.left;
	
	$('contenedor').setStyles({
		zIndex: 2,
		width: 797,
		height: 585,
		position: 'absolute',
		top: contTop-42,
		left: contLeft
	});
	divP=$('contePlayer');
	if(typeof(divP)!='undefined' && divP!=null ){
		playerExist=true;
	}
	if(!videoCargado && playerExist){
		cambiarVideo();
	}
}

function cambiarVideo(clipFile){
	
	
	var divPlayer=$('contePlayer');
	divPlayer.innerHTML='<div id="player"></div>';
	if(clipFile != null){
		strVideoFile = 'http://www.bravozulu.com.ar/videos/'+ clipFile;
	}else{
		strVideoFile = 'http://www.bravozulu.com.ar/videos/P8 Bloque 01.flv';
	}
	
	var api = flashembed("player",
		{
			src:'http://www.bravozulu.com.ar/flowplayer/FlowPlayerDark.swf',
			width: 320, 
			height: 260
			/*width: 470, 
			height: 380*/
		},	
		{
			config: {   
			autoPlay: false,
			autoBuffering: true,
			controlBarBackgroundColor:'0x7E7E7E', //0x2e8860
			initialScale: 'scale',
			videoFile: strVideoFile,			
			usePlayOverlay: true,
			showMenu: false,
			loop: false
		}} 
	);
	videoCargado=true;

}
function ir(id){
	if(idBotActivo!=id){
		if(id!='home'){
			location.href=id + '.php';
		}else{
			location.href='./';
		}
	}
}
function botOn(id){
	if(idBotActivo!=id){
		$(id).setStyles({		
		backgroundImage: 'url(imgs/' + id + '-on.gif)'		
	});
	}
}
function botOff(id){
	if(idBotActivo!=id){
		$(id).setStyles({		
		backgroundImage: 'url(imgs/' + id + '-off.gif)'
		
	});
	}
}