// inicializa las variables globales
var video=null;

//back to top
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

//carga una ventana popup para mostrar el video
function ventanavideo(videoclip){
	if(video==null || video.closed){
		video=window.open('', 'video', 'location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes,left=100,top=80,width=425,height=338');
        video.document.open();
		video.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
		video.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n");
		video.document.write("<head>\n");
		video.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n");
		video.document.write("<title>Terapias Metabólicas - ventana de video</title>\n");
		video.document.write("</head>\n");
		video.document.write("<body style=\"margin: -5px 0; padding:0; text-align:center;\">\n");
		video.document.write('<object width="425" height="350">\n<param name="movie" value="'+videoclip+'">\n</param><param name="bgcolor" value="#FFFFFF">\n</param><embed src="'+videoclip+'" type="application/x-shockwave-flash" bgcolor="#FFFFFF" width="425" height="350">\n</embed>\n</object>\n');
		video.document.write("</body>\n</html>\n");
		video.document.close();
		video.videoclip=videoclip;
	} else {
		if(video.videoclip!=videoclip) {
			video=null;
			ventanavideo(videoclip);
		}
	}
	video.focus();
}	

//acordeón con mootools
var load_method = (window.ie ? 'load' : 'domready');
window.addEvent(load_method, function(){
		// accordion
	var accordion = new Accordion('h3.acordeonTitulo', 'div.acordeonContenido', {
		alwaysHide: true,
		opacity: false,
		duration: 200,
		display: 0,
		show: 0,
		onActive: function(titulo){
			titulo.setStyle('background-position','bottom left');
			},
		onBackground: function(titulo){
			titulo.setStyle('background-position','top left');
			}
		}, $('acordeonContenedor'));
});