﻿$(document).ready(function () {

    //$(document).pngFix();

    $("#LanguageBar > ul > li > a > img").bind("mouseover mouseout", function (event) {

        var img = $(this);

        if (!img.parent("a").hasClass("active")) {

            var originalImagePath = img.attr("src");
            var newImagePath;

            if (event.type == "mouseover") {
                newImagePath = originalImagePath.replace("_off.png", "_on.png");
            }
            else {
                newImagePath = originalImagePath.replace("_on.png", "_off.png");
            }

            img.attr("src", newImagePath);

        }

    });

    $("#dialog").dialog({ autoOpen: false,
        dialogClass: 'tipModal',
        resizable: false,
        draggable: false,
        width: 500,
        position: top,
        modal: true,
        buttons: {
            "Cancel": function () {
                $("#Form :input").val("");
                $('form :input').val("");
                $(this).dialog("close");
            }
        }
    });

    $("#dialog_link").click(function () {

        $("#dialog").dialog({ autoOpen: false,
            dialogClass: 'tipModal',
            resizable: false,
            draggable: false,
            width: 500,
            position: top,
            modal: true,
            buttons: {
                "Close": function () {
                    $("#Form :input").val("");
                    $('form :input').val("");
                    $(this).dialog("close");
                }
            }
        });
        $("#dialog").load().dialog("open");

    });

    $(".MoreInfo").each(function () {
        // find dialog
        var dlg = $(this).parent().find(".tombstone");
        var date = $(this).parent().find("p.date").html();
        // store reference 
        $(this).data("dialog", dlg);
        // init dialog 
        dlg.dialog({
            autoOpen: false,
            width: 580,
            resizable: false,
            draggable: false,
            position: 'top',
            top: '50px',
            modal: true,
            title: date,
            buttons: { "Close": function () {
                $(this).dialog("close");
            }
            }
        });


    }).click(function () { $(this).data("dialog").dialog("open"); });

    $("#NewsTickerList").innerfade({
        //animationtype: 'slide',
        speed: 'slow',
        timeout: 5000,
        containerheight: '1em'
    });

    $(document).ready(function () {
        var carousel = $(".TombstoneCarousel").jCarouselLite({
            auto: 5000,
            speed: 2000,
            hoverSpeed: 500,
            visible: 4,
            hoverNext: ".TombstoneCarousel .NavigateRight",
            hoverPrev: ".TombstoneCarousel .NavigateLeft"
        }).css("width", "900px");
    });
});

function openTombstone(id) {

    $(".tombstone").each(function () {

        var $this = $(this);
        var template = $("#tombstoneTemplate");

        if ($this.hasClass("t" + id)) {

            var date = "";

            $this.find("iframe").attr("src", $this.find("iframe").attr("src"));

            $this.hide().show();

            template.dialog({
                autoOpen: true,
                width: 580,
                resizable: false,
                draggable: false,
                position: 'top',
                top: '50px',
                modal: true,
                title: date,
                buttons: {
                    "Close": function () {
                        $(this).dialog("close");
                    }
                }
            }).dialog("open");

            // Workaround for FF
            setTimeout(function () {
                template.find("iframe").attr("src", $this.find("iframe").attr("src"));
            }, 1000);

        }

    });

}