function js_yt () {
	$ES('a.ytpop').addEvent ('click', function (e) {
		e = new Event(e).stop();
		js_divYT (this.hash.substr (1), this.hasClass ('publicidad'), this.hasClass ('pubpopup'));
		return false;
	});
}

function js_divYT (ydID, conPublicidad, conPubPopup) {
	if ($('divYT')) $('divYT').remove ()
	
	if (conPublicidad) {
		b = ydID.split ('|');
		ydID = b [0];
		ytPubli = b [1];
		ytPubId = b [2]
	}
	
	oDiv = document.createElement ('div');
	$(oDiv).setProperty ('id', 'divYT');
	$(oDiv).setStyles ({
		'background': '#7696E3',
		'border': '#7696E3 solid 4px',
		'font': 'bold 11px Arial',
		'overflow': 'hidden',
		'padding': '0',
		'position': (window.ie6 ? 'absolute' : 'fixed'),
		'text-align': 'center',
		'top': (window.ie6 ? document.body.parentNode.scrollTop+200 : '200px'),
		'left': (window.getWidth () - 425)/2,
		'width': '425px',
		'height': conPublicidad ? '390px' : '366px'
	});
	oClose = document.createElement ('img');
	$(oClose).src = 'img/frmno.gif';
	$(oClose).alt = 'cerrar';
	$(oClose).width = 13;
	$(oClose).height = 13;
	$(oClose).setStyles ({
		'background': '#D7DEF8',
		'border': '#7696e3 solid',
		'border-width': '0 0 4px 4px',
		'cursor': (window.ie ? 'hand' : 'pointer'),
		'position': 'absolute',
		'right': (window.ie6 ? -1 : 0),
		'z-align': 10000
	});
	$(oClose).addEvent ('click', function () { this.parentNode.remove (); });
	$(oDiv).adopt (oClose);
	
	oBig = document.createElement ('iframe');
	$(oBig).setProperty ('border', '0');
	$(oBig).setProperty ('frameborder', '0');
	$(oBig).setProperty ('scrolling', 'no');
	$(oBig).setProperty ('width', '425');
	$(oBig).setProperty ('height', '355');
	$(oBig).setProperty ('src', 'video.popup.php?v='+ ydID +'&w=425&h=366');
	$(oDiv).adopt (oBig);
	
	if (conPublicidad) {
		oPub = document.createElement ('a');
		$(oPub).setStyles ({
			'background': 'none',
			'border': 'none',
			'margin': '10px auto',
			'padding': 0,
			'width': 123, 'height': 35
		});
		$(oPub).setProperties ({
			'target': '_blank',
			'href': ytPubli +'?a='+ ytPubId
		});
		if (conPubPopup) {
			$(oPub).addEvent ('click', function (e) {
				e = new Event(e).stop();
				oPop = window.open (this.href, 'popupinfo', 'location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,screenX=0,screenY=0,width='+ screen.width +',height='+ screen.height);
				this.parentNode.remove ();
				return false;
			});
		}
		else $(oPub).addEvent ('click', function () { this.parentNode.remove (); });
		
		$(oPub).setHTML ('<img src="img.1024/ytdestacado.jpg" width="123" height="35" alt="+ información" border="0" />');
		$(oDiv).adopt (oPub);
	}

	$(oDiv).injectInside ('cuerpocen');
}

function js_ytbuscapub () {
	if (infProvincia = $ES('.inf_provincia')) infProvincia = (infProvincia [0] ? infProvincia [0].getValue () : false);
	if (infTematica = $ES('.inf_tematica')) infTematica = (infTematica [0] ? infTematica [0].getValue () : false);
	if (infTemas = $ES('.inf_tematica')) {
		infTemas.addEvent ('change', function () {
			window.location = $ES('.modbuscador').pop().action +'?t='+ this.getValue () + (infProvincia ? '&p='+ infProvincia : '');
		});
	}
	if (infProvs = $ES('.inf_provincia')) {
		infProvs.addEvent ('change', function () {
			window.location = $ES('.modbuscador').pop().action +'?'+ (infTematica ? 't='+ infTematica +'&' : '') +'p='+ this.getValue ();
		});
	}
	if ($('pro_submit')) {
		$('pro_submit').addEvent ('click', function (e) {
			e = new Event(e).stop();
			var propuesto = false;
			$ES('input[type=radio]').forEach (function (o) {
				if (o.checked) propuesto = o.getValue ();
			});
			if (!propuesto || $('pro_tematica').getValue () == 0) {
				alert ('Debe seleccionar un video y una temática');
				return false;
			}
			else this.form.submit ();
		});
	}
}

function js_infoPopUp () {
	if ($('piedestacado')) {
		$('piedestacado').addEvent ('click', function () {
			if (!$('divInfo')) {
				posTop = $('piedestacado').getTop () - 400;
				if (posTop < 100) posTop = 100;
				oDiv = document.createElement ('div');
				$(oDiv).setProperty ('id', 'divInfo');
				$(oDiv).setStyles ({
					'background': '#fff',
					'border': '#7696E3 solid 4px',
					'cursor': (window.ie ? 'hand' : 'pointer'),
					'font': 'bold 11px Arial',
					'overflow': 'hidden',
					'position': 'absolute',
					'text-align': 'center',
					'top': posTop,
					'left': '180px',
					'width': '620px',
					'height': '400px'
				});
				oDiv2 = document.createElement ('div');
				$(oDiv2).setStyles ({
					'cursor': (window.ie ? 'hand' : 'pointer'),
					'padding': '20px 0 0 0',
					'overflow': 'scroll',
					'width': '620px',
					'height': '400px'
				});
				$(oDiv2).setHTML (
					'<img src="img/popup-videotutor_cab.png" width="600" height="180" alt="Academias.com todas las academias y escuelas" />'
					+ '<img src="img/popup-videotutor_1.jpg" width="600" height="175" alt="Grabe todo lo que quiera" />'
					+ '<img src="img/popup-videotutor_2.jpg" width="600" height="170" alt="Editelo con Windows Movie Maker" />'
					+ '<img src="img/popup-videotutor_3.jpg" width="600" height="170" alt="Súbalo a Youtube" />'
					+ '<img src="img/popup-videotutor_pie.gif" width="600" height="126" alt="¡Listo! ya puee incorporar el vídeo a su publicidad en academias.com" />'
				);
				$(oDiv2).addEvent ('click', function () {
					js_divYT ('RpihVc0vREg');
					this.parentNode.remove ();
				});
				$(oDiv).adopt (oDiv2);
				
				oClose = document.createElement ('img');
				$(oClose).src = 'img/frmno.gif';
				$(oClose).alt = 'cerrar';
				$(oClose).width = 13;
				$(oClose).height = 13;
				$(oClose).setStyles ({
					'background': '#D7DEF8',
					'border': '#7696e3 solid',
					'border-width': '0 4px 4px 4px',
					'position': 'absolute',
					'right': (window.ie6 ? '19px' : '20px'),
					'top': 0,
					'z-align': 10000
				});
				$(oClose).addEvent ('click', function () { this.parentNode.remove (); });
				$(oDiv).adopt (oClose);
	
				$(oDiv).injectAfter ('piedestacado');
			}
			else $('divInfo').setStyle ('display', 'block');
		});
	}
}

window.addEvent ('domready', js_yt);
window.addEvent ('domready', js_ytbuscapub);