
$(document).ready(function () {
    $(".menuoverstate").each(function (i) {

        preload_image = new Image();
        preload_image.src = this.src.replace(".png", "_o.png");

        $(this).hover(
            function () {
                if (this.src.indexOf("_o.png") == -1) {
                    this.src = this.src.replace(".png", "_o.png");
                }

            },

            function () {
                this.src = this.src.replace("_o.png", ".png");

            });

        if ((navigator.appVersion).split(";")[1] == " MSIE 7.0" /*|| (navigator.appVersion).split(";")[1] == " MSIE 9.0"*/) {

            $('.date-fix').css("margin-bottom", "16px");
        }

    });

    //cufon
    Cufon.replace('#comments, #post-comment, #debatetext, #older-posts, #hide-posts, #nav, #footer, .sidebar-text, .sidebar-text-noimage, .side-debate-title, .side-gallery-title, .side-blog-title, .side-stories-title, .side-twitter-title, .column-2, .column-3, .column-4, .column-5, #project-links, #debate-date, #debate-posts-content h1, .comment-title-left, #debate-dates span, #debate-dates ul li, .box-text, .box-text-noimage, .box-debate-title, .box-gallery-title, .box-blog-title, .box-stories-title, .box-twitter-title, .box-full-text, .box-full-debate-title,', { hover: true });

    $('#debatetext u').css('border-bottom', '1px solid #000');

    setTimeout(function () {

        if ((navigator.appVersion).split(";")[1] == " MSIE 9.0") {
            $('.date-fix > .cufon').css("margin-top", "-2px");

            $('.date-fix > img').css("margin-top", "-3px");

            $('.date-fix > .cufon').css("height", "0px");

        }
    }, 2000);


    //side bar collapse

    $("#expand").click(function () {
        $("#sidebar-more").slideDown();
        $("#expand").hide();
        $("#collapse").show();
        $("#arrow-right").css("right", "260px");
    })


    $("#collapse").click(function () {
        $("#sidebar-more").slideUp();
        $("#collapse").hide();
        $("#expand").show();
        $("#arrow-right").css("right", "30px");
    })

    //side bar auto hide
    $("#sidebar-more").hide();
    $("#collapse").hide();
    $("#expand").show();
    $("#arrow-right").css("right", "30px");

    //older-posts

    $("#older-posts").click(function () {
        $("#sidebar-wrapper, #sidebar-more").css("width", "+=440");
        $("#older-hide").show();
        $("#older-posts").hide();
        $("#hide-posts").show();
    })

    $("#hide-posts").click(function () {
        $("#sidebar-wrapper, #sidebar-more").css("width", "-=440");
        $("#older-hide").hide();
        $("#hide-posts").hide();
        $("#older-posts").show();
    })

    //sideboxes hover opacity
    $(".sidebox").hover(function () {
        $(".sidebox").stop().animate({ opacity: 0.5 }, 100);
        $(this).stop().animate({ opacity: 1.0 }, 100);
    }, function () {
        $(".sidebox").stop().animate({ opacity: 1.0 }, 200);
    })

    // dropdown menus        
    $("#nav").find("li").filter(function () {
        return ($(this).children("ul").length > 0);
    }).hover(function () {
        $(this).children("ul").show();
        $(this).children("a").addClass("current");
    }, function () {
        $(this).children("ul").hide();
        $(this).children("a").removeClass("current");
    });

    //links
    $(".box-hide").hide();
    $("#nav-links li").hover(function () {
        $(this).children(".box-hide").show();
    }, function () {
        $(this).children(".box-hide").hide();
    });

    //hide content
    $(".column-open").hide();
    $(".column-close").click(function () {
        $(".column-content").hide();
        $(".column-close").hide();
        $(".column-open").show();
    })

    $(".column-open").click(function () {
        $(".column-content").show();
        $(".column-open").hide();
        $(".column-close").show();
    })

    // debate dates
    $("#debate-dates span").click(function () {
        $(this).parent().children("#debate-dates ul").slideToggle();
    });
});

