//<?
// pre-carga de imagenes
function preloadImg() {
	var doc = document;
	if(doc.images) {
		if(!doc.preLoaded) { doc.preLoaded = new Array(); }
		var aUrlImages = preloadImg.arguments;
		for(var x = 0; x < aUrlImages.length; x++) {
			var tmpImg = new Image();
			tmpImg.src = aUrlImages[x];
		}
	}
}

// cambia las imagenes
function swapImg(img, name) {
	if(name) {
		prevImg = img.src;
		img.src = 'theme/images/menu/'+name;
	} else {
		img.src = prevImg;
	}
}

window.onload = function () {
	preloadImg(
		'theme/images/menu/home_over.jpg',
		'theme/images/menu/cjl_over.jpg',
		'theme/images/menu/novedades_over.jpg',
		'theme/images/menu/anteriores_over.jpg',
		'vimages/menu/comunidades_over.jpg',
		'theme/images/menu/ngen_over.jpg',
		'theme/images/menu/galeria_over.jpg',
		'theme/images/menu/links_over.jpg'
	);
}


function overlay() {
	var $nHeight = Math["max"] (
			Math["max"](document.body["scrollHeight"], document.documentElement["scrollHeight"]),
			Math["max"](document.body["offsetHeight"], document.documentElement["offsetHeight"]),
			Math["max"](document.body["clientHeight"], document.documentElement["clientHeight"])
	);

	var $eOverlay = document.createElement("DIV");
	$eOverlay.id = "overlayMask";
	$eOverlay.style.position = "absolute";
	$eOverlay.style.top = "0px";
	$eOverlay.style.left = "0px";
	$eOverlay.style.padding = "0px";
	$eOverlay.style.margin = "0px";
	$eOverlay.style.textAlign = "center";
	$eOverlay.style.width = "100%";
	$eOverlay.style.height = $nHeight+"px";
	$eOverlay.style.backgroundColor = "#333333";
	
	if(navigator.appName=="Netscape") {
		$eOverlay.style["opacity"] = 0.75;
	} else if(navigator.appName=="Microsoft Internet Explorer") {
		$eOverlay.style["filter"] = "alpha(opacity:75)";
	} else {
		$eOverlay.style["KHTMLOpacity"] = 0.75;
	}
	
	document.body.appendChild($eOverlay);
}


function ajaxHandler() {
    var xmlhttp = false;
    try {
        $eHTTP = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        try {
            $eHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(E) {
            $eHTTP = false;
        }
    }

    if(!$eHTTP && typeof XMLHttpRequest!="undefined") {
        $eHTTP = new XMLHttpRequest();
    }

    return $eHTTP;
}


function loadVideo($sURL, $eTarget) {
    $eAjax = ajaxHandler(); 
    $eAjax.open("GET", $sURL, true); 
    
	$eAjax.onreadystatechange = function() {
        if($eAjax.readyState==1) {
            //Sucede cuando se esta cargando la pagina
            $eTarget.innerHTML = "cargando...";
        } else if($eAjax.readyState==4) {
            //Sucede cuando la pagina se cargó
            if($eAjax.status==200){
                //Todo OK
                $eTarget.innerHTML = $eAjax.responseText;
            } else if($eAjax.status==404) {
                //La pagina no existe
                $eTarget.innerHTML = "La pagina no existe";
            } else {
                //Mostramos el posible error
                $eTarget.innerHTML = "Error:".$eAjax.status; 
            }
        }
    }

    $eAjax.send(null);
}

function openVideo($sCode) {
	var $nWidth = Math["max"] (
			Math["max"](document.body["scrollWidth"], document.documentElement["scrollWidth"]),
			Math["max"](document.body["offsetWidth"], document.documentElement["offsetWidth"]),
			Math["max"](document.body["clientWidth"], document.documentElement["clientWidth"])
	);

	var $eDivPopup = document.createElement("DIV");
	$eDivPopup.id 						= "divPopup";
	$eDivPopup.style.position 			= "absolute";
	$eDivPopup.style.top 				= "160px";
	$eDivPopup.style.left 				= ($nWidth-450)/2+"px";
	$eDivPopup.style.padding 			= "0px";
	$eDivPopup.style.margin 			= "0px";
	$eDivPopup.style.textAlign 			= "center";
	$eDivPopup.style.width 				= "450px";
	$eDivPopup.style.height 			= "420px";
	$eDivPopup.style.backgroundColor 	= "#FFFFFF";
	$eDivPopup.style.color 				= "#000000";
	
	window.scrollTo(0,0);
	overlay();	
	document.body.appendChild($eDivPopup);
	loadVideo("video.php?mc="+$sCode, $eDivPopup);
}

function closeVideo() {
	var $eOverlay = document.getElementById("overlayMask");
	var $eDivPopup = document.getElementById("divPopup");
	
	$eOverlay.parentNode.removeChild($eOverlay);
	$eDivPopup.parentNode.removeChild($eDivPopup);
}
