﻿/// <reference path="jQuery.intellisense.js" />

currentlyShownTab = "aktuellt";

$(document).ready(function() {

    if ($.browser.msie) {
        $("ul.leftMenu1 > li > a").each(function() {
            $(this).wrapInner("<span style=\"display:block;\"></span>");
        });
        $("ul.leftMenu1 span").each(function() {
            var h = $(this).height();
            if (h > 20) {
                $(this).css("margin-top", (24 - Math.floor(h / 2)).toString() + "px");
                $(this).parent().css("padding-top", "0");
            }
        });
        // Transparens PNG i IE 6
        // $("img[src*='png']").pngfix();
    }

    if ($.browser.mozilla) {
        if ($.browser.version.substr(0, 3) == "1.9") {
            $("body").css("margin-right", "2px");
        }
    }

    // Pyjamasrandig tabell
    $(".striped tr:odd").addClass("odd");
    $(".contentbox table td:first-child,.contentbox table th:first-child").addClass("first");

    $(".contentbox table").each(function() {
        var thiswidth = $(this).width();
        var thisfloat = "";
        if ($(this).attr("align") == "left" || $(this).attr("align") == "right") {
            thisfloat = "float: " + $(this).attr("align") + ";";
            thisfloat += "margin-" + ($(this).attr("align") == "left" ? "right" : "left") + ":20px;";
        }
        var wrapdiv = $("<div style=\"width:" + thiswidth + "px; " + thisfloat + "\">");
        $(this).wrap(wrapdiv);
        if ($(this).attr("summary")) {
            var summary = $(this).attr("summary");
            if (summary.split(" ").length > 2) {
                sumarr = summary.split(" ");
                summary = "<strong>" + sumarr[0] + " " + sumarr[1] + "</strong>";
                for (j = 2; j < sumarr.length; j++) {
                    summary += " " + sumarr[j];
                }
            }
            $(this).after("<p class=\"imagetext\"" + ($(this).hasClass("emphasized") ? " style=\"margin-top:0;\"" : "") + ">" + summary + "</p>");
        }
        if ($(this).hasClass("emphasized")) {
            $(this).wrap("<div class=\"table-shadow\">");
        }
        $(this).removeAttr("align");
        $(this).removeAttr("width");
        $(this).css("width", thiswidth + "px");
    });

    $(".contentbox img").each(function() {
        if ($(this).attr("align") || $(this).attr("title")) {
            var thiswidth = $(this).width();
            var thisfloat = "";
            var wrapdiv = $("<div>");
            $(wrapdiv).css("width", thiswidth);
            if ($(this).attr("align") == "left" || $(this).attr("align") == "right") {
                $(wrapdiv).css("float", $(this).attr("align"));
                $(wrapdiv).css("margin-" + ($(this).attr("align") == "left" ? "right" : "left"), "20px");
                $(this).removeAttr("align");
            }
            if ($(this).parent().get(0).tagName == "A") {
                var parentA = $(this).parent().get(0);
                $(parentA).wrap(wrapdiv);
            }
            else {
                $(this).wrap(wrapdiv);
            };
            if ($(this).attr("title")) {
                var summary = $(this).attr("title");
                if (summary.split(" ").length > 2) {
                    sumarr = summary.split(" ");
                    summary = "<strong>" + sumarr[0] + " " + sumarr[1] + "</strong>";
                    for (j = 2; j < sumarr.length; j++) {
                        summary += " " + sumarr[j];
                    }
                }
                $(this).after("<p class=\"imagetext\">" + summary + "</p>");
            }
        }
    });
    // Ändrar bakgrundsfärg i vänsternav vid hover
    $(".leftMenu1 > li").hover(
    function() {
        if (!$(this).hasClass("selected")) {
            $(this).addClass("hoverlevel1");
        }
    },
    function() {
        $(this).removeClass("hoverlevel1");
    });

    $(".startPage-sidebarItem").css("position", "absolute");
    $(".startPage-sidebarItem").hide();
    $(".startPage-sidebarItem.aktuellt").show();

    $(".startpageTabs .aktuelltImg").click(function() { showStartPageTab('aktuellt'); });
    $(".startpageTabs .kundformanerImg").click(function() { showStartPageTab('kundformaner'); });
    $(".startpageTabs .ledigajobbImg").click(function() { showStartPageTab('ledigajobb'); });

    /* Comment Sogeti 090113 */

    $(".teaser .teaserImageText").each(function() {
        var h = $(this).parents(".teaser")[0];
        var t = $(this).height();
        var v = Math.floor((($(h).height() - t) - 26) / 2);
        $(this).css("margin-top", v.toString() + "px");
    });

    $(".contact").click(function() {
        location.href = ($(this).find("a").attr("href"));
    });

    $(".greenTable").each(function() {
        $(this).wrap("<div class=\"tableShadow\">");
    });

    $(".footer div").click(function() { $(".footerInfo").slideToggle(100); });

    $(".startPage-driftinfo:has(a.redarrow)").css("background-color", "#fcc").css("border-color", "#f00").each(function() {
        var obj = this;
        setTimeout(function() {
            $(obj).animate({
                borderTopColor: "#F8C85B",
                borderBottomColor: "#F8C85B",
                borderLeftColor: "#F8C85B",
                borderRightColor: "#F8C85B",
                backgroundColor: "#FFF1D2"
            }, 1000);
        }, 2000);
    });
    if ($("h1.categoryPageImageAbove").length > 0) {
        if (typeof (headingX) != 'undefined' || typeof (headingY) != 'undefined' || typeof (headingColor) != 'undefined') {
            $("h1.categoryPageImageAbove").wrapInner("<span></span>");
            $("h1.categoryPageImageAbove span").css("display", "block");
            if (typeof (headingX) != 'undefined') {
                $("h1.categoryPageImageAbove span").css("margin-left", headingX + "px");
            }
            if (typeof (headingY) != 'undefined') {
                $("h1.categoryPageImageAbove span").css("margin-top", headingY + "px");
            }
            if (typeof (headingColor) != 'undefined') {
                $("h1.categoryPageImageAbove span").css("color", headingColor);
            }
        }
    }
    $("h1.above").each(function() {

        theimg = $(this).parents(".contentbox").find("img");
        $(this).css("position", "absolute");
        $(this).css("top", $(theimg).offset().top + 10 + "px");
        $(this).css("left", $(theimg).offset().left + 10 + "px");
        if (typeof (headingX) != 'undefined') {
            $(this).css("left", $(theimg).offset().left + headingX + "px");
        }
        if (typeof (headingY) != 'undefined') {
            $(this).css("top", $(theimg).offset().top + headingY + "px");
        }
        if (typeof (headingColor) != 'undefined') {
            $(this).css("color", headingColor);
        }

    });
    $(".share_info_link").hover(function() {
        $(".share_info").css("top", ($(".share").offset().top + 30) + "px");
        $(".share_info").css("left", ($(".share").offset().left + 5) + "px");
        $(".share_info").fadeIn(100);
    },
	function() {
	    $(".share_info").fadeOut(100);
	});
    // START meny funktion - Ger klickbara pilar som expanderar undernivåer i menyn.
    // 
    /*
    addImages();
    $("img").click(function(event) {
    if ($(this).is(".expandable")) {
    var img = $(this);
    var ul = $(this).parent().find("ul")[0];
    if ($(this).parent().hasClass("leftMenuSelectedItem")) {
    $(this).parent().removeClass("leftMenuSelectedItem");
    $(this).parent().addClass("leftMenuNotSelected");
    $(this).attr("src", "/Administration/WebsiteImages/Icons/menu_icon_closed.gif");
    /*$(this).parent().find("li").each(function() {
    if (ul == $(this).parent()) {
    $(this).find("li").addClass("leftMenuNotSelected");
    $(this).find("li").removeClass("leftMenuSelectedItem");
    }
    });
    *
    }
    else {
    $(this).parent().removeClass("leftMenuNotSelected");
    $(this).parent().addClass("leftMenuSelectedItem");
    $(this).attr("src", "/Administration/WebsiteImages/Icons/menu_icon_open.gif");
    /*$(this).parent().find("li").each(function() {
    if (ul == $(this).parent()) {
    $(this).find("li").removeClass("leftMenuNotSelected");
    $(this).find("li").addClass("leftMenuSelectedItem");
    }
    });
    *
    }
            
    event.preventDefault();
    }
    });*/
    // END meny funktion

});

//Visa exempel-funktion
function showExample(obj,exampletext) {
	$(".examplebox").text(exampletext);
	alert($(obj).html());
}

//Menyfunktion
function addImages() {
    $(".leftMenu1 a").each(function() {

        if (!$(this).parent().parent().is(".leftMenu1")) {
            if (($(this).parent().is(".leftMenuSelectedItem") || $(this).parent().is(".leftMenuSelectedParent")) && $(this).parent().is(".leftMenuHasChildren")) {
                $('<img class="expandable" src="/Administration/WebsiteImages/Icons/menu_icon_open.gif" />').insertBefore(this);
                $('<br class="clr" />').insertAfter(this);
            }
            else if ($(this).parent().is(".leftMenuNotSelected") && $(this).parent().is(".leftMenuHasChildren")) {
                $('<img class="expandable" src="/Administration/WebsiteImages/Icons/menu_icon_closed.gif" />').insertBefore(this);
                $('<br class="clr" />').insertAfter(this);
            }
            
            if ($(this).parent().is(".leftMenuHasChildren")) {
                $(this).css("background-image", "none");
            }
        }


    });
}
//Menyfunktion
function setCSS() {
    $(".leftMenuNotSelected ul").css("display", "none");
    $(".leftMenuSelectedItem ul").css("display", "block");
    $("ul.leftMenu1 li.leftMenuNotSelected").each(function() {
        if ($(this).parent().is(".leftMenu1")) {
            $(this).css("display", "block");
        }
    });
   }

// Flikar på startsidan
function showStartPageTab(tab) {
	$("img.aktuelltImg").attr("src", "/Administration/WebsiteImages/tab-aktuellt-i.gif");
	$("img.kundformanerImg").attr("src", "/Administration/WebsiteImages/tab-kundformaner-i.gif");
	$("img.ledigajobbImg").attr("src", "/Administration/WebsiteImages/tab-ledigajobb-i.gif");
	$("img." + tab + "Img").attr("src", "/Administration/WebsiteImages/tab-" + tab + ".gif");
//	$(".startPage-sidebarContainer .aktuellt").hide();
//	$(".startPage-sidebarContainer .kundformaner").hide();
	//	$(".startPage-sidebarContainer .ledigajobb").hide();
	if (tab != currentlyShownTab) {
		$(".startPage-sidebarContainer ." + currentlyShownTab).fadeOut(150);
		$(".startPage-sidebarContainer ." + tab).fadeIn(150, function() { currentlyShownTab = tab; });
	}
}