/***********************************************
 other item 関連
***********************************************/
var othersTimer;
var othersInterval = 10000;

function otherItem() {
    var target_url = '/printOtherItems.php?_others=';

    var otherCount = (document.getElementById('otherCount')) ? document.getElementById('otherCount').value : '';
    var otherGenre = (document.getElementById('otherGenre')) ? document.getElementById('otherGenre').value : '';
    var otherCategory = (document.getElementById('otherCategory')) ? document.getElementById('otherCategory').value : '';
    var otherDate = (document.getElementById('otherDate')) ? document.getElementById('otherDate').value : '';
    var otherWidth = (document.getElementById('otherWidth')) ? document.getElementById('otherWidth').value : '';
    var otherHeight = (document.getElementById('otherHeight')) ? document.getElementById('otherHeight').value : '';

    var board = document.getElementById('others');

    var d = new Date();

    target_url += '&count=' + otherCount;
    target_url += '&genre=' + otherGenre;
    target_url += '&category=' + otherCategory;
    target_url += '&date=' + otherDate;
    target_url += '&width=' + otherWidth;
    target_url += '&height=' + otherHeight;
    target_url += '&' + d.getTime();

    var funcRef = function(text_data) {
        var funcChangeText = function() {
            document.getElementById('others').innerHTML = text_data;
            fadeInWindow(board, 0);
            setListenersOtherItem();
        }

        fadeOutWindow(board, 100, null, funcChangeText);

    }
    req = new httpRequest( target_url, funcRef );
    req.doGet();

}

function setListenersOtherItem() {
    if (obj = document.getElementById('others')) {
        obj.style.width = "100%";
        clearTimeout(othersTimer);
        if (othersInterval > 0) {
            othersTimer = setTimeout(otherItem, othersInterval);
        }
    }
}

/***********************************************
 hige関連
***********************************************/
function hige(e) {
    var target_url = '/printHige?m=';

    var target_node;

    if (e.target) {
        target_node = e.target;
    } else {
        target_node = e.srcElement;
    }

    if (target_node.nodeName == "IMG") {
        target_node = target_node.parentNode;
    }

    var check_id = target_node.id;

    if (check_id == 'hige_up') {
        target_url += '1';
    } else if(check_id == 'hige_down') {
        target_url += '2';
    } else {
        return;
    }

    var hige_page = document.getElementById("hige_page").value;
    target_url += "&p=" + hige_page;

    if (document.getElementById("entry_id")) {
        var entry_id = document.getElementById("entry_id").value;
        target_url += "&e=" + entry_id;
    }

    var funcRef = function(text_data) {
        document.getElementById('hige').innerHTML = text_data;
        setListenersHige();
    }
    req = new httpRequest( target_url, funcRef );
    req.doGet();
}

function setListenersHige() {
    if ( btn_up=document.getElementById('hige_up') ) {
        addListener( btn_up, 'click', hige, false );
    }
    if ( btn_down=document.getElementById('hige_down') ) {
        addListener( btn_down, 'click', hige, false );
    }
}



/***********************************************
 初期設定
***********************************************/
function setListeners(e) {
    // for Namzu Hige
    setListenersHige();

    // for Other Item
    setListenersOtherItem();
}

addListener(window, 'load', setListeners, false );




/***********************************************
 追記部分折りたたみ
***********************************************/
function showHide(entryID, entryLink, htmlObj) {
    extTextDivID = ('Text' + (entryID));
    extLinkDivID = ('Link' + (entryID));
    if( document.getElementById ) {
        if( document.getElementById(extTextDivID).style.display ) {
            if( entryLink != 0 ) {
                document.getElementById(extTextDivID).style.display = "block";
                document.getElementById(extLinkDivID).style.display = "none";
                htmlObj.blur();
            } else {
                document.getElementById(extTextDivID).style.display = "none";
                document.getElementById(extLinkDivID).style.display = "block";
            }
        } else {
            location.href = entryLink;
            return true;
        }
    } else {
        location.href = entryLink;
        return true;
    }
}
