var state = 2;
var amp1,amp2,amp3;

function sI(screenId, image) {	
	urlImage="#336699 url('../images/obras/" + image + ".jpg') no-repeat center center"
    $(screenId).setStyle({
		'background': urlImage
	});
	eval(screenId + "='" + image + "'");
}

function showLine(numLine) {
    var lineId = getLineObject(numLine);
    if (lineId !== null)
        lineId.style.display = "block";
}

function hideLine(numLine) {
    var lineId = getLineObject(numLine);
    if (lineId !== null)
        lineId.style.display = "none";
}

function getLineObject(numLine) {
    return $("line" + numLine);
}

function showBF(isShowed) {
    var bf = $("anterior");
    if (bf !== null) {
        bf.style.visibility = (isShowed)?"visible":"hidden";
    }
}

function showNXF(isShowed) {
    var nx = $("siguiente");
    if (nx !== null) {
        nx.style.visibility = (isShowed)?"visible":"hidden";
    }
}

function sBL() {
    if (state == 0) {
        showNXF(true);
        hideLine(5);
        showLine(2);
        state = 1;
    } else if (state == 1) {
        showBF(false);
        hideLine(4);
        showLine(1);
        state = 2;
    }
}

function sNL() {
    if (state == 2) {
        showBF(true);
        hideLine(1);
        showLine(4);
        state = 1;
    } else if (state == 1) {
        showNXF(false);
        hideLine(2);
        showLine(5);
        state = 0;
    }
}

function clearBorderColor(elements) {
    for (var i = 0; i < elements.length; i++) {
        elements[i].style.borderColor = "";
    }
}
/*
function getElementsbyXPath(xpath, parentE) {
if (isIe) {
   var results = [];
   var result1 = document.evaluate(xpath, $(parentE) || document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
   var item = result1.iterateNext();
   while (item) {
       results.push(item);
       item = result1.iterateNext()
   }
   return results;
} else {
   return document._getElementsByXPath(xpath, parentE);
}
}     */

function putWhiteBorderColorOnClick(minis) {

    //   var minisDespues = getElementsbyXPath(xpath, "contenido");

    minis.each(function(element) {
        element.onclick = function() {
            clearBorderColor(minis);
            this.style.borderColor = "#cc6633";
            this.parentNode.blur();
        }
    }
            );
}

function putOpenBigScript() {
    var extraLayer = $("extra");
    extraLayer.onclick = function() {
        this.style.display = "none";
        Element.hide("extrax");
    }
    var amps = new Array();
    amps[0] = $("amp1");
    amps[1] = $("amp2");
    amps[2] = $("amp3");
    var i,directionMove;
    Element.hide("extra");
    Element.hide("extrax");
    $("extrax").style.backgroundColor = "black";
    amps.each(function (element) {
        element.onclick = function () {
            Element.setOpacity("extrax", 0.7);
            Element.show("extrax");
            Element.hide("extra");			
			tempText="#336699 url(../images/obras/" + eval(this.id) + "_z.jpg) no-repeat center center";			

            switch (this.id) {
                case "amp1": directionMove = 'top-left';tempTop = "183px"; break;
                case "amp2": directionMove = 'top-left'; tempTop = "413px"; break;
                case "amp3": directionMove = 'bottom-left'; tempTop = "425px"; break;
            }			
			
			extraLayer.setStyle({
					top : tempTop,
            		background : tempText,
					left : '355px' 
			});	
			
            Effect.Grow("extra", {duration:1.0,direction:directionMove,opacityTransition:Effect.Transitions.linear});
        }
        element.onmouseover = function() {
            this.style.cursor = "pointer";
        }
    }
            );

    putWhiteBorderColorOnClick(getElementsMinis("fila1"));
    putWhiteBorderColorOnClick(getElementsMinis("fila2"));
    putWhiteBorderColorOnClick(getElementsMinis("fila3"));
}

function getElementsMinis(filaS) {
    var fila = document.getElementsByClassName(filaS);
    var filaImages = new Array();

    fila.each(function (fila) {
        var iconsAntes = document.getElementsByClassName("iconsAntes", fila);
        iconsAntes.each(function (icon) {
            var img = $A(icon.getElementsByTagName("img"));
            img.each(function (item) {
                filaImages.push(item);
            });
        });
        var iconsDespues = document.getElementsByClassName("iconsDespues", fila);
        iconsDespues.each(function (icon) {
            var img = $A(icon.getElementsByTagName("img"));
            img.each(function (item) {
                filaImages.push(item);
            });
        });
    });
    return filaImages;
}