
// <input id="hide-inherited-methods" type="checkbox" /><label for="hide-inherited-methods">Hide inherited methods</label>


function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}



function init() {
    initOptions();
//     document.getElementBy
}

function initOptions() {
    var optionsContainer = document.getElementById('options');
    var markup = '<input id="hide-inherited-methods" type="checkbox"  /><label for="hide-inherited-methods">Hide inherited methods</label><img src="images/rounded-bottom-left.png" id="rounded-bottom-left" /><img src="images/rounded-bottom-right.png" id="rounded-bottom-right" />';
    optionsContainer.innerHTML = markup;
    readOptionsStateCookie();
    setTimeout(hookupOptions, 0);
}

var optionsState = [1];

function hookupOptions() {
    var checkbox, val;
//     checkbox = document.getElementById('hide-inherited-methods');
    var checkboxes = [
        [document.getElementById('hide-inherited-methods'), hideOrShowInheritedMethods, hideInheritedMethods, showInheritedMethods]
    ];
    for(var i = 0, j = checkboxes.length; i < j; ++i) {
        checkbox = checkboxes[i][0];
        val = optionsState[i];
        checkbox.onclick = checkboxes[i][1];
        checkbox.checked = val;
        if(val)
            checkboxes[i][2]();
        else
            checkboxes[i][3]();
    }
    
//     document.getElementById('hide-inherited-methods').onclick = hideOrShowInheritedMethods;
    // it may be checked already 
//     setTimeout(hideOrShowInheritedMethods, 100);
}

function updateOptionsStateCookie() {
    optionsState = [
        document.getElementById('hide-inherited-methods').checked ? 1 : 0
    ];
    createCookie('options', optionsState.join(','), 365);
}
function readOptionsStateCookie() {
    var cook = readCookie('options');
    if(cook) {
        optionsState = cook.split(",");
        for(var i = 0, j = optionsState.length; i < j; ++i) {
            optionsState[i] = parseInt(optionsState[i]);
        }
    }
}

function hideOrShowInheritedMethods() {
    if(this.checked)
        hideInheritedMethods();
    else
        showInheritedMethods();
    updateOptionsStateCookie();
}

function hideInheritedMethods() {
    var divs = document.getElementsByTagName('div'), div;
    for(var i = 0, j = divs.length; i < j; ++i) {
         div = divs[i];
         if(div.className.indexOf("inherited") != -1) {
             div.style.display = "none";
         }
    }
}
function showInheritedMethods() {
    var divs = document.getElementsByTagName('div'), div;
    for(var i = 0, j = divs.length; i < j; ++i) {
        div = divs[i];
        if(div.className.indexOf("inherited") != -1) {
            div.style.display = "block";
        }
    }
}


window.onload = init;


