/*
 * Detail Modal Dialog
 *
 * For index.html to intitial on load.
 *
 */
    var flag_report_0 = true;
    var flag_report_1 = true;
    var flag_report_2 = true;
    var flag_report_3 = true;
    var flag_report_4 = true;
    var flag_report_5 = true;
    var flag_report_6 = true;

    var flag_report_0FirstTime = true;
    var flag_report_1FirstTime = true;
    var flag_report_2FirstTime = true;
    var flag_report_3FirstTime = true;
    var flag_report_4FirstTime = true;
    var flag_report_5FirstTime = true;
    var flag_report_6FirstTime = true;

    var flag_report_wedget = true;
    
    $(document).ready(function(){
        init();
    });
    function init(){
        //make tab
        $("#menu_tab ul").tabs({fx: { height: 'toggle', opacity: 'toggle', duration: 200 }});

        $('.ui-tabs-nav').bind('tabsshow', function(event, ui) {
        //--DO EVERY TIME
            // Objects available in the function context:
            //ui.options // options used to intialize this widget
            //ui.tab     // anchor element of the selected (clicked) tab
            //ui.panel   // element, that contains the selected/clicked tab contents
            //ui.index   // zero-based index of the selected (clicked) tab

            $("#div_wgWebAttackQuery").children().remove();//DO EVERY TIME--
            $("#div_wgWebAttackQuery").empty();
            $("#div_wgPhishingQuery").children().remove();
            $("#div_wgPhishingQuery").empty();
            $("#div_wgPhishingQuery").children().remove();
            $("#div_wgSpamQuery").empty();
            $("#div_wgSpamQuery").children().remove();
            $("#div_wgMalwareQuery").empty();
            $("#div_wgMalwareQuery").children().remove();
            $("#div_wgMalwareQuery").empty();
            //--DO EVERY TIME

            if(ui.index == 2)
            {
                if(flag_report_1){//DO ONE TIME
                    $("#web_attack_page").load("FRMWEBATTACK.jsp",function(){
                        initWebAttackFlash();
                        $(this).find(".column").sortable({
                            connectWith: ['.column']
                        });

                        $(this)
                            .find(".portlet")
                                .addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
                                .end()
                            .find(".portlet-header")
                                .addClass("ui-widget-header ui-corner-all")
                                .prepend('<span class="ui-icon ui-icon-plusthick"></span><span class="ui-icon ui-icon-refresh refresh"></span>')
                                .end()
                            .find(".portlet-content");

                        $(this).find(".portlet-header .ui-icon-plusthick").click(function() {
                            $(this).toggleClass("ui-icon-minusthick");
                            $(this).parents(".portlet:first").find(".portlet-content").toggle();
                        });

                        $(this).find("h3:first").trigger("click");

                        initWebAttackRefresh();
                    });
                    flag_report_1 = false;
                }
            }
            if(ui.index == 3)
            {
                if(flag_report_2){//DO ONE TIME
                    $("#phishing_page").load("FRMPHISHING.jsp",function(){
                        initPhishingFlash();
                        $(this).find(".column").sortable({
                            connectWith: ['.column']
                        });

                        $(this)
                            .find(".portlet")
                                .addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
                                .end()
                            .find(".portlet-header")
                                .addClass("ui-widget-header ui-corner-all")
                                .prepend('<span class="ui-icon ui-icon-plusthick"></span><span class="ui-icon ui-icon-refresh refresh"></span>')
                                .end()
                            .find(".portlet-content");

                        $(this).find(".portlet-header .ui-icon-plusthick").click(function() {
                            $(this).toggleClass("ui-icon-minusthick");
                            $(this).parents(".portlet:first").find(".portlet-content").toggle();
                        });

                        $(this).find("h3:first").trigger("click");

                        initPhishingRefresh();
                    });
                    flag_report_2 = false;
                }
            }
            if(ui.index == 4)
            {
                if(flag_report_3){//DO ONE TIME
                    $("#spam_page").load("FRMSPAM.jsp",function(){
                        initSpamFlash();
                        $(this).find(".column").sortable({
                            connectWith: ['.column']
                        });

                        $(this)
                            .find(".portlet")
                                .addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
                                .end()
                            .find(".portlet-header")
                                .addClass("ui-widget-header ui-corner-all")
                                .prepend('<span class="ui-icon ui-icon-plusthick"></span><span class="ui-icon ui-icon-refresh refresh"></span>')
                                .end()
                            .find(".portlet-content");

                        $(this).find(".portlet-header .ui-icon-plusthick").click(function() {
                            $(this).toggleClass("ui-icon-minusthick");
                            $(this).parents(".portlet:first").find(".portlet-content").toggle();
                        });

                        $(this).find("h3:first").trigger("click");

                        initSpamRefresh();
                    });
                    flag_report_3 = false;
                }
            }
            if(ui.index == 5)
            {
                if(flag_report_4){//DO ONE TIME
                    $("#malware_page").load("FRMMALWARE.jsp",function(){
                        initMalwareFlash();
                        $(this).find(".column").sortable({
                            connectWith: ['.column']
                        });

                        $(this)
                            .find(".portlet")
                                .addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
                                .end()
                            .find(".portlet-header")
                                .addClass("ui-widget-header ui-corner-all")
                                .prepend('<span class="ui-icon ui-icon-plusthick"></span><span class="ui-icon ui-icon-refresh refresh"></span>')
                                .end()
                            .find(".portlet-content");

                        $(this).find(".portlet-header .ui-icon-plusthick").click(function() {
                            $(this).toggleClass("ui-icon-minusthick");
                            $(this).parents(".portlet:first").find(".portlet-content").toggle();
                        });

                        $(this).find("h3:first").trigger("click");
                        
                        initMalwareRefresh();
                    });
                    flag_report_4 = false;
                }
            }

        });

        
        //END --check page loaded, so do..-- END//

        //$("#report_page").load("FRMREPORT.jsp",function(){});

        $("#internet_page").load("FRMKEYWORD.jsp",function(){});

        $("#doc_page").load("home_page_content.jsp",function(){
            $("#slider1").codaSlider();
            $(".part_paging ul").each(function(){
                var $lyr = $(this).parent().parent().find(".lyr");
                var high$lyr = document.getElementById($lyr.attr("id")).offsetHeight;
                if(high$lyr > 480)
                    $(this).append("<li><a class='part1' style='cursor:pointer'>1</a></li><li><a class='part2' style='cursor:pointer'>2</a></li>");
                if(high$lyr > 960)
                    $(this).append("<li><a class='part3' style='cursor:pointer'>3</a></li>");
                if(high$lyr > 1440)
                    $(this).append("<li><a class='part4' style='cursor:pointer'>4</a></li>");
                if(high$lyr > 1920)
                    $(this).append("<li><a class='part5' style='cursor:pointer'>5</a></li>");
                if(high$lyr > 2400)
                    $(this).append("<li><a class='part6' style='cursor:pointer'>6</a></li>");
                if(high$lyr > 2880)
                    $(this).append("<li><a class='part7' style='cursor:pointer'>7</a></li>");
                if(high$lyr > 3360)
                    $(this).append("<li><a class='part8' style='cursor:pointer'>8</a></li>");
                if(high$lyr > 3840)
                    $(this).append("<li><a class='part9' style='cursor:pointer'>9</a></li>");
                if(high$lyr > 4320)
                    $(this).append("<li><a class='part10' style='cursor:pointer'>10</a></li>");
            });
            $(".mouseover_up").click(function (){
                var $lyr = $(this).parent().parent().parent().parent().find('.lyr');
                var $diveq1 =$(this).parent().parent().parent().parent().find('div:eq(1)');
                $lyr
                .animate({top: ($lyr.offset().top >= $diveq1.offset().top)  ? "0":"+=100px"},{queue:false,duration:1000});
                
                //alert($("div").html());
            });
            $(".mouseover_up").hover(function hover_up(){
                $(this).parent().parent().parent().parent().find('.lyr')
                //.animate({top: "+=1px"});
                //hover_up();
                //alert($(this).parent().parent().parent().parent().find('.lyr')+"  "+$(this).parent().parent().parent().parent().find('.lyr').offset().top+"   "+$(this).parent().parent().parent().parent().find('div:eq(1)').offset().top);
                //alert($("div").html());
            }, function (){});
            $(".mouseover_down").click(function (){
                var $lyr = $(this).parent().parent().parent().parent().find('.lyr');
                var high$lyr = document.getElementById($lyr.attr("id")).offsetHeight;
                var cal = parseInt(high$lyr) + parseInt($lyr.offset().top);
                $lyr.animate({top: (cal < 480)  ? $lyr.offset().top:"-=100px"},{queue:false,duration:1000});
//                alert("cal < 400  ? $lyr.offset().top\n"
//                    +"high$lyr"+high$lyr
//                    +"\n$lyr.offset().top  "+$lyr.offset().top
//                    +"\nhigh$lyr + $lyr.offset().top  "+cal
//                    +"\n$diveq1.offset().top   "+$diveq1.offset().top);
            });
            $(".part1").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"0px"},{queue:false,duration:1000});
            });
            $(".part2").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"-480px"},{queue:false,duration:1000});
            });
            $(".part3").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"-960px"},{queue:false,duration:1000});
            });
            $(".part4").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"-1440px"},{queue:false,duration:1000});
            });
            $(".part5").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"-1920px"},{queue:false,duration:1000});
            });
            $(".part6").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"-2400px"},{queue:false,duration:1000});
            });
            $(".part7").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"-2880px"},{queue:false,duration:1000});
            });
            $(".part8").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"-3360px"},{queue:false,duration:1000});
            });
            $(".part9").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"-3840px"},{queue:false,duration:1000});
            });
            $(".part10").click(function (){
                $(this).parent().parent().parent().parent().find('.lyr').animate({top:"-4320px"},{queue:false,duration:1000});
            });

        });
    }