/**
 * Used for interactive elements
 *
 * @author Madison Bryan (madison@westga.edu)
*/
$(document).ready(init);
function init(){
    $('.breadcrumb li a').after(" &gt; ");
    var searchwords = 'people, places, things';
    var searchinput = document.getElementById("searchwords");
    $(searchinput).attr("value",searchwords);
    $(searchinput).focus(function(){ this.value = ""; });
    $(searchinput).blur(function(){
        if(this.value === ''){
            this.value = searchwords;
        }
    });
    $('input#searchSubmit').click(function(e){
        if(searchinput.value == searchwords){
            alert("Please Enter a Search Term");
            searchinput.focus();
            e.preventDefault();
            e.stopPropagation();
        }
    });
    addCaption();
    addStripe();
    styleList();
}
function styleList(){    
    var type;    
    $("#contentBody ul").add($("#contentBody ol")).each(function(i){
        type = $(this).attr("type");
        switch(type){
            case "disc":
                $(this).css("listStyleType","disc").children("li").css("listStyleType","disc");
                break
            case "circle":
                $(this).css("listStyleType","circle").children("li").css("listStyleType","circle");
                break
            case "square":
                $(this).css("listStyleType","square").children("li").css("listStyleType","square");
                break
            case "A":
                $(this).css("listStyleType","upper-alpha").children("li").css("listStyleType","upper-alpha");
                break
            case "a":
                $(this).css("listStyleType","lower-alpha").children("li").css("listStyleType","lower-alpha");
                break
            case "1":
                $(this).css("listStyleType","decimal").children("li").css("listStyleType","decimal");
                break
            case "I":
                $(this).css("listStyleType","upper-roman").children("li").css("listStyleType","upper-roman");
                break
            case "i":
                $(this).css("listStyleType","lower-roman").children("li").css("listStyleType","lower-roman");
                break            
        }
        $(this).removeAttr("type");        
    });
}
function addStripe(){
    $('.stripeMe tr:even').addClass('alt');
    $(".stripeMe tr").hover(function(){
        $(this).addClass("over");
    },function(){
         $(this).removeClass("over");
    });    
}
function addCaption() {
    var allImages = $("#contentBody img");
    
    for (var i=0; i < allImages.length; i++) {
        var imageCaption = document.createTextNode(allImages[i].title);
        if($(allImages[i]).attr("align") == 'right'){
            $(allImages[i]).addClass("imgRight");
        }else{
            $(allImages[i]).addClass("imgLeft");
        }                        
        if (allImages[i].title != "") {
            xClass = $(allImages[i]).attr('class');
            $(allImages[i]).removeAttr("align");
            var imageContainer = document.createElement("div");
            var imagePara = document.createElement("p");
            var imageWidth = allImages[i].getAttribute("width");        
            imagePara.className = "caption";
            imagePara.appendChild(imageCaption);
            allImages[i].parentNode.insertBefore(imageContainer, allImages[i]);
            imageContainer.appendChild(allImages[i]);
            imageContainer.appendChild(imagePara);
            imageContainer.className = xClass;
            allImages[i].className = "img";
            imageContainer.style.width = imageWidth + "px";
        }
    }
}