﻿/*
* App.js for Flügger eshop
* created : 2009-07-31
* by : jte@netcompany.com
*/
function log(s) {
    if (window.console) {
        console.log(s);
    }
};
function SelectProject(dropdown) {
    var index = dropdown.selectedIndex;
    var value = dropdown.options[index].value;
    location.href = value;
};
function sortNumber(a, b) { return b - a; };
var App = {
    Flugger: {
        productConfig: function() {
            // if productconfig
            if ($(".customizePnl").hasClass("colorPnl") == false) {
                var heights = [], topHeights = [];
                $(".customizeLine.first").css({ "height": "auto", "min-height": "auto" });
                $(".customizeLine.first").each(function(i) {
                    topHeights[i] = $(this).height();
                });
                topHeights.sort(sortNumber);
                $(".customizeLine.first").each(function() {
                    $(this).css("height", topHeights[0]);
                });
                topHeights.sort(sortNumber);
                $(".firstItem .customizeLine.first").each(function() {
                    $(this).css("height", topHeights[0] + 24);
                });

                $(".customizePnl .customizeItemWrap").each(function(i) {
                    heights[i] = $(this).height();
                    heights[i] += 15;
                });
                heights.sort(sortNumber);
                $(".customizePnl .customizeBottom").each(function(i) {
                    $(this).css("height", heights[0] - topHeights[0]);
                });
                $(".firstItem .customizeBottom").each(function(i) {
                    $(this).css("height", 5);
                });

            } else {
                // else paintconfig
                var heights = [];
                $(".customizeBottom").each(function(i) {
                    heights[i] = $(this).height();
                    heights[i] += 35; // 35 is the height of the buttons. They are positioned absolute, so their heights does not count when measuring the height. Therefore we need to add 35px.
                });

                heights.sort(sortNumber);
                //log(heights);
                $(".customizeBottom").each(function(i) {
                    $(this).css("height", heights[0]);
                });

                $(".firstItem .customizeBottom").each(function(i) {
                    $(this).css("height", 5);
                });

            }
        },
        productLoad: function() {
            if ($("input[id*=colorcodeTextbox]").hasClass("invalidColor") == true) {
                $("#lnkInvalidControl").click();
            }
            App.Flugger.productConfig();
        },
        print: function() {
            $(".printBtn .btn").click(function(e) {
                window.print();
            });
        },
        popupLinks: function() {
            $("a.popup").click(function(e) {
                e.preventDefault();
                var sb = "";
                if ($(this).hasClass("scrollbars")) sb = ",scrollbars=1";
                var dest = $(this).attr("href");
                window.open(dest, "_blank", "menubar=0,location=0" + sb);
            });
        },
        searchFocus: function() {
            $(".tbquery").focus(function() { $(this).val(""); });
        },
        FluggerTv: function() {
            $(".tvTabs a").click(function(e) {
                $(".tvTabs li.selected").removeClass("selected");
                $(".tvContent.show").removeClass("show");
                $(this).parent().addClass("selected");
                var content = $(this).attr("href");
                $(content).addClass("show");
                e.preventDefault();
            });
            $(".tvTabs li:not(.selected) a").hover(function() {
                $(this).addClass("selected");
            }, function() {
                $(this).removeClass("selected");
            });
            $(".tvTabs li:first").addClass("selected");
        },
        orderLineHeight: function() {
            if ($("#cart table.orderLine span").hasClass("amountLabelReceipt") == true) {
                $("#cart table.orderLine table.amountTable").each(function() {
                    $(this).css("height", ($(this).closest("table.orderLine").height() - 30)); //26
                });
            } else {
                $("#cart table.orderLine table.amountTable").each(function() {
                    $(this).css("height", ($(this).closest("table.orderLine").height() - 22)); //26
                });
            }
        },
        serviceBoxHeight: function() {
            $(".service.line").each(function() {
                var heights = [];
                $(this).find(".serviceBorder").each(function(i) {
                    heights[i] = $(this).height();
                });
                heights.sort(sortNumber);
                //$(this).find(".serviceBorder").css("height", heights[0]).end().find(".backgroundBottom").css("height", heights[0]-90);
                $(this).find(".backgroundBottom").css("height", heights[0] - 90).addClass("js");
            });
        },
        init: function() {
            if ($("#cart h3").hasClass("line") == true) {
                $("#cart h3.line:first").css("background", "#fff");
            }
            App.Flugger.FluggerTv();
            App.Flugger.searchFocus();
            App.Flugger.popupLinks();
            App.Flugger.print();
            App.Flugger.orderLineHeight();
            App.Flugger.serviceBoxHeight();

            $(".productdetails p.productdescription").each(function(i) {
                // lineheight = 16
                // show lines = 6, maxheight = 16x6=96
                var maxHeight = 96;
                var currentHeight = this.offsetHeight;
                if (currentHeight > maxHeight) {
                    var text = $(this).find(".readMoreText");
                    var readMoreLink = $(this).find(".readMoreBtn");
                    $(text).attr("id", "readMoreText" + i).css("margin-bottom", "1em");
                    $(readMoreLink).attr("id", "readMoreBtn" + i).removeClass("hidden");
                    $("#readMoreText" + i, this).css({ "height": maxHeight + "px", "overflow": "hidden", "display": "block" });
                    $("#readMoreBtn" + i).data("assoText", ("readMoreText" + i)).toggle(
                        function() {
                            $("#" + $(this).data("assoText")).stop().animate({ "height": currentHeight + "px" }, 300);
                        },
                        function() {
                            $("#" + $(this).data("assoText")).stop().animate({ "height": maxHeight + "px" }, 150);
                        }
                    );
                }
            });
            $(".showLogin").toggle(
                function() {
                    $("div[id$=phLogin]").slideDown();
                },
                function() {
                    $("div[id$=phLogin]").slideUp();
                }
            )
            var href = $("#topmenu li a").eq(0).attr("href");
            //            if (href.indexOf("eshop") >= 0) {
            //                $("#topmenu li").eq(0).css("position", "relative").append("<img src='/resources/eshop/images/flugger_menu_pil.png' style='position:absolute;right:0;top:0;cursor:pointer;' onclick='window.location.href = \"" + href + "\"' />");
            //            }
            $("div[id$=phLogin]").hide();
        }
    }
}
$("document").ready(function() {
    App.Flugger.init();
});

function ShowFluggerShop() {
    $('input[id$=rbShipment3]').trigger("click");
}

function ShowAddress(no) {
    $('input[id$=rbShipment' + no + ']').trigger("click");
}
function AnimateCart() {
    window.onload = function() {
        $("#previewDiv").slideDown('slow');
    }
}

$(function() {
    if ($("#productCarousel div").hasClass("products") == true) {
        $(".products").jCarouselLite({
            btnPrev: ".back",
            btnNext: ".forth",
            visible: 5
        });
    }
    /* resize select box i productconfig */
    $("select[id$=productDropDownList]").live("mousedown", function() {
        if ($.browser.msie) {
            $(this).css({ "width" : "auto" });
        }
    });
    /* undo resize select box i productconfig */
    $("select[id$=productDropDownList]").blur(function() {
        if ($.browser.msie) {
            $(this).attr("style", "");
        }
    });
});
//$("document").ready(function() { $("document").pngFix(); });
