﻿$(document).ready(function () {
    var timer
    var hideNav = function () {
        $(".CategoryNavigation").css({ "opacity": ".4", "-khtml-opacity": ".4", "-moz-opacity": ".4" });
        $(".CategoryNavigationTable").hide();
        $(".CategoryNavigationLoading").show();
        return false
    }

    $(".CategoryNavPrev").click(function () {
        hideNav()
    })
    $(".CategoryNavNext").click(function () {
        hideNav()
    })
    $(".CategoryNavDropdown").change(function () {
        hideNav()
    })


    var ad = $("#ScrollingAd");
    var scrollAdIntoView = function () {
        var pos = $(window).scrollTop();
        if (pos > 549) {
            ad.css({ "position": "fixed", "top": "0px" })
        }
        else {
            ad.css({ "position": "absolute", "top": "auto" })

        }
    }


    var cancelScroll = function () {
        window.clearTimeout(timer)
    }
    $(window).scroll(function () {
        cancelScroll()
        scrollAdIntoView()
    })

    $(".SendLinks a").hover(function () {
        $(this).parent().css("background-color", "#F8AD27");
    }, function () {
        $(this).parent().css("background-color", "#2A6391");
    })

    $(".ImageLink").hover(function (e) {
        // if there is a value for attribute ThumbName, show it
        var fileName = $(this).attr("ThumbName")
        if (fileName !== "") {
            var imgPath = "/images/ver4/funny_pics/thumbs/" + fileName
            // We have a thumb, let's show a preview
            var img = $("img")[0]; // Get my img elem
            var pic_real_width, pic_real_height;
            $("<img/>") // Make in memory copy of image to avoid css issues
                .attr("src", imgPath)
                .load(function () {
                    pic_real_width = this.width;   // Note: $(this).width() will not
                    pic_real_height = this.height; // work for in memory images.
                }).appendTo("#ImageThumbnailPreview");
            $("#ImageThumbnailPreview").css("top", e.pageY - 150);
            $("#ImageThumbnailPreview").fadeIn();
        }
    }, function () {
        // hide preview
        // remove child image

        $("#ImageThumbnailPreview").hide();
        $("#ImageThumbnailPreview").empty()
    })
})

