var idMenMov;
var _iMenu;
var iPosX;
var	strLayerName;
var iIntervalLayer;
var iTrans;


// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
//	window.status = "xMousePos=" + xMousePos + ", yMousePos=" + yMousePos + ", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax;
}


strLayerName = "";
iTrans = 0;

function getRef(obj) { //devuelde el objeto entero en formato document.getElementByID
	if(typeof obj == "string")
		 obj= document.getElementById(obj);
	return obj;
}				
function goCrazyOld() {
	for (i=0; i<12; i++)
		document.getElementById("im"+i).src="../images/cubeoff.gif";
	total_cubes = Math.floor(Math.random()*12)
	if (total_cubes == 0) total_cubes++;
	for (i=0; i<total_cubes; i++) {
		num = Math.floor(Math.random()*12);
		while (document.getElementById("im"+(num%12)).src == "../images/cubeon.gif")
			num++;
		document.getElementById("im"+(num%12)).src="../images/cubeon.gif";
	}
}
function goIluminate(index) {
	if (index!=null) {
		getRef("tmenu"+index).style.color= "#FAA331";
	}
}
function goHideAll() {
	for (i=0; i<6; i++) {
		getRef("menu"+i).style.visibility="hidden";
		getRef("menu"+i).style.top = (87 - getRef("menu"+i).style.heigth);		
		clearInterval(idMenMov);
	}

}
function goAnimate() {
	iPosX+=3;
	getRef("menu"+_iMenu).style.top = iPosX;
	
	if (iPosX > 82)
		clearInterval(idMenMov);
}
function goShow(iMenu) {
	goHideAll();
	_iMenu = iMenu;	
	iPosX = (87 - getRef("menu"+iMenu).style.heigth);
	getRef("menu"+iMenu).style.visibility="visible";
	idMenMov = setInterval("goAnimate()",10 );
}

function goHideStatus() {
	window.status = "www.nispero.com :: Nísperos de Callosa d'En Sarrià";
	return true;	
}

function goOpenWindow(_url, _title, _width, _height) {
	var offset_vert;
	var offset_hor; 
	var especificaciones;

	offset_hor = (screen.width/2)-(_width/2);	
	offset_vert = (screen.height/2)-(_height/2);	
	especificaciones="top="+offset_vert+", left="+offset_hor+", toolbar=no,location=no, status=no,menubar=no,scrollbars=no, resizable=no, width="+_width+",height="+_height;
	
	window.open(_url,_title,especificaciones); 
}

function goCursorHand(obj) {
	obj.style.cursor = "hand";
}
function hideAllLayer() {
	getRef("dir1c").style.background = '#FFFFFF';
	getRef("dir2c").style.background = '#FFFFFF';
	getRef("dir3c").style.background = '#FFFFFF';
	getRef("dir4c").style.background = '#FFFFFF';
	getRef("dir5c").style.background = '#FFFFFF';
	getRef("dir6c").style.background = '#FFFFFF';
	getRef("dir7c").style.background = '#FFFFFF';

	getRef("dir1c").style.color = '#000000';
	getRef("dir2c").style.color = '#000000';
	getRef("dir3c").style.color = '#000000';
	getRef("dir4c").style.color = '#000000';
	getRef("dir5c").style.color = '#000000';
	getRef("dir6c").style.color = '#000000';
	getRef("dir7c").style.color = '#000000';

	getRef("dir1").style.visibility = "hidden";
	getRef("dir2").style.visibility = "hidden";
	getRef("dir3").style.visibility = "hidden";
	getRef("dir4").style.visibility = "hidden";
	getRef("dir5").style.visibility = "hidden";
	getRef("dir6").style.visibility = "hidden";
	getRef("dir7").style.visibility = "hidden";
}
function showLayer(_idLayer) {
	hideAllLayer();
	getRef(_idLayer).style.visibility = "visible";
	getRef(_idLayer+"c").style.background = "#FAA331";
	getRef(_idLayer+"c").style.color = "#FFFFFF";
}
function hideAllLayerComprar() {
	getRef("dir0").style.visibility = "hidden";
	getRef("dir1").style.visibility = "hidden";
	getRef("dir11").style.visibility = "hidden";
	getRef("dir12").style.visibility = "hidden";
	//getRef("dir2").style.visibility = "hidden";
	getRef("dir21").style.visibility = "hidden";
	getRef("dir22").style.visibility = "hidden";
	getRef("dir23").style.visibility = "hidden";
	getRef("dir24").style.visibility = "hidden";
	getRef("dir251").style.visibility = "hidden";
	getRef("dir252").style.visibility = "hidden";
	getRef("dir26").style.visibility = "hidden";
	getRef("dir27").style.visibility = "hidden";
	getRef("dir28").style.visibility = "hidden";
	getRef("dir29").style.visibility = "hidden";
	getRef("dir2a").style.visibility = "hidden";

//	getRef("dir3").style.visibility = "hidden";
//	getRef("dir31").style.visibility = "hidden";
//	getRef("dir32").style.visibility = "hidden";
//	getRef("dir4").style.visibility = "hidden";
//	getRef("dir5").style.visibility = "hidden";


}

function showLayerComprar(_idLayer) {
	hideAllLayerComprar();
	getRef(_idLayer).style.visibility = "visible";
}

function doTransLayer() {
	//filter:alpha(opacity="+i_strngth+")
	getRef(strLayerName).style.filter="alpha(opacity="+iTrans+")";
	iTrans +=15;
	if (iTrans >= 255) {
		clearInterval(iIntervalLayer);
		strLayerName="";
		iTrans = 0;
	}
}

function doAppearLayer(idLayer) {
	//alert("vivo");
	strLayerName = idLayer;		
	getRef(strLayerName).style.filter="alpha(opacity=0)";	
	getRef(strLayerName).style.visibility = "visible";
	clearInterval(iIntervalLayer);
	iTrans=0;
	iIntervalLayer = setInterval("doTransLayer()", 100);
}
function getImage(img) {
	getRef('texto_der').style.visibility = 'hidden';
	getRef('texto_der_aux').style.visibility = 'visible';
	getRef('texto_der_aux2').style.visibility = 'visible';
	getRef('ShowImg').src='../images/'+img+'.jpg';
}

function changeText(idLayer, strText) {
	getRef(idLayer).innerHTML = strText;
}
function goDisplay(idLayer) {
	objLayer=getRef(idLayer);
	if (objLayer.style.display == "none")
		objLayer.style.display = "Block";
	else
		objLayer.style.display = "none";
}

function goShowLayer(idLayer) {
	objLayer=getRef(idLayer);
	objLayer.style.display="";
}

function goHideLayer(idLayer) {
	objLayer=getRef(idLayer);
	objLayer.style.display="none";
}

function openPopup(URL,Name,features) { 
  window.open(URL,Name,'menubars, scrollbars');
}
