﻿$(document).ready(function () {

    $(".c4setimg").mouseover(function (e) {
        var mytarget = $(this).attr("c4target");
        var mysrc = $(this).attr("c4value");
        if ($(mytarget).attr("src") != mysrc) {
            $(mytarget).attr("src", mysrc);
        }
    });

    $(".c4hover").mouseover(function (e) {
        var myid = $(mytarget).attr("id");
        var myclass = $(this).parent().attr("class");
        var changed = !($(this).hasClass("hover"));
        $(".c4hover").each(function () {
            if ($(this).attr("id") != myid) {
                if ($(this).parent().attr("class") == myclass) {
                    $(this).removeClass("hover");
                }
            }
        });
        $(this).addClass("hover");
        var mytarget = $(this).attr("c4target");
        var myhide = $(this).attr("c4hide");
        var myhide2 = $(this).attr("c4alsohide");
        if (myhide != null) {
            $(myhide).each(function () {
                var hideid = $(this).attr("id");
                if ("#" + hideid != mytarget) {
                    $(this).hide();
                }
            });
        }
        if (changed) {
            if (myhide2 != null) {
                $(myhide2).each(function () {
                    var hideid = $(this).attr("id");
                    if ("#" + hideid != mytarget) {
                        $(this).fadeOut(500);
                    }
                });
            }
        }
        if ($(mytarget) != null) {
               $(mytarget).fadeIn(600);
    //        $(mytarget).slideDown(500);
        }
    }).mouseout(function (e) {
        var mytarget = $(this).attr("c4target");
        var myhide = $(this).attr("c4hide");
    });

    // Visa den meny vi tittar på
    $(".meny1").find("a").each(function () {
        if ($(this).hasClass("hover")) {
            $(this).trigger("mouseover");
        }
    });
    $(".meny2").find("a").each(function () {
        if ($(this).hasClass("hover")) {
            $(this).trigger("mouseover");
        }
    });

    $(".bildspel").cycle({
        next: '.bildspel',
        pause: 1,
        speed: 300
    });

    $(".fadein").fadeIn(800);

    $(".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) {
                document.location = $(this).attr("href");
                return false;
            }
        });
        return false;
    });

    $(".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);
    })

});
