﻿$(document).ready(function() {
    //preload all images
    $.preloadCssImages();

    //remove link outlines with mouse clicks (retained for tabbing)
    $("a").mousedown(function() {
        this.blur();
        this.hideFocus = true;
        this.style.outline = 'none';
    });

    //setup BG Image Link
    $(".bgImageIcon").html(getBGImagePath());

    //slimbox call
    $("#bgImageLink").click(function() {
        $("#divContentLeft").hide();
        var ImageURL = $(this).attr("href")
        jQuery.slimbox(ImageURL, "", {
            captionAnimationDuration: 400,
            overlayFadeDuration: 100,
            initialWidth: 500
        });
        return false;
    });

    //launch links in new window
    $("a[rel='external']").click(function() {
        window.open($(this).attr("href"));
        return false;
    });
});


//Functions

function getBGImagePath() {
    //Get background image URL from divContent (now divcontent is server side control, need to use class name (maincontent)
    var bgImageURL = $(".maincontent").css("background-image");
    var iconLink = ""

    //BG image URL will be in format "url(http://www.etc.etc) so strip url out
    var iStringLocation = bgImageURL.indexOf("http")
    if (iStringLocation > 0) {
        bgImageURL = bgImageURL.substring(iStringLocation, bgImageURL.length - 1).replace('"', '');
        //build HTML for image and link
        iconLink = "<a href='" + bgImageURL + "' id='bgImageLink' class='left'><img src='/library/Images/showBGimage.png' runat='server' /></a>"
    }
    return iconLink;
}