var duration = 0.5;
var class_switch = "foldswitch";

/^(.*)img/.test($('logo').getElementsByTagName('img')[0].src);
var img_open = new Image();
img_open.src = RegExp.$1 + 'img/foldingswitch_open.jpg';
var img_close = new Image();
img_close.src = RegExp.$1 + 'img/foldingswitch_close.jpg';

var backgroundImage_open = 'url(' + img_open.src + ')';
var backgroundImage_close = 'url(' + img_close.src + ')';

var flg_fold = 'close';
var switches = document.getElementsByClassName(class_switch);

for(var i = 0 ; i < switches.length ; i++ ) {
    switches[i].style.height = switches[i].parentNode.clientHeight + "px";
}

function foldBox (iD) {
    var sw = $(iD).getElementsByClassName(class_switch)[0];
    if(flg_fold == 'close') {
        sw.style.backgroundImage = backgroundImage_open;
        sw.style.backgroundPosition = 'right center';
        sw.title = 'クリックで非表示にします';
        $(iD).morph('width : 300px;',
                    {
                        duration : duration
                    });
        flg_fold = 'open';
    }
    else if(flg_fold == 'open') {
        sw.style.backgroundImage = backgroundImage_close;
        sw.style.backgroundPosition = 'right center';
        sw.title = "クリックするとメニューが表示されます";
        $(iD).morph('width : 10px;',
                    {
                        duration : duration
                    });
        flg_fold = 'close';
    }
}
