/* Script for making the buttons work */

/* Modify the first part as necessary to add/remove buttons */

// These are the button names (as in, the images are labeled "img/btn-NAME.png"
var buttonnames=["home","membership","student","community","gallery"];

// these are the submenu names and links
var subnamesHome = ["Welcome", "About the Club", "Who is St. Cecilia?", "Support"];
var sublinksHome = ["https://sites.google.com/site/cmcmemberinfo/homepage",
                    "http://sites.google.com/site/cecilianclub/about-us",
                     "http://sites.google.com/site/cecilianclub/st_cecilia",
                     "http://sites.google.com/site/cecilianclub/giving"];

var subnamesMem = ["Cecilian Notes", "Current Officers", "Join the Club", "Member Directory"];
var sublinksMem = ["http://sites.google.com/site/cmcmemberinfo/notes", "http://sites.google.com/site/cmcmemberinfo/officers", "http://sites.google.com/site/cmcmemberinfo/join", "http://sites.google.com/site/cmcmemberinfo/directory"];

var subnamesOpps = ["Young Artist Competition", "Monster Concert", 
                   "Cecilian Award Competition", "Student Showcase", 
                   "Cecilian Scholarship"];
var sublinksOpps = ["http://sites.google.com/site/cmcstudentopps/young-artist", "http://sites.google.com/site/cmcstudentopps/monster-concert", "http://sites.google.com/site/cmcstudentopps/cecilian-award", "http://sites.google.com/site/cmcstudentopps/showcase", "http://sites.google.com/site/cmcstudentopps/scholarship"];

var subnamesOutreach = ["Community Events", "Musical Hours"];
var sublinksOutreach = ["http://sites.google.com/site/cmcoutreach/main", "http://sites.google.com/site/cmcoutreach/music-hour"];

var subnamesGal = ["Gallery", "International Festivals", "Monster Concert Videos"];
//var subnamesGal = ["Blank", "Monster Concert Videos"];
var sublinksGal = ["gallery/index.html","http://sites.google.com/site/cmcmultimedia/italy-2008", "http://sites.google.com/site/cmcmultimedia/monster-concert-videos"];

// these are for the three links on the side
var specials = ["http://sites.google.com/site/cecilianclub/contact-us",
                "http://sites.google.com/site/cecilianclub/sitemap",
                "http://sites.google.com/site/cecilianclub/links"];

// add these to the main variable
// these need to be in the same order as the buttons on the left
var subnames = [subnamesHome, subnamesMem, subnamesOpps, subnamesOutreach, subnamesGal];
var sublinks = [sublinksHome, sublinksMem, sublinksOpps, sublinksOutreach, sublinksGal];

function anchormouseover(){
    // set the window status on link mouseover, so it doesn't say 'javascript:blahblah'
    // doesn't work on all browsers
    var anchors = document.getElementsByTagName('a');
    for (var i=0; i < anchors.length; i++) {
        anchors[i].onmouseover = function() {window.status = ''; return true;}
        anchors[i].onmouseout = function() {window.status = ''; return true;}
    }
}

function btnclick(n){
    buttonsetter(n);
    headreset(n,0);
    setInnerPage(n,0);
    anchormouseover();
}

function buttonsetter(n){
    var table = document.getElementById('navbar');
    var imgs = table.getElementsByTagName("img");
    
    for(var i=0; i < imgs.length; i++){
        img = imgs[i];
        if(i==n){
            img.src = "img/btn-" + buttonnames[i] + "-sel.gif";
        }
        else{
            img.src = "img/btn-" + buttonnames[i] + ".gif";
        }
        
    }
}

function speciallink(n){
    var iframe = document.getElementById("mainframe");
    headreset(0,0);
    buttonsetter(0);
    iframe.src = specials[n];
}

function headreset(n,i){
    var table = document.getElementById('submenu');
    var texts = subnames[n];
    table.deleteRow(0);
    var newrow = table.insertRow(0);
    
    newrow.className = "submenu";
    //cell = newrow.insertCell(0);
    //cell.className = "submenu";
    
    for(var j=0; j<texts.length; j++){
        cella = document.createElement("a");
        cella.href = "javascript:subbtnclicked(" + n + "," + j + ")";
        cella.innerHTML = texts[j];
        cell = newrow.insertCell(-1);
        cell.className = "text";
        cell.valign="middle";
        cella.className = "text";
        if(j==i){
            cell.className = "sel";
            cella.className = "sel";
        }
        cell.appendChild(cella);
    }
    cell = newrow.insertCell(-1);
    //cell.className = "submenu";
    //cell.width = '*';
    //setInnerPage(n,0);
    //table.insertRow(newrow);
}

function subbtnclicked(n,i){
    var table = document.getElementById('submenu');
    
    headreset(n,i);
    
    setInnerPage(n,i);
}

function setInnerPage(category,pg){
    var iframe = document.getElementById("mainframe");
    iframe.src = sublinks[category][pg];
}

function iframeload(){
    // This doesn't work - permission denied for getting the URL.
    // iframe.src is allowed, but doesn't update. Hmph.
    
    //var iframe = document.getElementById("mainframe");
    //alert('iframe');
    //var url = document.getElementById('MyIFrame').contentWindow. location.href;
    //alert(url);
    //var links = [];
    // 
    //for(var n=0; n<sublinks.length; n++){
    //    links = sublinks[n];
    //    for(var j=0; j<links.length; j++){
    //        
    //        if(url == links[j]){
    //            headreset(n,j);
    //            return;
    //        }
    //    }
    //}
};

