/***********************************
**        template.js             **
**                                **
**       Java required for        **
**     rendering the template     **
***********************************/
var prevElement=1;

$(function(){
    /*set up the rollovers on pageload*/
    $(".topnavitem").each(function(){
        var temp=$(this).find("a img.notselected");
        $(temp).mouseover(function(){
            $(temp).attr("src",$(temp).attr("src").replace(".gif","_over.gif"));
        });
        $(temp).mouseout(function(){
            $(temp).attr("src",$(temp).attr("src").replace("_over.gif",".gif"));
        });
    });
    /*learn more button*/
    temp=$("#learnmore a img");
    $(temp).mouseover(function(){
        $(temp).attr("src",$(temp).attr("src").replace(".gif","_over.gif"));
    });
    $(temp).mouseout(function(){
        $(temp).attr("src",$(temp).attr("src").replace("_over.gif",".gif"));
    });
    /*perform page setup function*/
    underlineText();
    leftButtons();
    moreButtons();
    bottomTabs();
    bottomText();
});

function leftButtons(){
    $("#leftcontainer a").each(function(){
        var temp=$(this).find("#leftbaritem");
        $(temp).mouseover(function(){
            $(temp).addClass("linkhover");
        });
        $(temp).mouseout(function(){
            $(temp).removeClass("linkhover");
        });
    });
}

function moreButtons(){
    /*give the 'more' buttons mouseover*/
    $(".morebutton").each(function(){
        /*mouseover*/
        $(this).find("a img").mouseover(function(){
            
            $(this).attr("src",$(this).attr("src").replace(".gif","_over.gif"));
            
        });
        /*mouseout*/
        $(this).find("a img").mouseout(function(){
          
            $(this).attr("src",$(this).attr("src").replace("_over.gif",".gif"));
            
        });
    });
}
function bottomTabs(){
    var temp=null;
    /*give the 'more' buttons mouseover*/
    $(".rightfootertab").each(function(){
     //   alert("got one");
        temp=$(this).find("#rightfootertabcontent");
        /*mouseover*/
        $(this).find("#rightfootertabcontent").mouseover(function(){
            $(this).addClass("hover");
            
        });
        /*mouseout*/
        $(this).find("#rightfootertabcontent").mouseout(function(){
            $(this).removeClass("hover");
            
        });
    });
}

/*show clickable text*/
function bottomText(){
    $("#contentarea .clickable").each(function(){
        $(this).find("a").click(function(){
            if ($(this).parent().hasClass("open")){
                $(this).parent().find(".subcontent").removeClass("open");
                $(this).parent().removeClass("open")
                /*image*/
                $(this).parent().find("img").attr("src","/images/triangle_small_closed.gif");
            }
            else{
                $("#contentarea .open #subcontent.open").removeClass("open");
                $("#contentarea .open").removeClass("open");
                $(this).parent().find(".subcontent").addClass("open");
                $(this).parent().addClass("open")
                /*image*/
                $(this).parent().find("img").attr("src","/images/triangle_small_open.gif");
            }
        });
    });
}

/*show accordion elements*/
function showelement(elementnum){
    if (prevElement!=elementnum){
        if (elementnum==1){/*first*/
            /*toggle stuff*/
            $("#accordionbox .first #accordionbody").addClass("openBody");
            $(".openBody").slideToggle("slow",function(){
                /*clear any potential open state for 2 and 3, open for 1*/
                $("#accordionbox .open #accordionbody").removeClass("openBody");
                $("#accordionbox .first #accordionbody").addClass("openBody");
                $("#accordionbox .first").addClass("open");
                $("#accordionbox .second").removeClass("open");
                $("#accordionbox .third").removeClass("open");
                /*update the images*/
                $("#accordionbox .second").removeClass("thirdopen");
            });
            
        }
        else if (elementnum==2){
            /*toggle stuff*/
            //$("#accordionbox .test").addClass("open");
            $("#accordionbox .second #accordionbody").addClass("openBody");
            $(".openBody").slideToggle("slow",function(){
                /*clear any potential open state for 1 and 3, open for 2*/
                $("#accordionbox .open #accordionbody").removeClass("openBody");
                $("#accordionbox .second #accordionbody").addClass("openBody");
                $("#accordionbox .first").removeClass("open");
                $("#accordionbox .second").addClass("open");
                $("#accordionbox .third").removeClass("open");
                /*update the images*/
                $("#accordionbox .second").removeClass("thirdopen");
            });
            
            
        }
        else if (elementnum==3){
            /*toggle stuff*/
           $("#accordionbox .third #accordionbody").addClass("openBody");
            $(".openBody").slideToggle("slow",function(){
                /*clear any potential open state for 1 and 2, open for 3*/
                $("#accordionbox .open #accordionbody").removeClass("openBody");
                $("#accordionbox .third #accordionbody").addClass("openBody");
                $("#accordionbox .first").removeClass("open");
                $("#accordionbox .second").removeClass("open");
                $("#accordionbox .third").addClass("open");
                /*update the images*/
                $("#accordionbox .second").addClass("thirdopen");
            });
            
        }
        prevElement=elementnum;
    }

}

function openText(){
}

function underlineText(){
    $(".learnmorelink").each(function(){
        $(this).mouseover(function(){
            $(this).css("text-decoration","underline");
        });
        $(this).mouseout(function(){
            $(this).css("text-decoration","none");
        });
    });
}

function openFeed(myURL) {
        prompt('Copy the URL below into your RSS reader to read headlines:',myURL);
}

