
// Page Load Event for all commonly invoked functions.
$(document).ready(function () {
    
    MoveItem();
    loadSideImagesCSS();
    outboundFilter();
    shadows();

});




function shadows() {
    $("h1").dropShadow({ left: 2, top: 2, opacity: 0.3, blur: 1 });
    $(".RightPanelTab, .spotlight h2").dropShadow({left: 1, top:1, opacity: 0.2, blur: 1 });
    $(".LeftPanelTab").dropShadow({ left: 1, top: 1, opacity: 0.2, blur: 1 });
}




// Use for collapsable panel, Childhood obesity
function collapsePans() {
    
    $(".toggle_container").hide();

    
    $("h3.trigger").toggle(function () {
            $(this).addClass("active");
        }, function () {
            $(this).removeClass("active");
        }
    );

    $("h3.trigger").click(function () {
        $(this).next(".toggle_container").slideToggle("slow,");
    });
    
    var qs = QueryString.get("sent");
    if (qs == "1") {
        $(".trigger a").eq(4).click();
    }
    else {
        $(".trigger a").eq(0).click();
    }
}



// rollover functions for the COmmunity Update Newsletter banner
function MoveItem() {
    $(".CUholder a.ltst")
    .mouseover(function () {
        $(this).parent().addClass("CUholder_ltst");
    })
    .mouseout(function () {
        $(this).parent().removeClass("CUholder_ltst");
    })
    ;
    $(".CUholder a.subs")
    .mouseover(function () {
        $(this).parent().addClass("CUholder_subs");
    })
    .mouseout(function () {
        $(this).parent().removeClass("CUholder_subs");
    })
    ;
}




// DO NOT USE -- may be some problems with IE8.
$.fn.equalHeights = function (px) {
    $(this).each(function () {
        var currentTallest = 0;
        $(this).children().each(function (i) {
            if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
        });
        // commented out below since we dont use the pxToEm method
        // need to pass (true) as 
        //if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
        // for ie6, set height since min-height isn't supported
        //if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({ 'height': currentTallest }); }
        $(this).children().css({ 'min-height': currentTallest });
    });
    return this;
};




function loadSideImagesCSS() {
var loc22 = window.location.toString().toLowerCase();
if (loc22.indexOf('govauthoring') == -1 && loc22.indexOf('tmossapp1') == -1) {
$("head").append("<link type='text/css' rel='stylesheet' href='/style%20library/ProductionOnly.css' />");
}
}




function outboundFilter() {

    // get the current domain
    var loc = window.location.toString().toLowerCase();
    
    // we only want to invoke this function if
    // in alachuacounty.us domain
    if (loc.indexOf('alachuacounty.us') > 0) {
        
        // these domains are excluded from the filter
        var domains = [
                "alachuacounty.us",
                "alachua.fl.us",
                "alachuaclerk.org",
				"govauthoring",
				"production_internet",
				"alachua.granicus",
				"agency.governmentjobs",
				"test_internet",
				"integration_internet"
            ];


        $("a").each(function () {
            var href = $(this).attr("href");
            var doneWithThisLink = false;

            // go ahead and add target=blank to 'exclude' links because we 
            // know that they are external anyway. ('exclude' is only put on external links)
            if ($(this).hasClass("exclude")) {
                $(this).attr("target", "_blank");
                return true; // same as 'continue' in jqery .each loop
            }


            // if this link starts with "http" 
            // then we consider if for the outbound link filter.
            if (href.indexOf("http") == 0) {
                var found = false;
                for (var i in domains) {
                    if ($(this).attr("href").indexOf(domains[i]) != -1) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    $(this).attr("href", "/outbound/?text=" + $(this).attr("title") + "&link=" + $(this).attr("href"));
                    //$(this).append("--out!");
                }
                return true; // same as 'continue' in jqery .each loop
            }


            // check out the link to see if its a document link

            // if the last segement of the URL has a "." but NOT a ".aspx"
            // then its a document link, like "/EPD/Library/land/file.doc"

            var ar = href.split("/");
            var lastseg = ar[ar.length - 1];
            if (lastseg.indexOf(".") != -1 && lastseg.indexOf("aspx") == -1) {
                $(this).attr("target", "_blank");

                // add the image icon if there isn't an IMG tag inside this A tag...
                if ($(this).find("img").size() == 0) {
                    $(this).prepend("<img src='" + docLinkImage(lastseg) + "' class='ms-asset-icon' border='0' alt='' />");
                }
                
                // add the Analytics code to track downloaded media files (PDF, DOC, etc)
                var pageTracker = _gat._getTracker("UA-16484336-1");
                $(this).click(function(){
                    pageTracker._trackPageview(getStrippedPath($(this).attr("href")));
                });
                
                return true; // same as 'continue' in jqery .each loop
            }

            if (href.indexOf("mailto:") != -1) {
                if ($(this).find("img").size() == 0) {
                    $(this).prepend("<img src='" + docLinkImage("@") + "' class='ms-asset-icon' border='0' alt='' />");
                }
            }


        });
    }

}


function getStrippedPath(href) {
    var domains = new Array();
    domains[0] = "http://www.alachuacounty.us";
    domains[1] = "http://alachuacounty.us";
    // rip out the domain, if its there.
    href = href.replace(domains[0], "").replace(domains[1], "");
    
    // if href was a relative link ("Docs/Foo.pdf") then add a front "/" to make it match
    // the other links. Root relative links and absolute links with both have a starting "/"
    // at this point in the function.
    if (href.charAt(0) != "/")
        href = "/" + href;
        
    return "/Downloads" + href;
}


function docLinkImage(segment) {
    // http://govauthoring/_layouts/IMAGES/ictif.gif - tif
    // http://govauthoring/_layouts/IMAGES/icgen.gif - generic
    // http://govauthoring/_layouts/IMAGES/icpdf.gif - pdf
    // http://govauthoring/_layouts/IMAGES/icjpg.gif - jpg
    // http://govauthoring/_layouts/IMAGES/icdoc.gif - doc
    // http://govauthoring/_layouts/IMAGES/ichtm.gif - html
    // http://govauthoring/_layouts/IMAGES/icppt.gif - PPT
    // http://govauthoring/_layouts/IMAGES/icmail.gif - @

    var seg = "/_layouts/IMAGES/";

    if (segment.indexOf(".doc") > 0)
        seg += "icdoc";

    else if (segment.indexOf(".tif") > 0)
        seg += "ictif";

    else if (segment.indexOf(".pdf") > 0)
        seg += "icpdf";

    else if (segment.indexOf(".jpg") > 0 || segment.indexOf(".jpeg") > 0)
        seg += "icjpg";

    else if (segment.indexOf(".htm") > 0)
        seg += "ichtm";

    else if (segment.indexOf(".ppt") > 0)
        seg += "icppt";

    else if (segment.indexOf("@") > 0)
        seg += "icmail";

    else
        seg += "icgen";

    return seg + ".gif";


}

