﻿$(document).ready(function () {
    // Starta slideshow
    $('.bildspel').cycle({
        fx: 'fade',
        timeout: 11000,
        speed: 2000,
        delay: -10999
    });

    $('.aktuelltsnurra').cycle(
    {
        timeout: 11000,
        speed: 800,
        fx: 'fade',
        pause: 1
    });

    $(".fadein").fadeIn(800);

    $(".puff").animate({
        paddingLeft: "0px"
    }, 1500);

    $(".klick").mouseover(function (e) {
        $(this).addClass("hover");
        return false;
    }).mouseout(function (e) {
        $(this).removeClass("hover");
        return false;
    }).click(function (e) {
        $(this).find("a").each(function (e) {
            if ($(this).attr("href") != null) {
                var mytarget = $(this).attr("target");
                if (mytarget != null && mytarget != "") {
                    window.open($(this).attr("href"));
                }
                else {
                    document.location = $(this).attr("href");
                }
                return false;
            }
        });
        return false;
    });

    /* Anv i rullgardsinsmenyer */
    $(".klick2").mouseover(function (e) {
        $(this).addClass("hover");
    }).mouseout(function (e) {
        $(this).removeClass("hover");
        return false;
    }).click(function (e) {
        $(this).find("a").each(function (e) {
            if ($(this).attr("href") != null) {
                document.location = $(this).attr("href");
                return false;
            }
        });
        return false;
    });

    $(".rull").mouseover(function (e) {
        $(this).addClass("hover");
        var MinGardin = $(this).attr("c4target");
        // Göm alla andra menyer
        $(".gardin").each(function () {
            //if ("#" + $(this).attr("id") != MinGardin) {
            if (!$(this).is(MinGardin)) {
                $(this).hide(200);
            }
            // }
        });
        if (MinGardin != null) {
            $(MinGardin).show(190);
        }
        return false;
    }).mouseout(function (e) {
        $(this).removeClass("hover");
        var MinGardin = $(this).attr("c4target");
        if (MinGardin != null) {
            $(MinGardin).oneTime(7000,
            function () {
                if ($("#callander1").val() != MinGardin) {
                    $(MinGardin).hide(200)
                }
            });
        }
        return false;
    }).click(function (e) {
        $(this).find("a").each(function (e) {
            if ($(this).attr("href") != null) {
                document.location = $(this).attr("href");
            }
            return false;
        });
    });

    $(".gardin").mouseover(function (e) {
        $("#callander1").val("#" + $(this).attr("id"));
    })
    .mouseout(function () {
        $("#callander1").val("");
    });

    $(".c4reveal").click(function () {
        var mytarget = $(this).attr("c4target");
        var targetid = $(mytarget).attr("id");
        var myhide = $(this).attr("c4hide");
        if (myhide != null) {
            $(myhide).each(function () {
                if ($(this).attr("id") != targetid) {
                    $(this).hide();
                }
            });
        }
        $(mytarget).fadeIn(500);
    })

    // Generell klickyta
    $(".klick3").mouseover(function (e) {
        $(this).addClass("hover");
    }).mouseout(function (e) {
        $(this).removeClass("hover");
    }).click(function () {
        var hide = $(this).attr("c4hide");
        $(hide).hide();
        var targetId = "#" + $(this).attr("c4target");
        if (!$(targetId).visible) {
            $(targetId).fadeIn(1500);
        }
        $(this).removeClass("c4slide");
    });

    // Pressbilds klickyta
    $(".pressbild").mouseover(function (e) {
        $(this).addClass("presshover");
    }).mouseout(function (e) {
        $(this).removeClass("presshover");
    }).click(function (e) {
        $(this).find("a").each(function (e) {
            if ($(this).attr("href") != null) {
                document.location = $(this).attr("href");
            }
        });
    });

    // Paging post right menu
    if ($(".getitems").length > 0) {
        var ctitle = $(".getitems").get(0).title;
        $(".getitems").load("/ajax/items.aspx?y=" + ctitle, function () {
            $(this).slideDown(400);
        });
    }
    $(".clicktofetch").click(function () {
        var y = $(this).attr("title");
        //$(this).hide();
        $(this).load("/ajax/items.aspx?y=" + y, function () {
            $(this).slideDown(400);
        });
    });

    // Öppna externa länkar i nytt fönster
    $('a[href^="http://d"]').attr({
        target: "_blank",
        title: "Öppnar i nytt fönster"
    });
    $('a[href^="http://n"]').attr({
        target: "_blank",
        title: "Öppnar i nytt fönster"
    });
    $('a[href^="http://w"]').attr({
        target: "_blank",
        title: "Öppnar i nytt fönster"
    });
});
