var cur1;
var cur2;

var curobj=null;
var timeoutid=null;
var obj;


window.onload = function() {
    init();
    ctr = document.getElementsByTagName("td");
    for ( i=0; i<ctr.length; i++ )
    {
        if (ctr[i].className == "btn")
        {
            ctr[i].onmouseover = function()
            {
                this.className = "selbtn";
            }
            ctr[i].onmouseout = function()
            {
                this.className = "btn";
            }
        }

        //        if (ctr[i].className == "btn2")
        //        {
        //            ctr[i].onmouseover = function()
        //            {   
        //                obj = this;
        //                timeoutid = window.setTimeout(function(){
        //                    if (curobj != null){
        //                        curobj.className = "btn2";
        //                        tmp = document.getElementById("a_" + curobj.id);
        //                        tmp.style.color = "#ffffff";
        //                    }
        //                    curobj = obj;
        //                    obj.className = "selbtn2";
        //                    tmp = document.getElementById("a_" + obj.id);
        //                    tmp.style.color = "#333333";
        //                    tmp.click();
        //                    clearTimeout(timeoutid);
        //                },500);
        //                              
        //            }
        //            ctr[i].onmouseout = function()
        //            {   
        //                clearTimeout(timeoutid);
        //                              
        //            }
        //            ctr[i].onclick = function()
        //            {   
        //                if (curobj != null){
        //                    curobj.className = "btn2";
        //                }
        //                curobj = this;
        //                this.className = "selbtn2";
        //                tmp = document.getElementById("a_" + this.id);
        //                tmp.click();
        //                tmp.style.color = "#333333";
        //                clearTimeout(timeoutid);                              
        //            }
        //
        //        }

        if (ctr[i].className == "probtn")
        {
            ctr[i].onclick = function()
            {
                $$('.onprobtn').each(function(e){e.removeClassName('onprobtn')});
                this.className = "onprobtn";
            }
        }

        if (ctr[i].className == "onprobtn")
        {
            ctr[i].onclick = function()
            {
                $$('.onprobtn').each(function(e){e.removeClassName('onprobtn')});
                this.className = "onprobtn";
            }
        }
        
    }

    $$('.btn2_un').each(function(e){
        e.observe('click', function(ev){
            id = ev.element().id;
            i = id.substr(id.indexOf('_')+1);
            btn2active(i);
        })
        e.observe('mouseover', function(ev){
            id = ev.element().id;
            i = id.substr(id.indexOf('_')+1);
            timeoutid = setTimeout(function(){btn2active(i)}, 1000);
        })
        e.observe('mouseout', function(ev){
            clearTimeout(timeoutid);
        })
    })
}

function btn2active(n)
{
    $$('.btn2_visit').each(function(e){e.removeClassName('btn2_visit')});
    $('btn2_'+n).addClassName('btn2_visit');
    new Ajax.Updater('intro_div', '/pages/get_intro/' + n, {
        asynchronous:true, 
        evalScripts:true, 
        parameters:'authenticity_token=' + encodeURIComponent('e93deb333338acdaed120290ba2762ed3606ecf9')
    });
}
