﻿var debug = "";
$(document).ready(function() {

    if ($("div.top_10").size() > 0) {

        //$("#top10content").html();
        $("#top10content").html($("div.top_10:first").html());
        $("table#varekortMain").hide();

	$(".ProductMenu_TD").append($(".top10box"));
	$(".Basket_TD > .top10box").remove();
        $(".top10box").show();
    }

    /* SPAR XX,- beregnes - sep'09 / klh-web.dk 
    Rettet til % okt'09 */
    $(".Price_ProductInfo_TR").each(function() {
        var origin = $(this).find(".PriceStriked_Productinfo").text().replace(".", "").replace(",", ".");
        var offer = $(this).find(".SpecialOfferPrice_ProductInfo").text().replace(".", "").replace(" DKK", "").replace(",", ".");

        if (origin.replace(/^\s+|\s+$/g, '') != "") {
            $(this).children(".PriceBefore_ProductInfo_TD").after("<td><div style=\"background-image:url('/images/save.png');padding:8px 0px 0px 0px;background-repeat:none;width:53px;height:27px;display:inline-block;color:#99af06;font-size:17px;font-weight:bold;text-align:center;\">-" + (100 - ((parseFloat("100") / parseFloat(origin)) * parseFloat(offer))).toFixed(0) + "%</div></td>")
        }
    });

    // Implementeret på vareliste / klh-web.dk
    $(".varelisteJQhelper").each(function() {
        if ($(this).find(".priceBefore").text().replace(/^\s+|\s+$/g, '') == "") {
            $(this).find(".priceBefore").css("visibility", "hidden");
        }
        else {
            var origin = $(this).find(".priceBefore").text().replace(".", "").replace(",", ".");
            var offer = $(this).find(".priceCurrent").text().replace(".", "").replace(",", ".");
            $(this).find(".product_info").append("<span style=\"color:#C80E00;margin: 2px 2px 2px 2px;\">F&oslash;r: <strike>" + $(this).find(".priceBefore:first").text() + "</strike></span>");
            $(this).find(".priceBefore").text("-" + (100 - ((parseFloat("100") / parseFloat(origin)) * parseFloat(offer))).toFixed(0) + "%")
        }
    });

    // Implementeret på forsidevarer / klh-web.dk
    $(".frontpagePrices").each(function() {
        if ($(this).find(".item_savingsPrice_wrapper").text().replace(/^\s+|\s+$/g, '') == "") {
            $(this).find(".item_savingsPrice").text($(this).find(".item_price").text());
            $(this).find(".item_price").text("");
        }
        else {
            var origin = $(this).find(".item_price").text().replace(".", "").replace(",", ".");
            var offer = $(this).find(".item_savingsPrice").text().replace(".", "").replace(",", ".");
            $(this).find(".item_infoButton").prepend("<div class=\"spar\" style=\"clear:both;float:left;margin:2px 2px 4px 2px;overflow:hidden;padding: 0px 2px;position:relative;\"><div class=\"item_left\"></div><div class=\"item_spar\" style=\"color:#C80E00;\">F&oslash;r: <strike>" + $(this).find(".item_price").text() + "</strike></div><div class=\"item_right\"></div></div><br />");
            $(this).find(".item_price").html("-" + (100 - ((parseFloat("100") / parseFloat(origin)) * parseFloat(offer))).toFixed(0) + "%")
        }
    });

    // Forsideanimation
    $(document).ready(function() {
        $('.slideshow').cycle({
            fx: 'fade',
            speed: 1000 // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        });
    });

    /*
    Har prøvet at få 8-taller i priser til også at blive overstregede i varelister i Dandomain webshop. Det er dog sværere end man måtte håbe!

	$(".price_left").each(function() {
    var b = $(this).text();
    var temp = new Array();
    temp = b.split(" ");
		
		if (temp.length>1) {
    $(this).html("<strike>"+temp[0]+"</strike> "+temp[1]+"");
    alert("changed string. "+$(this).html());
    } else debug += $(this).text() + "\n";
    });
    */
});

