﻿$(document).ready(function() { 
    if(/MSIE 6.0/.test(navigator.userAgent)&&!(/MSIE 7.0/.test(navigator.userAgent))&&!(/MSIE 8.0/.test(navigator.userAgent))){
                //do not use if IE6
    }else{
        $("#new_improved_report h3").after("<p style=\"margin-left:10px;\"><a id=\"glossarytogglea\" href=\"JavaScript:GlossaryToggle();\">Turn Glossary Off</a></p>");
        $("head").append("<link rel=\"stylesheet\" href=\"css/new_report2.css\" type=\"text/css\" />");
        //move header 4 for TAB
        $("#new_improved_report h4:first").before("<div style=\"clear:both;\"><!-- EMPTY --></div>");
        $("#new_improved_report h4:first").after($("#new_improved_report h4:last"));
        $("#new_improved_report h4:last").after("<div style=\"clear:both;\"><!-- EMPTY --></div>");
        $("#new_improved_report h4:last").addClass("state1");

        $("#Aval_Haz_Obse").hide();
        
        $("#new_improved_report h4:last").click(function(){
            $("#Aval_Haz_Fore").hide();
            $("#Aval_Haz_Obse").show();
            $(this).removeClass("state1");
            $("#new_improved_report h4:first").addClass("state2");
        });
        
        $("#new_improved_report h4:first").click(function(){
            $("#Aval_Haz_Fore").show();
            $("#Aval_Haz_Obse").hide();
            $(this).removeClass("state2");
            $("#new_improved_report h4:last").addClass("state1");
        });
        
        //do glossary
        $("span.glossary").each(function(){
            $(this).attr("rel",$(this).attr("title"));
            $(this).attr("title","");
            $(this).css("color","#4c7abf");
            $(this).css("cursor","pointer");
            $(this).css("font-weight","bold");            
            $(this).mouseenter(function(){
                $(this).append("<div class=\"glossary_pop\">" + $(this).attr("rel").replace(/\n/,"<br />") + "</div>");
            });
            $(this).mouseleave(function(){
                $(".glossary_pop").remove();
            });
        });
        
        //do blog posts
        if($("#hotscot_blog").attr("rel")!=""){
        $.getJSON($("#hotscot_blog").attr("rel") + "feeds/posts/default?orderby=published&alt=json-in-script&max-results=3&callback=?",
            function(data) {
                $("#hotscot_blog").html("");
                $.each(data.feed.entry, function(i, postentry) {
                    var posttitle = postentry.title.$t
                    var postdate = postentry.published.$t.substring(0, 10);
                    var postyear = postdate.substring(0, 4);
                    var postmonth = postdate.substring(5, 7);
                    var postday = postdate.substring(8, 10);
                    
                    $.each(postentry.link, function(j, postlink) {
                        if (postlink.rel == 'alternate') {
                            $("#hotscot_blog").append("<li><a target=\"_blank\" href=\"" + postlink.href + "\">" + postday + "/" + postmonth + "/" + postyear + " - " + posttitle + "</a></li>"); 
                        }
                    });
                    
                });
                
                $("#hotscot_blog").append("<li><a target=\"_blank\" href=\"" + $("#hotscot_blog").attr("rel") + "\"><b>Read Our Blog</b></a></li>"); 
            });
         }
    }
});

function GlossaryToggle(){
    if($("#glossarytogglea").html()=="Turn Glossary Off"){
        $("#glossarytogglea").html("Turn Glossary On");
        $("span.glossary").each(function(){
            $(this).css("color","#000000");
            $(this).css("font-weight","normal");
            $(this).unbind("mouseenter");
            $(this).unbind("mouseleave");
        });
    }else{
        $("#glossarytogglea").html("Turn Glossary Off");
        $("span.glossary").each(function(){
            $(this).css("color","#4c7abf");
            $(this).css("cursor","pointer");
            $(this).css("font-weight","bold");
            $(this).mouseenter(function(){
                $(this).append("<div class=\"glossary_pop\">" + $(this).attr("rel").replace(/\n/,"<br />") + "</div>");
            });
            $(this).mouseleave(function(){
                $(".glossary_pop").remove();
            });
        });
    }     
}