
function BrowserCheck()
{
	var b = navigator.appName;

	if (b=="Netscape") this.b = "ns";
	else if (b=="Microsoft Internet Explorer") this.b = "ie";
	else this.b = b;

	this.version = navigator.appVersion;
	this.v = parseInt(this.version);

	this.ns  = (this.b=="ns" && this.v>=4);
	this.ns4 = (this.b=="ns" && this.v==4);
	this.ns5 = (this.b=="ns" && this.v==5);

	this.ie  = (this.b=="ie" && this.v>=4);
	this.ie4 = (this.version.indexOf('MSIE 4')>0);
	this.ie5 = (this.version.indexOf('MSIE 5')>0);
	this.ie6 = (this.version.indexOf('MSIE 6')>0);
	this.ie7 = (this.version.indexOf('MSIE 7')>0);

	this.min = (this.ns||this.ie);
	this.comp = (this.ns5||this.ie5||this.ie6);

	this.platf = navigator.platform.toUpperCase();
	this.linux = (this.platf.indexOf('LINUX')!=-1);
}

is = new BrowserCheck();

// depends on prototype
function changePngs() {
	if(is.ie6) {
		$$('img[src$=png]').each(function (img) {
				var src = img.src;
				img.src = "/img/1.gif";
				img.runtimeStyle.filter =
				 "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
					+src+"',sizingMethod='image')";
		})
	}
}

function pngBg(obj, src) {
	obj.style.filter =
		"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
		+ src + "', sizingMethod='crop')";

	obj.style.backgroundImage = 'url(/img/blank.gif)';
}

function pngBghoverize(obj, png0, png1)
{
	if(!obj) return;

	pngBg(obj, png0);

	Event.observe(obj, "mouseover", function(event) {
		pngBg(obj, png1); // closure
	});

	Event.observe(obj,  "mouseout", function(event) {
		pngBg(obj, png0);
	});
}

/*
	Esta funcion, soluciona -no de manera generica- el problema del
	flickering de background CSS combinado al uso de imagenes PNG en
	explorer 6.

	El flickering se soluciona mediante un truco propietario de MS,
	en vez de implementar sprites o doble fondo.

	El alpha de los PNG se soluciona mediante el filtro exspecifico de IE,
	pero esto anula el hover. Por ello tenemos que emularlo con JS, y
	lo hacemos explicitamente con los valores CSS necesarios, en este caso
	poner la imagen.
*/
function fixIE6()
{
	try {
		document.execCommand('BackgroundImageCache', false, true);
	}
	catch(e) {}

	if(is.ie6 || is.ie7) {
		pngBghoverize($$('#pager .prev a').first(),
			'/img/pager_prev0.png', '/img/pager_prev1.png');

		pngBghoverize($$('#pager .next a').first(),
			'/img/pager_next0.png', '/img/pager_next1.png');

		pngBghoverize($$('#pager .last a').first(),
			'/img/pager_last0.png', '/img/pager_last1.png');

		pngBghoverize($$('#pager .first a').first(),
			'/img/pager_first0.png', '/img/pager_first1.png');
	}
}

// depends on prototype too ;)
function processPopups() {
	$$('a.popup2').each(function(a) {
		Event.observe(a, "click", function(event) {
			var element = Event.element(event);
			popup(element.href);
			Event.stop(event);
		});
	});
}

var lastid;

function showsub(id)
{
	if(lastid==id) return;

	toggle(lastid);
	toggle(id);

	lastid = id;
	document.getElementById("video-options").className="clearfix on";
}

function mouseOut(event)
{
	if(is.ie) return;

	if (event.relatedTarget != null && (
		event.relatedTarget == event.currentTarget ||
		event.relatedTarget.childOf(event.currentTarget))) return;

	mouseLeave(event);
}

function mouseLeave(event)
{
	if(lastid) toggle(lastid);
	lastid = null;

	$('video-options').className="clearfix";
}

function toggle(id) {
	if(!id) return;

	$(id).toggleClassName('on');

	var sub = $("ul_"+id);
	if(sub) sub.toggle();
}

function writebig() {
	document.write(
		"<link rel='stylesheet' type='text/css' href='/styles/big.css'/>");
}

// opens a centered popup window
function popup(url) {
	var aw = screen.availWidth-10;
	var w = 560;
	var h = 540;

	xc=(aw-w)/2; // center

	features =
		'status=no,scrollbars=yes,menubar=no,toolbar=no,'+
		'location=no,directories=no,resizable=yes,copyhistory=no,'+
		'width='+w+',height='+h+','+
		'left='+xc+',top=0,screenX='+xc+',screenY=0';

	window.open(url, 'popup', features).focus();
}

function changeopacity(idvideo, onoff) {
	if(onoff==1) {
		document.getElementById(idvideo).className="imgactive";
	}
	else {
		document.getElementById(idvideo).className="";
	}
}
