/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var x;

function mudaDestaque(num) {
    var aux = parseInt(num)+1;
    var prox = document.getElementById('content'+aux) ? parseInt(num)+1 : 0;
    num = document.getElementById('content'+num) ? num : 0;
    i = 0;
    while(document.getElementById('content'+i)) {
        document.getElementById('content'+i).style.opacity = 1;
        document.getElementById("ball"+i).setAttribute("src", "images/ball_red.png");
        document.getElementById("end_black"+i).style.display = "none";
        document.getElementById("black_div"+i).style.zIndex = 0;
        i++;
    }
    document.getElementById("black_div"+prox).style.zIndex = 99;
    document.getElementById("end_black"+prox).style.display = "block";
    document.getElementById("ball"+prox).setAttribute("src", "images/ball_green.png");
    clearTimeout(x);
    x = setTimeout("some("+num+")", 100);
}

function some(num) {
    if (document.getElementById('content'+num).style.opacity > 0) {
        var antes = document.getElementById('content'+num).style.opacity;
        document.getElementById('content'+num).style.opacity = parseFloat(document.getElementById('content'+num).style.opacity) - parseFloat(0.25);
        if (document.getElementById('content'+num).style.opacity == antes) {
            document.getElementById('content'+num).style.opacity = 0;
        }
        clearTimeout(x);
        x = setTimeout("some("+num+")", 100);
    } else {
        clearTimeout(x);
        x = setTimeout("aparece("+num+");", 100);
    }
}

function aparece(num) {
    var aux = parseInt(num)+1;
    var prox = document.getElementById('content'+aux) ? parseInt(num)+1 : 0;
    
    i = 0;
    while(document.getElementById('content'+i)) {
        document.getElementById('content'+i).style.display = "none";
        document.getElementById('content'+i).style.opacity = 1;
        document.getElementById("ball"+i).setAttribute("src", "images/ball_red.png");
        document.getElementById("end_black"+i).style.display = "none";
        document.getElementById("black_div"+i).style.zIndex = 0;
        i++;
    }
    document.getElementById("black_div"+prox).style.zIndex = 99;
    document.getElementById("ball"+prox).setAttribute("src", "images/ball_green.png");
    document.getElementById('content'+prox).style.display = "block";
    document.getElementById("end_black"+prox).style.display = "block";
    clearTimeout(x);
    x = setTimeout("mudaDestaque("+prox+");", 5000);
}

function muda(num) {
    var aux = parseInt(num)+1;
    var prox = document.getElementById('content'+aux) ? parseInt(num)+1 : 0;
    i = 0;
    while(document.getElementById('content'+i)) {
        document.getElementById('content'+i).style.display = "none";
        document.getElementById('content'+i).opacity = 1;
        document.getElementById("ball"+i).setAttribute("src", "images/ball_red.png");
        document.getElementById("end_black"+i).style.display = "none";
        document.getElementById("black_div"+i).style.zIndex = 0;
        i++;
    }
    document.getElementById("black_div"+num).style.zIndex = 99;
    document.getElementById("end_black"+num).style.display = "block";
    document.getElementById("ball"+num).setAttribute("src", "images/ball_green.png");
    document.getElementById('content'+num).style.display = "block";
    clearTimeout(x);
    x = setTimeout("mudaDestaque("+num+");", 5000);
}

function atualizar_campos(obj) {
    var xmlhttp;
    try{
        xmlhttp = new XMLHttpRequest();
    }catch(ee){
        try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                xmlhttp = false;
            }
        }
    }
    
    campo = obj.id;
    i = obj.selectedIndex;
    what = obj.options[i].value;

    xmlhttp.open("GET", "imovel.do.action.php?action=atualiza_campos&campo="+campo+"&what="+what,true);

    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            
        }
    }
    xmlhttp.send(null);
}
