
var dialogFirst=true;
function dialog(title,content,width,height,cssName){
    contentType = content.substring(0,content.indexOf(":"));
    content = content.substring(content.indexOf(":")+1,content.length);
    if(dialogFirst==true){
        var temp_float=new String;
        temp_float="<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";
        temp_float+="<div id=\"floatBox\" class=\"floatBox\">";
        temp_float+="<div class=\"title\"><p></p><span></span></div>";
        temp_float+="<div class=\"content\"></div>";
        temp_float+="<iframe width=\"450\" height=\"390\" frameborder=\"0\" style=\"position:absolute; top:5px;filter:alpha(opacity=0);opacity:0;-moz-opacity:0; left:5px; z-index:-1;\"></iframe>";
        temp_float+="</div>";
        $("body").append(temp_float);
        dialogFirst=false;
    }

    $("#floatBox .title span").click(function(){
        $("#format_base").html($("#format").html());
        $("#hardware_base").html($("#hardware").html());
        $("#hardware_base").attr("value", $("#hardware").val());
        $("#format_base").attr("value", $("#format").val());
        $("#"+content+"").html($("#floatBox .content").html());
        set_base_val("VideoEncList");
        set_base_val("Resolutions");
        set_base_val("VideoBitrates");
        set_base_val("FrameRates");
        set_base_val("AudioEncList");
        set_base_val("AudioBitrates");
        set_base_val("SampleRates");
        set_base_val("Channels");
        set_base_val("Zoom");
        set_base_val("Norm");
        set_base_val("FourCC");
        set_base_val("Format");
        $("#floatBox .content").html("");
        $("#floatBoxBg").animate({
            opacity:"0"
        },"normal",function(){
            $(this).hide();
        });
        $("#floatBox").animate({
            top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px"
        },"normal",function(){
            $(this).hide();
        });
    });

    $("#floatBox .title p").html(title);
    
    switch(contentType){
        case "url":
            var content_array=content.split("?");
            $("#floatBox .content").ajaxStart(function(){
                $(this).html("loading...");
            });
            $.ajax({
                type:content_array[0],
                url:content_array[1],
                data:content_array[2],
                error:function(){
                    $("#floatBox .content").html("error...");
                },
                success:function(html){
                    $("#floatBox .content").html(html);
                }
            });
            break;
        case "text":
            $("#floatBox .content").html(content);
            break;
        case "id":
            $("#floatBox .content").html($("#"+content+"").html());
            $("#"+content+"").html("");
            $("#hardware").attr("value", $("#hardware_base").val());
            $("#format").attr("value", $("#format_base").val());
            break;
        case "iframe":
            $("#floatBox .content").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
    }
  
    $("#floatBoxBg").show();
    $("#floatBoxBg").animate({
        opacity:"0.5"
    },"normal");
    $("#floatBox").attr("class","floatBox "+cssName);
    $("#floatBox").css({
        display:"block",
        left:(($(document).width())/2-(parseInt(width)/2))+"px",
        top:($(document).scrollTop()-(height=="auto"?300:parseInt(height)))+"px",
        width:width,
        height:height
    });
    $("#floatBox").animate({
        top:($(document).scrollTop()+100)+"px"
    },"normal");
}

function set_base_val(id) {
    $("#" + id + "_base").val($("#" + id).val());
}
