var DDSPEED = 5;
var DDTIMER = 20;
var OPENED = new Object();

var query = "";
// fileq_toがあるか
if(window.fileq_to){
    query = "?fileq_to=" + window.fileq_to;
}
if(window.fileq_name){
    var sep = query != "" ? sep = "&" : "?";
    query += sep + "fileq_name=" + window.fileq_name;
}
if(window.fileq_demo){
    var sep = query != "" ? sep = "&" : "?";
    query += sep + "fileq_demo=" + window.fileq_demo;
}
var url = "http://fileq.lisonal.com";
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\""+url+"/css/dropdown.css\" />");
document.write("<div class=\"dropdown\">");
document.write("    <div class=\"ddhead\" id=\"fileuploadform1-header\" onClick=\"menu('fileuploadform1');\"><img src=\""+url+"/images/FileQ_Blog.png\"></div>");
document.write("    <div class=\"ddcontent\" id=\"fileuploadform1-content\" style=\"border:1px solid #999999;\">");
document.write("        <iframe src=\""+url+"/jsp/blogparts.jsp"+query+"\" id=\"fileqiframe\" name=\"fileqiframe\" style=\"padding:0px;margin:0px;overflow:auto\" frameborder=0 scrolling=auto ></iframe>");
document.write("    </div>");
document.write("</div>");

var isIE = false;
function checkUA(){
    var ua = navigator.userAgent;
    if(ua.match(/MSIE/)){
        isIE = true;
    }
}

function setFrameSize(){
    checkUA();
    var iFrameHeight = 510;
    var iFrameWidth = 342;
    var pFrame = document.getElementById("fileqiframe");
    var pContent = document.getElementById("fileuploadform1-content");
    if(isIE){
        pFrame.style.height = iFrameHeight + 10 + "px";
        pFrame.style.width = iFrameWidth + "px";
        pContent.style.height = iFrameHeight + 9 + "px";
        pContent.style.width = iFrameWidth + "px";
    } else {
        pFrame.style.height = iFrameHeight + 52 + "px";
        pFrame.style.width = iFrameWidth + 35 + "px";
        pContent.style.height = iFrameHeight + 48 + "px";
        pContent.style.width = iFrameWidth + 2 + "px";
    }
}

window.onload = function(){
    setFrameSize();
}

// -------------------------------------------------------------------
// dropDown
// -------------------------------------------------------------------

function menu(id){
    if(OPENED[id] == undefined){
        OPENED[id] = false;
    }
    if(!OPENED[id]){
        OPENED[id] = true;
        ddMenu(id, 1);
    } else {
        OPENED[id] = false;
        ddMenu(id, -1);
    }
}

// main function to handle the mouse events //
function ddMenu(id, d){
    var h = document.getElementById(id + '-header');
    var c = document.getElementById(id + '-content');
    clearInterval(c.timer);
    if(d == 1){
        clearTimeout(h.timer);
        if(c.maxh && c.maxh <= c.style.height){
            return;
        } else if(!c.maxh){
            c.style.display = 'block';
            c.maxh = c.style.height.replace(/px/g, "") - 0;
        }
        c.timer = setInterval(function(){ddSlide(c, 1)}, DDTIMER);
    }else{
        c.maxh = c.style.height.replace(/px/g, "") - 0;
        h.timer = setTimeout(function(){ddCollapse(c)}, 10);
    }
}

// collapse the menu //
function ddCollapse(c){
    c.timer = setInterval(function(){ddSlide(c,-1)}, DDTIMER);
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c, d){
    var currh = c.offsetHeight;
    var dist;
    if(d == 1){
        dist = (Math.round((c.maxh - currh) / DDSPEED));
    }else{
        dist = (Math.round(currh / DDSPEED));
    }
    if(dist <= 1 && d == 1){
        dist = 1;
    }
    c.style.height = currh + (dist * d) + 'px';
    c.style.opacity = currh / c.maxh;
    c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
    if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
        clearInterval(c.timer);
    }
    if(c.style.opacity <= 0.1 && d != 1){
        c.style.opacity = 0;
        c.style.filter = 'alpha(opacity=0)';
        clearInterval(c.timer);
    }
}
