﻿// Replace fonts

Cufon.replace(".top_nav a.orange", {
    hover: {
        color: "#4c9ba2"
    }
});
Cufon.replace(".top_nav a", {
    hover: {
        color: "#f26522"
    }
});
Cufon.replace(".sub_nav a", { hover: {
    color: "#f26522"
}
});
Cufon.replace("#main h1");
Cufon.replace("#main h2");
Cufon.replace("#main h3");
Cufon.replace("#main h4");
Cufon.replace(".form h1");
Cufon.replace("#footer");
Cufon.replace("#header .banner p");
Cufon.replace("#language", {
    hover: {
        color: "#eee"
    }
});
Cufon.replace(".loggin", {
    hover: {
        color: "#eee"
    }
});


Cufon.replace("#triangleMap a.active,#triangleMap .ballLeft,#triangleMap .ballRight,#triangleMap .ballMiddle", {
    hover: {
        color: "#599BA1"
    }
});
Cufon.replace("#triangleMap .linkCenter a, #triangleMap .linkMiddle a, #triangleMap .linkRight a, #triangleMap .linkLeft a", {
    hover: {
        color: "#757575"
    }
});
// Form

function closeForm() {
    $("iframe").trigger("close");
}

// Open video

function openVideo(href) {
    $.url.setUrl(href);

    var popupHeight = $.url.param("height") != null ? parseInt($.url.param("height")) : 444;
    var popupWidth = $.url.param("width") != null ? parseInt($.url.param("width")) : 790;

    //var body = (window.parent != null) ? $("body", window.parent.document) : $("body");
    var body = $("body");
    body.append("<div id='player' style=\"width: " + popupWidth + "px; height: " + popupHeight + "px;\"></div>");

    var player = $("#player");

    player.flash({
        src: "/Web/UI/Flash/Player.swf",
        width: popupWidth,
        height: popupHeight,
        allowFullScreen: true,
        flashvars: {
            source: $.url.attr("path"),
            onClose: "videoOnClose"
        }
    });

    player.lightbox_me({
        centered: true,
        destroyOnClose: true
    });

    top.closeForm();
}

// Callback functions for video

function slideshowVideoOnComplete() {
    var slideshow = $(".slideshow");
    slideshow.find(".player").html("");
    slideshow.find(".player").remove();
    //slideshow.find(".slides").cycle("resume");
    slideshow.find(".pager").css("display", "block");
}

function slideshowVideoOnClose() {
    slideshowVideoOnComplete();
}

function videoOnClose() {
    $("#player").html("");
    $("#player").trigger("close");
}

$(document).ready(function () {
    // Catch clicks on video links

    $("#header a[href*='.flv'], #content a[href$='.flv'], #sidebar a[href$='.flv'], body.popup a[href$='.flv'], .slideshow a[href$='.flv']").click(function (e) {
        var link = $(e.currentTarget);

        if (link.parents(".slideshow").length > 0 && (link.hasClass("inline") || link.hasClass("link_video_inline"))) {
            return false;
        }

        var href = link.attr("href");

        top.openVideo(href);

        return false;
    });

    // Catch clicks on video links in a slideshow

    $(".slideshow a.inline[href$='.flv']").click(function (e) {
        var link = $(e.currentTarget);
        var slide = link.parents(".slide");
        var slideshow = slide.parents(".slideshow");

        slideshow.find(".slides").cycle("pause");
        slideshow.find(".pager").css("display", "none");

        slide.append("<div class='player'></div>");

        slide.find(".player").flash({
            src: "/Web/UI/Flash/Player.swf",
            width: 790,
            height: 366,
            allowFullScreen: true,
            flashvars: {
                source: link.attr("href"),
                onComplete: "slideshowVideoOnComplete",
                onClose: "slideshowVideoOnClose"
            }
        });

        return false;
    });
    // Catch clicks on video links in a slideshow

    $(".slideshow a.link_video_inline[href$='.flv']").click(function (e) {
        var link = $(e.currentTarget);
        var slide = link.parents(".slide");
        var slideshow = slide.parents(".slideshow");

        slideshow.find(".slides").cycle("pause");
        slideshow.find(".pager").css("display", "none");

        slide.append("<div class='player'></div>");

        slide.find(".player").flash({
            src: "/Web/UI/Flash/Player.swf",
            width: 790,
            height: 366,
            allowFullScreen: true,
            flashvars: {
                source: link.attr("href"),
                onComplete: "slideshowVideoOnComplete",
                onClose: "slideshowVideoOnClose"
            }
        });

        return false;
    });
    // Pause slideshow on click

    $(".slideshow").click(function () {
        $(this).find(".slides").cycle("pause");
    });

    // Catch form events

    $("a[href*=FormTemplate.aspx]").click(function (e) {
        var link = $(e.currentTarget);

        var iframe = $("<iframe class='" + link.attr("class") + "' src='" + link.attr("href") + "'></iframe>");

        $("body").append(iframe);

        iframe.lightbox_me({
            centered: true,
            destroyOnClose: true
        });

        return false;
    });
    $(".formPopUpSmall").click(function (e) {
        var link = $(e.currentTarget);

        var iframe = $("<iframe class='" + link.attr("class") + "' src='" + link.attr("href") + "'></iframe>");

        $("body").append(iframe);

        iframe.lightbox_me({
            centered: true,
            destroyOnClose: true
        });

        return false;
    });


    $(".popup_medium").click(function (e) {
        var link = $(e.currentTarget);

        var iframe = $("<iframe class='" + link.attr("class") + "' src='" + link.attr("href") + "'></iframe>");

        $("body").append(iframe);

        iframe.lightbox_me({
            centered: true,
            destroyOnClose: true
        });

        return false;
    });

    $(".popup_large").click(function (e) {
        var link = $(e.currentTarget);

        var iframe = $("<iframe class='" + link.attr("class") + "' src='" + link.attr("href") + "'></iframe>");

        $("body").append(iframe);

        iframe.lightbox_me({
            centered: true,
            destroyOnClose: true
        });

        return false;
    });

    var $toggleButton = $('#forgottonLink');
    if ($toggleButton.length) {
        $toggleButton.bind('click', function () {


            $('.forgottonBox').slideUp()
            $('.forgottonBox').slideDown()


        });
    }
    var $toggleButton = $('#A1');
    if ($toggleButton.length) {
        $toggleButton.bind('click', function () {
            $('.forgottonBox').slideUp()
            $('.forgottonBox').slideDown()
            //            $('.forgottonBox').slideToggle('slow', function () {
            //                // Animation complete.
            //            });

        });
    }



    $(".popup_small_Iframe").click(function (e) {
        var link = $(e.currentTarget);

        var iframe = $("<iframe class='" + link.attr("class") + "' src='" + link.attr("href") + "'></iframe>");

        $("body").append(iframe);

        iframe.lightbox_me({
            centered: true,
            destroyOnClose: true
        });

        return false;
    });
    $(".popup_medium_Iframe").click(function (e) {
        var link = $(e.currentTarget);

        var iframe = $("<iframe  class='" + link.attr("class") + "' src='" + link.attr("href") + "'></iframe>");

        $("body").append(iframe);

        iframe.lightbox_me({
            centered: true,
            destroyOnClose: true
        });

        return false;
    });

    $(".popup_medium_Iframe_SlideShare").click(function (e) {
        var link = $(e.currentTarget);

        var iframe = $("<iframe  class='" + link.attr("class") + "' src='" + link.attr("href") + "'></iframe>");

        $("body").append(iframe);

        iframe.lightbox_me({
            centered: true,
            destroyOnClose: true
        });

        return false;
    });
    $(".form a.close_link").click(function () {
        top.closeForm();

        return false;
    });
});

/*AJAX SERVICES*/
vote = function (pollPageId, radioButtonListElement) {

    // Get selected poll option
    var answerId = $("#" + radioButtonListElement + " input:radio:checked").val();

    if (answerId == undefined)
        return false;

    // Disable radiobuttons
    $("#" + radioButtonListElement + " input").each(function (i) {
        $(this).attr('disabled', 'disabled');
    });

    if ($.getCookie("poll" + pollPageId) == null) {
        $.setCookie("poll" + pollPageId, "true", { expires: 100 });
        $.ajax({
            url: "/PollService.rst/Vote/" + pollPageId + "/" + answerId,
            contentType: "application/json",
            dataType: "json",
            type: "GET",
            success: function (data) {
                if (data) {
                    $("#pollResponse").show();
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(textStatus + " - " + errorThrown);
            },
            complete: function () {
            }
        });
    }
    else {
        alert("Du har redan röstat!");
    }
};

